Skip to content

Commit 2fcd542

Browse files
committed
overlays: allow to update messages by id instead of text
1 parent 146619d commit 2fcd542

File tree

10 files changed

+143
-38
lines changed

10 files changed

+143
-38
lines changed

rpcs3/Emu/Audio/audio_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ namespace audio
5252
g_cfg.audio.volume.set(std::clamp<s32>(new_volume, g_cfg.audio.volume.min, g_cfg.audio.volume.max));
5353
Emu.GetCallbacks().update_emu_settings();
5454

55-
rsx::overlays::queue_message(get_localized_string(localized_string_id::AUDIO_CHANGED, fmt::format("%d%%", g_cfg.audio.volume.get()).c_str()), 3'000'000);
55+
rsx::overlays::queue_message(localized_string(localized_string_id::AUDIO_CHANGED, "%d%%", g_cfg.audio.volume.get()), 3'000'000, {}, rsx::overlays::message_pin_location::top_left, {}, true, true);
5656
}
5757
} // namespace audio

rpcs3/Emu/Cell/Modules/cellGame.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ error_code cellHddGameCheck(ppu_thread& ppu, u32 version, vm::cptr<char> dirName
550550

551551
case CELL_HDDGAME_CBRESULT_ERR_NOSPACE:
552552
cellGame.error("cellHddGameCheck(): callback returned CELL_HDDGAME_CBRESULT_ERR_NOSPACE. Space Needed: %d KB", result->errNeedSizeKB);
553-
error_msg = get_localized_string(localized_string_id::CELL_HDD_GAME_CHECK_NOSPACE, fmt::format("%d", result->errNeedSizeKB).c_str());
553+
error_msg = get_localized_string(localized_string_id::CELL_HDD_GAME_CHECK_NOSPACE, "%d", result->errNeedSizeKB);
554554
break;
555555

556556
case CELL_HDDGAME_CBRESULT_ERR_BROKEN:
@@ -565,12 +565,12 @@ error_code cellHddGameCheck(ppu_thread& ppu, u32 version, vm::cptr<char> dirName
565565

566566
case CELL_HDDGAME_CBRESULT_ERR_INVALID:
567567
cellGame.error("cellHddGameCheck(): callback returned CELL_HDDGAME_CBRESULT_ERR_INVALID. Error message: %s", result->invalidMsg);
568-
error_msg = get_localized_string(localized_string_id::CELL_HDD_GAME_CHECK_INVALID, fmt::format("%s", result->invalidMsg).c_str());
568+
error_msg = get_localized_string(localized_string_id::CELL_HDD_GAME_CHECK_INVALID, "%s", result->invalidMsg);
569569
break;
570570

571571
default:
572572
cellGame.error("cellHddGameCheck(): callback returned unknown error (code=0x%x). Error message: %s", result->invalidMsg);
573-
error_msg = get_localized_string(localized_string_id::CELL_HDD_GAME_CHECK_INVALID, fmt::format("%s", result->invalidMsg).c_str());
573+
error_msg = get_localized_string(localized_string_id::CELL_HDD_GAME_CHECK_INVALID, "%s", result->invalidMsg);
574574
break;
575575
}
576576

@@ -1169,7 +1169,7 @@ error_code cellGameDataCheckCreate2(ppu_thread& ppu, u32 version, vm::cptr<char>
11691169
}
11701170
case CELL_GAMEDATA_CBRESULT_ERR_NOSPACE:
11711171
cellGame.error("cellGameDataCheckCreate2(): callback returned CELL_GAMEDATA_CBRESULT_ERR_NOSPACE. Space Needed: %d KB", cbResult->errNeedSizeKB);
1172-
error_msg = get_localized_string(localized_string_id::CELL_GAMEDATA_CHECK_NOSPACE, fmt::format("%d", cbResult->errNeedSizeKB).c_str());
1172+
error_msg = get_localized_string(localized_string_id::CELL_GAMEDATA_CHECK_NOSPACE, "%d", cbResult->errNeedSizeKB);
11731173
break;
11741174

11751175
case CELL_GAMEDATA_CBRESULT_ERR_BROKEN:
@@ -1184,12 +1184,12 @@ error_code cellGameDataCheckCreate2(ppu_thread& ppu, u32 version, vm::cptr<char>
11841184

11851185
case CELL_GAMEDATA_CBRESULT_ERR_INVALID:
11861186
cellGame.error("cellGameDataCheckCreate2(): callback returned CELL_GAMEDATA_CBRESULT_ERR_INVALID. Error message: %s", cbResult->invalidMsg);
1187-
error_msg = get_localized_string(localized_string_id::CELL_GAMEDATA_CHECK_INVALID, fmt::format("%s", cbResult->invalidMsg).c_str());
1187+
error_msg = get_localized_string(localized_string_id::CELL_GAMEDATA_CHECK_INVALID, "%s", cbResult->invalidMsg);
11881188
break;
11891189

11901190
default:
11911191
cellGame.error("cellGameDataCheckCreate2(): callback returned unknown error (code=0x%x). Error message: %s", cbResult->invalidMsg);
1192-
error_msg = get_localized_string(localized_string_id::CELL_GAMEDATA_CHECK_INVALID, fmt::format("%s", cbResult->invalidMsg).c_str());
1192+
error_msg = get_localized_string(localized_string_id::CELL_GAMEDATA_CHECK_INVALID, "%s", cbResult->invalidMsg);
11931193
break;
11941194
}
11951195

@@ -1686,7 +1686,7 @@ error_code cellGameContentErrorDialog(s32 type, s32 errNeedSizeKB, vm::cptr<char
16861686
break;
16871687
case CELL_GAME_ERRDIALOG_NOSPACE:
16881688
// Not enough available space. The application will continue.
1689-
error_msg = get_localized_string(localized_string_id::CELL_GAME_ERROR_NOSPACE, fmt::format("%d", errNeedSizeKB).c_str());
1689+
error_msg = get_localized_string(localized_string_id::CELL_GAME_ERROR_NOSPACE, "%d", errNeedSizeKB);
16901690
break;
16911691
case CELL_GAME_ERRDIALOG_BROKEN_EXIT_GAMEDATA:
16921692
// Game data is corrupted. The application will be terminated.
@@ -1698,7 +1698,7 @@ error_code cellGameContentErrorDialog(s32 type, s32 errNeedSizeKB, vm::cptr<char
16981698
break;
16991699
case CELL_GAME_ERRDIALOG_NOSPACE_EXIT:
17001700
// Not enough available space. The application will be terminated.
1701-
error_msg = get_localized_string(localized_string_id::CELL_GAME_ERROR_NOSPACE_EXIT, fmt::format("%d", errNeedSizeKB).c_str());
1701+
error_msg = get_localized_string(localized_string_id::CELL_GAME_ERROR_NOSPACE_EXIT, "%d", errNeedSizeKB);
17021702
break;
17031703
default:
17041704
return CELL_GAME_ERROR_PARAM;
@@ -1712,7 +1712,7 @@ error_code cellGameContentErrorDialog(s32 type, s32 errNeedSizeKB, vm::cptr<char
17121712
}
17131713

17141714
error_msg += '\n';
1715-
error_msg += get_localized_string(localized_string_id::CELL_GAME_ERROR_DIR_NAME, fmt::format("%s", dirName).c_str());
1715+
error_msg += get_localized_string(localized_string_id::CELL_GAME_ERROR_DIR_NAME, "%s", dirName);
17161716
}
17171717

17181718
return open_exit_dialog(error_msg, type > CELL_GAME_ERRDIALOG_NOSPACE, msg_dialog_source::_cellGame);

rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ error_code cellMsgDialogOpenErrorCode(u32 errorCode, vm::ptr<CellMsgDialogCallba
506506
default: string_id = localized_string_id::CELL_MSG_DIALOG_ERROR_DEFAULT; break; // An error has occurred.
507507
}
508508

509-
const std::string error = get_localized_string(string_id, fmt::format("%08x", errorCode).c_str());
509+
const std::string error = get_localized_string(string_id, "%08x", errorCode);
510510

511511
return cellMsgDialogOpen2(CELL_MSGDIALOG_TYPE_SE_TYPE_ERROR | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK, vm::make_str(error), callback, userData, extParam);
512512
}

rpcs3/Emu/Cell/Modules/cellSaveData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static error_code display_callback_result_error_message(ppu_thread& ppu, const C
396396
switch (result.result)
397397
{
398398
case CELL_SAVEDATA_CBRESULT_ERR_NOSPACE:
399-
msg = get_localized_string(localized_string_id::CELL_SAVEDATA_CB_NO_SPACE, fmt::format("%d", result.errNeedSizeKB).c_str());
399+
msg = get_localized_string(localized_string_id::CELL_SAVEDATA_CB_NO_SPACE, "%d", result.errNeedSizeKB);
400400
break;
401401
case CELL_SAVEDATA_CBRESULT_ERR_FAILURE:
402402
msg = get_localized_string(localized_string_id::CELL_SAVEDATA_CB_FAILURE);

rpcs3/Emu/RSX/Overlays/Trophies/overlay_trophy_list_dialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ namespace rsx
421421
m_list->select_entry(selected_index);
422422
}
423423

424-
m_description->set_text(get_localized_string(localized_string_id::HOME_MENU_TROPHY_LIST_TITLE, fmt::format("%d%% (%d/%d)", percentage, unlocked_trophies, all_trophies).c_str()));
424+
m_description->set_text(get_localized_string(localized_string_id::HOME_MENU_TROPHY_LIST_TITLE, "%d%% (%d/%d)", percentage, unlocked_trophies, all_trophies));
425425
m_description->auto_resize();
426426
}
427427
} // namespace overlays

