Skip to content

Commit

Permalink
feat: Add 'Overlay Subscreens'
Browse files Browse the repository at this point in the history
These subscreens draw over the screen at all times, both during play and the active subscreen.
As usual, widgets can have the 'Display' settings on widgets to change their visibility while the active subscreen is up, down, and scrolling.
This can be used for various things like displaying your current keys over the corner of the game screen.
  • Loading branch information
EmilyV99 committed Aug 20, 2023
1 parent eae4f80 commit 82a7b00
Show file tree
Hide file tree
Showing 25 changed files with 1,035 additions and 811 deletions.
1 change: 1 addition & 0 deletions modules/zquest/ZQuestGUI.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ src/dialog/about.cpp
src/dialog/subscr_props.cpp
src/dialog/subscr_settings.cpp
src/dialog/subscr_transition.cpp
src/dialog/subscr_lists_edit.cpp
src/dialog/room.cpp
src/dialog/foodlg.cpp
src/dialog/quest_rules.cpp
Expand Down
3 changes: 3 additions & 0 deletions resources/docs/ZScript_Additions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6515,6 +6515,9 @@ int ActiveSubscreen;

int PassiveSubscreen;
* The passive subscreen ID.

int OverlaySubscreen;
* The overlay subscreen ID.

int Grid[8];
* The rooms displayed either when the player has the map item,
Expand Down
1 change: 1 addition & 0 deletions src/base/dmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct dmap
byte tmusictrack;
byte active_subscreen;
byte passive_subscreen;
byte overlay_subscreen;
// int32_t emusic;
//byte padding;
//204
Expand Down
2 changes: 1 addition & 1 deletion src/base/zdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ enum {ENC_METHOD_192B104=0, ENC_METHOD_192B105, ENC_METHOD_192B185, ENC_METHOD_2
#define V_COMBOS 42
#define V_CSETS 5 //palette data
#define V_MAPS 28
#define V_DMAPS 18
#define V_DMAPS 19
#define V_DOORS 1
#define V_ITEMS 57
#define V_WEAPONS 8
Expand Down
148 changes: 148 additions & 0 deletions src/dialog/subscr_lists_edit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#include "subscr_lists_edit.h"
#include <gui/builder.h>
#include "alert.h"
#include <utility>
#include <sstream>
#include <fmt/format.h>
#include "new_subscr.h"
#include "zq/zq_subscr.h"
#include "zc_list_data.h"
#include "gui/use_size.h"
#include "gui/common.h"

extern ZCSubscreen subscr_edit;
extern DIALOG *subscreen_dlg;

void delete_subscreen(size_t ind, byte ty);
void do_edit_subscr(size_t ind, byte ty);

static std::vector<ZCSubscreen>* subscr_vecs[sstMAX];
static const std::string _titles[sstMAX] = {"Active","Passive","Overlay"};
static const std::string _infos[sstMAX] = {
"The subscreen that actively opens when you press 'Start'",
"The subscreen visible at the top of the screen normally, which moves down when the active opens.",
"Like the passive, but visible across the whole screen and does NOT move down for the active opening."
};

void call_subscr_listedit_dlg()
{
SubscrListEditDialog().show();
}

static size_t editsub_tabptr = 0;
std::shared_ptr<GUI::Widget> SubscrListEditDialog::view()
{
using namespace GUI::Builder;
using namespace GUI::Props;

std::shared_ptr<GUI::TabPanel> g;
window = Window(
title = "Edit Subscreens",
onClose = message::DONE,
Column(
g = TabPanel(ptr = &editsub_tabptr),
Rows<2>(
Button(
text = "Done",
topPadding = 0.5_em,
minwidth = 90_px,
onClick = message::DONE,
focused = true)
)
)
);

subscr_vecs[0] = &subscreens_active;
subscr_vecs[1] = &subscreens_passive;
subscr_vecs[2] = &subscreens_overlay;
for(int q = 0; q < sstMAX; ++q)
{
auto* vec = subscr_vecs[q];
subscr_lists[q] = GUI::ListData(vec->size(),
[&,vec](size_t ind)
{
return fmt::format("{} ({:03d})",(*vec)[ind].name,ind);
},
[&](size_t ind){return int32_t(ind);});
subscr_lists[q].add(fmt::format("<New {} Subscreen>",_titles[q]),vec->size());
message edit_msg = message(int(message::EDIT0)+q),
del_msg = message(int(message::DEL0)+q);
g->add(TabRef(name = _titles[q],
Column(
INFOBTN_EX(_infos[q], maxheight = 1.5_em),
List(data = subscr_lists[q],
selectedValue = sel_inds[q],
onDClick = edit_msg,
onSelectFunc = [&,q](int32_t val)
{
sel_inds[q] = val;
}),
Row(
Button(
text = "Edit",
minwidth = 90_px, hAlign = 1.0,
onClick = edit_msg),
Button(
text = "Delete",
minwidth = 90_px, hAlign = 0.0,
onClick = del_msg)
)
)
));
}

return window;
}

bool SubscrListEditDialog::handleMessage(const GUI::DialogMessage<message>& msg)
{
bool refresh = false;
switch(msg.message)
{
case message::REFR_INFO:
break;
case message::EDIT0:
case message::EDIT1:
case message::EDIT2:
{
size_t cur_type = int(msg.message)-int(message::EDIT0);
do_edit_subscr(sel_inds[cur_type],cur_type);
refresh = true;
break;
}
case message::DEL0:
case message::DEL1:
case message::DEL2:
{
size_t cur_type = int(msg.message)-int(message::DEL0);
auto& vec = *subscr_vecs[cur_type];
if(sel_inds[cur_type] >= vec.size())
return false;
bool run = false;
AlertDialog(fmt::format("Delete {} Subscreen?",_titles[cur_type]),
fmt::format("Are you sure you want to delete {} Subscreen {} '{}'?"
" This cannot be undone!", _titles[cur_type], sel_inds[cur_type],
vec[sel_inds[cur_type]].name),
[&](bool ret,bool)
{
run = ret;
}).show();
if(run)
delete_subscreen(sel_inds[cur_type],cur_type);
refresh = true;
break;
}
case message::REFRESH:
refresh = true;
break;
case message::DONE:
return true;
}
if(refresh)
{
rerun_dlg = true;
return true;
}
return false;
}

35 changes: 35 additions & 0 deletions src/dialog/subscr_lists_edit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef ZC_DIALOG_SUBSCR_LISTS_EDIT_H
#define ZC_DIALOG_SUBSCR_LISTS_EDIT_H

#include <gui/dialog.h>
#include <gui/window.h>
#include <gui/button.h>
#include <initializer_list>
#include <string>
#include <string_view>
#include "subscr.h"

void call_subscr_listedit_dlg();

class SubscrListEditDialog: public GUI::Dialog<SubscrListEditDialog>
{
public:
enum class message
{
REFR_INFO, REFRESH, DONE, EDIT0, EDIT1, EDIT2, DEL0, DEL1, DEL2
};

SubscrListEditDialog() = default;

std::shared_ptr<GUI::Widget> view() override;
bool handleMessage(const GUI::DialogMessage<message>& msg);
protected:
std::shared_ptr<GUI::Window> window;

GUI::ListData subscr_lists[sstMAX];
size_t sel_inds[sstMAX];

void refr_info();
};

#endif
11 changes: 7 additions & 4 deletions src/dialog/subscr_props.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,9 @@ std::shared_ptr<GUI::Widget> SubscrPropDialog::view()
std::shared_ptr<GUI::Grid> g1;
loc_grid = Column(
Row(
Column(
Label(text = "Display:"),
Rows<2>(
Label(text = "Display:", colSpan = 2),
INFOBTN("Draws while the active subscreen is UP (closed)"),
Checkbox(
text = "Active Up", hAlign = 0.0,
checked = local_subref->posflags & sspUP,
Expand All @@ -366,6 +367,7 @@ std::shared_ptr<GUI::Widget> SubscrPropDialog::view()
SETFLAG(local_subref->posflags,sspUP,state);
}
),
INFOBTN("Draws while the active subscreen is DOWN (open)"),
Checkbox(
text = "Active Down", hAlign = 0.0,
checked = local_subref->posflags & sspDOWN,
Expand All @@ -374,6 +376,7 @@ std::shared_ptr<GUI::Widget> SubscrPropDialog::view()
SETFLAG(local_subref->posflags,sspDOWN,state);
}
),
INFOBTN("Draws while the active subscreen is SCROLLING (opening/closing)"),
Checkbox(
text = "Active Scrolling", hAlign = 0.0,
checked = local_subref->posflags & sspSCROLLING,
Expand Down Expand Up @@ -893,10 +896,10 @@ std::shared_ptr<GUI::Widget> SubscrPropDialog::view()
INFOBTN("If >1, displays multiple gauge pieces height-wise."),
//
Label(text = "HSpace:", hAlign = 1.0),
gauge_gw[g++] = NUM_FIELD(w->hspace, 0, 255),
gauge_gw[g++] = NUM_FIELD(w->hspace, -128, 127),
INFOBTN("Extra space between gauge pieces width-wise."),
Label(text = "VSpace:", hAlign = 1.0),
gauge_gw[g++] = NUM_FIELD(w->vspace, 0, 255),
gauge_gw[g++] = NUM_FIELD(w->vspace, -128, 127),
INFOBTN("Extra space between gauge pieces height-wise."),
//
Label(text = "Grid XOffset:", hAlign = 1.0),
Expand Down
1 change: 1 addition & 0 deletions src/gui/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int32_t List::getSelectedValue() const

void List::setIndex()
{
if (!listData || !listData->size()) return;
// Find a valid selection. We'll take the first thing with a matching
// value. If nothing matches exactly, take the one that's closest to
// the selected value.
Expand Down
40 changes: 28 additions & 12 deletions src/jwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9284,33 +9284,49 @@ int32_t new_tab_proc(int32_t msg, DIALOG *d, int32_t c)



int32_t jwin_hline_proc(int32_t msg, DIALOG *d, int32_t c)
int32_t jwin_hline_proc(int32_t msg, DIALOG *d, int32_t)
{
//these are here to bypass compiler warnings about unused arguments
c=c;

ASSERT(d);

if(msg==MSG_DRAW)
{
_allegro_hline(screen, d->x, d->y, d->x+d->w-1, scheme[jcMEDDARK]);
_allegro_hline(screen, d->x, d->y+1, d->x+d->w-1, scheme[jcLIGHT]);
if(d->w < 1) return D_O_K;
for(int q = 0; q <= d->d1; ++q)
{
if(d->d2&1)
{
_allegro_hline(screen, d->x, d->y+q, d->x+d->w-1, d->fg);
}
else
{
_allegro_hline(screen, d->x, d->y-q, d->x+d->w-1, scheme[jcMEDDARK]);
_allegro_hline(screen, d->x, d->y+1+q, d->x+d->w-1, scheme[jcLIGHT]);
}
}
}

return D_O_K;
}

int32_t jwin_vline_proc(int32_t msg, DIALOG *d, int32_t c)
int32_t jwin_vline_proc(int32_t msg, DIALOG *d, int32_t)
{
//these are here to bypass compiler warnings about unused arguments
c=c;

ASSERT(d);

if(msg==MSG_DRAW)
{
_allegro_vline(screen, d->x, d->y, d->y+d->h-1, scheme[jcMEDDARK]);
_allegro_vline(screen, d->x+1, d->y, d->y+d->h-1, scheme[jcLIGHT]);
if(d->h < 1) return D_O_K;
for(int q = 0; q <= d->d1; ++q)
{
if(d->d2&1)
{
_allegro_vline(screen, d->x+q, d->y, d->y+d->h-1, d->fg);
}
else
{
_allegro_vline(screen, d->x+q, d->y, d->y+d->h-1, scheme[jcMEDDARK]);
_allegro_vline(screen, d->x+1-q, d->y, d->y+d->h-1, scheme[jcLIGHT]);
}
}
}

return D_O_K;
Expand Down
14 changes: 7 additions & 7 deletions src/new_subscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3906,7 +3906,7 @@ int32_t SW_MiscGaugePiece::read(PACKFILE *f, word s_version)
{
if(auto ret = SW_GaugePiece::read(f, s_version))
return ret;
if(!p_getc(&counter, f))
if(!p_igetw(&counter, f))
return qe_invalid;
if(!p_igetw(&per_container,f))
return qe_invalid;
Expand All @@ -3916,7 +3916,7 @@ int32_t SW_MiscGaugePiece::write(PACKFILE *f) const
{
if(auto ret = SW_GaugePiece::write(f))
return ret;
if(!p_putc(counter, f))
if(!p_iputw(counter, f))
new_return(1);
if(!p_iputw(per_container,f))
new_return(1);
Expand Down Expand Up @@ -4880,8 +4880,8 @@ int32_t ZCSubscreen::read(PACKFILE *f, word s_version)
return qe_invalid;
if(!p_igetl(&flags,f))
new_return(1);
bool passive = sub_type == sstPASSIVE;
if(!passive)
bool active = sub_type == sstACTIVE;
if(active)
{
for(int q = 0; q < 4; ++q)
if(!p_igetw(&def_btns[q],f))
Expand Down Expand Up @@ -4924,8 +4924,8 @@ int32_t ZCSubscreen::write(PACKFILE *f) const
new_return(1);
if(!p_iputl(flags,f))
new_return(1);
bool passive = sub_type == sstPASSIVE;
if(!passive)
bool active = sub_type == sstACTIVE;
if(active)
{
for(int q = 0; q < 4; ++q)
if(!p_iputw(def_btns[q],f))
Expand All @@ -4948,7 +4948,7 @@ int32_t ZCSubscreen::write(PACKFILE *f) const
}
}
byte pagecnt = zc_min(MAX_SUBSCR_PAGES,pages.size());
if(pagecnt && passive)
if(pagecnt && !active)
pagecnt = 1;
if(!p_putc(pagecnt,f))
new_return(1);
Expand Down
6 changes: 3 additions & 3 deletions src/new_subscr.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,8 @@ struct SW_GaugePiece : public SubscrWidget
{
SubscrMTInfo mts[4];
word frames = 1, speed = 1, delay, container;
byte gauge_wid, gauge_hei;
byte hspace, vspace, unit_per_frame;
byte gauge_wid, gauge_hei, unit_per_frame;
int8_t hspace, vspace;
int16_t grid_xoff, grid_yoff;
word anim_val;
int16_t inf_item = -1;
Expand Down Expand Up @@ -845,7 +845,7 @@ struct SW_MagicGaugePiece : public SW_GaugePiece

struct SW_MiscGaugePiece : public SW_GaugePiece
{
byte counter;
int16_t counter;
word per_container = 1;

SW_MiscGaugePiece() = default;
Expand Down
Loading

0 comments on commit 82a7b00

Please sign in to comment.