Skip to content

Commit

Permalink
feat: ton more subscreen work
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Aug 20, 2023
1 parent ac5f25f commit e935320
Show file tree
Hide file tree
Showing 32 changed files with 1,413 additions and 1,424 deletions.
14 changes: 8 additions & 6 deletions src/base/qrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
byte quest_rules[QUESTRULES_NEW_SIZE];
byte extra_rules[EXTRARULES_SIZE];

bool get_qr(int index)
bool get_qr(int index,byte* qrptr)
{
return get_bit(quest_rules,index)!=0;
if(!qrptr) qrptr = quest_rules;
return get_bit(qrptr,index)!=0;
}
void set_qr(int index,bool state)
void set_qr(int index,bool state,byte* qrptr)
{
set_bit(quest_rules,index,state);
if(!qrptr) qrptr = quest_rules;
set_bit(qrptr,index,state);
}
bool get_er(int index)
{
return get_bit(extra_rules,index)!=0;
return get_qr(index,extra_rules);
}
void set_er(int index,bool state)
{
set_bit(extra_rules,index,state);
set_qr(index,state,extra_rules);
}

21 changes: 19 additions & 2 deletions src/base/qrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ enum
//52
qr_FREEFORM_SUBSCREEN_CURSOR, qr_SUBSCR_PRESS_TO_EQUIP, qr_FAIRY_FLAG_COMPAT, qr_MIRROR_PRISM_LAYERS,
qr_OLD_LENS_LAYEREFFECT, qr_PUSHBLOCK_SPRITE_LAYER, qr_OLD_SUBSCR, qr_ITM_0_INVIS_ON_BTNS,
//53
qr_NO_BUTTON_VERIFY,
//EMILY SPOT
//60
//CONNOR SPOT qr_ = 60*8,
Expand Down Expand Up @@ -221,10 +223,25 @@ enum extraRules
er_MAX
};

bool get_qr(int index);
void set_qr(int index,bool state);
enum //Rulesets
{
rulesetNONE, rulesetNES, rulesetFixedNES, rulesetBSZ, rulesetZ3, rulesetModern, rulesetLast
};

enum //Rule Templates
{
ruletemplateFixCompat, ruletemplateFixZSCompat,
ruletemplateNewSubscreen, ruletemplateOldSubscreen,
sz_ruletemplate
};

bool get_qr(int index,byte* qrptr = nullptr);
void set_qr(int index,bool state,byte* qrptr = nullptr);
bool get_er(int index);
void set_er(int index,bool state);
//Want to move these here, but looks complicated...
// void applyRuleset(int32_t ruleset, byte* qrptr = nullptr);
// void applyRuleTemplate(int32_t ruleTemplate, byte* qrptr = nullptr);

#endif

20 changes: 14 additions & 6 deletions src/base/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,25 +1050,33 @@ void zc_trace_clear()
ASSERT(trace_file);
}

std::string QRHINT(std::vector<int> qrs)
static std::string HINT_TY(std::vector<int> vals, dword ty)
{
if(qrs.empty()) return "";
if(vals.empty()) return "";
std::ostringstream oss;
bool comma = false;
oss << "$";
for(int qr : qrs)
oss << "$#" << ty << "#";
for(int v : vals)
{
if(comma)
oss << "," << qr;
oss << "," << v;
else
{
comma = true;
oss << qr;
oss << v;
}
}
oss << "$";
return oss.str();
}
std::string QRHINT(std::vector<int> qrs)
{
return HINT_TY(qrs,INFOHINT_T_QR);
}
std::string RULETMPL_HINT(std::vector<int> tmpls)
{
return HINT_TY(tmpls,INFOHINT_T_RULETMPL);
}

