Skip to content

Commit

Permalink
Reduce string conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
AJenbo committed Mar 20, 2022
1 parent 0d1ee6e commit 1409e60
Show file tree
Hide file tree
Showing 49 changed files with 338 additions and 329 deletions.
2 changes: 1 addition & 1 deletion Source/DiabloUI/diabloui.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void UiSelHeroSingDialog(bool (*fninfo)(bool (*fninfofunc)(_uiheroinfo *)), bool
bool UiCreditsDialog();
bool UiSupportDialog();
bool UiMainMenuDialog(const char *name, _mainmenu_selections *pdwResult, void (*fnSound)(const char *file), int attractTimeOut);
bool UiProgressDialog(const char *msg, int (*fnfunc)());
bool UiProgressDialog(int (*fnfunc)());
bool UiSelectGame(GameData *gameData, int *playerId);
bool UiSelectProvider(GameData *gameData);
void UiFadeIn();
Expand Down
11 changes: 6 additions & 5 deletions Source/DiabloUI/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "utils/display.h"
#include "utils/language.h"
#include "utils/log.hpp"
#include "utils/stdcompat/string_view.hpp"

namespace devilution {

Expand Down Expand Up @@ -159,7 +160,7 @@ void LoadFallbackPalette()
BlackPalette();
}

void Init(const char *caption, const char *text, bool error, bool renderBehind)
void Init(string_view caption, string_view text, bool error, bool renderBehind)
{
if (!renderBehind) {
ArtBackground.Unload();
Expand All @@ -171,7 +172,7 @@ void Init(const char *caption, const char *text, bool error, bool renderBehind)
}
}

if (caption == nullptr) {
if (caption.empty()) {
LoadMaskedArt(error ? "ui_art\\srpopup.pcx" : "ui_art\\spopup.pcx", &dialogArt);
} else if (error) {
LoadArt(&dialogArt, PopupData, 385, 280);
Expand All @@ -184,12 +185,12 @@ void Init(const char *caption, const char *text, bool error, bool renderBehind)

wrappedText = WordWrapString(text, textWidth, FontSizeDialog);

if (caption == nullptr) {
if (caption.empty()) {
SDL_Rect rect1 = MakeSdlRect(PANEL_LEFT + 180, UI_OFFSET_Y + 168, dialogArt.w(), dialogArt.h());
vecOkDialog.push_back(std::make_unique<UiImage>(&dialogArt, rect1));

SDL_Rect rect2 = MakeSdlRect(PANEL_LEFT + 200, UI_OFFSET_Y + 211, textWidth, 80);
vecOkDialog.push_back(std::make_unique<UiText>(wrappedText.c_str(), rect2, UiFlags::AlignCenter | UiFlags::ColorDialogWhite));
vecOkDialog.push_back(std::make_unique<UiText>(wrappedText, rect2, UiFlags::AlignCenter | UiFlags::ColorDialogWhite));

SDL_Rect rect3 = MakeSdlRect(PANEL_LEFT + 265, UI_OFFSET_Y + 265, SML_BUTTON_WIDTH, SML_BUTTON_HEIGHT);
vecOkDialog.push_back(std::make_unique<UiButton>(&SmlButton, _("OK"), &DialogActionOK, rect3));
Expand All @@ -201,7 +202,7 @@ void Init(const char *caption, const char *text, bool error, bool renderBehind)
vecOkDialog.push_back(std::make_unique<UiText>(caption, rect2, UiFlags::AlignCenter | UiFlags::ColorDialogYellow));

SDL_Rect rect3 = MakeSdlRect(PANEL_LEFT + 147, UI_OFFSET_Y + 141, textWidth, 190);
vecOkDialog.push_back(std::make_unique<UiText>(wrappedText.c_str(), rect3, UiFlags::AlignCenter | UiFlags::ColorDialogWhite));
vecOkDialog.push_back(std::make_unique<UiText>(wrappedText, rect3, UiFlags::AlignCenter | UiFlags::ColorDialogWhite));

SDL_Rect rect4 = MakeSdlRect(PANEL_LEFT + 264, UI_OFFSET_Y + 335, SML_BUTTON_WIDTH, SML_BUTTON_HEIGHT);
vecOkDialog.push_back(std::make_unique<UiButton>(&SmlButton, _("OK"), &DialogActionOK, rect4));
Expand Down
2 changes: 1 addition & 1 deletion Source/DiabloUI/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void MainmenuLoad(const char *name, void (*fnSound)(const char *file))

if (gbIsSpawn && gbIsHellfire) {
SDL_Rect rect1 = { (Sint16)(PANEL_LEFT), (Sint16)(UI_OFFSET_Y + 145), 640, 30 };
vecMainMenuDialog.push_back(std::make_unique<UiArtText>(_("Shareware"), rect1, UiFlags::FontSize30 | UiFlags::ColorUiSilver | UiFlags::AlignCenter, 8));
vecMainMenuDialog.push_back(std::make_unique<UiArtText>(_("Shareware").c_str(), rect1, UiFlags::FontSize30 | UiFlags::ColorUiSilver | UiFlags::AlignCenter, 8));
}

vecMainMenuDialog.push_back(std::make_unique<UiList>(vecMenuItems, vecMenuItems.size(), PANEL_LEFT + 64, (UI_OFFSET_Y + 192), 510, 43, UiFlags::FontSize42 | UiFlags::ColorUiGold | UiFlags::AlignCenter, 5));
Expand Down
6 changes: 3 additions & 3 deletions Source/DiabloUI/progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void DialogActionCancel()
endMenu = true;
}

void ProgressLoad(const char *msg)
void ProgressLoad()
{
LoadBackgroundArt("ui_art\\black.pcx");
LoadArt("ui_art\\spopup.pcx", &ArtPopupSm);
Expand Down Expand Up @@ -63,9 +63,9 @@ void ProgressRender(BYTE progress)

} // namespace

bool UiProgressDialog(const char *msg, int (*fnfunc)())
bool UiProgressDialog(int (*fnfunc)())
{
ProgressLoad(msg);
ProgressLoad();
SetFadeLevel(256);

endMenu = false;
Expand Down
19 changes: 10 additions & 9 deletions Source/DiabloUI/selconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "stores.h"
#include "storm/storm_net.hpp"
#include "utils/language.h"
#include "utils/utf8.hpp"

namespace devilution {

Expand Down Expand Up @@ -50,25 +51,25 @@ void SelconnLoad()
UiAddLogo(&vecSelConnDlg);

SDL_Rect rect1 = { (Sint16)(PANEL_LEFT + 24), (Sint16)(Sint16)(UI_OFFSET_Y + 161), 590, 35 };
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("Multi Player Game"), rect1, UiFlags::AlignCenter | UiFlags::FontSize30 | UiFlags::ColorUiSilver, 3));
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("Multi Player Game").c_str(), rect1, UiFlags::AlignCenter | UiFlags::FontSize30 | UiFlags::ColorUiSilver, 3));

SDL_Rect rect2 = { (Sint16)(PANEL_LEFT + 35), (Sint16)(UI_OFFSET_Y + 218), DESCRIPTION_WIDTH, 21 };
vecSelConnDlg.push_back(std::make_unique<UiArtText>(selconn_MaxPlayers, rect2, UiFlags::FontSize12 | UiFlags::ColorUiSilverDark));

SDL_Rect rect3 = { (Sint16)(PANEL_LEFT + 35), (Sint16)(UI_OFFSET_Y + 256), DESCRIPTION_WIDTH, 21 };
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("Requirements:"), rect3, UiFlags::FontSize12 | UiFlags::ColorUiSilverDark));
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("Requirements:").c_str(), rect3, UiFlags::FontSize12 | UiFlags::ColorUiSilverDark));

