Revert use of embedded icons (#2509)

Co-authored-by: rainmakerv2 <30595646+jpau02@users.noreply.github.com>
This commit is contained in:
rainmakerv2 2025-02-23 23:00:26 +08:00 committed by GitHub
parent 10486db091
commit e1e697a3ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 61 deletions

View file

@ -31,23 +31,6 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin
fmt::UTF(trophyIconPath.u8string())); fmt::UTF(trophyIconPath.u8string()));
} }
std::string pathString;
if (trophy_type == "P") {
pathString = "Resources/platinum.png";
} else if (trophy_type == "G") {
pathString = "Resources/gold.png";
} else if (trophy_type == "S") {
pathString = "Resources/silver.png";
} else if (trophy_type == "B") {
pathString = "Resources/bronze.png";
}
auto resource = cmrc::res::get_filesystem();
auto trophytypefile = resource.open(pathString);
std::filesystem::path trophyTypePath = pathString;
if (std::filesystem::exists(trophyTypePath))
trophy_type_icon = RefCountedTexture::DecodePngFile(trophyTypePath);
AddLayer(this); AddLayer(this);
} }
@ -76,38 +59,24 @@ void TrophyUI::Draw() {
if (Begin("Trophy Window", nullptr, if (Begin("Trophy Window", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoInputs)) { ImGuiWindowFlags_NoInputs)) {
if (trophy_type_icon) { if (trophy_icon) {
SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight)); SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight));
Image(trophy_type_icon.GetTexture().im_id, Image(trophy_icon.GetTexture().im_id, ImVec2((50 * AdjustWidth), (50 * AdjustHeight)));
ImVec2((50 * AdjustWidth), (50 * AdjustHeight))); ImGui::SameLine();
} else { } else {
// placeholder // placeholder
const auto pos = GetCursorScreenPos(); const auto pos = GetCursorScreenPos();
ImGui::GetWindowDrawList()->AddRectFilled(pos, pos + ImVec2{50.0f * AdjustHeight}, ImGui::GetWindowDrawList()->AddRectFilled(pos, pos + ImVec2{50.0f * AdjustHeight},
GetColorU32(ImVec4{0.7f})); GetColorU32(ImVec4{0.7f}));
ImGui::Indent(60);
} }
ImGui::SameLine();
SetWindowFontScale((1.2 * AdjustHeight)); SetWindowFontScale((1.2 * AdjustHeight));
char earned_text[] = "Trophy earned!\n%s"; char earned_text[] = "Trophy earned!\n%s";
const float text_height = const float text_height =
ImGui::CalcTextSize(std::strcat(earned_text, trophy_name.c_str())).y; ImGui::CalcTextSize(std::strcat(earned_text, trophy_name.c_str())).y;
SetCursorPosY((window_size.y - text_height) * 0.5f); SetCursorPosY((window_size.y - text_height) * 0.5f);
ImGui::PushTextWrapPos(window_size.x - (60 * AdjustWidth));
TextWrapped("Trophy earned!\n%s", trophy_name.c_str()); TextWrapped("Trophy earned!\n%s", trophy_name.c_str());
ImGui::SameLine(window_size.x - (60 * AdjustWidth));
if (trophy_icon) {
SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight));
Image(trophy_icon.GetTexture().im_id, ImVec2((50 * AdjustWidth), (50 * AdjustHeight)));
} else {
// placeholder
const auto pos = GetCursorScreenPos();
ImGui::GetWindowDrawList()->AddRectFilled(pos, pos + ImVec2{30.0f * AdjustHeight},
GetColorU32(ImVec4{0.7f}));
}
} }
End(); End();

View file

@ -118,20 +118,18 @@ void TrophyViewer::PopulateTrophyWidget(QString title) {
item->setData(Qt::DecorationRole, icon); item->setData(Qt::DecorationRole, icon);
item->setFlags(item->flags() & ~Qt::ItemIsEditable); item->setFlags(item->flags() & ~Qt::ItemIsEditable);
tableWidget->setItem(row, 1, item); tableWidget->setItem(row, 1, item);
const std::string filename = GetTrpType(trpType[row].at(0));
QTableWidgetItem* typeitem = new QTableWidgetItem(); QTableWidgetItem* typeitem = new QTableWidgetItem();
auto resource = cmrc::res::get_filesystem(); QString type;
std::string resourceString = "Resources/" + filename; if (trpType[row] == "P") {
auto trophytypefile = resource.open(resourceString); type = "Platinum";
} else if (trpType[row] == "G") {
QImage type_icon = type = "Gold";
QImage(QString::fromStdString(resourceString)) } else if (trpType[row] == "S") {
.scaled(QSize(64, 64), Qt::KeepAspectRatio, Qt::SmoothTransformation); type = "Silver";
typeitem->setData(Qt::DecorationRole, type_icon); } else if (trpType[row] == "B") {
typeitem->setFlags(typeitem->flags() & ~Qt::ItemIsEditable); type = "Bronze";
tableWidget->setItem(row, 6, typeitem); }
std::string detailString = trophyDetails[row].toStdString(); std::string detailString = trophyDetails[row].toStdString();
std::size_t newline_pos = 0; std::size_t newline_pos = 0;
@ -146,6 +144,7 @@ void TrophyViewer::PopulateTrophyWidget(QString title) {
SetTableItem(tableWidget, row, 3, QString::fromStdString(detailString)); SetTableItem(tableWidget, row, 3, QString::fromStdString(detailString));
SetTableItem(tableWidget, row, 4, trpId[row]); SetTableItem(tableWidget, row, 4, trpId[row]);
SetTableItem(tableWidget, row, 5, trpHidden[row]); SetTableItem(tableWidget, row, 5, trpHidden[row]);
SetTableItem(tableWidget, row, 6, type);
SetTableItem(tableWidget, row, 7, trpPid[row]); SetTableItem(tableWidget, row, 7, trpPid[row]);
} }
tableWidget->verticalHeader()->resizeSection(row, icon.height()); tableWidget->verticalHeader()->resizeSection(row, icon.height());

View file

@ -31,18 +31,4 @@ private:
QStringList headers; QStringList headers;
QString gameTrpPath_; QString gameTrpPath_;
TRP trp; TRP trp;
std::string GetTrpType(const QChar trp_) {
switch (trp_.toLatin1()) {
case 'B':
return "bronze.png";
case 'S':
return "silver.png";
case 'G':
return "gold.png";
case 'P':
return "platinum.png";
}
return "Unknown";
}
}; };