diff --git a/common/lc_library.cpp b/common/lc_library.cpp index 0d112c9b..aefcdfa0 100644 --- a/common/lc_library.cpp +++ b/common/lc_library.cpp @@ -1808,7 +1808,7 @@ void lcPiecesLibrary::GetParts(std::vector& Parts) const Parts.emplace_back(PartIt.second); } -std::vector lcPiecesLibrary::GetTrainTrackParts(quint32 ConnectionType) const +std::vector lcPiecesLibrary::GetTrainTrackParts(const lcTrainTrackConnectionType& ConnectionType) const { std::vector Parts; diff --git a/common/lc_library.h b/common/lc_library.h index 76bedc4b..8180070e 100644 --- a/common/lc_library.h +++ b/common/lc_library.h @@ -6,6 +6,7 @@ class PieceInfo; class lcTrainTrackInfo; +struct lcTrainTrackConnectionType; class lcZipFile; class lcLibraryMeshData; class lcThumbnailManager; @@ -156,7 +157,7 @@ public: void GetCategoryEntries(int CategoryIndex, bool GroupPieces, std::vector& SinglePieces, std::vector& GroupedPieces); void GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, std::vector& SinglePieces, std::vector& GroupedPieces); void GetParts(std::vector& Parts) const; - std::vector GetTrainTrackParts(quint32 ConnectionType) const; + std::vector GetTrainTrackParts(const lcTrainTrackConnectionType& ConnectionType) const; std::vector GetPartsFromSet(const std::vector& PartIds) const; std::string GetPartId(const PieceInfo* Info) const; diff --git a/common/lc_traintrack.cpp b/common/lc_traintrack.cpp index 86f6e3ee..174b460b 100644 --- a/common/lc_traintrack.cpp +++ b/common/lc_traintrack.cpp @@ -6,8 +6,9 @@ #include "lc_application.h" // todo: +// add the rest of the 9v and 12v tracks, look into 4.5v +// better insert gizmo mouse detection // auto replace cross when going over a straight section -// add other track types // set focus connection after adding void lcTrainTrackInit(lcPiecesLibrary* Library) @@ -47,9 +48,21 @@ void lcTrainTrackInit(lcPiecesLibrary* Library) lcVector3 Position(JsonPosition[0].toDouble(), JsonPosition[1].toDouble(), JsonPosition[2].toDouble()); float Rotation = JsonConnection["Rotation"].toDouble() * LC_DTOR; - quint32 Type = qHash(JsonConnection["Type"].toString()); + QString ConnectionGroup = JsonConnection["Type"].toString(); + int ConnectionDirection = 0; - TrainTrackInfo->AddConnection(lcMatrix44(lcMatrix33RotationZ(Rotation), Position), Type); + if (ConnectionGroup.startsWith('+')) + { + ConnectionDirection = 1; + ConnectionGroup = ConnectionGroup.mid(1); + } + else if (ConnectionGroup.startsWith('-')) + { + ConnectionDirection = -1; + ConnectionGroup = ConnectionGroup.mid(1); + } + + TrainTrackInfo->AddConnection(lcMatrix44(lcMatrix33RotationZ(Rotation), Position), { qHash(ConnectionGroup), ConnectionDirection } ); } } } diff --git a/common/lc_traintrack.h b/common/lc_traintrack.h index 6327f848..f37094a9 100644 --- a/common/lc_traintrack.h +++ b/common/lc_traintrack.h @@ -5,20 +5,16 @@ class lcPiece; class lcPiecesLibrary; +struct lcTrainTrackConnectionType +{ + quint32 Group; + int Format; +}; + struct lcTrainTrackConnection { lcMatrix44 Transform; - quint32 Type; -}; - -enum class lcTrainTrackType -{ - Straight, - Left, - Right, - BranchLeft, - BranchRight, - Count + lcTrainTrackConnectionType Type; }; class lcTrainTrackInfo @@ -31,7 +27,7 @@ public: static std::optional CalculateTransformToConnection(const lcMatrix44& ConnectionTransform, PieceInfo* Info, quint32 ConnectionIndex); static int GetPieceConnectionIndex(const lcPiece* Piece1, int ConnectionIndex1, const lcPiece* Piece2); - void AddConnection(const lcMatrix44 &Transform, quint32 Type) + void AddConnection(const lcMatrix44 &Transform, const lcTrainTrackConnectionType& Type) { mConnections.emplace_back(lcTrainTrackConnection{Transform, Type}); } @@ -41,10 +37,10 @@ public: return mConnections; } - bool CanConnectTo(quint32 ConnectionType) const + bool CanConnectTo(lcTrainTrackConnectionType ConnectionType) const { for (const lcTrainTrackConnection& Connection : mConnections) - if (Connection.Type == ConnectionType) + if (Connection.Type.Group == ConnectionType.Group && Connection.Type.Format + ConnectionType.Format == 0) return true; return false; diff --git a/common/lc_view.cpp b/common/lc_view.cpp index 2557fb51..8c7466ff 100644 --- a/common/lc_view.cpp +++ b/common/lc_view.cpp @@ -326,7 +326,7 @@ void lcView::ShowTrainTrackPopup() return; int ConnectionIndex = mTrackToolSection - LC_PIECE_SECTION_TRAIN_TRACK_CONNECTION_FIRST; - quint32 ConnectionType = TrainTrackInfo->GetConnections()[ConnectionIndex].Type; + const lcTrainTrackConnectionType& ConnectionType = TrainTrackInfo->GetConnections()[ConnectionIndex].Type; PieceInfo* Info = lcShowTrainTrackPopup(mWidget, ConnectionType); diff --git a/qt/lc_qutils.cpp b/qt/lc_qutils.cpp index c9094361..cc24618e 100644 --- a/qt/lc_qutils.cpp +++ b/qt/lc_qutils.cpp @@ -229,7 +229,7 @@ void lcPieceIdPickerPopup::Close() Menu->close(); } -lcTrainTrackPickerPopup::lcTrainTrackPickerPopup(QWidget* Parent, quint32 ConnectionType) +lcTrainTrackPickerPopup::lcTrainTrackPickerPopup(QWidget* Parent, const lcTrainTrackConnectionType& ConnectionType) : QWidget(Parent) { QVBoxLayout* Layout = new QVBoxLayout(this); @@ -280,7 +280,7 @@ void lcTrainTrackPickerPopup::Close() Menu->close(); } -PieceInfo* lcShowTrainTrackPopup(QWidget* Parent, quint32 ConnectionType) +PieceInfo* lcShowTrainTrackPopup(QWidget* Parent, const lcTrainTrackConnectionType& ConnectionType) { std::unique_ptr Menu(new QMenu(Parent)); QWidgetAction* Action = new QWidgetAction(Menu.get()); diff --git a/qt/lc_qutils.h b/qt/lc_qutils.h index 10b6eb05..f919de35 100644 --- a/qt/lc_qutils.h +++ b/qt/lc_qutils.h @@ -4,6 +4,7 @@ class lcPartSelectionWidget; class lcPartSelectionListView; +struct lcTrainTrackConnectionType; QString lcFormatValue(float Value, int Precision); QString lcFormatValueLocalized(float Value); @@ -196,7 +197,7 @@ class lcTrainTrackPickerPopup : public QWidget Q_OBJECT public: - lcTrainTrackPickerPopup(QWidget* Parent, quint32 ConnectionType); + lcTrainTrackPickerPopup(QWidget* Parent, const lcTrainTrackConnectionType& ConnectionType); PieceInfo* GetPickedTrainTrack() const { @@ -215,7 +216,7 @@ protected: PieceInfo* mPickedTrainTrack = nullptr; }; -PieceInfo* lcShowTrainTrackPopup(QWidget* Parent, quint32 ConnectionType); +PieceInfo* lcShowTrainTrackPopup(QWidget* Parent, const lcTrainTrackConnectionType& ConnectionType); class lcColorDialogPopup : public QWidget { diff --git a/resources/traintrack.json b/resources/traintrack.json index 5eb619a8..4eb40129 100644 --- a/resources/traintrack.json +++ b/resources/traintrack.json @@ -4,6 +4,7 @@ { "2859c04.dat": { + "Description": "Train Track 9V Point Right Branching (Complete)", "Connections": [ { @@ -25,6 +26,7 @@ }, "2861c04.dat": { + "Description": "Train Track 9V Point Left Branching (Complete)", "Connections": [ { @@ -46,6 +48,7 @@ }, "32087.dat": { + "Description": "Train Track 9V Crossing", "Connections": [ { @@ -72,6 +75,7 @@ }, "74746.dat": { + "Description": "Train Track 9V Straight", "Connections": [ { @@ -88,6 +92,7 @@ }, "74747.dat": { + "Description": "Train Track 9V Curved", "Connections": [ { @@ -101,6 +106,128 @@ "Type": "9V" } ] + }, + "3241ac01.dat": + { + "Description": "Train Track 12V Slotted Curved (Complete 1 Segment)", + "Connections": + [ + { + "Position": [ 156.072265625, -15.371826171875, 0.0 ], + "Rotation": -11.25, + "Type": "+12V" + }, + { + "Position": [ -156.072265625, -15.371826171875, 0.0 ], + "Rotation": -168.75, + "Type": "+12V" + } + ] + }, + "4166a.dat": + { + "Description": "Train Track Sleeper Plate 2 x 8 without Cable Grooves", + "Connections": + [ + { + "Position": [ 0.0, 0.0, 16.0 ], + "Rotation": 90.0, + "Type": "-12V" + }, + { + "Position": [ 0.0, 0.0, 16.0 ], + "Rotation": -90.0, + "Type": "-12V" + } + ] + }, + "3240bc02.dat": + { + "Description": "Train Track 12V Slotted Straight with Conductive Centre Rail with Sockets (Complete without End Sleepers)", + "Connections": + [ + { + "Position": [ 160.0, 0.0, 0.0 ], + "Rotation": 0.0, + "Type": "+12V" + }, + { + "Position": [ -160.0, 0.0, 0.0 ], + "Rotation": -180.0, + "Type": "+12V" + } + ] + }, + "73697ac03.dat": + { + "Description": "Train Track 12V Slotted Point Left Electric (Straight)", + "Connections": + [ + { + "Position": [ 320.0, 0.0, 0.0 ], + "Rotation": 0.0, + "Type": "+12V" + }, + { + "Position": [ 320.0, 160.0, 0.0 ], + "Rotation": 0.0, + "Type": "+12V" + }, + { + "Position": [ -320.0, 0.0, 0.0 ], + "Rotation": 180.0, + "Type": "+12V" + } + ] + }, + "73696ac04.dat": + { + "Description": "Train Track 12V Slotted Point Right Electric (Branching)", + "Connections": + [ + { + "Position": [ 320.0, 0.0, 0.0 ], + "Rotation": 0.0, + "Type": "+12V" + }, + { + "Position": [ 320.0, -160, 0.0 ], + "Rotation": 0.0, + "Type": "+12V" + }, + { + "Position": [ -320.0, 0.0, 0.0 ], + "Rotation": 180, + "Type": "+12V" + } + ] + }, + "73698.dat": + { + "Description": "Train Track 12V Slotted Crossing", + "Connections": + [ + { + "Position": [ 160.0, 0.0, 0.0 ], + "Rotation": 0.0, + "Type": "+12V" + }, + { + "Position": [ 0.0, 160.0, 0.0 ], + "Rotation": 90.0, + "Type": "+12V" + }, + { + "Position": [ -160.0, 0.0, 0.0 ], + "Rotation": 180.0, + "Type": "+12V" + }, + { + "Position": [ 0.0, -160.0, 0.0 ], + "Rotation": -90.0, + "Type": "+12V" + } + ] } } }