SDL_Rect rect4 = { (Sint16)(PANEL_LEFT + 35), (Sint16)(UI_OFFSET_Y + 275), DESCRIPTION_WIDTH, 66 };
vecSelConnDlg.push_back(std::make_unique<UiArtText>(selconn_Description, rect4, UiFlags::FontSize12 | UiFlags::ColorUiSilverDark, 1, 16));

SDL_Rect rect5 = { (Sint16)(PANEL_LEFT + 30), (Sint16)(UI_OFFSET_Y + 356), 220, 31 };
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("no gateway needed"), rect5, UiFlags::AlignCenter | UiFlags::FontSize24 | UiFlags::ColorUiSilver, 0));
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("no gateway needed").c_str(), rect5, UiFlags::AlignCenter | UiFlags::FontSize24 | UiFlags::ColorUiSilver, 0));

SDL_Rect rect6 = { (Sint16)(PANEL_LEFT + 35), (Sint16)(UI_OFFSET_Y + 393), DESCRIPTION_WIDTH, 21 };
vecSelConnDlg.push_back(std::make_unique<UiArtText>(selconn_Gateway, rect6, UiFlags::AlignCenter | UiFlags::FontSize12 | UiFlags::ColorUiSilverDark));

SDL_Rect rect7 = { (Sint16)(PANEL_LEFT + 300), (Sint16)(UI_OFFSET_Y + 211), 295, 33 };
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("Select Connection"), rect7, UiFlags::AlignCenter | UiFlags::FontSize30 | UiFlags::ColorUiSilver, 3));
vecSelConnDlg.push_back(std::make_unique<UiArtText>(_("Select Connection").c_str(), rect7, UiFlags::AlignCenter | UiFlags::FontSize30 | UiFlags::ColorUiSilver, 3));

