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
|
/*
* file menu_level.c - level selection menu
*
* $Id: menu_level.c,v 1.9 2006/03/28 11:41:19 fzago Exp $
*
* Program XBLAST
* (C) by Oliver Vogel (e-mail: m.vogel@ndh.net)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2; or (at your option)
* any later version
*
* This program is distributed in the hope that it will be entertaining,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "xblast.h"
/*
* local types
*/
typedef struct
{
XBAtom atom;
const char *name;
XBBool newSelect;
XBBool oldSelect;
} XBLevelSelection;
/*
* local variables
*/
static int numLevels = 0;
static XBLevelSelection *selectList = NULL;
static int levelFirst = 0;
static int levelLast = 0;
/*
* compare to level selection elments by name
*/
static int
CompareLevelSelections (const void *a, const void *b)
{
return strcmp (((const XBLevelSelection *) a)->name, ((const XBLevelSelection *) b)->name);
} /* CompareLevelSelections */
/*
* create list with all levels configs
*/
static XBLevelSelection *
CreateLevelSelection (int *pNumLevels)
{
XBLevelSelection *list;
int i;
XBAtom atom;
assert (pNumLevels != NULL);
/* how many levels do we have */
*pNumLevels = GetNumLevels ();
/* alloc data field */
list = calloc (*pNumLevels, sizeof (XBLevelSelection));
assert (list != NULL);
/* store levels */
for (i = 0; i < *pNumLevels; i++) {
/* get level data */
atom = GetLevelAtom (i);
assert (ATOM_INVALID != atom);
/* set selection data */
list[i].atom = atom;
list[i].name = GetLevelNameByAtom (atom);
list[i].newSelect = list[i].oldSelect = GetLevelSelected (atom);
}
/* sort list */
qsort (list, *pNumLevels, sizeof (XBLevelSelection), CompareLevelSelections);
/* that's all */
return list;
} /* CreateLevelList */
/*
* select all levels
*/
static XBBool
ButtonLevelSelectAll (void *par)
{
int i;
for (i = 0; i < numLevels; i++) {
selectList[i].newSelect = XBTrue;
}
return XBFalse;
} /* ButtonLevelSelectAll */
/*
* deselect all levels
*/
static XBBool
ButtonLevelSelectNone (void *par)
{
int i;
for (i = 0; i < numLevels; i++) {
selectList[i].newSelect = XBFalse;
}
return XBFalse;
} /* ButtonLevelSelectNone */
/*
* Forward in selection
*/
static XBBool
ButtonLevelForward (void *par)
{
if (levelLast < numLevels) {
levelFirst = levelLast;
}
return CreateLevelMenu (par);
} /* ButtonLevelForward */
/*
* Continue with game setup
*/
static XBBool
ButtonContinue (void *par)
{
int i;
XBMenuLevelPar *mlp = par;
assert (mlp != NULL);
/* store level selection */
for (i = 0; i < numLevels; i++) {
if (selectList[i].newSelect != selectList[i].oldSelect) {
StoreLevelSelected (selectList[i].atom, selectList[i].newSelect);
selectList[i].oldSelect = selectList[i].newSelect; /* KOEN 26-06-2002 */
}
}
/* call start game funtion */
return (*mlp->funcDefault) (mlp->parDefault);
} /* ButtonContinue */
/*
* Forward in selection
*/
static XBBool
ButtonLevelBackward (void *par)
{
levelFirst -= LEVEL_ROWS * LEVEL_COLS;
if (levelFirst < 0) {
levelFirst = 0;
}
return CreateLevelMenu (par);
} /* ButtonLevelForward */
/*
* create level selection menu
*/
XBBool
CreateLevelMenu (void *par)
{
int i, c, r;
XBMenuLevelPar *mlp = par;
/* get parameter */
assert (mlp != NULL);
/* init level selection */
if (NULL == selectList) {
selectList = CreateLevelSelection (&numLevels);
assert (selectList != NULL);
levelFirst = 0;
}
MenuClear ();
/* Title */
MenuAddLabel (TITLE_LEFT, TITLE_TOP, TITLE_WIDTH, N_("Level Selection"));
/* levels */
c = 0;
r = 0;
for (i = levelFirst; i < numLevels; i++) {
MenuAddToggle ((c * 6 + 3) * CELL_W / 2, MENU_TOP + r * CELL_H / 2, 13 * CELL_W / 4,
selectList[i].name, &selectList[i].newSelect);
r++;
if (r >= LEVEL_ROWS) {
r = 0;
c++;
if (c >= LEVEL_COLS) {
break;
}
}
}
levelLast = i + 1;
/* backwards and forwards */
MenuSetActive (MenuAddVButton
(0, 3 * CELL_H, LEVEL_ROWS * CELL_H / 2, N_("Backward"), ButtonLevelBackward, mlp),
(levelFirst > 0));
MenuSetActive (MenuAddVButton
(14 * CELL_W, 3 * CELL_H, LEVEL_ROWS * CELL_H / 2, N_("Forward"), ButtonLevelForward,
mlp), (levelLast < numLevels));
/* selection buttons */
MenuAddHButton (9 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, N_("All"), ButtonLevelSelectAll, mlp);
MenuAddHButton (15 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, N_("None"), ButtonLevelSelectNone, mlp);
/* cancel & ok */
MenuSetAbort (MenuAddHButton
(3 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, mlp->textAbort, mlp->funcAbort,
mlp->parAbort));
MenuSetDefault (MenuAddHButton
(21 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, mlp->textDefault, ButtonContinue,
mlp));
/* --- */
MenuSetLinks ();
/* that's all */
return XBFalse;
} /* CreateLevelMenu */
/*
* finish list with all levels configs
*/
void
FinishLevelSelection (void)
{
if (NULL != selectList) {
free (selectList);
selectList = NULL;
}
} /* FinishLevelSelection */
/*
* end of file menu_level.h
*/
|