Skip to content

Commit

Permalink
refactor: don't tint behind dropdown lists (allow skipping dlgs tint)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 authored and connorjclark committed Dec 15, 2023
1 parent cbb1ee9 commit cb8f871
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 224 deletions.
86 changes: 23 additions & 63 deletions src/base/gui.cpp
Expand Up @@ -40,21 +40,12 @@ void broadcast_dialog_message(DIALOG* dialog, int32_t msg, int32_t c)
/********** GUI ***********/
/****************************/

// make it global so the joystick button routine can set joy_on=TRUE
DIALOG_PLAYER *player = NULL;

int32_t do_zqdialog(DIALOG *dialog, int32_t focus_obj, bool checkexit)
static int run_zq_dialog(DIALOG *dlg, int focus_obj, bool checkexit)
{
DIALOG_PLAYER *player2;
ASSERT(dialog);

popup_zqdialog_start();

player2 = init_dialog(dialog, focus_obj);

DIALOG_PLAYER *player = init_dialog(dlg,focus_obj);
bool should_draw = true;
int num_idle_frames = 0;
while(update_dialog(player2))
while(update_dialog(player))
{
if(checkexit)
{
Expand All @@ -65,9 +56,9 @@ int32_t do_zqdialog(DIALOG *dialog, int32_t focus_obj, bool checkexit)
return -1;
}
}
if (player2->res & D_REDRAWME)
if (player->res & D_REDRAWME)
{
player2->res &= ~D_REDRAWME;
player->res &= ~D_REDRAWME;
should_draw = true;
}
if (should_draw)
Expand All @@ -87,67 +78,36 @@ int32_t do_zqdialog(DIALOG *dialog, int32_t focus_obj, bool checkexit)
}
al_rest(1. / 60);
}

int ret = shutdown_dialog(player2);

return shutdown_dialog(player);
}
int do_zqdialog(DIALOG *dialog, int focus_obj, bool checkexit)
{
ASSERT(dialog);
popup_zqdialog_start();
int ret = run_zq_dialog(dialog, focus_obj, checkexit);
popup_zqdialog_end();
return ret;
}
int32_t do_zqdialog_custom(DIALOG *dialog, int32_t focus_obj, bool checkexit, std::function<bool(int)> proc)
int do_zq_subdialog(DIALOG *dialog, int focus_obj, bool checkexit)
{
ASSERT(dialog);
popup_zqdialog_start();
zqdialog_set_skiptint(true);
int ret = run_zq_dialog(dialog, focus_obj, checkexit);
popup_zqdialog_end();
return ret;
}
int do_zqdialog_custom(DIALOG *dialog, int focus_obj, bool checkexit, std::function<bool(int)> proc)
{
DIALOG_PLAYER *player2;
ASSERT(dialog);
int ret;

popup_zqdialog_start();

while(true)
{
player2 = init_dialog(dialog, focus_obj);

bool should_draw = true;
int num_idle_frames = 0;
while(update_dialog(player2))
{
if(checkexit)
{
HANDLE_CLOSE_ZQDLG();
if(exiting_program)
{
proc(-1);
popup_zqdialog_end();
return -1;
}
}
if (player2->res & D_REDRAWME)
{
player2->res &= ~D_REDRAWME;
should_draw = true;
}
if (should_draw)
{
should_draw = false;
num_idle_frames = 0;
update_hw_screen(true);
al_rest(1. / 60);
continue;
}

// Not perfect, but beats using 100% of CPU.
// The above may miss things, so draw at least a few times a second.
if (num_idle_frames++ == 15)
{
should_draw = 1;
}
al_rest(1. / 60);
}

ret = shutdown_dialog(player2);

ret = run_zq_dialog(dialog, focus_obj, checkexit);
if(proc(ret))
break;
}

popup_zqdialog_end();
return ret;
}
Expand Down
17 changes: 9 additions & 8 deletions src/base/gui.h
Expand Up @@ -4,11 +4,12 @@
#include "base/zdefs.h"
#include "base/render.h"

