1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/config-manager.h"
24 #include "common/savefile.h"
25 #include "ags/lib/std/algorithm.h"
26 #include "ags/lib/std/set.h"
27 #include "ags/lib/allegro.h" // find files
28 #include "ags/engine/ac/listbox.h"
29 #include "ags/shared/ac/common.h"
30 #include "ags/engine/ac/game.h"
31 #include "ags/shared/ac/game_setup_struct.h"
32 #include "ags/engine/ac/game_state.h"
33 #include "ags/engine/ac/global_game.h"
34 #include "ags/engine/ac/path_helper.h"
35 #include "ags/engine/ac/string.h"
36 #include "ags/shared/gui/gui_main.h"
37 #include "ags/engine/debugging/debug_log.h"
38 #include "ags/shared/util/path.h"
39 #include "ags/shared/debugging/out.h"
40 #include "ags/engine/script/script_api.h"
41 #include "ags/engine/script/script_runtime.h"
42 #include "ags/engine/ac/dynobj/script_string.h"
43 #include "ags/ags.h"
44 #include "ags/globals.h"
45
46 namespace AGS3 {
47
48 using namespace AGS::Shared;
49
50 // *** LIST BOX FUNCTIONS
51
ListBox_AddItem(GUIListBox * lbb,const char * text)52 int ListBox_AddItem(GUIListBox *lbb, const char *text) {
53 if (lbb->AddItem(text) < 0)
54 return 0;
55 return 1;
56 }
57
ListBox_InsertItemAt(GUIListBox * lbb,int index,const char * text)58 int ListBox_InsertItemAt(GUIListBox *lbb, int index, const char *text) {
59 if (lbb->InsertItem(index, text) < 0)
60 return 0;
61 return 1;
62 }
63
ListBox_Clear(GUIListBox * listbox)64 void ListBox_Clear(GUIListBox *listbox) {
65 listbox->Clear();
66 }
67
FillSaveList(std::set<String> & files,const String & filePattern)68 static void FillSaveList(std::set<String> &files, const String &filePattern) {
69 size_t wildcard = filePattern.FindChar('*');
70 assert(wildcard != String::npos);
71 Common::String prefix(filePattern.GetCStr(), wildcard);
72 Common::StringArray matches = g_system->getSavefileManager()->listSavefiles(filePattern);
73
74 for (uint idx = 0; idx < matches.size(); ++idx) {
75 Common::String name = matches[idx];
76 name = Common::String(name.c_str() + wildcard);
77
78 files.insert(name);
79 }
80 }
81
FillDirList(std::set<String> & files,const String & path)82 void FillDirList(std::set<String> &files, const String &path) {
83 String dirName = Path::GetDirectoryPath(path);
84 String filePattern = Path::get_filename(path);
85
86 if (dirName.CompareLeftNoCase(_GP(ResPaths).DataDir) == 0) {
87 String subDir = dirName.Mid(_GP(ResPaths).DataDir.GetLength());
88 if (!subDir.IsEmpty() && subDir[0u] == '/')
89 subDir.ClipLeft(1);
90 dirName = ConfMan.get("path");
91 } else if (dirName.CompareLeftNoCase(get_save_game_directory()) == 0) {
92 // Save files listing
93 FillSaveList(files, filePattern);
94 return;
95 }
96
97 Common::FSDirectory dir(dirName.GetCStr());
98 Common::ArchiveMemberList fileList;
99 dir.listMatchingMembers(fileList, filePattern.GetCStr());
100 for (Common::ArchiveMemberList::iterator iter = fileList.begin(); iter != fileList.end(); ++iter) {
101 files.insert((*iter)->getName());
102 }
103 }
104
ListBox_FillDirList(GUIListBox * listbox,const char * filemask)105 void ListBox_FillDirList(GUIListBox *listbox, const char *filemask) {
106 listbox->Clear();
107
108 ResolvedPath rp;
109 if (!ResolveScriptPath(filemask, true, rp))
110 return;
111
112 std::set<String> files;
113 FillDirList(files, rp.FullPath);
114 if (!rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
115 FillDirList(files, rp.AltPath);
116
117 // TODO: method for adding item batch to speed up update
118 for (std::set<String>::const_iterator it = files.begin(); it != files.end(); ++it) {
119 listbox->AddItem(*it);
120 }
121 }
122
ListBox_GetSaveGameSlots(GUIListBox * listbox,int index)123 int ListBox_GetSaveGameSlots(GUIListBox *listbox, int index) {
124 if ((index < 0) || (index >= listbox->ItemCount))
125 quit("!ListBox.SaveGameSlot: index out of range");
126
127 return listbox->SavedGameIndex[index];
128 }
129
ListBox_FillSaveGameList(GUIListBox * listbox)130 int ListBox_FillSaveGameList(GUIListBox *listbox) {
131 SaveStateList saveList = ::AGS::g_vm->listSaves();
132
133 // The original AGS sorts the list from most recent to oldest.
134 // We don't have the modification date in ScummVM though. We could try to
135 // parse the date string, but for now, sort by decreasing slot number, which
136 // should work better than the default sort by increasing slot.
137 Common::sort(saveList.begin(), saveList.end(),
138 [](const SaveStateDescriptor & x, const SaveStateDescriptor & y) {
139 return x.getSaveSlot() > y.getSaveSlot();
140 });
141
142 // fill in the list box
143 listbox->Clear();
144 // TODO: method for adding item batch to speed up update
145 for (const auto &item : saveList) {
146 int slot = item.getSaveSlot();
147 Common::String desc = item.getDescription();
148
149 listbox->AddItem(desc);
150 listbox->SavedGameIndex[listbox->ItemCount - 1] = slot;
151 }
152
153 // update the global savegameindex[] array for backward compatibilty
154 for (size_t n = 0; n < saveList.size(); ++n) {
155 _GP(play).filenumbers[n] = saveList[n].getSaveSlot();
156 }
157
158 listbox->SetSvgIndex(true);
159
160 if (saveList.size() >= MAXSAVEGAMES)
161 return 1;
162 return 0;
163 }
164
ListBox_GetItemAtLocation(GUIListBox * listbox,int x,int y)165 int ListBox_GetItemAtLocation(GUIListBox *listbox, int x, int y) {
166
167 if (!_GP(guis)[listbox->ParentId].IsDisplayed())
168 return -1;
169
170 data_to_game_coords(&x, &y);
171 x = (x - listbox->X) - _GP(guis)[listbox->ParentId].X;
172 y = (y - listbox->Y) - _GP(guis)[listbox->ParentId].Y;
173
174 if ((x < 0) || (y < 0) || (x >= listbox->Width) || (y >= listbox->Height))
175 return -1;
176
177 return listbox->GetItemAt(x, y);
178 }
179
ListBox_GetItemText(GUIListBox * listbox,int index,char * buffer)180 char *ListBox_GetItemText(GUIListBox *listbox, int index, char *buffer) {
181 if ((index < 0) || (index >= listbox->ItemCount))
182 quit("!ListBoxGetItemText: invalid item specified");
183 strncpy(buffer, listbox->Items[index].GetCStr(), 198);
184 buffer[199] = 0;
185 return buffer;
186 }
187
ListBox_GetItems(GUIListBox * listbox,int index)188 const char *ListBox_GetItems(GUIListBox *listbox, int index) {
189 if ((index < 0) || (index >= listbox->ItemCount))
190 quit("!ListBox.Items: invalid index specified");
191
192 return CreateNewScriptString(listbox->Items[index].GetCStr());
193 }
194
ListBox_SetItemText(GUIListBox * listbox,int index,const char * newtext)195 void ListBox_SetItemText(GUIListBox *listbox, int index, const char *newtext) {
196 if ((index < 0) || (index >= listbox->ItemCount))
197 quit("!ListBoxSetItemText: invalid item specified");
198
199 if (strcmp(listbox->Items[index].GetCStr(), newtext)) {
200 listbox->SetItemText(index, newtext);
201 }
202 }
203
ListBox_RemoveItem(GUIListBox * listbox,int itemIndex)204 void ListBox_RemoveItem(GUIListBox *listbox, int itemIndex) {
205
206 if ((itemIndex < 0) || (itemIndex >= listbox->ItemCount))
207 quit("!ListBoxRemove: invalid listindex specified");
208
209 listbox->RemoveItem(itemIndex);
210 }
211
ListBox_GetItemCount(GUIListBox * listbox)212 int ListBox_GetItemCount(GUIListBox *listbox) {
213 return listbox->ItemCount;
214 }
215
ListBox_GetFont(GUIListBox * listbox)216 int ListBox_GetFont(GUIListBox *listbox) {
217 return listbox->Font;
218 }
219
ListBox_SetFont(GUIListBox * listbox,int newfont)220 void ListBox_SetFont(GUIListBox *listbox, int newfont) {
221
222 if ((newfont < 0) || (newfont >= _GP(game).numfonts))
223 quit("!ListBox.Font: invalid font number.");
224
225 if (newfont != listbox->Font) {
226 listbox->SetFont(newfont);
227 }
228
229 }
230
ListBox_GetShowBorder(GUIListBox * listbox)231 bool ListBox_GetShowBorder(GUIListBox *listbox) {
232 return listbox->IsBorderShown();
233 }
234
ListBox_SetShowBorder(GUIListBox * listbox,bool newValue)235 void ListBox_SetShowBorder(GUIListBox *listbox, bool newValue) {
236 if (listbox->IsBorderShown() != newValue) {
237 listbox->SetShowBorder(newValue);
238 }
239 }
240
ListBox_GetShowScrollArrows(GUIListBox * listbox)241 bool ListBox_GetShowScrollArrows(GUIListBox *listbox) {
242 return listbox->AreArrowsShown();
243 }
244
ListBox_SetShowScrollArrows(GUIListBox * listbox,bool newValue)245 void ListBox_SetShowScrollArrows(GUIListBox *listbox, bool newValue) {
246 if (listbox->AreArrowsShown() != newValue) {
247 listbox->SetShowArrows(newValue);
248 }
249 }
250
ListBox_GetHideBorder(GUIListBox * listbox)251 int ListBox_GetHideBorder(GUIListBox *listbox) {
252 return !ListBox_GetShowBorder(listbox);
253 }
254
ListBox_SetHideBorder(GUIListBox * listbox,int newValue)255 void ListBox_SetHideBorder(GUIListBox *listbox, int newValue) {
256 ListBox_SetShowBorder(listbox, !newValue);
257 }
258
ListBox_GetHideScrollArrows(GUIListBox * listbox)259 int ListBox_GetHideScrollArrows(GUIListBox *listbox) {
260 return !ListBox_GetShowScrollArrows(listbox);
261 }
262
ListBox_SetHideScrollArrows(GUIListBox * listbox,int newValue)263 void ListBox_SetHideScrollArrows(GUIListBox *listbox, int newValue) {
264 ListBox_SetShowScrollArrows(listbox, !newValue);
265 }
266
ListBox_GetSelectedBackColor(GUIListBox * listbox)267 int ListBox_GetSelectedBackColor(GUIListBox *listbox) {
268 return listbox->SelectedBgColor;
269 }
270
ListBox_SetSelectedBackColor(GUIListBox * listbox,int colr)271 void ListBox_SetSelectedBackColor(GUIListBox *listbox, int colr) {
272 if (listbox->SelectedBgColor != colr) {
273 listbox->SelectedBgColor = colr;
274 listbox->NotifyParentChanged();
275 }
276 }
277
ListBox_GetSelectedTextColor(GUIListBox * listbox)278 int ListBox_GetSelectedTextColor(GUIListBox *listbox) {
279 return listbox->SelectedTextColor;
280 }
281
ListBox_SetSelectedTextColor(GUIListBox * listbox,int colr)282 void ListBox_SetSelectedTextColor(GUIListBox *listbox, int colr) {
283 if (listbox->SelectedTextColor != colr) {
284 listbox->SelectedTextColor = colr;
285 listbox->NotifyParentChanged();
286 }
287 }
288
ListBox_GetTextAlignment(GUIListBox * listbox)289 int ListBox_GetTextAlignment(GUIListBox *listbox) {
290 return listbox->TextAlignment;
291 }
292
ListBox_SetTextAlignment(GUIListBox * listbox,int align)293 void ListBox_SetTextAlignment(GUIListBox *listbox, int align) {
294 if (listbox->TextAlignment != align) {
295 listbox->TextAlignment = (HorAlignment)align;
296 listbox->NotifyParentChanged();
297 }
298 }
299
ListBox_GetTextColor(GUIListBox * listbox)300 int ListBox_GetTextColor(GUIListBox *listbox) {
301 return listbox->TextColor;
302 }
303
ListBox_SetTextColor(GUIListBox * listbox,int colr)304 void ListBox_SetTextColor(GUIListBox *listbox, int colr) {
305 if (listbox->TextColor != colr) {
306 listbox->TextColor = colr;
307 listbox->NotifyParentChanged();
308 }
309 }
310
ListBox_GetSelectedIndex(GUIListBox * listbox)311 int ListBox_GetSelectedIndex(GUIListBox *listbox) {
312 if ((listbox->SelectedItem < 0) || (listbox->SelectedItem >= listbox->ItemCount))
313 return -1;
314 return listbox->SelectedItem;
315 }
316
ListBox_SetSelectedIndex(GUIListBox * guisl,int newsel)317 void ListBox_SetSelectedIndex(GUIListBox *guisl, int newsel) {
318
319 if (newsel >= guisl->ItemCount)
320 newsel = -1;
321
322 if (guisl->SelectedItem != newsel) {
323 guisl->SelectedItem = newsel;
324 if (newsel >= 0) {
325 if (newsel < guisl->TopItem)
326 guisl->TopItem = newsel;
327 if (newsel >= guisl->TopItem + guisl->VisibleItemCount)
328 guisl->TopItem = (newsel - guisl->VisibleItemCount) + 1;
329 }
330 guisl->NotifyParentChanged();
331 }
332
333 }
334
ListBox_GetTopItem(GUIListBox * listbox)335 int ListBox_GetTopItem(GUIListBox *listbox) {
336 return listbox->TopItem;
337 }
338
ListBox_SetTopItem(GUIListBox * guisl,int item)339 void ListBox_SetTopItem(GUIListBox *guisl, int item) {
340 if ((guisl->ItemCount == 0) && (item == 0))
341 ; // allow resetting an empty box to the top
342 else if ((item >= guisl->ItemCount) || (item < 0))
343 quit("!ListBoxSetTopItem: tried to set top to beyond top or bottom of list");
344
345 guisl->TopItem = item;
346 guisl->NotifyParentChanged();
347 }
348
ListBox_GetRowCount(GUIListBox * listbox)349 int ListBox_GetRowCount(GUIListBox *listbox) {
350 return listbox->VisibleItemCount;
351 }
352
ListBox_ScrollDown(GUIListBox * listbox)353 void ListBox_ScrollDown(GUIListBox *listbox) {
354 if (listbox->TopItem + listbox->VisibleItemCount < listbox->ItemCount) {
355 listbox->TopItem++;
356 listbox->NotifyParentChanged();
357 }
358 }
359
ListBox_ScrollUp(GUIListBox * listbox)360 void ListBox_ScrollUp(GUIListBox *listbox) {
361 if (listbox->TopItem > 0) {
362 listbox->TopItem--;
363 listbox->NotifyParentChanged();
364 }
365 }
366
367
is_valid_listbox(int guin,int objn)368 GUIListBox *is_valid_listbox(int guin, int objn) {
369 if ((guin < 0) | (guin >= _GP(game).numgui)) quit("!ListBox: invalid GUI number");
370 if ((objn < 0) | (objn >= _GP(guis)[guin].GetControlCount())) quit("!ListBox: invalid object number");
371 if (_GP(guis)[guin].GetControlType(objn) != kGUIListBox)
372 quit("!ListBox: specified control is not a list box");
373 return (GUIListBox *)_GP(guis)[guin].GetControl(objn);
374 }
375
376 //=============================================================================
377 //
378 // Script API Functions
379 //
380 //=============================================================================
381
382 // int (GUIListBox *lbb, const char *text)
Sc_ListBox_AddItem(void * self,const RuntimeScriptValue * params,int32_t param_count)383 RuntimeScriptValue Sc_ListBox_AddItem(void *self, const RuntimeScriptValue *params, int32_t param_count) {
384 API_OBJCALL_INT_POBJ(GUIListBox, ListBox_AddItem, const char);
385 }
386
387 // void (GUIListBox *listbox)
Sc_ListBox_Clear(void * self,const RuntimeScriptValue * params,int32_t param_count)388 RuntimeScriptValue Sc_ListBox_Clear(void *self, const RuntimeScriptValue *params, int32_t param_count) {
389 API_OBJCALL_VOID(GUIListBox, ListBox_Clear);
390 }
391
392 // void (GUIListBox *listbox, const char *filemask)
Sc_ListBox_FillDirList(void * self,const RuntimeScriptValue * params,int32_t param_count)393 RuntimeScriptValue Sc_ListBox_FillDirList(void *self, const RuntimeScriptValue *params, int32_t param_count) {
394 API_OBJCALL_VOID_POBJ(GUIListBox, ListBox_FillDirList, const char);
395 }
396
397 // int (GUIListBox *listbox)
Sc_ListBox_FillSaveGameList(void * self,const RuntimeScriptValue * params,int32_t param_count)398 RuntimeScriptValue Sc_ListBox_FillSaveGameList(void *self, const RuntimeScriptValue *params, int32_t param_count) {
399 API_OBJCALL_INT(GUIListBox, ListBox_FillSaveGameList);
400 }
401
402 // int (GUIListBox *listbox, int x, int y)
Sc_ListBox_GetItemAtLocation(void * self,const RuntimeScriptValue * params,int32_t param_count)403 RuntimeScriptValue Sc_ListBox_GetItemAtLocation(void *self, const RuntimeScriptValue *params, int32_t param_count) {
404 API_OBJCALL_INT_PINT2(GUIListBox, ListBox_GetItemAtLocation);
405 }
406
407 // char *(GUIListBox *listbox, int index, char *buffer)
Sc_ListBox_GetItemText(void * self,const RuntimeScriptValue * params,int32_t param_count)408 RuntimeScriptValue Sc_ListBox_GetItemText(void *self, const RuntimeScriptValue *params, int32_t param_count) {
409 API_OBJCALL_OBJ_PINT_POBJ(GUIListBox, char, _GP(myScriptStringImpl), ListBox_GetItemText, char);
410 }
411
412 // int (GUIListBox *lbb, int index, const char *text)
Sc_ListBox_InsertItemAt(void * self,const RuntimeScriptValue * params,int32_t param_count)413 RuntimeScriptValue Sc_ListBox_InsertItemAt(void *self, const RuntimeScriptValue *params, int32_t param_count) {
414 API_OBJCALL_INT_PINT_POBJ(GUIListBox, ListBox_InsertItemAt, const char);
415 }
416
417 // void (GUIListBox *listbox, int itemIndex)
Sc_ListBox_RemoveItem(void * self,const RuntimeScriptValue * params,int32_t param_count)418 RuntimeScriptValue Sc_ListBox_RemoveItem(void *self, const RuntimeScriptValue *params, int32_t param_count) {
419 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_RemoveItem);
420 }
421
422 // void (GUIListBox *listbox)
Sc_ListBox_ScrollDown(void * self,const RuntimeScriptValue * params,int32_t param_count)423 RuntimeScriptValue Sc_ListBox_ScrollDown(void *self, const RuntimeScriptValue *params, int32_t param_count) {
424 API_OBJCALL_VOID(GUIListBox, ListBox_ScrollDown);
425 }
426
427 // void (GUIListBox *listbox)
Sc_ListBox_ScrollUp(void * self,const RuntimeScriptValue * params,int32_t param_count)428 RuntimeScriptValue Sc_ListBox_ScrollUp(void *self, const RuntimeScriptValue *params, int32_t param_count) {
429 API_OBJCALL_VOID(GUIListBox, ListBox_ScrollUp);
430 }
431
432 // void (GUIListBox *listbox, int index, const char *newtext)
Sc_ListBox_SetItemText(void * self,const RuntimeScriptValue * params,int32_t param_count)433 RuntimeScriptValue Sc_ListBox_SetItemText(void *self, const RuntimeScriptValue *params, int32_t param_count) {
434 API_OBJCALL_VOID_PINT_POBJ(GUIListBox, ListBox_SetItemText, const char);
435 }
436
437 // int (GUIListBox *listbox)
Sc_ListBox_GetFont(void * self,const RuntimeScriptValue * params,int32_t param_count)438 RuntimeScriptValue Sc_ListBox_GetFont(void *self, const RuntimeScriptValue *params, int32_t param_count) {
439 API_OBJCALL_INT(GUIListBox, ListBox_GetFont);
440 }
441
442 // void (GUIListBox *listbox, int newfont)
Sc_ListBox_SetFont(void * self,const RuntimeScriptValue * params,int32_t param_count)443 RuntimeScriptValue Sc_ListBox_SetFont(void *self, const RuntimeScriptValue *params, int32_t param_count) {
444 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_SetFont);
445 }
446
Sc_ListBox_GetShowBorder(void * self,const RuntimeScriptValue * params,int32_t param_count)447 RuntimeScriptValue Sc_ListBox_GetShowBorder(void *self, const RuntimeScriptValue *params, int32_t param_count) {
448 API_OBJCALL_BOOL(GUIListBox, ListBox_GetShowBorder);
449 }
450
Sc_ListBox_SetShowBorder(void * self,const RuntimeScriptValue * params,int32_t param_count)451 RuntimeScriptValue Sc_ListBox_SetShowBorder(void *self, const RuntimeScriptValue *params, int32_t param_count) {
452 API_OBJCALL_VOID_PBOOL(GUIListBox, ListBox_SetShowBorder);
453 }
454
Sc_ListBox_GetShowScrollArrows(void * self,const RuntimeScriptValue * params,int32_t param_count)455 RuntimeScriptValue Sc_ListBox_GetShowScrollArrows(void *self, const RuntimeScriptValue *params, int32_t param_count) {
456 API_OBJCALL_BOOL(GUIListBox, ListBox_GetShowScrollArrows);
457 }
458
Sc_ListBox_SetShowScrollArrows(void * self,const RuntimeScriptValue * params,int32_t param_count)459 RuntimeScriptValue Sc_ListBox_SetShowScrollArrows(void *self, const RuntimeScriptValue *params, int32_t param_count) {
460 API_OBJCALL_VOID_PBOOL(GUIListBox, ListBox_SetShowScrollArrows);
461 }
462
463 // int (GUIListBox *listbox)
Sc_ListBox_GetHideBorder(void * self,const RuntimeScriptValue * params,int32_t param_count)464 RuntimeScriptValue Sc_ListBox_GetHideBorder(void *self, const RuntimeScriptValue *params, int32_t param_count) {
465 API_OBJCALL_INT(GUIListBox, ListBox_GetHideBorder);
466 }
467
468 // void (GUIListBox *listbox, int newValue)
Sc_ListBox_SetHideBorder(void * self,const RuntimeScriptValue * params,int32_t param_count)469 RuntimeScriptValue Sc_ListBox_SetHideBorder(void *self, const RuntimeScriptValue *params, int32_t param_count) {
470 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_SetHideBorder);
471 }
472
473 // int (GUIListBox *listbox)
Sc_ListBox_GetHideScrollArrows(void * self,const RuntimeScriptValue * params,int32_t param_count)474 RuntimeScriptValue Sc_ListBox_GetHideScrollArrows(void *self, const RuntimeScriptValue *params, int32_t param_count) {
475 API_OBJCALL_INT(GUIListBox, ListBox_GetHideScrollArrows);
476 }
477
478 // void (GUIListBox *listbox, int newValue)
Sc_ListBox_SetHideScrollArrows(void * self,const RuntimeScriptValue * params,int32_t param_count)479 RuntimeScriptValue Sc_ListBox_SetHideScrollArrows(void *self, const RuntimeScriptValue *params, int32_t param_count) {
480 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_SetHideScrollArrows);
481 }
482
483 // int (GUIListBox *listbox)
Sc_ListBox_GetItemCount(void * self,const RuntimeScriptValue * params,int32_t param_count)484 RuntimeScriptValue Sc_ListBox_GetItemCount(void *self, const RuntimeScriptValue *params, int32_t param_count) {
485 API_OBJCALL_INT(GUIListBox, ListBox_GetItemCount);
486 }
487
488 // const char* (GUIListBox *listbox, int index)
Sc_ListBox_GetItems(void * self,const RuntimeScriptValue * params,int32_t param_count)489 RuntimeScriptValue Sc_ListBox_GetItems(void *self, const RuntimeScriptValue *params, int32_t param_count) {
490 API_CONST_OBJCALL_OBJ_PINT(GUIListBox, const char, _GP(myScriptStringImpl), ListBox_GetItems);
491 }
492
493 // int (GUIListBox *listbox)
Sc_ListBox_GetRowCount(void * self,const RuntimeScriptValue * params,int32_t param_count)494 RuntimeScriptValue Sc_ListBox_GetRowCount(void *self, const RuntimeScriptValue *params, int32_t param_count) {
495 API_OBJCALL_INT(GUIListBox, ListBox_GetRowCount);
496 }
497
498 // int (GUIListBox *listbox, int index)
Sc_ListBox_GetSaveGameSlots(void * self,const RuntimeScriptValue * params,int32_t param_count)499 RuntimeScriptValue Sc_ListBox_GetSaveGameSlots(void *self, const RuntimeScriptValue *params, int32_t param_count) {
500 API_OBJCALL_INT_PINT(GUIListBox, ListBox_GetSaveGameSlots);
501 }
502
Sc_ListBox_GetSelectedBackColor(void * self,const RuntimeScriptValue * params,int32_t param_count)503 RuntimeScriptValue Sc_ListBox_GetSelectedBackColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
504 API_OBJCALL_INT(GUIListBox, ListBox_GetSelectedBackColor);
505 }
506
507 // void (GUIListBox *guisl, int newsel)
Sc_ListBox_SetSelectedBackColor(void * self,const RuntimeScriptValue * params,int32_t param_count)508 RuntimeScriptValue Sc_ListBox_SetSelectedBackColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
509 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_SetSelectedBackColor);
510 }
511
Sc_ListBox_GetSelectedTextColor(void * self,const RuntimeScriptValue * params,int32_t param_count)512 RuntimeScriptValue Sc_ListBox_GetSelectedTextColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
513 API_OBJCALL_INT(GUIListBox, ListBox_GetSelectedTextColor);
514 }
515
516 // void (GUIListBox *guisl, int newsel)
Sc_ListBox_SetSelectedTextColor(void * self,const RuntimeScriptValue * params,int32_t param_count)517 RuntimeScriptValue Sc_ListBox_SetSelectedTextColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
518 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_SetSelectedTextColor);
519 }
520
Sc_ListBox_GetTextAlignment(void * self,const RuntimeScriptValue * params,int32_t param_count)521 RuntimeScriptValue Sc_ListBox_GetTextAlignment(void *self, const RuntimeScriptValue *params, int32_t param_count) {
522 API_OBJCALL_INT(GUIListBox, ListBox_GetTextAlignment);
523 }
524
525 // void (GUIListBox *guisl, int newsel)
Sc_ListBox_SetTextAlignment(void * self,const RuntimeScriptValue * params,int32_t param_count)526 RuntimeScriptValue Sc_ListBox_SetTextAlignment(void *self, const RuntimeScriptValue *params, int32_t param_count) {
527 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_SetTextAlignment);
528 }
529
Sc_ListBox_GetTextColor(void * self,const RuntimeScriptValue * params,int32_t param_count)530 RuntimeScriptValue Sc_ListBox_GetTextColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
531 API_OBJCALL_INT(GUIListBox, ListBox_GetTextColor);
532 }
533
534 // void (GUIListBox *guisl, int newsel)
Sc_ListBox_SetTextColor(void * self,const RuntimeScriptValue * params,int32_t param_count)535 RuntimeScriptValue Sc_ListBox_SetTextColor(void *self, const RuntimeScriptValue *params, int32_t param_count) {
536 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_SetTextColor);
537 }
538
539 // int (GUIListBox *listbox)
Sc_ListBox_GetSelectedIndex(void * self,const RuntimeScriptValue * params,int32_t param_count)540 RuntimeScriptValue Sc_ListBox_GetSelectedIndex(void *self, const RuntimeScriptValue *params, int32_t param_count) {
541 API_OBJCALL_INT(GUIListBox, ListBox_GetSelectedIndex);
542 }
543
544 // void (GUIListBox *guisl, int newsel)
Sc_ListBox_SetSelectedIndex(void * self,const RuntimeScriptValue * params,int32_t param_count)545 RuntimeScriptValue Sc_ListBox_SetSelectedIndex(void *self, const RuntimeScriptValue *params, int32_t param_count) {
546 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_SetSelectedIndex);
547 }
548
549 // int (GUIListBox *listbox)
Sc_ListBox_GetTopItem(void * self,const RuntimeScriptValue * params,int32_t param_count)550 RuntimeScriptValue Sc_ListBox_GetTopItem(void *self, const RuntimeScriptValue *params, int32_t param_count) {
551 API_OBJCALL_INT(GUIListBox, ListBox_GetTopItem);
552 }
553
554 // void (GUIListBox *guisl, int item)
Sc_ListBox_SetTopItem(void * self,const RuntimeScriptValue * params,int32_t param_count)555 RuntimeScriptValue Sc_ListBox_SetTopItem(void *self, const RuntimeScriptValue *params, int32_t param_count) {
556 API_OBJCALL_VOID_PINT(GUIListBox, ListBox_SetTopItem);
557 }
558
559
560
RegisterListBoxAPI()561 void RegisterListBoxAPI() {
562 ccAddExternalObjectFunction("ListBox::AddItem^1", Sc_ListBox_AddItem);
563 ccAddExternalObjectFunction("ListBox::Clear^0", Sc_ListBox_Clear);
564 ccAddExternalObjectFunction("ListBox::FillDirList^1", Sc_ListBox_FillDirList);
565 ccAddExternalObjectFunction("ListBox::FillSaveGameList^0", Sc_ListBox_FillSaveGameList);
566 ccAddExternalObjectFunction("ListBox::GetItemAtLocation^2", Sc_ListBox_GetItemAtLocation);
567 ccAddExternalObjectFunction("ListBox::GetItemText^2", Sc_ListBox_GetItemText);
568 ccAddExternalObjectFunction("ListBox::InsertItemAt^2", Sc_ListBox_InsertItemAt);
569 ccAddExternalObjectFunction("ListBox::RemoveItem^1", Sc_ListBox_RemoveItem);
570 ccAddExternalObjectFunction("ListBox::ScrollDown^0", Sc_ListBox_ScrollDown);
571 ccAddExternalObjectFunction("ListBox::ScrollUp^0", Sc_ListBox_ScrollUp);
572 ccAddExternalObjectFunction("ListBox::SetItemText^2", Sc_ListBox_SetItemText);
573 ccAddExternalObjectFunction("ListBox::get_Font", Sc_ListBox_GetFont);
574 ccAddExternalObjectFunction("ListBox::set_Font", Sc_ListBox_SetFont);
575 ccAddExternalObjectFunction("ListBox::get_ShowBorder", Sc_ListBox_GetShowBorder);
576 ccAddExternalObjectFunction("ListBox::set_ShowBorder", Sc_ListBox_SetShowBorder);
577 ccAddExternalObjectFunction("ListBox::get_ShowScrollArrows", Sc_ListBox_GetShowScrollArrows);
578 ccAddExternalObjectFunction("ListBox::set_ShowScrollArrows", Sc_ListBox_SetShowScrollArrows);
579 // old "inverted" properties
580 ccAddExternalObjectFunction("ListBox::get_HideBorder", Sc_ListBox_GetHideBorder);
581 ccAddExternalObjectFunction("ListBox::set_HideBorder", Sc_ListBox_SetHideBorder);
582 ccAddExternalObjectFunction("ListBox::get_HideScrollArrows", Sc_ListBox_GetHideScrollArrows);
583 ccAddExternalObjectFunction("ListBox::set_HideScrollArrows", Sc_ListBox_SetHideScrollArrows);
584 //
585 ccAddExternalObjectFunction("ListBox::get_ItemCount", Sc_ListBox_GetItemCount);
586 ccAddExternalObjectFunction("ListBox::geti_Items", Sc_ListBox_GetItems);
587 ccAddExternalObjectFunction("ListBox::seti_Items", Sc_ListBox_SetItemText);
588 ccAddExternalObjectFunction("ListBox::get_RowCount", Sc_ListBox_GetRowCount);
589 ccAddExternalObjectFunction("ListBox::geti_SaveGameSlots", Sc_ListBox_GetSaveGameSlots);
590 ccAddExternalObjectFunction("ListBox::get_SelectedBackColor", Sc_ListBox_GetSelectedBackColor);
591 ccAddExternalObjectFunction("ListBox::set_SelectedBackColor", Sc_ListBox_SetSelectedBackColor);
592 ccAddExternalObjectFunction("ListBox::get_SelectedIndex", Sc_ListBox_GetSelectedIndex);
593 ccAddExternalObjectFunction("ListBox::set_SelectedIndex", Sc_ListBox_SetSelectedIndex);
594 ccAddExternalObjectFunction("ListBox::get_SelectedTextColor", Sc_ListBox_GetSelectedTextColor);
595 ccAddExternalObjectFunction("ListBox::set_SelectedTextColor", Sc_ListBox_SetSelectedTextColor);
596 ccAddExternalObjectFunction("ListBox::get_TextAlignment", Sc_ListBox_GetTextAlignment);
597 ccAddExternalObjectFunction("ListBox::set_TextAlignment", Sc_ListBox_SetTextAlignment);
598 ccAddExternalObjectFunction("ListBox::get_TextColor", Sc_ListBox_GetTextColor);
599 ccAddExternalObjectFunction("ListBox::set_TextColor", Sc_ListBox_SetTextColor);
600 ccAddExternalObjectFunction("ListBox::get_TopItem", Sc_ListBox_GetTopItem);
601 ccAddExternalObjectFunction("ListBox::set_TopItem", Sc_ListBox_SetTopItem);
602 }
603
604 } // namespace AGS3
605