Skip to content

Commit

Permalink
refactor: split subscrwidget flags into two vars, trim gridflags
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Aug 20, 2023
1 parent 7d54ca5 commit a3db000
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 50 deletions.
14 changes: 7 additions & 7 deletions src/dialog/subscr_props.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,13 @@ std::shared_ptr<GUI::Widget> SubscrPropDialog::view()
}
),
INFOBTN("If the grid order should go right-to-left instead of left-to-right"),
gauge_gw[g++] = CBOX(w->gridflags, GAUGE_GRID_RTOL, "Grid Right to Left", 1),
gauge_gw[g++] = CBOX(w->flags, SUBSCR_GAUGE_GRID_RTOL, "Grid Right to Left", 1),
INFOBTN("If the grid order should go top-to-bottom instead of bottom-to-top"),
gauge_gw[g++] = CBOX(w->gridflags, GAUGE_GRID_TTOB, "Grid Top to Bottom", 1),
gauge_gw[g++] = CBOX(w->flags, SUBSCR_GAUGE_GRID_TTOB, "Grid Top to Bottom", 1),
INFOBTN("If the grid should grow in the columns before the rows"),
gauge_gw[g++] = CBOX(w->gridflags, GAUGE_GRID_COLUMN1ST, "Grid Column First", 1),
gauge_gw[g++] = CBOX(w->flags, SUBSCR_GAUGE_GRID_COLUMN1ST, "Grid Column First", 1),
INFOBTN("If the grid should alternate direction when finishing a row (or column)"),
gauge_gw[g++] = CBOX(w->gridflags, GAUGE_GRID_SNAKE, "Grid Snake Pattern", 1)
gauge_gw[g++] = CBOX(w->flags, SUBSCR_GAUGE_GRID_SNAKE, "Grid Snake Pattern", 1)
)
)
)
Expand Down Expand Up @@ -1430,10 +1430,10 @@ std::shared_ptr<GUI::Widget> SubscrPropDialog::view()
Column(padding = 0_px,
Checkbox(
text = "Is Selectable",
checked = local_subref->flags & SUBSCRFLAG_SELECTABLE,
checked = local_subref->genflags & SUBSCRFLAG_SELECTABLE,
onToggleFunc = [&](bool state)
{
SETFLAG(local_subref->flags, SUBSCRFLAG_SELECTABLE, state);
SETFLAG(local_subref->genflags, SUBSCRFLAG_SELECTABLE, state);
updateSelectable();
}),
selgs[0] = Rows<3>(
Expand Down Expand Up @@ -1527,7 +1527,7 @@ std::shared_ptr<GUI::Widget> SubscrPropDialog::view()

void SubscrPropDialog::updateSelectable()
{
bool seldis = !(local_subref->flags & SUBSCRFLAG_SELECTABLE);
bool seldis = !(local_subref->genflags & SUBSCRFLAG_SELECTABLE);
selgs[0]->setDisabled(seldis);
selframes[0]->setDisabled(seldis);
selframes[1]->setDisabled(seldis);
Expand Down
33 changes: 16 additions & 17 deletions src/new_subscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,11 @@ int32_t SubscrWidget::read(PACKFILE *f, word s_version)
return qe_invalid;
if(!p_igetw(&h,f))
return qe_invalid;
if(!p_igetl(&genflags,f))
return qe_invalid;
if(!p_igetl(&flags,f))
return qe_invalid;
if(flags&SUBSCRFLAG_SELECTABLE)
if(genflags&SUBSCRFLAG_SELECTABLE)
{
if(!p_igetl(&pos,f))
return qe_invalid;
Expand Down Expand Up @@ -791,9 +793,11 @@ int32_t SubscrWidget::write(PACKFILE *f) const
new_return(1);
if(!p_iputw(h,f))
new_return(1);
if(!p_iputl(genflags,f))
new_return(1);
if(!p_iputl(flags,f))
new_return(1);
if(flags&SUBSCRFLAG_SELECTABLE)
if(genflags&SUBSCRFLAG_SELECTABLE)
{
if(!p_iputl(pos,f))
new_return(1);
Expand Down Expand Up @@ -2160,7 +2164,7 @@ bool SW_ItemSlot::load_old(subscreen_object const& old)
pos_down = old.d5;
pos_left = old.d6;
pos_right = old.d7;
SETFLAG(flags,SUBSCRFLAG_SELECTABLE,pos>=0);
SETFLAG(genflags,SUBSCRFLAG_SELECTABLE,pos>=0);
SETFLAG(flags,SUBSCR_CURITM_INVIS,!(old.d2&0x1));
SETFLAG(flags,SUBSCR_CURITM_NONEQP,old.d2&0x2);
return true;
Expand Down Expand Up @@ -3229,9 +3233,9 @@ void SW_GaugePiece::draw(BITMAP* dest, int xofs, int yofs, SubscrPage& page) con
}
else
{
bool colbased = (gridflags&GAUGE_GRID_COLUMN1ST) || !gauge_wid;
bool rtol = (gridflags&GAUGE_GRID_RTOL), ttob = (gridflags&GAUGE_GRID_TTOB),
snake = (gridflags&GAUGE_GRID_SNAKE);
bool colbased = (flags&SUBSCR_GAUGE_GRID_COLUMN1ST) || !gauge_wid;
bool rtol = (flags&SUBSCR_GAUGE_GRID_RTOL), ttob = (flags&SUBSCR_GAUGE_GRID_TTOB),
snake = (flags&SUBSCR_GAUGE_GRID_SNAKE);
auto sz = (flags&SUBSCR_GAUGE_FULLTILE)?16:8;
bool snakeoffs = false;
if(colbased) //columns then rows
Expand Down Expand Up @@ -3318,7 +3322,6 @@ bool SW_GaugePiece::copy_prop(SubscrWidget const* src, bool all)
vspace = other->vspace;
grid_xoff = other->grid_xoff;
grid_yoff = other->grid_yoff;
gridflags = other->gridflags;
}
bool frcond = frames <= 1;
bool acond = frcond || !(flags & (SUBSCR_GAUGE_ANIM_UNDER|SUBSCR_GAUGE_ANIM_OVER));
Expand Down Expand Up @@ -3374,8 +3377,6 @@ int32_t SW_GaugePiece::read(PACKFILE* f, word s_version)
return qe_invalid;
if(gauge_wid || gauge_hei)
{
if(!p_getc(&gridflags, f))
return qe_invalid;
if(!p_getc(&hspace, f))
return qe_invalid;
if(!p_getc(&vspace, f))
Expand Down Expand Up @@ -3427,8 +3428,6 @@ int32_t SW_GaugePiece::write(PACKFILE* f) const
new_return(1);
if(gauge_wid || gauge_hei)
{
if(!p_putc(gridflags, f))
new_return(1);
if(!p_putc(hspace, f))
new_return(1);
if(!p_putc(vspace, f))
Expand Down Expand Up @@ -4117,7 +4116,7 @@ void SubscrPage::move_cursor(int dir, bool item_only)

for(int32_t i=0; i < contents.size(); ++i)
{
if(contents[i]->flags&SUBSCRFLAG_SELECTABLE)
if(contents[i]->genflags&SUBSCRFLAG_SELECTABLE)
{
if(firstValidPos==-1 && contents[i]->pos>=0)
firstValidPos=i;
Expand Down Expand Up @@ -4184,7 +4183,7 @@ void SubscrPage::move_cursor(int dir, bool item_only)
oldPositions.insert(curpos);

//Valid stop point?
if((widg->flags & SUBSCRFLAG_SELECTABLE) && (!item_only || widg->getItemVal() > -1))
if((widg->genflags & SUBSCRFLAG_SELECTABLE) && (!item_only || widg->getItemVal() > -1))
{
cursor_pos = curpos;
return;
Expand Down Expand Up @@ -4219,7 +4218,7 @@ int32_t SubscrPage::movepos_legacy(int dir, word startp, word fp, word fp2, word
if(SubscrWidget* widg = get_widg_pos(startp>>8,item_only))
if(widg->getType() == widgITEMSLOT
&& !(widg->flags&SUBSCR_CURITM_NONEQP)
&& (widg->flags & SUBSCRFLAG_SELECTABLE)
&& (widg->genflags & SUBSCRFLAG_SELECTABLE)
&& (!item_only || widg->getItemVal() > -1))
return startp; //Valid selectable slot
}
Expand All @@ -4231,7 +4230,7 @@ int32_t SubscrPage::movepos_legacy(int dir, word startp, word fp, word fp2, word

for(int32_t i=0; i < contents.size(); ++i)
{
if(contents[i]->getType()==widgITEMSLOT && (contents[i]->flags&SUBSCRFLAG_SELECTABLE))
if(contents[i]->getType()==widgITEMSLOT && (contents[i]->genflags&SUBSCRFLAG_SELECTABLE))
{
if(firstValidPos==-1 && contents[i]->pos>=0)
firstValidPos=i;
Expand Down Expand Up @@ -4310,7 +4309,7 @@ int32_t SubscrPage::movepos_legacy(int dir, word startp, word fp, word fp2, word

//Valid stop point?
if((!stay_on_page||(cp2&0xFF)==index)
&& (widg->flags & SUBSCRFLAG_SELECTABLE)
&& (widg->genflags & SUBSCRFLAG_SELECTABLE)
&& cp2 != fp && cp2 != fp2 && cp2 != fp3
&& (!equip_only || widg->getType()!=widgITEMSLOT || !(widg->flags & SUBSCR_CURITM_NONEQP))
&& (!item_only || widg->getItemVal()>-1))
Expand All @@ -4325,7 +4324,7 @@ SubscrWidget* SubscrPage::get_widg_pos(byte pos, bool item_only) const
{
for(size_t q = 0; q < contents.size(); ++q)
{
if(!(contents[q]->flags & SUBSCRFLAG_SELECTABLE))
if(!(contents[q]->genflags & SUBSCRFLAG_SELECTABLE))
continue;
if (item_only && contents[q]->getType() == widgITEMSLOT)
if (static_cast<SW_ItemSlot*>(contents[q])->flags & SUBSCR_CURITM_NONEQP)
Expand Down
64 changes: 38 additions & 26 deletions src/new_subscr.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,38 @@ enum //subscreen text alignment

#define SUBSCRFLAG_SELECTABLE 0x00000001

#define SUBSCRFLAG_GENERAL 0x0000FFFF

#define SUBSCRFLAG_SPEC_01 0x00010000
#define SUBSCRFLAG_SPEC_02 0x00020000
#define SUBSCRFLAG_SPEC_03 0x00040000
#define SUBSCRFLAG_SPEC_04 0x00080000
#define SUBSCRFLAG_SPEC_05 0x00100000
#define SUBSCRFLAG_SPEC_06 0x00200000
#define SUBSCRFLAG_SPEC_07 0x00400000
#define SUBSCRFLAG_SPEC_08 0x00800000
#define SUBSCRFLAG_SPEC_09 0x01000000
#define SUBSCRFLAG_SPEC_10 0x02000000
#define SUBSCRFLAG_SPEC_11 0x04000000
#define SUBSCRFLAG_SPEC_12 0x08000000
#define SUBSCRFLAG_SPEC_13 0x10000000
#define SUBSCRFLAG_SPEC_14 0x20000000
#define SUBSCRFLAG_SPEC_15 0x40000000
#define SUBSCRFLAG_SPEC_16 0x80000000
#define SUBSCRFLAG_SPECIFIC 0xFFFF0000
#define SUBSCRFLAG_SPEC_01 0x00000001
#define SUBSCRFLAG_SPEC_02 0x00000002
#define SUBSCRFLAG_SPEC_03 0x00000004
#define SUBSCRFLAG_SPEC_04 0x00000008
#define SUBSCRFLAG_SPEC_05 0x00000010
#define SUBSCRFLAG_SPEC_06 0x00000020
#define SUBSCRFLAG_SPEC_07 0x00000040
#define SUBSCRFLAG_SPEC_08 0x00000080
#define SUBSCRFLAG_SPEC_09 0x00000100
#define SUBSCRFLAG_SPEC_10 0x00000200
#define SUBSCRFLAG_SPEC_11 0x00000400
#define SUBSCRFLAG_SPEC_12 0x00000800
#define SUBSCRFLAG_SPEC_13 0x00001000
#define SUBSCRFLAG_SPEC_14 0x00002000
#define SUBSCRFLAG_SPEC_15 0x00004000
#define SUBSCRFLAG_SPEC_16 0x00008000
#define SUBSCRFLAG_SPEC_17 0x00010000
#define SUBSCRFLAG_SPEC_18 0x00020000
#define SUBSCRFLAG_SPEC_19 0x00040000
#define SUBSCRFLAG_SPEC_20 0x00080000
#define SUBSCRFLAG_SPEC_21 0x00100000
#define SUBSCRFLAG_SPEC_22 0x00200000
#define SUBSCRFLAG_SPEC_23 0x00400000
#define SUBSCRFLAG_SPEC_24 0x00800000
#define SUBSCRFLAG_SPEC_25 0x01000000
#define SUBSCRFLAG_SPEC_26 0x02000000
#define SUBSCRFLAG_SPEC_27 0x04000000
#define SUBSCRFLAG_SPEC_28 0x08000000
#define SUBSCRFLAG_SPEC_29 0x10000000
#define SUBSCRFLAG_SPEC_30 0x20000000
#define SUBSCRFLAG_SPEC_31 0x40000000
#define SUBSCRFLAG_SPEC_32 0x80000000

#define SUBSCRCOMPAT_FONT_RAND 0x01
struct SubscrWidget
Expand All @@ -197,7 +210,7 @@ struct SubscrWidget
int16_t y;
word w;
word h;
dword flags;
dword flags, genflags;

//if SUBSCRFLAG_SELECTABLE...
//...storing these as ints, but they could probably be bytes?
Expand Down Expand Up @@ -709,16 +722,15 @@ struct SW_Selector : public SubscrWidget
#define SUBSCR_GAUGE_ANIM_SKIP SUBSCRFLAG_SPEC_10
#define SUBSCR_GAUGE_INFITM_REQ SUBSCRFLAG_SPEC_11
#define SUBSCR_GAUGE_INFITM_BAN SUBSCRFLAG_SPEC_12

#define GAUGE_GRID_RTOL 0x01
#define GAUGE_GRID_TTOB 0x02
#define GAUGE_GRID_COLUMN1ST 0x04
#define GAUGE_GRID_SNAKE 0x08
#define SUBSCR_GAUGE_GRID_RTOL SUBSCRFLAG_SPEC_13
#define SUBSCR_GAUGE_GRID_TTOB SUBSCRFLAG_SPEC_14
#define SUBSCR_GAUGE_GRID_COLUMN1ST SUBSCRFLAG_SPEC_15
#define SUBSCR_GAUGE_GRID_SNAKE SUBSCRFLAG_SPEC_16
struct SW_GaugePiece : public SubscrWidget
{
SubscrMTInfo mts[4];
word frames = 1, speed = 1, delay, container;
byte gauge_wid, gauge_hei, gridflags;
byte gauge_wid, gauge_hei;
byte hspace, vspace, unit_per_frame;
int16_t grid_xoff, grid_yoff;
word anim_val;
Expand Down

0 comments on commit a3db000

Please sign in to comment.