-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobalScript.asc
279 lines (242 loc) · 6.26 KB
/
GlobalScript.asc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// main global script file
//test
// called when the game starts, before the first room is loaded
function game_start()
{
// register a GUI to use for the inventory bar
TwoClickHandler.InventoryGUI = gInventoryBar;
// register a Label to use for action text
TwoClickHandler.ActionLabel = lblAction;
// optionally set the popup distance for the inventory bar
//TwoClickHandler.PopupProportional = 0.5;
//TwoClickHandler.PopupDistance = 50;
// optionally reverse the left and right mouse buttons
//TwoClickHandler.ReversedClicks = true;
StoryProgression.InitializeQuestSystem(gDebug);
//default dialog for each character you want
StoryProgression.AddDefaultDialogs(cEgo, dEgoDefault);
StoryProgression.Add(eLocationCharacter, CHARACTER_EGO, 1000, DIALOG_01, "", ROOM_MAIN, eInteract, iKey);
StoryProgression.Add(eLocationObject, OBJECT_BOOTS, 1001, DIALOG_NULL, "", ROOM_MAIN, eInteract, null);
StoryProgression.Add(eLocationCharacter, CHARACTER_EGO, 1002, DIALOG_02, "", ROOM_MAIN, eInteract, iCup);
StoryProgression.Add(eLocationHotspot, -1, 1003, -1, "", -1, eInteract, null);
}
// called on every game cycle, except when the game is blocked
function repeatedly_execute()
{
}
// called on every game cycle, even when the game is blocked
function repeatedly_execute_always()
{
}
// open a GUI
function open_gui(GUI* gui_to_open)
{
TwoClickHandler.Close();
mouse.UseModeGraphic(eModeWalkto);
gui_to_open.Visible = true;
}
// hide a GUI
function close_gui(GUI *gui_to_close)
{
gui_to_close.Visible = false;
mouse.UseDefaultGraphic();
}
// hide a GUI, based on a GUI control
function close_owning_gui(GUIControl* control)
{
close_gui(control.OwningGUI);
}
// hide a GUI directly from an OnClick event
function close_gui_onclick(GUIControl *control, MouseButton button)
{
close_owning_gui(control);
}
function show_save_game_dialog()
{
// get the list of save games
lstSaveGamesList.FillSaveGameList();
if (lstSaveGamesList.ItemCount > 0)
{
// if there is at least one, set the default text
// to be the first game's name
txtNewSaveName.Text = lstSaveGamesList.Items[0];
}
else
{
// no save games yet, so default to empty text
txtNewSaveName.Text = "";
}
open_gui(gSaveGame);
}
function show_restore_game_dialog()
{
lstRestoreGamesList.FillSaveGameList();
open_gui(gRestoreGame);
}
// called when a key is pressed
function on_key_press(eKeyCode keycode)
{
// check for Escape first, so it can be used on GUIs that pause the game
if (keycode == eKeyEscape)
{
if (gExitGame.Visible)
{
// Escape will cancel exiting the game
close_gui(gExitGame);
}
else if (gRestoreGame.Visible)
{
close_gui(gRestoreGame);
}
else if (gSaveGame.Visible)
{
close_gui(gSaveGame);
}
else
{
// Escape will prompt to exit the game
open_gui(gExitGame);
}
}
else if (IsGamePaused())
{
// game paused, so don't react to any keypresses
keycode = 0;
}
else if (keycode == eKeyCtrlQ)
{
// Ctrl-Q will quit the game
open_gui(gExitGame);
}
else if (keycode == eKeyF5)
{
// F5 will open the save game dialog
show_save_game_dialog();
}
else if (keycode == eKeyF7)
{
// F7 will open the restore game dialog
show_restore_game_dialog();
}
else if (keycode == eKeyF9)
{
// F9 will restart the game
RestartGame();
}
else if (keycode == eKeyF12)
{
// F12 will save a screenshot to the save game folder
SaveScreenShot("screenshot.pcx");
}
else if (keycode == eKeyCtrlS)
{
// Ctrl-S will give the player all defined inventory items
Debug(0, 0);
}
else if (keycode == eKeyCtrlV)
{
// Ctrl-V will show game engine version and build date
Debug(1, 0);
}
else if (keycode == eKeyCtrlA)
{
// Ctrl-A will show walkable areas
Debug(2, 0);
}
else if (keycode == eKeyCtrlX)
{
// Ctrl-X will let the player teleport to any room
Debug(3, 0);
}
}
// called when a mouse button is clicked
function on_mouse_click(MouseButton button)
{
// all clicks handled by TwoClickHandler script
}
// Called when a dialog script line "run-script" is processed
function dialog_request(int param)
{
}
function btnInvUp_OnClick(GUIControl *control, MouseButton button)
{
invCustom.ScrollUp();
}
function btnInvDown_OnClick(GUIControl *control, MouseButton button)
{
invCustom.ScrollDown();
}
function btnExitGame_OnClick(GUIControl *control, MouseButton button)
{
open_gui(gExitGame);
}
function btnQuit_OnClick(GUIControl *control, MouseButton button)
{
QuitGame(0);
}
int find_save_slot(String name)
{
bool slots[] = new bool[999];
int i = 0;
while (i < lstSaveGamesList.ItemCount)
{
if (lstSaveGamesList.Items[i] == name)
{
// found existing save with matching name
return lstSaveGamesList.SaveGameSlots[i];
}
// remember which slots are already taken
slots[lstSaveGamesList.SaveGameSlots[i]] = true;
i ++;
}
// find first free save slot, starting with slot 1
i = 1;
while (i < 999)
{
if (!slots[i])
{
return i;
}
i ++;
}
// no free slots found
return -1;
}
function btnSaveGame_OnClick(GUIControl *control, MouseButton button)
{
int gameSlotToSaveInto = find_save_slot(txtNewSaveName.Text);
if (gameSlotToSaveInto < 0)
{
Display("No more free save slots!");
}
else
{
SaveGameSlot(gameSlotToSaveInto, txtNewSaveName.Text);
close_owning_gui(control);
}
}
function btnRestoreGame_OnClick(GUIControl *control, MouseButton button)
{
if (lstRestoreGamesList.SelectedIndex >= 0)
{
RestoreGameSlot(lstRestoreGamesList.SaveGameSlots[lstRestoreGamesList.SelectedIndex]);
}
close_owning_gui(control);
}
function lstSaveGamesList_OnSelectionCh(GUIControl *control)
{
txtNewSaveName.Text = lstSaveGamesList.Items[lstSaveGamesList.SelectedIndex];
}
function txtNewSaveName_OnActivate(GUIControl *control)
{
// pressing Return in the text box simulates clicking the save button
btnSaveGame_OnClick(control, eMouseLeft);
}
function btnDeleteSave_OnClick(GUIControl *control, MouseButton button)
{
if (lstSaveGamesList.SelectedIndex >= 0)
{
DeleteSaveSlot(lstSaveGamesList.SaveGameSlots[lstSaveGamesList.SelectedIndex]);
lstSaveGamesList.FillSaveGameList();
}
}