rpcs3/Emu/RSX/Overlays/overlay_controls.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ namespace rsx
402402
set_unicode_text(get_localized_u32string(id));
403403
}
404404

405+
void overlay_element::set_text(const localized_string& container)
406+
{
407+
set_text(container.str);
408+
}
409+
405410
void overlay_element::set_font(const char* font_name, u16 font_size)
406411
{
407412
font_ref = fontmgr::get(font_name, font_size);

rpcs3/Emu/RSX/Overlays/overlay_controls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ namespace rsx
206206
virtual void set_text(const std::string& text);
207207
virtual void set_unicode_text(const std::u32string& text);
208208
void set_text(localized_string_id id);
209+
void set_text(const localized_string& container);
209210
virtual void set_font(const char* font_name, u16 font_size);
210211
virtual void align_text(text_align align);
211212
virtual void set_wrap_text(bool state);

rpcs3/Emu/RSX/Overlays/overlay_message.cpp

Lines changed: 87 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ namespace rsx
1919
template <typename T>
2020
message_item::message_item(const T& msg_id, u64 expiration, std::shared_ptr<atomic_t<u32>> refs, std::shared_ptr<overlay_element> icon)
2121
{
22+
if constexpr (std::is_same_v<T, localized_string_id>)
23+
{
24+
m_loc_id = msg_id;
25+
}
26+
else if constexpr (std::is_same_v<T, localized_string>)
27+
{
28+
m_loc_id = msg_id.id;
29+
}
30+
2231
m_visible_duration = expiration;
2332
m_refs = std::move(refs);
2433

@@ -54,6 +63,7 @@ namespace rsx
5463
}
5564
template message_item::message_item(const std::string& msg_id, u64, std::shared_ptr<atomic_t<u32>>, std::shared_ptr<overlay_element>);
5665
template message_item::message_item(const localized_string_id& msg_id, u64, std::shared_ptr<atomic_t<u32>>, std::shared_ptr<overlay_element>);
66+
template message_item::message_item(const localized_string& msg_id, u64, std::shared_ptr<atomic_t<u32>>, std::shared_ptr<overlay_element>);
5767

5868
void message_item::reset_expiration()
5969
{
@@ -75,11 +85,22 @@ namespace rsx
7585
}
7686
}
7787

