diff --git a/common/lc_traintrack.cpp b/common/lc_traintrack.cpp index 218b67cc..593d8d6d 100644 --- a/common/lc_traintrack.cpp +++ b/common/lc_traintrack.cpp @@ -9,12 +9,11 @@ // auto replace cross when going over a straight section // redo gizmo // add cross to gizmo +// new rotate connection gizmo // rotate around connections shortcut // shortcuts for changing active connection // move config to json // add other track types -// macros to encode/decode mTrackToolSection -// better transform and connection selection when adding with the keyboard, keep the same curve direction and use straight for branches // set focus connection after adding void lcTrainTrackInit(lcPiecesLibrary* Library) @@ -55,8 +54,8 @@ void lcTrainTrackInit(lcPiecesLibrary* Library) { lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo(); - TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))}); TrainTrackInfo->AddConnection({lcMatrix44Translation(lcVector3(320.0f, 0.0f, 0.0f))}); + TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))}); TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(22.5f * LC_DTOR), lcVector3(BranchX, BranchY, 0.0f))}); Info->SetTrainTrackInfo(TrainTrackInfo); @@ -68,8 +67,8 @@ void lcTrainTrackInit(lcPiecesLibrary* Library) { lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo(); - TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))}); TrainTrackInfo->AddConnection({lcMatrix44Translation(lcVector3(320.0f, 0.0f, 0.0f))}); + TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))}); TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(-22.5f * LC_DTOR), lcVector3(BranchX, -BranchY, 0.0f))}); Info->SetTrainTrackInfo(TrainTrackInfo); diff --git a/common/lc_traintrack.h b/common/lc_traintrack.h index 359f20b9..310f8421 100644 --- a/common/lc_traintrack.h +++ b/common/lc_traintrack.h @@ -31,6 +31,19 @@ public: static std::optional CalculateTransformToConnection(const lcMatrix44& ConnectionTransform, PieceInfo* Info, quint32 ConnectionIndex); static int GetPieceConnectionIndex(const lcPiece* Piece1, int ConnectionIndex1, const lcPiece* Piece2); + static quint32 EncodeTrackToolSection(quint32 ConnectionIndex, lcTrainTrackType TrainTrackType) + { + return ConnectionIndex | (static_cast(TrainTrackType) << 8); + } + + static std::pair DecodeTrackToolSection(quint32 TrackToolSection) + { + quint32 ConnectionIndex = TrackToolSection & 0xff; + lcTrainTrackType TrainTrackType = static_cast((TrackToolSection >> 8) & 0xff); + + return { ConnectionIndex, TrainTrackType }; + } + void AddConnection(const lcTrainTrackConnection& TrainTrackConnection) { mConnections.emplace_back(TrainTrackConnection); diff --git a/common/lc_view.cpp b/common/lc_view.cpp index 53af95c5..e4654028 100644 --- a/common/lc_view.cpp +++ b/common/lc_view.cpp @@ -434,8 +434,7 @@ void lcView::UpdatePiecePreview() if (TrainTrackInfo) { - quint32 ConnectionIndex = mTrackToolSection & 0xff; - lcTrainTrackType TrainTrackType = static_cast((mTrackToolSection >> 8) & 0xff); + auto [ConnectionIndex, TrainTrackType] = lcTrainTrackInfo::DecodeTrackToolSection(mTrackToolSection); std::tie(PreviewInfo, mPiecePreviewTransform) = TrainTrackInfo->GetPieceInsertTransform(Piece, ConnectionIndex, TrainTrackType); @@ -2570,7 +2569,7 @@ void lcView::OnButtonDown(lcTrackButton TrackButton) case lcTrackTool::RotateTrainTrack: { - quint32 ConnectionIndex = mTrackToolSection & 0xff; + auto [ConnectionIndex, TrainTrackType] = lcTrainTrackInfo::DecodeTrackToolSection(mTrackToolSection); ActiveModel->RotateTrainTrackToolClicked(ConnectionIndex); diff --git a/common/lc_viewmanipulator.cpp b/common/lc_viewmanipulator.cpp index 4f2b436d..f593e291 100644 --- a/common/lc_viewmanipulator.cpp +++ b/common/lc_viewmanipulator.cpp @@ -1010,7 +1010,7 @@ std::pair lcViewManipulator::UpdateSelectMove() NewTrackTool = lcTrackTool::Insert; ClosestIntersectionDistance = IntersectionDistance; - NewTrackSection = ConnectionIndex | (VertexIndex << 8); + NewTrackSection = lcTrainTrackInfo::EncodeTrackToolSection(ConnectionIndex, static_cast(VertexIndex)); } } }