Skip to content

Commit

Permalink
feat: 'subscreenpage' datatype implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Sep 9, 2023
1 parent 6402650 commit 0d049c6
Show file tree
Hide file tree
Showing 9 changed files with 478 additions and 115 deletions.
46 changes: 44 additions & 2 deletions resources/docs/ZScript_Additions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8679,11 +8679,11 @@ void SetName(char32[] buf);
//
int TransClock;
* The timer clock used by the currently active transition.
* '-1' indicates no transition. Writing to '-1' clears the current transition.
* Writing a positive value starts a transition if none is currently active.
int TransType;
* The transition type currently active.
* Compare with the 'TRANS_TY_' constants.
* Will be 'TRANS_TY_NONE' if no transition is currently active.
* Write this to forcibly start/stop a transition.
bool TransFlags[];
* The flags for the current transition.
* Use the 'TRANSFLAG_' constants to access these.
Expand All @@ -8698,6 +8698,9 @@ int TransToPage;
// Only on ACTIVE subscreens:
//

void SwapPages(int index1, int index2);
* Swaps the pages at the two indexes.

int CursorPos;
* The position value of the selector.

Expand Down Expand Up @@ -8761,6 +8764,45 @@ int SelectorDelay[2];
// subscreenpage //
///////////////////// subscreenpage

int Index;
* Read-only. The index of this page within the subscreen.

int NumWidgets;
* Read-only. The number of widgets on the page.

subscreenwidget Widgets[];
* Read-only. The widgets on the page, ordered by their index.

subscreendata SubData;
* Read-only. The subscreendata that owns this page.

//
// Only on ACTIVE subscreens:
//

int CursorPos;
* The position value of the selector.

subscreenwidget CreateWidget(int type);
* Adds a new widget of the specified type to the end of the page.
* Returns that widget, or NULL if fails.

void SwapWidgets(int index1, int index2);
* Swaps the widgets at the two indexes.

subscreenwidget FindWidget(int cursor_pos);
* Returns the widget designated by the specified cursor position,
* or NULL if it fails.

int SelectorMove(int cursor_pos, int dir, int flags)
* Returns the new cursor position found by moving in 'dir' from 'cursor_pos'.
* 'flags' determines:
* - SUBSEL_FLAG_NO_NONEQUIP: Skip widgets that are "Non-equippable"
* - SUBSEL_FLAG_NEED_ITEM: Skip widgets that currently have no equippable item

void Delete();
* Deletes the page.
* If it is the last page, an empty page will be created in its' place.

///////////////////////
// subscreenwidget //
Expand Down
4 changes: 3 additions & 1 deletion resources/include/std_zh/std_constants.zh
Original file line number Diff line number Diff line change
Expand Up @@ -3975,7 +3975,6 @@ enum

enum //Transition Types
{
TRANS_TY_NONE = -1,
TRANS_TY_INSTANT,
TRANS_TY_SLIDE,
TRANS_TY_PIXEL,
Expand Down Expand Up @@ -4007,5 +4006,8 @@ enum //Transition Flags
TRANSFLAG_NO_HIDE_SELECTOR,
TRANSFLAG_MAX
};

DEFINE SUBSEL_FLAG_NO_NONEQUIP = 0x01;
DEFINE SUBSEL_FLAG_NEED_ITEM = 0x02;
//} End section for engine subscreen stuff

44 changes: 22 additions & 22 deletions src/parser/ByteCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2327,14 +2327,14 @@ string ZScript::VarToString(int32_t ID)
case SUBDATATRANSTOPG: return "SUBDATATRANSTOPG";
case SUBDATASELECTORFLASHCSET: return "SUBDATASELECTORFLASHCSET";
case GAMEASUBOPEN: return "GAMEASUBOPEN";
case RESRVD_VAR_EMILY_84: return "RESRVD_VAR_EMILY_84";
case RESRVD_VAR_EMILY_85: return "RESRVD_VAR_EMILY_85";
case RESRVD_VAR_EMILY_86: return "RESRVD_VAR_EMILY_86";
case RESRVD_VAR_EMILY_87: return "RESRVD_VAR_EMILY_87";
case RESRVD_VAR_EMILY_88: return "RESRVD_VAR_EMILY_88";
case RESRVD_VAR_EMILY_89: return "RESRVD_VAR_EMILY_89";
case RESRVD_VAR_EMILY_90: return "RESRVD_VAR_EMILY_90";
case RESRVD_VAR_EMILY_91: return "RESRVD_VAR_EMILY_91";
case GAMENUMASUB: return "GAMENUMASUB";
case GAMENUMPSUB: return "GAMENUMPSUB";
case GAMENUMOSUB: return "GAMENUMOSUB";
case SUBPGINDEX: return "SUBPGINDEX";
case SUBPGNUMWIDG: return "SUBPGNUMWIDG";
case SUBPGWIDGETS: return "SUBPGWIDGETS";
case SUBPGSUBDATA: return "SUBPGSUBDATA";
case SUBPGCURSORPOS: return "SUBPGCURSORPOS";
case RESRVD_VAR_EMILY_92: return "RESRVD_VAR_EMILY_92";
case RESRVD_VAR_EMILY_93: return "RESRVD_VAR_EMILY_93";
case RESRVD_VAR_EMILY_94: return "RESRVD_VAR_EMILY_94";
Expand Down Expand Up @@ -2703,9 +2703,9 @@ string OLoadSubscreenDataRV::toString() const
{
return "LOADSUBDATARV " + getFirstArgument()->toString() + "," + getSecondArgument()->toString();
}
string ONumSubscreensV::toString() const
string OSwapSubscrV::toString() const
{
return "NUMSUBSCREENSV " + getArgument()->toString();
return "SWAPSUBSCREENV " + getArgument()->toString();
}
string OGetSubscreenName::toString() const
{
Expand Down Expand Up @@ -6731,29 +6731,29 @@ string OReservedZ3_10::toString() const
}