int binary_search_int(int b1, int b2, std::function<int(int,int&)> proc, int defval)
{
Expand Down
7 changes: 7 additions & 0 deletions src/base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ int32_t zc_trace_handler(const char *);
void zc_trace_clear();

std::string QRHINT(std::vector<int> qrs);
std::string RULETMPL_HINT(std::vector<int> tmpls);
enum //special insert types
{
INFOHINT_T_QR,
INFOHINT_T_RULETMPL,
INFOHINT_T_MAX
};

enum
{
Expand Down
5 changes: 3 additions & 2 deletions src/base/zdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2624,8 +2624,7 @@ struct gamedata
int32_t global_d[MAX_SCRIPT_REGISTERS]; // script-controlled global variables
std::vector< ZCArray <int32_t> > globalRAM;

byte awpn, bwpn, xwpn, ywpn; // Currently selected weapon slots
byte awpnpg, bwpnpg, xwpnpg, ywpnpg;
word awpn = 255, bwpn = 255, xwpn = 255, ywpn = 255;
int16_t abtn_itm = -1, bbtn_itm = -1, xbtn_itm = -1, ybtn_itm = -1;
int16_t forced_awpn = -1, forced_bwpn = -1, forced_xwpn = -1, forced_ywpn = -1;
bool isclearing; // The gamedata is being cleared
Expand Down Expand Up @@ -3035,6 +3034,8 @@ enum controls //Args for 'getInput()'
#define INT_BTN_EX2 0x20
#define INT_BTN_EX3 0x40
#define INT_BTN_EX4 0x80
#define INT_BTN_X INT_BTN_EX1
#define INT_BTN_Y INT_BTN_EX2

///////////////
/// MODULES ///
Expand Down
3 changes: 1 addition & 2 deletions src/dialog/about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ bool AboutDialog::handleMessage(const GUI::DialogMessage<message>& msg)
{
switch(msg.message)
{
case message::OK;
case message::CANCEL;
case message::OK:
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool AlertDialog::handleMessage(const GUI::DialogMessage<message>& msg)
case message::OK:
onEnd(true,dontshowagain);
return true;
case message::CANCEL
case message::CANCEL:
onEnd(false,dontshowagain);
return true;
}
Expand Down
129 changes: 99 additions & 30 deletions src/dialog/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#ifdef IS_ZQUEST
#include "quest_rules.h"
#include "zq/zq_files.h"

extern const GUI::ListData ruletemplatesList;
#endif

void displayinfo(std::string title, std::string text)
Expand Down Expand Up @@ -59,6 +62,17 @@ void InfoDialog::postinit()
std::string sub = dlgText.substr(pos+1,nextpos-pos-1);
dlgText.erase(pos,nextpos-pos+1);
#ifdef IS_ZQUEST
dword special_type = 0; //qr by default
if(sub[0] == '#') //Special type id given
{
auto nexthash = sub.find_first_of("#",1);
if(nexthash == std::string::npos || nexthash == 1)
continue; //invalid
if(sub.find_first_not_of("0123456789",1) != nexthash)
continue; //invalid
special_type = atoi(sub.substr(1,nexthash).c_str());
sub.erase(0,nexthash+1);
}
bool running = true;
while(running)
{
Expand All @@ -77,12 +91,21 @@ void InfoDialog::postinit()
if(sub2.size() < 1 || sub2.find_first_not_of("0123456789") != std::string::npos)
continue; //invalid
int val = atoi(sub2.c_str());
qrs.insert(val);

switch(special_type)
{
case INFOHINT_T_QR:
qrs.insert(val);
break;
case INFOHINT_T_RULETMPL:
ruleTemplates.insert(val);
break;
}
}
#endif
}

if(qrs.size())
if(qrs.size() || ruleTemplates.size())
{
dest_qrs = next_dest_qr;
next_dest_qr = local_qrs;
Expand All @@ -94,29 +117,64 @@ std::shared_ptr<GUI::Widget> InfoDialog::view()
{
using namespace GUI::Builder;
using namespace GUI::Props;
std::shared_ptr<GUI::Widget> widg;
std::shared_ptr<GUI::Grid> gr;
std::shared_ptr<GUI::Grid> closeRow;

bool add_grid = false, addok = false;
#ifdef IS_ZQUEST
add_grid = addok = qrs.size() || ruleTemplates.size();
if(add_grid)
gr = Row(padding = 0_px);
if(qrs.size())
{
GUI::ListData tosearch = combinedQRList()+combinedZSRList();
widg = Frame(title = "Related QRs",
QRPanel(
padding = 3_px,
onToggle = message::TOGGLE_QR,
onCloseInfo = message::REFRESH,
initializer = local_qrs,
count = 0,
data = tosearch.filter(
[&](GUI::ListItem& itm)
GUI::ListData tosearch = (combinedQRList()+combinedZSRList()).filter(
[&](GUI::ListItem& itm)
{
if(qrs.contains(itm.value))
return true;
return false;
});
if(tosearch.size())
{
gr->add(Frame(title = "Related QRs",
QRPanel(
padding = 3_px,
onToggle = message::TOGGLE_QR,
onCloseInfo = message::REFR_INFO,
initializer = local_qrs,
count = 0,
data = tosearch
)
));
}
}
if(ruleTemplates.size())
{
std::shared_ptr<GUI::Grid> cboxes = Rows<2>();
cboxes->add(Label(colSpan = 2, text = "Note: Selecting a rule template"
"\nwill write to numerous QRs."));
int cnt = 0;
for(size_t q = 0; q < ruletemplatesList.size(); ++q)
{
if(!ruleTemplates.contains(q))
continue;
std::string infostr = ruletemplatesList.getInfo(q);
cboxes->add(infostr.size() ? INFOBTN(infostr) : DINFOBTN());
cboxes->add(Checkbox(
hAlign = 0.0, checked = false,
text = ruletemplatesList.getText(q),
onToggleFunc = [=](bool state)
{
if(qrs.contains(itm.value))
return true;
return false;
})
)
);
on_templates[q] = state;
}
));
++cnt;
}
if(cnt)
gr->add(Frame(title = "Related Rule Templates",cboxes));
}
#endif
if(addok)
{
closeRow = Row(padding = 0_px,
Button(
text = "OK",
Expand All @@ -130,9 +188,7 @@ std::shared_ptr<GUI::Widget> InfoDialog::view()
);
}
else
#endif
{
widg = DummyWidget(padding=0_px);
closeRow = Row(padding = 0_px,
Button(
text = "&Close",
Expand All @@ -141,23 +197,26 @@ std::shared_ptr<GUI::Widget> InfoDialog::view()
focused = true)
);
}

return Window(

std::shared_ptr<GUI::Grid> main_col;
window = Window(
title = dlgTitle,
onClose = 0,
onClose = message::CANCEL,
hPadding = 0_px,
Column(
main_col = Column(
hPadding = 0_px,
Label(noHLine = true,
hPadding = 2_em,
maxLines = 20,
maxwidth = Size::pixels(zq_screen_w)-12_px-5_em,
textAlign = 1,
text = dlgText),
widg,
closeRow
text = dlgText)
)
);
if(add_grid)
main_col->add(gr);
main_col->add(closeRow);
return window;
}

bool InfoDialog::handleMessage(const GUI::DialogMessage<message>& msg)
Expand All @@ -168,18 +227,28 @@ bool InfoDialog::handleMessage(const GUI::DialogMessage<message>& msg)
toggle_bit(local_qrs, msg.argument);
return false;
case message::OK:
#ifdef IS_ZQUEST
if(dest_qrs)
{
if(ruleTemplates.size())
{
for(int q = 0; q < sz_ruletemplate; ++q)
{
if(on_templates[q])
applyRuleTemplate(q,local_qrs);
}
}
memcpy(dest_qrs, local_qrs, sizeof(local_qrs));
}
#endif
[[fallthrough]];
case message::CANCEL:
if(dest_qrs)
{
next_dest_qr = dest_qrs;
}
return true;
case message::REFRESH:
case message::REFR_INFO:
rerun_dlg = true;
return true;
}
Expand Down
Loading

0 comments on commit e935320

Please sign in to comment.