extern DIALOG_PLAYER *player;

void zc_set_gui_bmp(BITMAP* bmp);
BITMAP* zc_get_gui_bmp();
int32_t do_zqdialog(DIALOG *dialog, int32_t focus_obj, bool checkexit = false);
int32_t do_zqdialog_custom(DIALOG *dialog, int32_t focus_obj, bool checkexit, std::function<bool(int)> proc);
void new_gui_popup_dialog(DIALOG* dialog, int32_t focus_obj, bool& done, bool& running);
#endif // _GUI_H_
void zc_set_gui_bmp(BITMAP* bmp);
BITMAP* zc_get_gui_bmp();
int do_zqdialog(DIALOG *dialog, int focus_obj, bool checkexit = false);
int do_zq_subdialog(DIALOG *dialog, int focus_obj, bool checkexit = false);
int do_zqdialog_custom(DIALOG *dialog, int focus_obj, bool checkexit, std::function<bool(int)> proc);
void new_gui_popup_dialog(DIALOG* dialog, int focus_obj, bool& done, bool& running);

#endif

32 changes: 19 additions & 13 deletions src/base/render.cpp
Expand Up @@ -649,6 +649,24 @@ namespace MouseSprite

BITMAP* zqdialog_bg_bmp = nullptr;
static RenderTreeItem* active_dlg_rti = nullptr;
void zqdialog_set_skiptint(bool skipTint)
{
if(active_dlg_rti)
active_dlg_rti->skip_tint = skipTint;
}
static RenderTreeItem* get_active_dialog(bool forTint = false)
{
auto& children = rti_dialogs.get_children();
for (auto it = children.rbegin(); it != children.rend(); it++)
{
auto child = *it;
if(forTint && child->skip_tint)
continue;
if(child->name != "tint")
return child;
}
return nullptr;
}
void popup_zqdialog_start(int x, int y, int w, int h, int transp)
{
if(w < 0) w = zq_screen_w;
Expand Down Expand Up @@ -684,18 +702,6 @@ void popup_zqdialog_start(int x, int y, int w, int h, int transp)
*allegro_errno = ENOMEM;
}
}

static RenderTreeItem* get_active_dialog()
{
auto& children = rti_dialogs.get_children();
for (auto it = children.rbegin(); it != children.rend(); it++)
{
auto child = *it;
if (child->name != "tint") return child;
}
return nullptr;
}

void popup_zqdialog_end()
{
if (active_dlg_rti)
Expand Down Expand Up @@ -828,7 +834,7 @@ void reload_dialog_tint()
rti_tint.dirty = false;
}

auto next_dialog_rti = get_active_dialog();
auto next_dialog_rti = get_active_dialog(true);
if (next_dialog_rti)
rti_dialogs.add_child_before(&rti_tint, next_dialog_rti);
else
Expand Down
2 changes: 2 additions & 0 deletions src/base/render.h
Expand Up @@ -126,6 +126,7 @@ class RenderTreeItem
// `bitmap` will still be rendered.
bool freeze = false;
bool dirty = true;
bool skip_tint = false;

RenderTreeItem(std::string name, RenderTreeItem* parent = nullptr);
virtual ~RenderTreeItem();
Expand Down Expand Up @@ -242,6 +243,7 @@ void render_a4_a5(BITMAP* src,int sx,int sy,int dx,int dy,int w,int h,int maskin

extern BITMAP* zqdialog_bg_bmp;
extern ALLEGRO_COLOR* override_dlg_tint;
void zqdialog_set_skiptint(bool skipTint);
void popup_zqdialog_start(int x = 0, int y = 0, int w = -1, int h = -1, int transp = 0xFF);
void popup_zqdialog_end();
void popup_zqdialog_start_a5();
Expand Down

0 comments on commit cb8f871

Please sign in to comment.