88+
bool message_item::id_matches(localized_string_id id) const
89+
{
90+
return m_loc_id == id;
91+
}
92+
7893
bool message_item::text_matches(const std::u32string& text) const
7994
{
8095
return m_text.text == text;
8196
}
8297

98+
void message_item::set_label_text(const std::string& text)
99+
{
100+
m_text.set_text(text);
101+
m_is_compiled = false;
102+
}
103+
83104
void message_item::set_pos(s16 _x, s16 _y)
84105
{
85106
rounded_rect::set_pos(_x, _y);
@@ -277,19 +298,54 @@ namespace rsx
277298
return cr;
278299
}
279300

280-
bool message::message_exists(message_pin_location location, localized_string_id id, bool allow_refresh)
301+
bool message::check_lists(message_pin_location location, std::function<bool(std::deque<message_item>& list)> check_list)
281302
{
282-
return message_exists(location, get_localized_u32string(id), allow_refresh);
303+
if (!check_list) return false;
304+
305+
switch (location)
306+
{
307+
case message_pin_location::bottom_right:
308+
return check_list(m_ready_queue_bottom_right) || check_list(m_visible_items_bottom_right);
309+
case message_pin_location::bottom_left:
310+
return check_list(m_ready_queue_bottom_left) || check_list(m_visible_items_bottom_left);
311+
case message_pin_location::top_right:
312+
return check_list(m_ready_queue_top_right) || check_list(m_visible_items_top_right);
313+
case message_pin_location::top_left:
314+
return check_list(m_ready_queue_top_left) || check_list(m_visible_items_top_left);
315+
}
316+
317+
return false;
283318
}
284319

