mirror of
https://github.com/libretro/devilutionX.git
synced 2026-11-13 04:34:45 -10:00
The backgrounds can be quite large, for example the Hellfire title background is a 2.4 MiB PCX file. Previously, we converted all background to SDL surfaces. This required extra memory, e.g. the 2.4 MiB Hellfire title background uses 4.6 MiB as an SDL surface. Changes the background to render directly from PCX instead to reduce the allocator pressure.
88 lines
2.4 KiB
C++
88 lines
2.4 KiB
C++
#include "DiabloUI/selok.h"
|
|
|
|
#include "DiabloUI/diabloui.h"
|
|
#include "control.h"
|
|
#include "engine/render/text_render.hpp"
|
|
#include "utils/language.h"
|
|
#include "utils/utf8.hpp"
|
|
|
|
namespace devilution {
|
|
|
|
namespace {
|
|
|
|
char dialogText[256];
|
|
|
|
} // namespace
|
|
|
|
bool selok_endMenu;
|
|
|
|
std::vector<std::unique_ptr<UiListItem>> vecSelOkDialogItems;
|
|
std::vector<std::unique_ptr<UiItemBase>> vecSelOkDialog;
|
|
|
|
#define MESSAGE_WIDTH 400
|
|
|
|
void selok_Free()
|
|
{
|
|
ArtBackground = std::nullopt;
|
|
|
|
vecSelOkDialogItems.clear();
|
|
|
|
vecSelOkDialog.clear();
|
|
}
|
|
|
|
void selok_Select(int /*value*/)
|
|
{
|
|
selok_endMenu = true;
|
|
}
|
|
|
|
void selok_Esc()
|
|
{
|
|
selok_endMenu = true;
|
|
}
|
|
|
|
void UiSelOkDialog(const char *title, const char *body, bool background)
|
|
{
|
|
if (!background) {
|
|
LoadBackgroundArt("ui_art\\black.pcx");
|
|
} else {
|
|
if (!gbIsSpawn) {
|
|
LoadBackgroundArt("ui_art\\mainmenu.pcx");
|
|
} else {
|
|
LoadBackgroundArt("ui_art\\swmmenu.pcx");
|
|
}
|
|
}
|
|
|
|
UiAddBackground(&vecSelOkDialog);
|
|
UiAddLogo(&vecSelOkDialog);
|
|
|
|
const Point uiPosition = GetUIRectangle().position;
|
|
|
|
if (title != nullptr) {
|
|
SDL_Rect rect1 = { (Sint16)(uiPosition.x + 24), (Sint16)(uiPosition.y + 161), 590, 35 };
|
|
vecSelOkDialog.push_back(std::make_unique<UiArtText>(title, rect1, UiFlags::AlignCenter | UiFlags::FontSize30 | UiFlags::ColorUiSilver, 3));
|
|
|
|
SDL_Rect rect2 = { (Sint16)(uiPosition.x + 140), (Sint16)(uiPosition.y + 210), 560, 168 };
|
|
vecSelOkDialog.push_back(std::make_unique<UiArtText>(dialogText, rect2, UiFlags::FontSize24 | UiFlags::ColorUiSilver));
|
|
} else {
|
|
SDL_Rect rect1 = { (Sint16)(uiPosition.x + 140), (Sint16)(uiPosition.y + 197), 560, 168 };
|
|
vecSelOkDialog.push_back(std::make_unique<UiArtText>(dialogText, rect1, UiFlags::FontSize24 | UiFlags::ColorUiSilver));
|
|
}
|
|
|
|
vecSelOkDialogItems.push_back(std::make_unique<UiListItem>(_("OK"), 0));
|
|
vecSelOkDialog.push_back(std::make_unique<UiList>(vecSelOkDialogItems, 1, uiPosition.x + 230, (uiPosition.y + 390), 180, 35, UiFlags::AlignCenter | UiFlags::FontSize30 | UiFlags::ColorUiGold));
|
|
|
|
CopyUtf8(dialogText, WordWrapString(body, MESSAGE_WIDTH, GameFont24), sizeof(dialogText));
|
|
|
|
UiInitList(nullptr, selok_Select, selok_Esc, vecSelOkDialog, false);
|
|
|
|
selok_endMenu = false;
|
|
while (!selok_endMenu) {
|
|
UiClearScreen();
|
|
UiRenderItems(vecSelOkDialog);
|
|
UiPollAndRender();
|
|
}
|
|
|
|
selok_Free();
|
|
}
|
|
} // namespace devilution
|