string OReservedEmily_3::toString() const
string OSubscrSwapPages::toString() const
{
return "RESRVD_OP_EMILY_3";
return "SUBDATA_SWAP_PAGES";
}
string OReservedEmily_4::toString() const
string OSubscrPgFindWidget::toString() const
{
return "RESRVD_OP_EMILY_4";
return "SUBPAGE_FIND_WIDGET";
}
string OReservedEmily_5::toString() const
string OSubscrPgMvCursor::toString() const
{
return "RESRVD_OP_EMILY_5";
return "SUBPAGE_MOVE_SEL";
}
string OReservedEmily_6::toString() const
string OSubscrPgSwapWidgets::toString() const
{
return "RESRVD_OP_EMILY_6";
return "SUBPAGE_SWAP_WIDG";
}
string OReservedEmily_7::toString() const
string OSubscrPgNewWidget::toString() const
{
return "RESRVD_OP_EMILY_7";
return "SUBPAGE_NEW_WIDG";
}
string OReservedEmily_8::toString() const
string OSubscrPgDelete::toString() const
{
return "RESRVD_OP_EMILY_8";
return "SUBPAGE_DELETE";
}
string OReservedEmily_9::toString() const
{
Expand Down
46 changes: 23 additions & 23 deletions src/parser/ByteCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1617,14 +1617,14 @@
#define SUBDATATRANSTOPG 1529
#define SUBDATASELECTORFLASHCSET 1530
#define GAMEASUBOPEN 1531
#define RESRVD_VAR_EMILY_84 1532
#define RESRVD_VAR_EMILY_85 1533
#define RESRVD_VAR_EMILY_86 1534
#define RESRVD_VAR_EMILY_87 1535
#define RESRVD_VAR_EMILY_88 1536
#define RESRVD_VAR_EMILY_89 1537
#define RESRVD_VAR_EMILY_90 1538
#define RESRVD_VAR_EMILY_91 1539
#define GAMENUMASUB 1532
#define GAMENUMPSUB 1533
#define GAMENUMOSUB 1534
#define SUBPGINDEX 1535
#define SUBPGNUMWIDG 1536
#define SUBPGWIDGETS 1537
#define SUBPGSUBDATA 1538
#define SUBPGCURSORPOS 1539
#define RESRVD_VAR_EMILY_92 1540
#define RESRVD_VAR_EMILY_93 1541
#define RESRVD_VAR_EMILY_94 1542
Expand Down Expand Up @@ -2544,14 +2544,14 @@ namespace ZScript
return new OLoadSubscreenDataRV(a->clone(),b->clone());
}
};
class ONumSubscreensV : public UnaryOpcode
class OSwapSubscrV : public UnaryOpcode
{
public:
ONumSubscreensV(Argument *A) : UnaryOpcode(A) {}
OSwapSubscrV(Argument *A) : UnaryOpcode(A) {}
std::string toString() const;
Opcode* clone() const
{
return new ONumSubscreensV(a->clone());
return new OSwapSubscrV(a->clone());
}
};
class OGetSubscreenName : public UnaryOpcode
Expand Down Expand Up @@ -11738,63 +11738,63 @@ namespace ZScript



class OReservedEmily_3 : public Opcode
class OSubscrSwapPages : public Opcode
{
public:
std::string toString() const;
Opcode* clone() const
{
return new OReservedEmily_3();
return new OSubscrSwapPages();
}
};

class OReservedEmily_4 : public Opcode
class OSubscrPgFindWidget : public Opcode
{
public:
std::string toString() const;
Opcode* clone() const
{
return new OReservedEmily_4();
return new OSubscrPgFindWidget();
}
};

class OReservedEmily_5 : public Opcode
class OSubscrPgMvCursor : public Opcode
{
public:
std::string toString() const;
Opcode* clone() const
{
return new OReservedEmily_5();
return new OSubscrPgMvCursor();
}
};

class OReservedEmily_6 : public Opcode
class OSubscrPgSwapWidgets : public Opcode
{
public:
std::string toString() const;
Opcode* clone() const
{
return new OReservedEmily_6();
return new OSubscrPgSwapWidgets();
}
};