285-
bool message::message_exists(message_pin_location location, const std::string& msg, bool allow_refresh)
320+
bool message::message_exists(message_pin_location location, localized_string_id id, bool allow_refresh, bool /*compare_id*/)
286321
{
287-
return message_exists(location, utf8_to_u32string(msg), allow_refresh);
322+
const auto check_list = [&](std::deque<message_item>& list)
323+
{
324+
return std::any_of(list.begin(), list.end(), [&](message_item& item)
325+
{
326+
if (item.id_matches(id))
327+
{
328+
if (allow_refresh)
329+
{
330+
item.reset_expiration();
331+
}
332+
return true;
333+
}
334+
return false;
335+
});
336+
};
337+
338+
return check_lists(location, check_list);
339+
}
340+
341+
bool message::message_exists(message_pin_location location, const std::string& msg, bool allow_refresh, bool compare_id)
342+
{
343+
return message_exists(location, utf8_to_u32string(msg), allow_refresh, compare_id);
288344
}
289345

290-
bool message::message_exists(message_pin_location location, const std::u32string& msg, bool allow_refresh)
346+
bool message::message_exists(message_pin_location location, const std::u32string& msg, bool allow_refresh, bool /*compare_id*/)
291347
{
292-
auto check_list = [&](std::deque<message_item>& list)
348+
const auto check_list = [&](std::deque<message_item>& list)
293349
{
294350
return std::any_of(list.begin(), list.end(), [&](message_item& item)
295351
{
@@ -305,19 +361,34 @@ namespace rsx
305361
});
306362
};
307363

308-
switch (location)
364+
return check_lists(location, check_list);
365+
}
366+
367+
bool message::message_exists(message_pin_location location, const localized_string& container, bool allow_refresh, bool compare_id)
368+
{
369+
if (compare_id)
309370
{
310-
case message_pin_location::bottom_right:
311-
return check_list(m_ready_queue_bottom_right) || check_list(m_visible_items_bottom_right);
312-
case message_pin_location::bottom_left:
313-
return check_list(m_ready_queue_bottom_left) || check_list(m_visible_items_bottom_left);
314-
case message_pin_location::top_right:
315-
return check_list(m_ready_queue_top_right) || check_list(m_visible_items_top_right);
316-
case message_pin_location::top_left:
317-
return check_list(m_ready_queue_top_left) || check_list(m_visible_items_top_left);
371+
const auto check_list = [&](std::deque<message_item>& list)
372+
{
373+
return std::any_of(list.begin(), list.end(), [&](message_item& item)
374+
{
375+
if (item.id_matches(container.id))
376+
{
377+
if (allow_refresh)
378+
{
379+
item.set_label_text(container.str);
380+
item.reset_expiration();
381+
}
382+
return true;
383+
}
384+
return false;
385+
});
386+
};
387+
388+
return check_lists(location, check_list);
318389
}
319390

320-
return false;
391+
return message_exists(location, utf8_to_u32string(container.str), allow_refresh, compare_id);
321392
}
322393

323394
void refresh_message_queue()

rpcs3/Emu/RSX/Overlays/overlay_message.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ namespace rsx
3030
void ensure_expired();
3131
compiled_resource& get_compiled() override;
3232

33+
bool id_matches(localized_string_id id) const;
3334
bool text_matches(const std::u32string& text) const;
3435

