From 06576fa16dd439af918669d91226e3d60c8553d6 Mon Sep 17 00:00:00 2001 From: rainmakerv2 <30595646+jpau02@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:03:48 +0800 Subject: [PATCH] Smaller type icons, center text vertically --- src/core/libraries/np_trophy/trophy_ui.cpp | 12 +++++++---- src/qt_gui/trophy_viewer.cpp | 24 +++++++++++++++++++++- src/qt_gui/trophy_viewer.h | 12 +++++------ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp index e40a9390a..1bf4069a8 100644 --- a/src/core/libraries/np_trophy/trophy_ui.cpp +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -73,7 +73,7 @@ void TrophyUI::Draw() { float AdjustWidth = io.DisplaySize.x / 1280; float AdjustHeight = io.DisplaySize.y / 720; const ImVec2 window_size{ - std::min(io.DisplaySize.x, (350 * AdjustWidth)), + std::min(io.DisplaySize.x, (330 * AdjustWidth)), std::min(io.DisplaySize.y, (70 * AdjustHeight)), }; @@ -96,18 +96,22 @@ void TrophyUI::Draw() { ImGui::SameLine(); if (trophy_type_icon) { - SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight)); + SetCursorPosY((window_size.y * 0.5f) - (15 * AdjustHeight)); Image(trophy_type_icon.GetTexture().im_id, - ImVec2((50 * AdjustWidth), (50 * AdjustHeight))); + ImVec2((30 * AdjustWidth), (30 * AdjustHeight))); } else { // placeholder const auto pos = GetCursorScreenPos(); - ImGui::GetWindowDrawList()->AddRectFilled(pos, pos + ImVec2{50.0f * AdjustHeight}, + ImGui::GetWindowDrawList()->AddRectFilled(pos, pos + ImVec2{30.0f * AdjustHeight}, GetColorU32(ImVec4{0.7f})); } ImGui::SameLine(); SetWindowFontScale((1.2 * AdjustHeight)); + char earned_text[] = "Trophy earned!\n%s"; + const float text_height = + ImGui::CalcTextSize(std::strcat(earned_text, trophy_name.c_str())).y; + SetCursorPosY((window_size.y - text_height) * 0.5f); TextWrapped("Trophy earned!\n%s", trophy_name.c_str()); } End(); diff --git a/src/qt_gui/trophy_viewer.cpp b/src/qt_gui/trophy_viewer.cpp index b68f9698a..0b9a92d36 100644 --- a/src/qt_gui/trophy_viewer.cpp +++ b/src/qt_gui/trophy_viewer.cpp @@ -116,6 +116,29 @@ void TrophyViewer::PopulateTrophyWidget(QString title) { item->setFlags(item->flags() & ~Qt::ItemIsEditable); tableWidget->setItem(row, 1, item); + std::filesystem::path trophyTypePath; + if (std::filesystem::exists(std::filesystem::current_path() / "Resources")) { + trophyTypePath = std::filesystem::current_path() / "Resources"; + } else { +#if defined(__linux__) + const char* AppDir = getenv("APPDIR"); + trophyTypePath = std::filesystem::path(AppDir); +#elif defined(__APPLE__) + trophyTypePath = Common::GetBundleParentDirectory().parent_path() / "Resources"; +#endif + } + + const std::string filename = GetTrpType(trpType[row].at(0)); + const std::filesystem::path typeIconpath = trophyTypePath / filename; + + QTableWidgetItem* typeitem = new QTableWidgetItem(); + QImage type_icon = + QImage(QFileInfo(typeIconpath).absoluteFilePath()) + .scaled(QSize(64, 64), Qt::KeepAspectRatio, Qt::SmoothTransformation); + typeitem->setData(Qt::DecorationRole, type_icon); + typeitem->setFlags(typeitem->flags() & ~Qt::ItemIsEditable); + tableWidget->setItem(row, 6, typeitem); + std::string detailString = trophyDetails[row].toStdString(); std::size_t newline_pos = 0; while ((newline_pos = detailString.find("\n", newline_pos)) != std::string::npos) { @@ -129,7 +152,6 @@ void TrophyViewer::PopulateTrophyWidget(QString title) { SetTableItem(tableWidget, row, 3, QString::fromStdString(detailString)); SetTableItem(tableWidget, row, 4, trpId[row]); SetTableItem(tableWidget, row, 5, trpHidden[row]); - SetTableItem(tableWidget, row, 6, GetTrpType(trpType[row].at(0))); SetTableItem(tableWidget, row, 7, trpPid[row]); } tableWidget->verticalHeader()->resizeSection(row, icon.height()); diff --git a/src/qt_gui/trophy_viewer.h b/src/qt_gui/trophy_viewer.h index 81b9b1adc..089de433e 100644 --- a/src/qt_gui/trophy_viewer.h +++ b/src/qt_gui/trophy_viewer.h @@ -32,17 +32,17 @@ private: QString gameTrpPath_; TRP trp; - QString GetTrpType(const QChar trp_) { + std::string GetTrpType(const QChar trp_) { switch (trp_.toLatin1()) { case 'B': - return "Bronze"; + return "bronze.png"; case 'S': - return "Silver"; + return "silver.png"; case 'G': - return "Gold"; + return "gold.png"; case 'P': - return "Platinum"; + return "platinum.png"; } return "Unknown"; } -}; \ No newline at end of file +};