3 The stage-select dialog when using the
4 teleporter in Arthur's House.
8 #include "StageSelect.h"
9 #include "StageSelect.fdh"
14 #define WARP_Y_START (WARP_Y + 8)
15 #define WARP_Y_SPEED 1
17 #define LOCS_Y (WARP_Y + 16)
18 #define LOCS_SPACING 8
20 TB_StageSelect::TB_StageSelect()
26 void c------------------------------() {}
29 void TB_StageSelect::ResetState()
34 void TB_StageSelect::SetVisible(bool enable
)
37 fWarpY
= WARP_Y_START
;
40 textbox
.SetFlags(TB_CURSOR_NEVER_SHOWN
, enable
);
41 textbox
.SetFlags(TB_LINE_AT_ONCE
, enable
);
42 textbox
.SetFlags(TB_VARIABLE_WIDTH_CHARS
, enable
);
45 fLastButtonDown
= true;
49 fMadeSelection
= false;
55 bool TB_StageSelect::IsVisible()
61 void c------------------------------() {}
64 void TB_StageSelect::Draw(void)
72 // draw "- WARP -" text
73 fWarpY
-= WARP_Y_SPEED
;
74 if (fWarpY
< WARP_Y
) fWarpY
= WARP_Y
;
76 draw_sprite(WARP_X
, fWarpY
, SPR_TEXT_WARP
, 0);
78 // draw teleporter locations
79 int nslots
= CountActiveSlots();
80 int total_spacing
= ((nslots
- 1) * LOCS_SPACING
);
81 int total_width
= total_spacing
+ (nslots
* sprites
[SPR_STAGEIMAGE
].w
);
82 int x
= (SCREEN_WIDTH
/ 2) - (total_width
/ 2);
84 for(int i
=0;i
<nslots
;i
++)
87 GetSlotByIndex(i
, &sprite
, NULL
);
89 draw_sprite(x
, LOCS_Y
, SPR_STAGEIMAGE
, sprite
);
91 if (i
== fSelectionIndex
)
94 draw_sprite(x
, LOCS_Y
, SPR_SELECTOR_ITEMS
, fSelectionFrame
);
97 x
+= (sprites
[SPR_STAGEIMAGE
].w
+ LOCS_SPACING
);
102 void c------------------------------() {}
105 void TB_StageSelect::HandleInput()
109 if (textbox
.YesNoPrompt
.IsVisible() || fMadeSelection
)
112 if (justpushed(LEFTKEY
))
116 else if (justpushed(RIGHTKEY
))
118 MoveSelection(RIGHT
);
121 // when user picks a location return the new script to execute
122 button_down
= buttondown();
123 if (button_down
&& !fLastButtonDown
)
126 if (!GetSlotByIndex(fSelectionIndex
, NULL
, &scriptno
))
128 stat("StageSelect: starting activation script %d", scriptno
);
129 JumpScript(scriptno
, SP_MAP
);
132 { // dismiss "no permission to teleport"
136 fMadeSelection
= true;
139 fLastButtonDown
= button_down
;
142 void TB_StageSelect::MoveSelection(int dir
)
144 int numslots
= CountActiveSlots();
145 if (numslots
== 0) return;
149 if (++fSelectionIndex
>= numslots
)
154 if (--fSelectionIndex
< 0)
155 fSelectionIndex
= (numslots
- 1);
158 sound(SND_MENU_MOVE
);
162 // updates the text by running the appropriate script
163 // from StageSelect.tsc
164 void TB_StageSelect::UpdateText()
168 if (GetSlotByIndex(fSelectionIndex
, NULL
, &scriptno
))
169 { // no permission to teleport
177 JumpScript(scriptno
+ 1000, SP_STAGESELECT
);
181 void c------------------------------() {}
184 // set teleporter slot "slotno" to run script "scriptno" when selected.
185 // this adds the slot to the menu if scriptno is nonzero and removes it if zero.
186 // the parameters here map directory to the <PS+ in the script.
187 void TB_StageSelect::SetSlot(int slotno
, int scriptno
)
189 if (slotno
>= 0 && slotno
< NUM_TELEPORTER_SLOTS
)
191 fSlots
[slotno
] = scriptno
;
195 stat("StageSelect::SetSlot: invalid slotno %d", slotno
);
199 void TB_StageSelect::ClearSlots()
201 for(int i
=0;i
<NUM_TELEPORTER_SLOTS
;i
++)
205 // return the slotno and scriptno associated with the n'th enabled teleporter slot,
207 // i.e. passing 1 for index returns the 2nd potential teleporter destination.
208 // if index is higher than the number of active teleporter slots, returns nonzero.
209 bool TB_StageSelect::GetSlotByIndex(int index
, int *slotno_out
, int *scriptno_out
)
215 for(int i
=0;i
<NUM_TELEPORTER_SLOTS
;i
++)
219 if (++slots_found
> index
)
221 if (slotno_out
) *slotno_out
= i
;
222 if (scriptno_out
) *scriptno_out
= fSlots
[i
];
229 if (slotno_out
) *slotno_out
= -1;
230 if (scriptno_out
) *scriptno_out
= -1;
234 int TB_StageSelect::CountActiveSlots()
238 for(int i
=0;i
<NUM_TELEPORTER_SLOTS
;i
++)