Smaller type icons, center text vertically

This commit is contained in:
rainmakerv2 2025-02-21 13:03:48 +08:00
parent d42cc49dab
commit 06576fa16d
3 changed files with 37 additions and 11 deletions

View File

@ -73,7 +73,7 @@ void TrophyUI::Draw() {
float AdjustWidth = io.DisplaySize.x / 1280; float AdjustWidth = io.DisplaySize.x / 1280;
float AdjustHeight = io.DisplaySize.y / 720; float AdjustHeight = io.DisplaySize.y / 720;
const ImVec2 window_size{ 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)), std::min(io.DisplaySize.y, (70 * AdjustHeight)),
}; };
@ -96,18 +96,22 @@ void TrophyUI::Draw() {
ImGui::SameLine(); ImGui::SameLine();
if (trophy_type_icon) { 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, Image(trophy_type_icon.GetTexture().im_id,
ImVec2((50 * AdjustWidth), (50 * AdjustHeight))); ImVec2((30 * AdjustWidth), (30 * AdjustHeight)));
} 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{30.0f * AdjustHeight},
GetColorU32(ImVec4{0.7f})); GetColorU32(ImVec4{0.7f}));
} }
ImGui::SameLine(); ImGui::SameLine();
SetWindowFontScale((1.2 * AdjustHeight)); 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()); TextWrapped("Trophy earned!\n%s", trophy_name.c_str());
} }
End(); End();

View File

@ -116,6 +116,29 @@ void TrophyViewer::PopulateTrophyWidget(QString title) {
item->setFlags(item->flags() & ~Qt::ItemIsEditable); item->setFlags(item->flags() & ~Qt::ItemIsEditable);
tableWidget->setItem(row, 1, item); 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::string detailString = trophyDetails[row].toStdString();
std::size_t newline_pos = 0; std::size_t newline_pos = 0;
while ((newline_pos = detailString.find("\n", newline_pos)) != std::string::npos) { 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, 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, GetTrpType(trpType[row].at(0)));
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

@ -32,16 +32,16 @@ private:
QString gameTrpPath_; QString gameTrpPath_;
TRP trp; TRP trp;
QString GetTrpType(const QChar trp_) { std::string GetTrpType(const QChar trp_) {
switch (trp_.toLatin1()) { switch (trp_.toLatin1()) {
case 'B': case 'B':
return "Bronze"; return "bronze.png";
case 'S': case 'S':
return "Silver"; return "silver.png";
case 'G': case 'G':
return "Gold"; return "gold.png";
case 'P': case 'P':
return "Platinum"; return "platinum.png";
} }
return "Unknown"; return "Unknown";
} }