Stud style

This commit is contained in:
Trevor SANDY 2021-01-20 11:56:30 +01:00
parent a8d757c0c4
commit 0a749f6f3a
10 changed files with 229 additions and 77 deletions

View file

@ -656,7 +656,7 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions()
} }
else if (Option == QLatin1String("-sl") || Option == QLatin1String("--stud-logo")) else if (Option == QLatin1String("-sl") || Option == QLatin1String("--stud-logo"))
{ {
ParseInteger(Options.StudLogo, 0, 5); ParseInteger(Options.StudLogo, 0, 7);
if (Options.StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO)) if (Options.StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO))
lcGetPiecesLibrary()->SetStudLogo(Options.StudLogo, false); lcGetPiecesLibrary()->SetStudLogo(Options.StudLogo, false);

View file

@ -209,46 +209,76 @@ int lcGetBrickLinkColor(int ColorIndex)
return 0; return 0;
} }
bool lcLoadColorFile(lcFile& File) bool lcLoadColorFile(lcFile& File, bool Update)
{ {
char Line[1024], Token[1024]; char Line[1024], Token[1024];
std::vector<lcColor>& Colors = gColorList; std::vector<lcColor>& Colors = gColorList;
lcColor Color, MainColor, EdgeColor; lcColor Color, MainColor, EdgeColor;
Colors.clear(); if (Update)
{
EdgeColor = Colors[lcGetColorIndex(24)];
for (auto EdgeColorIt = Colors.begin(); EdgeColorIt != Colors.end() ; EdgeColorIt++)
{
if (EdgeColorIt->Code == 24)
{
Colors.erase(EdgeColorIt);
break;
}
}
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++) MainColor = Colors[lcGetColorIndex(16)];
gColorGroups[GroupIdx].Colors.clear(); for (auto MainColorIt = Colors.begin(); MainColorIt != Colors.end() ; MainColorIt++)
{
if (MainColorIt->Code == 16)
{
Colors.erase(MainColorIt);
break;
}
}
gColorGroups[0].Name = QApplication::tr("Solid", "Colors"); std::vector<int>& SolidColors = gColorGroups[LC_COLORGROUP_SOLID].Colors;
gColorGroups[1].Name = QApplication::tr("Translucent", "Colors"); const auto& DefaultColorIt = std::find(SolidColors.begin(), SolidColors.end(), gDefaultColor);
gColorGroups[2].Name = QApplication::tr("Special", "Colors"); if (DefaultColorIt != SolidColors.end())
SolidColors.erase(DefaultColorIt);
}
else
{
Colors.clear();
MainColor.Code = 16; for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
MainColor.Translucent = false; gColorGroups[GroupIdx].Colors.clear();
MainColor.Value[0] = 1.0f;
MainColor.Value[1] = 1.0f;
MainColor.Value[2] = 0.5f;
MainColor.Value[3] = 1.0f;
MainColor.Edge[0] = 0.2f;
MainColor.Edge[1] = 0.2f;
MainColor.Edge[2] = 0.2f;
MainColor.Edge[3] = 1.0f;
strcpy(MainColor.Name, "Main Color");
strcpy(MainColor.SafeName, "Main_Color");
EdgeColor.Code = 24; gColorGroups[0].Name = QApplication::tr("Solid", "Colors");
EdgeColor.Translucent = false; gColorGroups[1].Name = QApplication::tr("Translucent", "Colors");
EdgeColor.Value[0] = 0.5f; gColorGroups[2].Name = QApplication::tr("Special", "Colors");
EdgeColor.Value[1] = 0.5f;
EdgeColor.Value[2] = 0.5f; MainColor.Code = 16;
EdgeColor.Value[3] = 1.0f; MainColor.Translucent = false;
EdgeColor.Edge[0] = 0.2f; MainColor.Value[0] = 1.0f;
EdgeColor.Edge[1] = 0.2f; MainColor.Value[1] = 1.0f;
EdgeColor.Edge[2] = 0.2f; MainColor.Value[2] = 0.5f;
EdgeColor.Edge[3] = 1.0f; MainColor.Value[3] = 1.0f;
strcpy(EdgeColor.Name, "Edge Color"); MainColor.Edge[0] = 0.2f;
strcpy(EdgeColor.SafeName, "Edge_Color"); MainColor.Edge[1] = 0.2f;
MainColor.Edge[2] = 0.2f;
MainColor.Edge[3] = 1.0f;
strcpy(MainColor.Name, "Main Color");
strcpy(MainColor.SafeName, "Main_Color");
EdgeColor.Code = 24;
EdgeColor.Translucent = false;
EdgeColor.Value[0] = 0.5f;
EdgeColor.Value[1] = 0.5f;
EdgeColor.Value[2] = 0.5f;
EdgeColor.Value[3] = 1.0f;
EdgeColor.Edge[0] = 0.2f;
EdgeColor.Edge[1] = 0.2f;
EdgeColor.Edge[2] = 0.2f;
EdgeColor.Edge[3] = 1.0f;
strcpy(EdgeColor.Name, "Edge Color");
strcpy(EdgeColor.SafeName, "Edge_Color");
}
while (File.ReadLine(Line, sizeof(Line))) while (File.ReadLine(Line, sizeof(Line)))
{ {
@ -340,7 +370,7 @@ bool lcLoadColorFile(lcFile& File)
GroupSpecial = true; GroupSpecial = true;
} }
else if (!strcmp(Token, "CHROME") || !strcmp(Token, "PEARLESCENT") || !strcmp(Token, "RUBBER") || else if (!strcmp(Token, "CHROME") || !strcmp(Token, "PEARLESCENT") || !strcmp(Token, "RUBBER") ||
!strcmp(Token, "MATTE_METALIC") || !strcmp(Token, "METAL") || !strcmp(Token, "LUMINANCE")) !strcmp(Token, "MATTE_METALIC") || !strcmp(Token, "METAL") || !strcmp(Token, "LUMINANCE"))
{ {
GroupSpecial = true; GroupSpecial = true;
} }
@ -361,19 +391,19 @@ bool lcLoadColorFile(lcFile& File)
Color.Edge[2] = 33.0f / 255.0f; Color.Edge[2] = 33.0f / 255.0f;
} }
bool Duplicate = false; bool ExistingColorUpdate = false;
for (lcColor& ExistingColor : Colors) for (lcColor& ExistingColor : Colors)
{ {
if (ExistingColor.Code == Color.Code) if (ExistingColor.Code == Color.Code)
{ {
ExistingColor = Color; ExistingColor = Color;
Duplicate = true; ExistingColorUpdate = true;
break; break;
} }
} }
if (Duplicate) if (ExistingColorUpdate)
continue; continue;
if (Color.Code == 16) if (Color.Code == 16)
@ -399,6 +429,7 @@ bool lcLoadColorFile(lcFile& File)
} }
gDefaultColor = (int)Colors.size(); gDefaultColor = (int)Colors.size();
Colors.push_back(MainColor); Colors.push_back(MainColor);
gColorGroups[LC_COLORGROUP_SOLID].Colors.push_back(gDefaultColor); gColorGroups[LC_COLORGROUP_SOLID].Colors.push_back(gDefaultColor);
@ -415,7 +446,7 @@ void lcLoadDefaultColors()
lcDiskFile ConfigFile(":/resources/ldconfig.ldr"); lcDiskFile ConfigFile(":/resources/ldconfig.ldr");
if (ConfigFile.Open(QIODevice::ReadOnly)) if (ConfigFile.Open(QIODevice::ReadOnly))
lcLoadColorFile(ConfigFile); lcLoadColorFile(ConfigFile, false);
} }
int lcGetColorIndex(quint32 ColorCode) int lcGetColorIndex(quint32 ColorCode)
@ -455,3 +486,72 @@ int lcGetColorIndex(quint32 ColorCode)
gColorList.push_back(Color); gColorList.push_back(Color);
return (int)gColorList.size() - 1; return (int)gColorList.size() - 1;
} }
void lcLoadLegoStyleDisplayColors()
{
QByteArray ColorData;
const char *ColorEntry = "0 !COLOUR Stud_Style_Black CODE 4242 VALUE #1B2A34 EDGE #000000\r\n";
ColorData.append(ColorEntry);
lcMemFile ColorMemFile;
ColorMemFile.WriteBuffer(ColorData.constData(), ColorData.size());
ColorMemFile.Seek(0, SEEK_SET);
lcLoadColorFile(ColorMemFile, true);
lcColor* DarkGrey = &gColorList[lcGetColorIndexByName("Stud Style Dark Gray Edge")];
lcColor* Black = &gColorList[lcGetColorIndexByName("Stud Style Black Edge")];
for (size_t ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
{
lcColor* Color = &gColorList[ColorIdx];
if (Color->Code == 4242)
continue;
float r = 0.0f, g = 0.0f, b = 0.0f;
float rr = Color->Value[0] * 255.0f,
gg = Color->Value[1] * 255.0f,
bb = Color->Value[2] * 255.0f;
if (30 * rr + 59 * gg + 11 * bb <= 3600)
{
if (DarkGrey)
{
r = DarkGrey->Edge[0];
g = DarkGrey->Edge[1];
b = DarkGrey->Edge[2];
}
else
{
r = 27.0f;
g = 42.0f;
b = 52.0f;
}
}
else
{
if (Color->Code == 0)
{
r = 255.0f;
g = 255.0f;
b = 255.0f;
}
else if (Black)
{
r = Black->Edge[0];
g = Black->Edge[1];
b = Black->Edge[2];
}
}
Color->Edge[0] = r / 255.0f;
Color->Edge[1] = g / 255.0f;
Color->Edge[2] = b / 255.0f;
}
}
int lcGetColorIndexByName(const char * ColorName)
{
for (size_t ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
if (gColorList[ColorIdx].Name == ColorName)
return (int)ColorIdx;
return 0x0;
}

View file

@ -49,8 +49,10 @@ extern int gEdgeColor;
extern int gDefaultColor; extern int gDefaultColor;
void lcLoadDefaultColors(); void lcLoadDefaultColors();
bool lcLoadColorFile(lcFile& File); void lcLoadLegoStyleDisplayColors();
bool lcLoadColorFile(lcFile& File, bool Update);
int lcGetColorIndex(quint32 ColorCode); int lcGetColorIndex(quint32 ColorCode);
int lcGetColorIndexByName(const char * ColorName);
int lcGetBrickLinkColor(int ColorIndex); int lcGetBrickLinkColor(int ColorIndex);
inline quint32 lcGetColorCodeFromExtendedColor(int Color) inline quint32 lcGetColorCodeFromExtendedColor(int Color)

View file

@ -238,24 +238,9 @@ bool lcPiecesLibrary::Load(const QString& LibraryPath, bool ShowProgress)
{ {
Unload(); Unload();
auto LoadCustomColors = []()
{
QString CustomColorsPath = lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
if (CustomColorsPath.isEmpty())
return false;
lcDiskFile ColorFile(CustomColorsPath);
return ColorFile.Open(QIODevice::ReadOnly) && lcLoadColorFile(ColorFile);
};
if (OpenArchive(LibraryPath, lcZipFileType::Official)) if (OpenArchive(LibraryPath, lcZipFileType::Official))
{ {
lcMemFile ColorFile; LoadColors(false);
if (!LoadCustomColors())
if (!mZipFiles[static_cast<int>(lcZipFileType::Official)]->ExtractFile("ldraw/ldconfig.ldr", ColorFile) || !lcLoadColorFile(ColorFile))
lcLoadDefaultColors();
mLibraryDir = QFileInfo(LibraryPath).absoluteDir(); mLibraryDir = QFileInfo(LibraryPath).absoluteDir();
QString UnofficialFileName = mLibraryDir.absoluteFilePath(QLatin1String("ldrawunf.zip")); QString UnofficialFileName = mLibraryDir.absoluteFilePath(QLatin1String("ldrawunf.zip"));
@ -270,20 +255,7 @@ bool lcPiecesLibrary::Load(const QString& LibraryPath, bool ShowProgress)
mLibraryDir.setPath(LibraryPath); mLibraryDir.setPath(LibraryPath);
if (OpenDirectory(mLibraryDir, ShowProgress)) if (OpenDirectory(mLibraryDir, ShowProgress))
{ LoadColors(false);
if (!LoadCustomColors())
{
lcDiskFile ColorFile(mLibraryDir.absoluteFilePath(QLatin1String("ldconfig.ldr")));
if (!ColorFile.Open(QIODevice::ReadOnly) || !lcLoadColorFile(ColorFile))
{
ColorFile.SetFileName(mLibraryDir.absoluteFilePath(QLatin1String("LDConfig.ldr")));
if (!ColorFile.Open(QIODevice::ReadOnly) || !lcLoadColorFile(ColorFile))
lcLoadDefaultColors();
}
}
}
else else
return false; return false;
} }
@ -295,6 +267,44 @@ bool lcPiecesLibrary::Load(const QString& LibraryPath, bool ShowProgress)
return true; return true;
} }
void lcPiecesLibrary::LoadColors(bool Update)
{
auto LoadCustomColors = [&Update]()
{
QString CustomColorsPath = lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
if (CustomColorsPath.isEmpty())
return false;
lcDiskFile ColorFile(CustomColorsPath);
return ColorFile.Open(QIODevice::ReadOnly) && lcLoadColorFile(ColorFile, Update);
};
if (mZipFiles[static_cast<int>(lcZipFileType::Official)])
{
lcMemFile ColorFile;
if (!LoadCustomColors())
if (!mZipFiles[static_cast<int>(lcZipFileType::Official)]->ExtractFile("ldraw/ldconfig.ldr", ColorFile) || !lcLoadColorFile(ColorFile, Update))
lcLoadDefaultColors();
}
else
{
if (!LoadCustomColors())
{
lcDiskFile ColorFile(mLibraryDir.absoluteFilePath(QLatin1String("ldconfig.ldr")));
if (!ColorFile.Open(QIODevice::ReadOnly) || !lcLoadColorFile(ColorFile, Update))
{
ColorFile.SetFileName(mLibraryDir.absoluteFilePath(QLatin1String("LDConfig.ldr")));
if (!ColorFile.Open(QIODevice::ReadOnly) || !lcLoadColorFile(ColorFile, Update))
lcLoadDefaultColors();
}
}
}
}
void lcPiecesLibrary::UpdateStudLogoSource() void lcPiecesLibrary::UpdateStudLogoSource()
{ {
if (!mSources.empty() && mSources.front()->Type == lcLibrarySourceType::StudLogo) if (!mSources.empty() && mSources.front()->Type == lcLibrarySourceType::StudLogo)
@ -305,7 +315,16 @@ void lcPiecesLibrary::UpdateStudLogoSource()
if (!mStudLogo) if (!mStudLogo)
return; return;
std::unique_ptr<lcDiskFile> StudLogoFile(new lcDiskFile(QString(":/resources/studlogo%1.zip").arg(QString::number(mStudLogo)))); if (mStudLogo > 5)
lcLoadLegoStyleDisplayColors();
std::unique_ptr<lcDiskFile> StudLogoFile;
if (mStudLogo < 6)
StudLogoFile = std::unique_ptr<lcDiskFile>(new lcDiskFile(QString(":/resources/studlogo%1.zip").arg(QString::number(mStudLogo))));
else if (mStudLogo == 6)
StudLogoFile = std::unique_ptr<lcDiskFile>(new lcDiskFile(QString(":/resources/studslegostyle1.zip")));
else
StudLogoFile = std::unique_ptr<lcDiskFile>(new lcDiskFile(QString(":/resources/studslegostyle2.zip")));
if (StudLogoFile->Open(QIODevice::ReadOnly)) if (StudLogoFile->Open(QIODevice::ReadOnly))
OpenArchive(std::move(StudLogoFile), lcZipFileType::StudLogo); OpenArchive(std::move(StudLogoFile), lcZipFileType::StudLogo);
@ -1520,6 +1539,9 @@ bool lcPiecesLibrary::SupportsStudLogo() const
void lcPiecesLibrary::SetStudLogo(int StudLogo, bool Reload) void lcPiecesLibrary::SetStudLogo(int StudLogo, bool Reload)
{ {
if (mStudLogo > 5 && StudLogo < 6 && Reload)
LoadColors(Reload);
mStudLogo = StudLogo; mStudLogo = StudLogo;
UpdateStudLogoSource(); UpdateStudLogoSource();
@ -1602,6 +1624,21 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
lcMeshLoader MeshLoader(Primitive->mMeshData, true, nullptr, false); lcMeshLoader MeshLoader(Primitive->mMeshData, true, nullptr, false);
auto StudLogoPrimitive = [this, &Primitive] ()
{
if (!mSources.empty() && mSources.front()->Type == lcLibrarySourceType::StudLogo)
{
char Name[LC_PIECE_NAME_LEN];
strcpy(Name, Primitive->mName);
strupr(Name);
const std::unique_ptr<lcLibrarySource>& Source = mSources.front();
const auto& PrimitiveIt = Source->Primitives.find(Name);
if (PrimitiveIt != Source->Primitives.end())
return true;
}
return false;
};
if (mZipFiles[static_cast<int>(lcZipFileType::Official)]) if (mZipFiles[static_cast<int>(lcZipFileType::Official)])
{ {
lcLibraryPrimitive* LowPrimitive = nullptr; lcLibraryPrimitive* LowPrimitive = nullptr;
@ -1610,7 +1647,7 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
if (Primitive->mStud) if (Primitive->mStud)
{ {
if (!strcmp(Primitive->mName, "stud.dat") || !strcmp(Primitive->mName, "stud2.dat")) if (StudLogoPrimitive())
Primitive->mMeshData.mHasLogoStud = true; Primitive->mMeshData.mHasLogoStud = true;
else if (strncmp(Primitive->mName, "8/", 2)) // todo: this is currently the only place that uses mName so use mFileName instead. this should also be done for the loose file libraries. else if (strncmp(Primitive->mName, "8/", 2)) // todo: this is currently the only place that uses mName so use mFileName instead. this should also be done for the loose file libraries.
{ {
@ -1647,7 +1684,7 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
{ {
if (Primitive->mStud) if (Primitive->mStud)
{ {
if (!strcmp(Primitive->mName,"stud.dat") || !strcmp(Primitive->mName, "stud2.dat")) if (StudLogoPrimitive())
Primitive->mMeshData.mHasLogoStud = true; Primitive->mMeshData.mHasLogoStud = true;
} }

View file

@ -102,6 +102,7 @@ public:
lcPiecesLibrary& operator=(lcPiecesLibrary&&) = delete; lcPiecesLibrary& operator=(lcPiecesLibrary&&) = delete;
bool Load(const QString& LibraryPath, bool ShowProgress); bool Load(const QString& LibraryPath, bool ShowProgress);
void LoadColors(bool Update);
void Unload(); void Unload();
void RemoveTemporaryPieces(); void RemoveTemporaryPieces();
void RemovePiece(PieceInfo* Info); void RemovePiece(PieceInfo* Info);

View file

@ -101,6 +101,8 @@
<file>resources/studlogo3.zip</file> <file>resources/studlogo3.zip</file>
<file>resources/studlogo4.zip</file> <file>resources/studlogo4.zip</file>
<file>resources/studlogo5.zip</file> <file>resources/studlogo5.zip</file>
<file>resources/studslegostyle1.zip</file>
<file>resources/studslegostyle2.zip</file>
<file>resources/ldconfig.ldr</file> <file>resources/ldconfig.ldr</file>
<file>resources/minifig.ini</file> <file>resources/minifig.ini</file>
<file>resources/ldraw.xml</file> <file>resources/ldraw.xml</file>

View file

@ -41,7 +41,7 @@ class lcQPreferencesDialog;
class lcQPreferencesDialog : public QDialog class lcQPreferencesDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogOptions* Options); lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogOptions* Options);
~lcQPreferencesDialog(); ~lcQPreferencesDialog();

View file

@ -390,27 +390,37 @@
<widget class="QComboBox" name="studLogoCombo"> <widget class="QComboBox" name="studLogoCombo">
<item> <item>
<property name="text"> <property name="text">
<string>Logo1</string> <string>1 LDraw Single Wire</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>Logo2</string> <string>2 LDraw Double Wire</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>Logo3</string> <string>3 LDraw Raised Floating</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>Logo4</string> <string>4 LDraw Raised Rounded </string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>Logo5</string> <string>5 LDraw Subtle Rounded</string>
</property>
</item>
<item>
<property name="text">
<string>6 LEGO Without Logo</string>
</property>
</item>
<item>
<property name="text">
<string>7 LEGO Single Wire</string>
</property> </property>
</item> </item>
</widget> </widget>

Binary file not shown.

Binary file not shown.