Skip to content

Commit 9352c73

Browse files
committed
GH-5560 fix issues with handling slim skins
This actually dumbs down detection of skins that would be broken as 'Classic' skins, but maybe we can do that better later.
1 parent 9e4da63 commit 9352c73

File tree

4 files changed

+46
-115
lines changed

4 files changed

+46
-115
lines changed

launcher/skins/SkinTypes.cpp

+40-70
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@ namespace Skins {
1818
SkinEntry::SkinEntry(const QString& name, const QString& path, const QImage& image, const QString& textureID, const QByteArray data) : name(name), filename(path)
1919
{
2020
internal = false;
21-
if (qAlpha(image.pixel(54, 20)) == 0)
22-
{
23-
// slim-only textures will have this pixel fully transparent
24-
slimVariant = SkinData{data, image, textureID};
25-
}
26-
else
27-
{
28-
classicVariant = SkinData{data, image, textureID};
29-
}
21+
fileVariant = SkinData{data, image, textureID};
3022
}
3123

3224
SkinEntry::SkinEntry(const QString& name, const QString& pathSlim, const QString& pathClassic): name(name)
@@ -56,73 +48,59 @@ SkinEntry::SkinEntry(const QString& name, const QString& pathSlim, const QString
5648

5749
const QImage& SkinEntry::getTextureFor(Model model) const
5850
{
59-
switch(model)
51+
if(internal)
6052
{
61-
case Model::Slim:
53+
switch(model)
6254
{
63-
if(slimVariant)
64-
{
55+
case Model::Slim:
6556
return slimVariant->texture;
66-
}
67-
}
68-
break;
69-
case Model::Classic:
70-
{
71-
if(classicVariant)
72-
{
57+
case Model::Classic:
7358
return classicVariant->texture;
74-
}
7559
}
76-
break;
60+
}
61+
62+
if(fileVariant)
63+
{
64+
return fileVariant->texture;
7765
}
7866
return nullImage;
7967
}
8068

8169
QString Skins::SkinEntry::getTextureIDFor(Model model) const
8270
{
83-
switch(model)
71+
if(internal)
8472
{
85-
case Model::Slim:
73+
switch(model)
8674
{
87-
if(slimVariant)
88-
{
75+
case Model::Slim:
8976
return slimVariant->textureID;
90-
}
91-
}
92-
break;
93-
case Model::Classic:
94-
{
95-
if(classicVariant)
96-
{
77+
case Model::Classic:
9778
return classicVariant->textureID;
98-
}
9979
}
100-
break;
80+
}
81+
82+
if(fileVariant)
83+
{
84+
return fileVariant->textureID;
10185
}
10286
return QString();
10387
}
10488

10589
QByteArray Skins::SkinEntry::getTextureDataFor(Model model) const
10690
{
107-
switch(model)
91+
if(internal)
10892
{
109-
case Model::Slim:
93+
switch(model)
11094
{
111-
if(slimVariant)
112-
{
95+
case Model::Slim:
11396
return slimVariant->data;
114-
}
115-
}
116-
break;
117-
case Model::Classic:
118-
{
119-
if(classicVariant)
120-
{
97+
case Model::Classic:
12198
return classicVariant->data;
122-
}
12399
}
124-
break;
125100
}
101+
102+
if(fileVariant)
103+
return fileVariant->data;
126104
return QByteArray();
127105
}
128106

@@ -251,46 +229,38 @@ const QImage & SkinData::getListTexture(Model model) const
251229

252230
const QImage & SkinEntry::getListTexture() const
253231
{
254-
if(slimVariant)
232+
if(internal)
255233
{
256234
return slimVariant->getListTexture(Model::Slim);
257235
}
258-
else if(classicVariant)
236+
237+
if(fileVariant)
259238
{
260-
return classicVariant->getListTexture(Model::Classic);
239+
return fileVariant->getListTexture(Model::Classic);
261240
}
262241
return nullImage;
263242
}
264243

265-
bool SkinEntry::hasModel(Model model) const
244+
bool SkinEntry::matchesId(const QString& textureID) const
266245
{
267-
switch(model)
246+
if(internal)
268247
{
269-
case Model::Slim:
248+
if(slimVariant && slimVariant->textureID == textureID)
270249
{
271-
return !!slimVariant;
250+
return true;
272251
}
273-
break;
274-
case Model::Classic:
252+
if(classicVariant && classicVariant->textureID == textureID)
275253
{
276-
return !!classicVariant;
254+
return true;
277255
}
278-
break;
256+
return false;
279257
}
280-
return false;
281-
}
282258

283-
nonstd::optional<Model> SkinEntry::matchesId(const QString& textureID) const
284-
{
285-
if(slimVariant && slimVariant->textureID == textureID)
286-
{
287-
return Model::Slim;
288-
}
289-
if(classicVariant && classicVariant->textureID == textureID)
259+
if(fileVariant && fileVariant->textureID == textureID)
290260
{
291-
return Model::Classic;
261+
return true;
292262
}
293-
return nonstd::nullopt;
263+
return false;
294264
}
295265

296266
}

launcher/skins/SkinTypes.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,25 @@ struct SkinEntry
4040
SkinEntry(const QString& name, const QString& pathSlim, const QString& pathClassic);
4141
SkinEntry() {};
4242

43-
nonstd::optional<Model> matchesId(const QString& textureID) const;
43+
bool matchesId(const QString& textureID) const;
4444
bool isNull() const
4545
{
46-
return !slimVariant && !classicVariant;
46+
if(internal)
47+
return !slimVariant && !classicVariant;
48+
return !fileVariant;
4749
}
4850

4951
const QImage& getListTexture() const;
5052
const QImage& getTextureFor(Model model) const;
5153
QString getTextureIDFor(Model model) const;
5254
QByteArray getTextureDataFor(Model model) const;
53-
bool hasModel(Model model) const;
5455

5556
bool internal = false;
5657
QString name;
5758
QString filename;
5859
nonstd::optional<SkinData> slimVariant;
5960
nonstd::optional<SkinData> classicVariant;
61+
nonstd::optional<SkinData> fileVariant;
6062
};
6163

