Added support for hiding redundant train tracks from the picker.

This commit is contained in:
Leonardo Zide
2025-03-20 12:41:20 -07:00
parent 228fb79667
commit bf22ed8f05
6 changed files with 118 additions and 79 deletions
+2 -2
View File
@@ -1808,7 +1808,7 @@ void lcPiecesLibrary::GetParts(std::vector<PieceInfo*>& Parts) const
Parts.emplace_back(PartIt.second);
}
std::vector<PieceInfo*> lcPiecesLibrary::GetTrainTrackParts(const lcTrainTrackConnectionType& ConnectionType) const
std::vector<PieceInfo*> lcPiecesLibrary::GetVisibleTrainTrackParts(const lcTrainTrackConnectionType& ConnectionType) const
{
std::vector<PieceInfo*> Parts;
@@ -1816,7 +1816,7 @@ std::vector<PieceInfo*> lcPiecesLibrary::GetTrainTrackParts(const lcTrainTrackCo
{
lcTrainTrackInfo* TrainTrackInfo = Info->GetTrainTrackInfo();
if (TrainTrackInfo && TrainTrackInfo->CanConnectTo(ConnectionType))
if (TrainTrackInfo && TrainTrackInfo->IsVisible() && TrainTrackInfo->CanConnectTo(ConnectionType))
Parts.emplace_back(Info);
}
+1 -1
View File
@@ -157,7 +157,7 @@ public:
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, std::vector<PieceInfo*>& SinglePieces, std::vector<PieceInfo*>& GroupedPieces);
void GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, std::vector<PieceInfo*>& SinglePieces, std::vector<PieceInfo*>& GroupedPieces);
void GetParts(std::vector<PieceInfo*>& Parts) const;
std::vector<PieceInfo*> GetTrainTrackParts(const lcTrainTrackConnectionType& ConnectionType) const;
std::vector<PieceInfo*> GetVisibleTrainTrackParts(const lcTrainTrackConnectionType& ConnectionType) const;
std::vector<PieceInfo*> GetPartsFromSet(const std::vector<std::string>& PartIds) const;
std::string GetPartId(const PieceInfo* Info) const;
+52 -37
View File
@@ -6,8 +6,8 @@
#include "lc_application.h"
// todo:
// add the rest of the 9v and 12v tracks, look into 4.5v
// see if we should remove some of the 12v tracks to avoid bloat
// add the rest of the 12v tracks, look into 4.5v
// hide some of the 12v tracks to avoid bloat
// lcView::GetPieceInsertTransform should use track connections when dragging a new track over an existing one
// better insert gizmo mouse detection
// auto replace cross when going over a straight section
@@ -22,56 +22,71 @@ void lcTrainTrackInfo::Initialize(lcPiecesLibrary* Library)
if (!ConfigFile.open(QIODevice::ReadOnly))
return;
QJsonDocument Document = QJsonDocument::fromJson(ConfigFile.readAll());
QJsonParseError Error;
QJsonDocument Document = QJsonDocument::fromJson(ConfigFile.readAll(), &Error);
if (Error.error != QJsonParseError::NoError)
{
qDebug() << Error.errorString();
}
QJsonObject Root = Document.object();
if (Root["Version"].toInt() != 1)
return;
QJsonObject JsonPieces = Root["Pieces"].toObject();
QJsonArray JsonPieces = Root["Pieces"].toArray();
for (QJsonObject::const_iterator PiecesIt = JsonPieces.constBegin(); PiecesIt != JsonPieces.constEnd(); ++PiecesIt)
for (QJsonArray::const_iterator PiecesIt = JsonPieces.constBegin(); PiecesIt != JsonPieces.constEnd(); ++PiecesIt)
{
QJsonObject JsonPiece = PiecesIt->toObject();
QJsonArray JsonParts = JsonPiece["Parts"].toArray();
for (QJsonArray::const_iterator PartsIt = JsonParts.constBegin(); PartsIt != JsonParts.constEnd(); ++PartsIt)
QJsonArray JsonConnections = JsonPiece["Connections"].toArray();
std::vector<lcTrainTrackConnection> Connections;
for (QJsonArray::const_iterator ConnectionIt = JsonConnections.constBegin(); ConnectionIt != JsonConnections.constEnd(); ++ConnectionIt)
{
PieceInfo* Info = Library->FindPiece(PartsIt->toString().toLatin1(), nullptr, false, false);
QJsonObject JsonConnection = ConnectionIt->toObject();
if (!Info)
continue;
QJsonArray JsonPosition = JsonConnection["Position"].toArray();
lcVector3 Position(JsonPosition[0].toDouble(), JsonPosition[1].toDouble(), JsonPosition[2].toDouble());
lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo();
float Rotation = JsonConnection["Rotation"].toDouble() * LC_DTOR;
QString ConnectionGroup = JsonConnection["Type"].toString();
lcTrainTrackConnectionSleeper ConnectionSleeper = lcTrainTrackConnectionSleeper::None;
Info->SetTrainTrackInfo(TrainTrackInfo);
QJsonArray JsonConnections = JsonPiece["Connections"].toArray();
for (QJsonArray::const_iterator ConnectionIt = JsonConnections.constBegin(); ConnectionIt != JsonConnections.constEnd(); ++ConnectionIt)
if (ConnectionGroup.startsWith('+'))
{
QJsonObject JsonConnection = ConnectionIt->toObject();
QJsonArray JsonPosition = JsonConnection["Position"].toArray();
lcVector3 Position(JsonPosition[0].toDouble(), JsonPosition[1].toDouble(), JsonPosition[2].toDouble());
float Rotation = JsonConnection["Rotation"].toDouble() * LC_DTOR;
QString ConnectionGroup = JsonConnection["Type"].toString();
lcTrainTrackConnectionSleeper ConnectionSleeper = lcTrainTrackConnectionSleeper::None;
if (ConnectionGroup.startsWith('+'))
{
ConnectionSleeper = lcTrainTrackConnectionSleeper::NeedsSleeper;
ConnectionGroup = ConnectionGroup.mid(1);
}
else if (ConnectionGroup.startsWith('-'))
{
ConnectionSleeper = lcTrainTrackConnectionSleeper::HasSleeper;
ConnectionGroup = ConnectionGroup.mid(1);
}
TrainTrackInfo->AddConnection(lcMatrix44(lcMatrix33RotationZ(Rotation), Position), { qHash(ConnectionGroup), ConnectionSleeper } );
ConnectionSleeper = lcTrainTrackConnectionSleeper::NeedsSleeper;
ConnectionGroup = ConnectionGroup.mid(1);
}
else if (ConnectionGroup.startsWith('-'))
{
ConnectionSleeper = lcTrainTrackConnectionSleeper::HasSleeper;
ConnectionGroup = ConnectionGroup.mid(1);
}
Connections.emplace_back(lcTrainTrackConnection{ lcMatrix44(lcMatrix33RotationZ(Rotation), Position), { qHash(ConnectionGroup), ConnectionSleeper } });
}
QJsonArray JsonIDs = JsonPiece["IDs"].toArray();
for (QJsonArray::const_iterator IDIt = JsonIDs.constBegin(); IDIt != JsonIDs.constEnd(); ++IDIt)
{
PieceInfo* Info = Library->FindPiece(IDIt->toString().toLatin1(), nullptr, false, false);
if (Info)
Info->SetTrainTrackInfo(new lcTrainTrackInfo(Connections, true));
}
JsonIDs = JsonPiece["HiddenIDs"].toArray();
for (QJsonArray::const_iterator IDIt = JsonIDs.constBegin(); IDIt != JsonIDs.constEnd(); ++IDIt)
{
PieceInfo* Info = Library->FindPiece(IDIt->toString().toLatin1(), nullptr, false, false);
if (Info)
Info->SetTrainTrackInfo(new lcTrainTrackInfo(Connections, false));
}
}
+11 -6
View File
@@ -35,7 +35,15 @@ struct lcTrainTrackInsert
class lcTrainTrackInfo
{
public:
lcTrainTrackInfo() = default;
lcTrainTrackInfo(const std::vector<lcTrainTrackConnection> &Connections, bool Visible)
: mConnections(Connections), mVisible(Visible)
{
}
bool IsVisible() const
{
return mVisible;
}
static void Initialize(lcPiecesLibrary* Library);
static std::vector<lcTrainTrackInsert> GetPieceInsertTransforms(lcPiece* CurrentPiece, PieceInfo* Info, quint32 Section);
@@ -43,11 +51,6 @@ public:
static std::optional<lcMatrix44> CalculateTransformToConnection(const lcMatrix44& ConnectionTransform, PieceInfo* Info, quint32 ConnectionIndex);
static int GetPieceConnectionIndex(const lcPiece* Piece1, int ConnectionIndex1, const lcPiece* Piece2);
void AddConnection(const lcMatrix44 &Transform, const lcTrainTrackConnectionType& Type)
{
mConnections.emplace_back(lcTrainTrackConnection{Transform, Type});
}
const std::vector<lcTrainTrackConnection>& GetConnections() const
{
return mConnections;
@@ -84,5 +87,7 @@ protected:
}
std::vector<lcTrainTrackConnection> mConnections;
bool mVisible = false;
static std::map<quint32, PieceInfo*> mSleepers;
};
+1 -1
View File
@@ -240,7 +240,7 @@ lcTrainTrackPickerPopup::lcTrainTrackPickerPopup(QWidget* Parent, const lcTrainT
mPartSelectionListView->setMinimumWidth(450);
mPartSelectionListView->setDragEnabled(false);
std::vector<PieceInfo*> Parts = lcGetPiecesLibrary()->GetTrainTrackParts(ConnectionType);
std::vector<PieceInfo*> Parts = lcGetPiecesLibrary()->GetVisibleTrainTrackParts(ConnectionType);
mPartSelectionListView->SetCustomParts(Parts);
+51 -32
View File
@@ -1,10 +1,11 @@
{
"Version": 1,
"Pieces":
{
"Train Track 9V Point Right":
[
{
"Parts": [ "2859c03.dat", "2859c04.dat" ],
"Description": "Train Track 9V Point Right",
"IDs": [ "2859c03.dat", "2859c04.dat" ],
"HiddenIDs": [ "2859c01.dat", "2859c02.dat" ],
"Connections":
[
{
@@ -24,9 +25,10 @@
}
]
},
"Train Track 9V Point Left":
{
"Parts": [ "2861c03.dat", "2861c04.dat" ],
"Description": "Train Track 9V Point Left",
"IDs": [ "2861c03.dat", "2861c04.dat" ],
"HiddenIDs": [ "2861c01.dat", "2861c02.dat" ],
"Connections":
[
{
@@ -46,9 +48,9 @@
}
]
},
"Train Track 9V Crossing":
{
"Parts": [ "32087.dat" ],
"Description": "Train Track 9V Crossing",
"IDs": [ "32087.dat" ],
"Connections":
[
{
@@ -73,9 +75,9 @@
}
]
},
"Train Track 9V Straight":
{
"Parts": [ "74746.dat" ],
"Description": "Train Track 9V Straight",
"IDs": [ "74746.dat" ],
"Connections":
[
{
@@ -90,9 +92,9 @@
}
]
},
"Train Track 9V Curved":
{
"Parts": [ "74747.dat" ],
"Description": "Train Track 9V Curved",
"IDs": [ "74747.dat" ],
"Connections":
[
{
@@ -107,9 +109,26 @@
}
]
},
"Train Track 12V Slotted Curved":
{
"Parts": [ "3241ac01.dat" ],
"Description": "Train Track 9V Curved (4 Segments)",
"HiddenIDs": [ "74747c04.dat" ],
"Connections":
[
{
"Position": [ 0.0, 0.0, 0.0 ],
"Rotation": 180,
"Type": "9V"
},
{
"Position": [ 800, -800, 0.0 ],
"Rotation": -90,
"Type": "9V"
}
]
},
{
"Description": "Train Track 12V Slotted Curved",
"IDs": [ "3241ac01.dat" ],
"Connections":
[
{
@@ -124,9 +143,9 @@
}
]
},
"Train Track Sleeper Plate 2 x 8":
{
"Parts": [ "4166a.dat", "4166b.dat" ],
"Description": "Train Track Sleeper Plate 2 x 8",
"IDs": [ "4166a.dat", "4166b.dat" ],
"Connections":
[
{
@@ -141,9 +160,9 @@
}
]
},
"Train Track 12V Slotted Straight With End Sleepers":
{
"Parts": [ "3240ac01.dat", "3240bc01.dat" ],
"Description": "Train Track 12V Slotted Straight With End Sleepers",
"IDs": [ "3240ac01.dat", "3240bc01.dat" ],
"Connections":
[
{
@@ -158,9 +177,9 @@
}
]
},
"Train Track 12V Slotted Straight Without End Sleepers":
{
"Parts": [ "3240ac02.dat", "3240bc02.dat" ],
"Description": "Train Track 12V Slotted Straight Without End Sleepers",
"IDs": [ "3240ac02.dat", "3240bc02.dat", "862ac01.dat" ],
"Connections":
[
{
@@ -175,9 +194,9 @@
}
]
},
"Train Track 12V Slotted Straight With Signal":
{
"Parts": [ "862ac02.dat" ],
"Description": "Train Track 12V Slotted Straight With Signal",
"IDs": [ "862ac02.dat" ],
"Connections":
[
{
@@ -192,9 +211,9 @@
}
]
},
"Train Track 12V Slotted Decoupler":
{
"Parts": [ "u9230c01.dat", "u9230c02.dat" ],
"Description": "Train Track 12V Slotted Decoupler",
"IDs": [ "u9230c01.dat", "u9230c02.dat" ],
"Connections":
[
{
@@ -209,9 +228,9 @@
}
]
},
"Train Track 12V Slotted Point Left":
{
"Parts": [ "73697ac01.dat", "73697ac02.dat", "73697ac03.dat", "73697ac04.dat" ],
"Description": "Train Track 12V Slotted Point Left",
"IDs": [ "73697ac01.dat", "73697ac02.dat", "73697ac03.dat", "73697ac04.dat" ],
"Connections":
[
{
@@ -231,9 +250,9 @@
}
]
},
"Train Track 12V Slotted Point Right":
{
"Parts": [ "73696ac01.dat", "73696ac02.dat", "73696ac03.dat", "73696ac04.dat" ],
"Description": "Train Track 12V Slotted Point Right",
"IDs": [ "73696ac01.dat", "73696ac02.dat", "73696ac03.dat", "73696ac04.dat" ],
"Connections":
[
{
@@ -253,9 +272,9 @@
}
]
},
"Train Track 12V Slotted Crossing":
{
"Parts": [ "73698.dat" ],
"Description": "Train Track 12V Slotted Crossing",
"IDs": [ "73698.dat" ],
"Connections":
[
{
@@ -280,9 +299,9 @@
}
]
},
"Train Track 4.5V Slotted Straight Without End Sleepers":
{
"Parts": [ "3228bc02.dat" ],
"Description": "Train Track 4.5V Slotted Straight Without End Sleepers",
"IDs": [ "3228bc02.dat" ],
"Connections":
[
{
@@ -297,7 +316,7 @@
}
]
}
},
],
"Sleepers":
{
"12V": "4166a.dat"