mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-17 17:05:02 +00:00
Fix and add back Trophy type icons for both the trophy pop-up and viewer (#2522)
* Add back fixed trophy type icons to trophy viewer * Remove unused declaration until it is needed again * Fix trophy pop-up icons * Adjust size and alignment based on trophy name length --------- Co-authored-by: rainmakerv2 <30595646+jpau02@users.noreply.github.com>
This commit is contained in:
parent
bc0b42ee53
commit
47ac8b6c03
3 changed files with 72 additions and 18 deletions
|
@ -31,6 +31,22 @@ 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 file = resource.open(pathString);
|
||||||
|
std::vector<u8> imgdata(file.begin(), file.end());
|
||||||
|
trophy_type_icon = RefCountedTexture::DecodePngTexture(imgdata);
|
||||||
|
|
||||||
AddLayer(this);
|
AddLayer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +75,10 @@ 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_icon) {
|
if (trophy_type_icon) {
|
||||||
SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight));
|
SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight));
|
||||||
Image(trophy_icon.GetTexture().im_id, ImVec2((50 * AdjustWidth), (50 * AdjustHeight)));
|
Image(trophy_type_icon.GetTexture().im_id,
|
||||||
|
ImVec2((50 * AdjustWidth), (50 * AdjustHeight)));
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
} else {
|
} else {
|
||||||
// placeholder
|
// placeholder
|
||||||
|
@ -71,12 +88,35 @@ void TrophyUI::Draw() {
|
||||||
ImGui::Indent(60);
|
ImGui::Indent(60);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetWindowFontScale((1.2 * AdjustHeight));
|
const std::string combinedString = "Trophy earned!\n%s" + trophy_name;
|
||||||
char earned_text[] = "Trophy earned!\n%s";
|
const float wrap_width =
|
||||||
const float text_height =
|
CalcWrapWidthForPos(GetCursorScreenPos(), (window_size.x - (60 * AdjustWidth)));
|
||||||
ImGui::CalcTextSize(std::strcat(earned_text, trophy_name.c_str())).y;
|
SetWindowFontScale(1.2 * AdjustHeight);
|
||||||
SetCursorPosY((window_size.y - text_height) * 0.5f);
|
// If trophy name exceeds 1 line
|
||||||
|
if (CalcTextSize(trophy_name.c_str()).x > wrap_width) {
|
||||||
|
SetCursorPosY(5 * AdjustHeight);
|
||||||
|
if (CalcTextSize(trophy_name.c_str()).x > (wrap_width * 2)) {
|
||||||
|
SetWindowFontScale(0.95 * AdjustHeight);
|
||||||
|
} else {
|
||||||
|
SetWindowFontScale(1.1 * AdjustHeight);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const float text_height = ImGui::CalcTextSize(combinedString.c_str()).y;
|
||||||
|
SetCursorPosY((window_size.y - text_height) * 0.5);
|
||||||
|
}
|
||||||
|
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{50.0f * AdjustHeight},
|
||||||
|
GetColorU32(ImVec4{0.7f}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
End();
|
End();
|
||||||
|
|
||||||
|
|
|
@ -118,18 +118,19 @@ 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();
|
||||||
|
|
||||||
QString type;
|
auto resource = cmrc::res::get_filesystem();
|
||||||
if (trpType[row] == "P") {
|
std::string resourceString = "Resources/" + filename;
|
||||||
type = "Platinum";
|
auto file = resource.open(resourceString);
|
||||||
} else if (trpType[row] == "G") {
|
std::vector<char> imgdata(file.begin(), file.end());
|
||||||
type = "Gold";
|
QImage type_icon = QImage::fromData(imgdata).scaled(QSize(64, 64), Qt::KeepAspectRatio,
|
||||||
} else if (trpType[row] == "S") {
|
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;
|
||||||
|
@ -144,7 +145,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, 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());
|
||||||
|
|
|
@ -31,4 +31,18 @@ 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";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue