-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
97 lines (95 loc) · 2.65 KB
/
menu.c
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
/* Copyright (C) 2005-2010 Valeriy Argunov (nporep AT mail DOT ru) */
/*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "menu.h"
#include "callbacks.h"
#include "errors.h"
#include "game.h"
#include "locations.h"
#include "text.h"
#include "variables.h"
QSP_BOOL qspStatementShowMenu(QSPVariant *args, int count, QSP_CHAR **jumpTo, int extArg)
{
QSPVar *var;
QSPVariant arg;
int ind, itemsCount, maxItems, len;
QSP_CHAR *menuLocs[QSP_MAXMENUITEMS], *imgPath, *str, *pos, *pos2;
if (!(var = qspVarReferenceWithType(QSP_STR(args[0]), QSP_FALSE, 0))) return QSP_FALSE;
qspCallDeleteMenu();
if (count == 1)
{
ind = 0;
maxItems = QSP_MAXMENUITEMS;
}
else
{
ind = QSP_NUM(args[1]);
if (ind < 0) ind = 0;
if (count == 2)
maxItems = QSP_MAXMENUITEMS;
else
{
maxItems = QSP_NUM(args[2]);
if (maxItems < 0) maxItems = 0;
}
}
itemsCount = 0;
while (ind < var->ValsCount)
{
if (itemsCount == maxItems) break;
if (!((str = var->Values[ind].Str) && qspIsAnyString(str))) break;
if (!(pos2 = qspInStrRChars(str, QSP_MENUDELIM, 0)))
{
qspSetError(QSP_ERR_COLONNOTFOUND);
return QSP_FALSE;
}
if (itemsCount == QSP_MAXMENUITEMS)
{
qspSetError(QSP_ERR_CANTADDMENUITEM);
return QSP_FALSE;
}
if (pos = qspInStrRChars(str, QSP_MENUDELIM, pos2))
{
len = (int)(pos2 - pos) - 1;
imgPath = (qspIsAnyString(++pos2) ? qspGetAbsFromRelPath(pos2) : 0);
}
else
{
pos = pos2;
len = -1;
imgPath = 0;
}
menuLocs[itemsCount++] = qspGetNewText(pos + 1, len);
*pos = 0;
qspCallAddMenuItem(str, imgPath);
*pos = QSP_MENUDELIM[0];
if (imgPath) free(imgPath);
++ind;
}
if (itemsCount)
{
ind = qspCallShowMenu();
if (ind >= 0 && ind < itemsCount)
{
arg.IsStr = QSP_FALSE;
QSP_NUM(arg) = ind + 1;
qspExecLocByNameWithArgs(menuLocs[ind], &arg, 1, 0);
}
while (--itemsCount >= 0)
free(menuLocs[itemsCount]);
}
return QSP_FALSE;
}