|
|
|
|
#include "DiabloUI/dialogs.h"
|
|
|
|
|
|
|
|
|
|
#include "controls/menu_controls.h"
|
|
|
|
|
#include "all.h"
|
|
|
|
|
#include "dx.h"
|
|
|
|
|
#include "DiabloUI/diabloui.h"
|
|
|
|
|
#include "DiabloUI/button.h"
|
|
|
|
|
#include "DiabloUI/fonts.h"
|
|
|
|
|
#include "DiabloUI/errorart.h"
|
|
|
|
|
#include "display.h"
|
|
|
|
|
|
|
|
|
|
namespace dvl {
|
|
|
|
|
|
|
|
|
|
extern HANDLE diabdat_mpq;
|
|
|
|
|
extern SDL_Surface *pal_surface;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
Art dialogArt;
|
|
|
|
|
char dialogText[256];
|
|
|
|
|
char dialogCaption[1024];
|
|
|
|
|
bool fontWasLoaded;
|
|
|
|
|
|
|
|
|
|
UiItem *dialogItems;
|
|
|
|
|
std::size_t dialogItemsSize;
|
|
|
|
|
|
|
|
|
|
bool dialogEnd;
|
|
|
|
|
|
|
|
|
|
void DialogActionOK()
|
|
|
|
|
{
|
|
|
|
|
dialogEnd = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr auto DIALOG_ART_L = UiImage(&dialogArt, { 127, 100, 385, 280 });
|
|
|
|
|
|
|
|
|
|
UiItem OK_DIALOG[] = {
|
|
|
|
|
UiImage(&dialogArt, { 180, 168, 280, 144 }),
|
|
|
|
|
UiText(dialogText, { 200, 211, 240, 80 }, UIS_CENTER),
|
|
|
|
|
MakeSmlButton("OK", &DialogActionOK, 265, 265),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UiItem OK_DIALOG_WITH_CAPTION[] = {
|
|
|
|
|
DIALOG_ART_L,
|
|
|
|
|
UiText(dialogText, SDL_Color{ 255, 255, 0, 0 }, { 147, 110, 345, 20 }, UIS_CENTER),
|
|
|
|
|
UiText(dialogCaption, { 147, 141, 345, 190 }, UIS_CENTER),
|
|
|
|
|
MakeSmlButton("OK", &DialogActionOK, 264, 335),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
#define BLANKCOLOR { 0, 0xFF, 0, 0 }
|
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
void LoadFallbackPalette()
|
|
|
|
|
{
|
|
|
|
|
// clang-format off
|
|
|
|
|
static const SDL_Color fallback_palette[256] = {
|
|
|
|
|
{ 0x00, 0x00, 0x00, 0 },
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR,
|
|
|
|
|
{ 0xff, 0xfd, 0x9f, 0 },
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, B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LANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR,
|
|
|
|
|
{ 0xf3, 0xf3, 0xf3, 0 },
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR,
|
|
|
|
|
{ 0xff, 0xff, 0x00, 0 },
|
|
|
|
|
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
|
|
|
|
|
BLANKCOLOR,
|
|
|
|
|
};
|
|
|
|
|
// clang-format on
|
|
|
|
|
ApplyGamma(logical_palette, fallback_palette, 256);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Init(const char *text, const char *caption, bool error, bool render_behind)
|
|
|
|
|
{
|
|
|
|
|
strcpy(dialogText, text);
|
|
|
|
|
if (!render_behind) {
|
|
|
|
|
LoadBackgroundArt("ui_art\\black.pcx");
|
|
|
|
|
if (ArtBackground.surface == nullptr) {
|
|
|
|
|
LoadFallbackPalette();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SetFadeLevel(256);
|
|
|
|
|
if (caption == nullptr) {
|
|
|
|
|
LoadMaskedArt(error ? "ui_art\\srpopup.pcx" : "ui_art\\spopup.pcx", &dialogArt);
|
|
|
|
|
dialogItems = OK_DIALOG;
|
|
|
|
|
dialogItemsSize = size(OK_DIALOG);
|
|
|
|
|
} else {
|
|
|
|
|
if (error) {
|
|
|
|
|
LoadArt(&dialogArt, popupData, DIALOG_ART_L.rect.w, DIALOG_ART_L.rect.h);
|
|
|
|
|
} else {
|
|
|
|
|
LoadMaskedArt("ui_art\\lpopup.pcx", &dialogArt);
|
|
|
|
|
}
|
|
|
|
|
strcpy(dialogCaption, caption);
|
|
|
|
|
dialogItems = OK_DIALOG_WITH_CAPTION;
|
|
|
|
|
dialogItemsSize = size(OK_DIALOG_WITH_CAPTION);
|
|
|
|
|
}
|
|
|
|
|
LoadSmlButtonArt();
|
|
|
|
|
|
|
|
|
|
fontWasLoaded = font != nullptr;
|
|
|
|
|
if (!fontWasLoaded)
|
|
|
|
|
LoadTtfFont();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Deinit()
|
|
|
|
|
{
|
|
|
|
|
dialogArt.Unload();
|
|
|
|
|
UnloadSmlButtonArt();
|
|
|
|
|
if (!fontWasLoaded)
|
|
|
|
|
UnloadTtfFont();
|
|
|
|
|
for (std::size_t i = 0; i < dialogItemsSize; ++i) {
|
|
|
|
|
dialogItems[i].FreeCache();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DialogLoop(UiItem *items, std::size_t num_items, UiItem *render_behind, std::size_t render_behind_size)
|
|
|
|
|
{
|
|
|
|
|
SDL_Event event;
|
|
|
|
|
dialogEnd = false;
|
|
|
|
|
do {
|
|
|
|
|
while (SDL_PollEvent(&event)) {
|
|
|
|
|
switch (event.type) {
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
|
|
|
|
UiItemMouseEvents(&event, items, num_items);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
switch (GetMenuAction(event)) {
|
|
|
|
|
case MenuAction::BACK:
|
|
|
|
|
case MenuAction::SELECT:
|
|
|
|
|
dialogEnd = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
UiHandleEvents(&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (render_behind_size == 0) {
|
|
|
|
|
SDL_FillRect(GetOutputSurface(), nullptr, 0);
|
|
|
|
|
} else {
|
|
|
|
|
UiRenderItems(render_behind, render_behind_size);
|
|
|
|
|
}
|
|
|
|
|
UiRenderItems(items, num_items);
|
|
|
|
|
DrawMouse();
|
|
|
|
|
UiFadeIn();
|
|
|
|
|
} while (!dialogEnd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
void UiOkDialog(const char *text, const char *caption, bool error, UiItem *render_behind, std::size_t render_behind_size)
|
|
|
|
|
{
|
|
|
|
|
static bool inDialog = false;
|
|
|
|
|
|
|
|
|
|
if (!gbActive || inDialog) {
|
|
|
|
|
if (SDL_ShowCursor(SDL_ENABLE) <= -1) {
|
|
|
|
|
SDL_Log(SDL_GetError());
|
|
|
|
|
}
|
|
|
|
|
#ifndef RUN_TESTS
|
|
|
|
|
if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, text, caption, NULL) <= -1) {
|
|
|
|
|
SDL_Log(SDL_GetError());
|
|
|
|
|
#else
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
SDL_Log(text);
|
|
|
|
|
SDL_Log(caption);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inDialog = true;
|
|
|
|
|
Init(text, caption, error, render_behind_size > 0);
|
|
|
|
|
DialogLoop(dialogItems, dialogItemsSize, render_behind, render_behind_size);
|
|
|
|
|
Deinit();
|
|
|
|
|
inDialog = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UiErrorOkDialog(const char *text, const char *caption, UiItem *render_behind, std::size_t render_behind_size)
|
|
|
|
|
{
|
|
|
|
|
UiOkDialog(text, caption, /*error=*/true, render_behind, render_behind_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UiErrorOkDialog(const char *text, const char *caption, bool error)
|
|
|
|
|
{
|
|
|
|
|
UiOkDialog(text, caption, error, nullptr, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UiErrorOkDialog(const char *text, UiItem *render_behind, std::size_t render_behind_size)
|
|
|
|
|
{
|
|
|
|
|
UiErrorOkDialog(text, nullptr, render_behind, render_behind_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace dvl
|