6264
struct CapeEntry

launcher/skins/SkinsModel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ const Skins::SkinEntry & SkinsModel::skinEntryByTextureID(const QString& texture
470470
{
471471
for(const auto& entry: m_skins)
472472
{
473-
if(entry.matchesId(textureID) != nonstd::nullopt)
473+
if(entry.matchesId(textureID))
474474
{
475475
return entry;
476476
}

launcher/ui/dialogs/AccountsDialog.cpp

-41
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ void AccountsDialog::revertEdits()
219219
m_skinEdit = nonstd::nullopt;
220220
ui->btnApplyChanges->setEnabled(false);
221221
ui->btnResetChanges->setEnabled(false);
222-
updateModelToMatchSkin();
223222
updateSkinDisplay();
224223
}
225224

@@ -285,7 +284,6 @@ void AccountsDialog::editSkin(const Skins::SkinEntry& newEntry)
285284
return;
286285

287286
m_skinEdit->skinEntry = newEntry;
288-
updateModelToMatchSkin();
289287
updateSkinDisplay();
290288
}
291289

@@ -442,44 +440,9 @@ void AccountsDialog::updateStates()
442440
(!maybeEntry.isNull()) ? maybeEntry : Skins::SkinEntry("player", "", image, textureID, playerSkinData)
443441
};
444442

445-
updateModelToMatchSkin();
446443
updateSkinDisplay();
447444
}
448445

449-
void AccountsDialog::updateModelToMatchSkin()
450-
{
451-
auto& skinEntry = effectiveSkin();
452-
auto model = effectiveModel();
453-
bool hasClassic = skinEntry.hasModel(Skins::Model::Classic);
454-
bool hasSlim = skinEntry.hasModel(Skins::Model::Slim);
455-
456-
if(m_skinEdit)
457-
{
458-
if(model == Skins::Model::Classic && !hasClassic)
459-
{
460-
m_skinEdit->model = Skins::Model::Slim;
461-
ui->radioSlim->setChecked(true);
462-
}
463-
if(model == Skins::Model::Slim && !hasSlim)
464-
{
465-
m_skinEdit->model = Skins::Model::Classic;
466-
ui->radioClassic->setChecked(true);
467-
}
468-
}
469-
else
470-
{
471-
if(model == Skins::Model::Classic && !hasClassic)
472-
{
473-
ui->radioSlim->setChecked(true);
474-
}
475-
if(model == Skins::Model::Slim && !hasSlim)
476-
{
477-
ui->radioClassic->setChecked(true);
478-
}
479-
}
480-
}
481-
482-
483446
void AccountsDialog::updateSkinDisplay()
484447
{
485448
QImage capeImage;
@@ -492,10 +455,6 @@ void AccountsDialog::updateSkinDisplay()
492455
auto& skin = effectiveSkin();
493456
auto model = effectiveModel();
494457

495-
bool hasClassic = skin.hasModel(Skins::Model::Classic);
496-
bool hasSlim = skin.hasModel(Skins::Model::Slim);
497-
ui->radioClassic->setEnabled(hasClassic);
498-
ui->radioSlim->setEnabled(hasSlim);
499458
auto textureID = skin.getTextureIDFor(model);
500459
ui->saveSkinButton->setEnabled(m_skinsModel->skinEntryByTextureID(textureID).isNull());
501460

0 commit comments

Comments
 (0)