class OReservedEmily_7 : public Opcode
class OSubscrPgNewWidget : public Opcode
{
public:
std::string toString() const;
Opcode* clone() const
{
return new OReservedEmily_7();
return new OSubscrPgNewWidget();
}
};

class OReservedEmily_8 : public Opcode
class OSubscrPgDelete : public Opcode
{
public:
std::string toString() const;
Opcode* clone() const
{
return new OReservedEmily_8();
return new OSubscrPgDelete();
}
};

Expand Down
30 changes: 18 additions & 12 deletions src/parser/symbols/GameSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,15 @@ static AccessorTable gameTable[] =
{ "LoadASubData", 0, ZTID_SUBSCREENDATA, -1, FL_INL, { ZTID_GAME, ZTID_FLOAT },{} },
{ "LoadPSubData", 0, ZTID_SUBSCREENDATA, -1, FL_INL, { ZTID_GAME, ZTID_FLOAT },{} },
{ "LoadOSubData", 0, ZTID_SUBSCREENDATA, -1, FL_INL, { ZTID_GAME, ZTID_FLOAT },{} },
{ "NumActiveSubscreens", 0, ZTID_FLOAT, -1, FL_INL, { ZTID_GAME },{} },
{ "NumPassiveSubscreens", 0, ZTID_FLOAT, -1, FL_INL, { ZTID_GAME },{} },
{ "NumOverlaySubscreens", 0, ZTID_FLOAT, -1, FL_INL, { ZTID_GAME },{} },
{ "SwapActiveSubscreens", 0, ZTID_FLOAT, -1, FL_INL, { ZTID_GAME, ZTID_FLOAT, ZTID_FLOAT },{} },
{ "SwapPassiveSubscreens", 0, ZTID_FLOAT, -1, FL_INL, { ZTID_GAME, ZTID_FLOAT, ZTID_FLOAT },{} },
{ "SwapOverlaySubscreens", 0, ZTID_FLOAT, -1, FL_INL, { ZTID_GAME, ZTID_FLOAT, ZTID_FLOAT },{} },
{ "getNumActiveSubscreens", 0, ZTID_FLOAT, GAMENUMASUB, FL_INL, { ZTID_GAME },{} },
{ "setNumActiveSubscreens", 0, ZTID_VOID, GAMENUMASUB, FL_INL, { ZTID_GAME, ZTID_FLOAT },{} },
{ "getNumPassiveSubscreens", 0, ZTID_FLOAT, GAMENUMPSUB, FL_INL, { ZTID_GAME },{} },
{ "setNumPassiveSubscreens", 0, ZTID_VOID, GAMENUMPSUB, FL_INL, { ZTID_GAME, ZTID_FLOAT },{} },
{ "getNumOverlaySubscreens", 0, ZTID_FLOAT, GAMENUMOSUB, FL_INL, { ZTID_GAME },{} },
{ "setNumOverlaySubscreens", 0, ZTID_VOID, GAMENUMOSUB, FL_INL, { ZTID_GAME, ZTID_FLOAT },{} },

//Intentionally undocumented
{ "getSTD[]", 0, ZTID_UNTYPED, STDARR, 0, { ZTID_GAME, ZTID_FLOAT },{} },
Expand Down Expand Up @@ -429,35 +435,35 @@ void GameSymbols::generateCode()
function->giveCode(code);
}

//NumActiveSubscreens
//SwapActiveSubscreens
{
Function* function = getFunction("NumActiveSubscreens");
Function* function = getFunction("SwapActiveSubscreens");
int32_t label = function->getLabel();
vector<shared_ptr<Opcode>> code;
ASSERT_NUL();
addOpcode2 (code, new ONumSubscreensV(new LiteralArgument(0*10000)));
addOpcode2 (code, new OSwapSubscrV(new LiteralArgument(0*10000)));
LABELBACK(label);
RETURN();
function->giveCode(code);
}
//NumPassiveSubscreens
//SwapPassiveSubscreens
{
Function* function = getFunction("NumPassiveSubscreens");
Function* function = getFunction("SwapPassiveSubscreens");
int32_t label = function->getLabel();
vector<shared_ptr<Opcode>> code;
ASSERT_NUL();
addOpcode2 (code, new ONumSubscreensV(new LiteralArgument(1*10000)));
addOpcode2 (code, new OSwapSubscrV(new LiteralArgument(1*10000)));
LABELBACK(label);
RETURN();
function->giveCode(code);
}
//NumOverlaySubscreens
//SwapOverlaySubscreens
{
Function* function = getFunction("NumOverlaySubscreens");
Function* function = getFunction("SwapOverlaySubscreens");
int32_t label = function->getLabel();
vector<shared_ptr<Opcode>> code;
ASSERT_NUL();
addOpcode2 (code, new ONumSubscreensV(new LiteralArgument(2*10000)));
addOpcode2 (code, new OSwapSubscrV(new LiteralArgument(2*10000)));
LABELBACK(label);
RETURN();
function->giveCode(code);
Expand Down

0 comments on commit 0d049c6

Please sign in to comment.