SDL_Rect rect8 = { (Sint16)(PANEL_LEFT + 16), (Sint16)(UI_OFFSET_Y + 427), 250, 35 };
vecSelConnDlg.push_back(std::make_unique<UiArtTextButton>(_("Change Gateway"), nullptr, rect8, UiFlags::AlignCenter | UiFlags::VerticalCenter | UiFlags::FontSize30 | UiFlags::ColorUiGold | UiFlags::ElementHidden));
Expand Down Expand Up @@ -104,21 +105,21 @@ void SelconnFocus(int value)
int players = MAX_PLRS;
switch (vecConnItems[value]->m_value) {
case SELCONN_TCP:
strcpy(selconn_Description, _("All computers must be connected to a TCP-compatible network."));
CopyUtf8(selconn_Description, _("All computers must be connected to a TCP-compatible network."), sizeof(selconn_Description));
players = MAX_PLRS;
break;
case SELCONN_ZT:
strcpy(selconn_Description, _("All computers must be connected to the internet."));
CopyUtf8(selconn_Description, _("All computers must be connected to the internet."), sizeof(selconn_Description));
players = MAX_PLRS;
break;
case SELCONN_LOOPBACK:
strcpy(selconn_Description, _("Play by yourself with no network exposure."));
CopyUtf8(selconn_Description, _("Play by yourself with no network exposure."), sizeof(selconn_Description));
players = 1;
break;
}

strcpy(selconn_MaxPlayers, fmt::format(_("Players Supported: {:d}"), players).c_str());
strcpy(selconn_Description, WordWrapString(selconn_Description, DESCRIPTION_WIDTH).c_str());
CopyUtf8(selconn_MaxPlayers, fmt::format(_("Players Supported: {:d}"), players), sizeof(selconn_MaxPlayers));
CopyUtf8(selconn_Description, WordWrapString(selconn_Description, DESCRIPTION_WIDTH), sizeof(selconn_Description));
}

void SelconnSelect(int value)
Expand Down
Loading

0 comments on commit 1409e60

Please sign in to comment.