36+
void set_label_text(const std::string& text);
37+
3538
private:
39+
localized_string_id m_loc_id = localized_string_id::INVALID;
3640
label m_text{};
3741
std::shared_ptr<overlay_element> m_icon{};
3842
animation_color_interpolate m_fade_in_animation;
@@ -59,7 +63,8 @@ namespace rsx
5963
std::shared_ptr<atomic_t<u32>> refs,
6064
message_pin_location location = message_pin_location::top_left,
6165
std::shared_ptr<overlay_element> icon = {},
62-
bool allow_refresh = false)
66+
bool allow_refresh = false,
67+
bool compare_id = false)
6368
{
6469
std::lock_guard lock(m_mutex_queue);
6570

@@ -85,13 +90,13 @@ namespace rsx
8590
{
8691
for (auto id : msg_id)
8792
{
88-
if (!message_exists(location, id, allow_refresh))
93+
if (!message_exists(location, id, allow_refresh, compare_id))
8994
{
9095
queue->emplace_back(id, expiration, refs, icon);
9196
}
9297
}
9398
}
94-
else if (!message_exists(location, msg_id, allow_refresh))
99+
else if (!message_exists(location, msg_id, allow_refresh, compare_id))
95100
{
96101
queue->emplace_back(msg_id, expiration, std::move(refs), icon);
97102
}
@@ -119,9 +124,11 @@ namespace rsx
119124
void update_queue(std::deque<message_item>& vis_set, std::deque<message_item>& ready_set, message_pin_location origin);
120125

121126
// Stacking. Extends the lifetime of a message instead of inserting a duplicate
122-
bool message_exists(message_pin_location location, localized_string_id id, bool allow_refresh);
123-
bool message_exists(message_pin_location location, const std::string& msg, bool allow_refresh);
124-
bool message_exists(message_pin_location location, const std::u32string& msg, bool allow_refresh);
127+
bool check_lists(message_pin_location location, std::function<bool(std::deque<message_item>& list)> check_list);
128+
bool message_exists(message_pin_location location, localized_string_id id, bool allow_refresh, bool compare_id);
129+
bool message_exists(message_pin_location location, const std::string& msg, bool allow_refresh, bool compare_id);
130+
bool message_exists(message_pin_location location, const std::u32string& msg, bool allow_refresh, bool compare_id);
131+
bool message_exists(message_pin_location location, const localized_string& container, bool allow_refresh, bool compare_id);
125132
};
126133

127134
template <typename T>
@@ -131,7 +138,8 @@ namespace rsx
131138
std::shared_ptr<atomic_t<u32>> refs = {},
132139
message_pin_location location = message_pin_location::top_left,
133140
std::shared_ptr<overlay_element> icon = {},
134-
bool allow_refresh = false)
141+
bool allow_refresh = false,
142+
bool compare_id = false)
135143
{
136144
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
137145
{
@@ -141,7 +149,7 @@ namespace rsx
141149
msg_overlay = std::make_shared<rsx::overlays::message>();
142150
msg_overlay = manager->add(msg_overlay);
143151
}
144-
msg_overlay->queue_message(msg_id, expiration, std::move(refs), location, std::move(icon), allow_refresh);
152+
msg_overlay->queue_message(msg_id, expiration, std::move(refs), location, std::move(icon), allow_refresh, compare_id);
145153
}
146154
}
147155

rpcs3/Emu/localized_string.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
#pragma once
22

3-
#include <string>
43
#include "localized_string_id.h"
4+
#include "Utilities/StrFmt.h"
55

66
std::string get_localized_string(localized_string_id id, const char* args = "");
77
std::u32string get_localized_u32string(localized_string_id id, const char* args = "");
8+
9+
template <typename CharT, usz N, typename... Args>
10+
requires (sizeof...(Args) > 0)
11+
std::string get_localized_string(localized_string_id id, const CharT(&fmt)[N], const Args&... args)
12+
{
13+
return get_localized_string(id, fmt::format(fmt, args...).c_str());
14+
}
15+
16+
struct localized_string
17+
{
18+
template <typename CharT, usz N, typename... Args>
19+
requires (sizeof...(Args) > 0)
20+
localized_string(localized_string_id _id, const CharT(&fmt)[N], const Args&... args)
21+
: id(_id), str(get_localized_string(id, fmt, args...))
22+
{
23+
}
24+
25+
localized_string_id id = localized_string_id::INVALID;
26+
std::string str;
27+
};

0 commit comments

Comments
 (0)