-
Notifications
You must be signed in to change notification settings - Fork 3
/
o_main.c
328 lines (271 loc) · 6.73 KB
/
o_main.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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/* o_main.c -- options menu */
#include "doomdef.h"
#include "p_local.h"
#include "st_main.h"
#define MOVEWAIT 5
#define ITEMSPACE 40
#define SLIDEWIDTH 90
extern int cx, cy;
extern int sfxvolume; /* range from 0 to 255 */
extern int controltype; /* 0 to 5 */
extern void print (int x, int y, char *string);
extern void IN_DrawValue(int x,int y,int value);
/* action buttons can be set to BT_A, BT_B, or BT_C */
/* strafe and use should be set to the same thing */
extern unsigned BT_ATTACK;
extern unsigned BT_USE;
extern unsigned BT_STRAFE;
extern unsigned BT_SPEED;
typedef enum
{
SFU,
SUF,
FSU,
FUS,
USF,
UFS,
NUMCONTROLOPTIONS
} control_t;
typedef enum
{
soundvol,
controls,
NUMMENUITEMS
} menupos_t;
menupos_t cursorpos;
typedef struct
{
int x;
int y;
boolean hasslider;
char name[20];
} menuitem_t;
menuitem_t menuitem[3];
typedef struct
{
int curval;
int maxval;
} slider_t;
slider_t slider[2];
int cursorframe, cursorcount;
int movecount;
jagobj_t *uchar[52];
jagobj_t *o_cursor1, *o_cursor2;
jagobj_t *o_slider, *o_slidertrack;
char buttona[NUMCONTROLOPTIONS][8] =
{"Speed","Speed","Fire","Fire","Use","Use"};
char buttonb[NUMCONTROLOPTIONS][8] =
{"Fire","Use ","Speed","Use","Speed","Fire"};
char buttonc[NUMCONTROLOPTIONS][8] =
{"Use","Fire","Use","Speed","Fire","Speed"};
unsigned configuration[NUMCONTROLOPTIONS][3] =
{
{BT_A, BT_B, BT_C},
{BT_A, BT_C, BT_B},
{BT_B, BT_A, BT_C},
{BT_C, BT_A, BT_B},
{BT_B, BT_C, BT_A},
{BT_C, BT_B, BT_A}
};
void O_SetButtonsFromControltype (void)
{
BT_SPEED = configuration[controltype][0];
BT_ATTACK = configuration[controltype][1];
BT_USE = configuration[controltype][2];
BT_STRAFE = configuration[controltype][2];
}
/* */
/* Draw control value */
/* */
void O_DrawControl(void)
{
EraseBlock(menuitem[controls].x + 40, menuitem[controls].y + 20, 90, 80);
print(menuitem[controls].x + 40, menuitem[controls].y + 20, buttona[controltype]);
print(menuitem[controls].x + 40, menuitem[controls].y + 40, buttonb[controltype]);
print(menuitem[controls].x + 40, menuitem[controls].y + 60, buttonc[controltype]);
/* IN_DrawValue(30, 20, controltype); */
O_SetButtonsFromControltype ();
}
/*
===============
=
= O_Init
=
===============
*/
void O_Init (void)
{
int i, l;
/* the eeprom has set controltype, so set buttons from that */
O_SetButtonsFromControltype ();
/* cache all needed graphics */
o_cursor1 = W_CacheLumpName ("M_SKULL1",PU_STATIC);
o_cursor2 = W_CacheLumpName ("M_SKULL2",PU_STATIC);
o_slider = W_CacheLumpName ("O_SLIDER", PU_STATIC);
o_slidertrack = W_CacheLumpName ("O_STRACK", PU_STATIC);
l = W_GetNumForName ("CHAR_065");
for (i = 0; i < 52; i++)
uchar[i] = W_CacheLumpNum(l+i, PU_STATIC);
/* initialize variables */
cursorcount = 0;
cursorframe = 0;
cursorpos = 0;
/* strcpy(menuitem[0].name, " Volume"); */
D_strncpy(menuitem[0].name, " Volume", 8); /* Fixed CEF */
menuitem[0].x = 95;
menuitem[0].y = 50;
menuitem[0].hasslider = true;
slider[0].maxval = 16;
slider[0].curval = 16*sfxvolume/255;
/* strcpy(menuitem[1].name, "Controls"); */
D_strncpy(menuitem[1].name, "Controls", 8); /* Fixed CEF */
menuitem[1].x = 95;
menuitem[1].y = 110;
menuitem[1].hasslider = false;
}
/*
==================
=
= O_Control
=
= Button bits can be eaten by clearing them in ticbuttons[playernum]
==================
*/
void O_Control (player_t *player)
{
int buttons, oldbuttons;
buttons = ticbuttons[playernum];
oldbuttons = oldticbuttons[playernum];
if ( (buttons & BT_OPTION) && !(oldbuttons & BT_OPTION) )
{
cursorpos = 0;
player->automapflags ^= AF_OPTIONSACTIVE;
if (player->automapflags & AF_OPTIONSACTIVE)
DoubleBufferSetup ();
else
WriteEEProm (); /* save new settings */
}
if ( !(player->automapflags & AF_OPTIONSACTIVE) )
return;
/* clear buttons so game player isn't moving aroung */
ticbuttons[playernum] &= BT_OPTION; /* leave option status alone */
if (playernum != consoleplayer)
return;
/* animate skull */
if (++cursorcount == 4)
{
cursorframe ^= 1;
cursorcount = 0;
}
/* check for movement */
if (! (buttons & (JP_UP|JP_DOWN|JP_LEFT|JP_RIGHT) ) )
movecount = 0; /* move immediately on next press */
else
{
if (buttons & JP_RIGHT)
{
if (menuitem[cursorpos].hasslider)
{
slider[cursorpos].curval++;
if (slider[cursorpos].curval > slider[cursorpos].maxval)
slider[cursorpos].curval = slider[cursorpos].maxval;
if (cursorpos == 0)
{
sfxvolume = 255*slider[0].curval / slider[0].maxval;
S_StartSound (NULL, sfx_pistol);
}
}
}
if (buttons & JP_LEFT)
{
if (menuitem[cursorpos].hasslider)
{
slider[cursorpos].curval--;
if (slider[cursorpos].curval < 0)
slider[cursorpos].curval = 0;
if (cursorpos == 0)
{
sfxvolume = 255*slider[0].curval / slider[0].maxval;
S_StartSound (NULL, sfx_pistol);
}
}
}
if (movecount == MOVEWAIT)
movecount = 0; /* repeat move */
if (++movecount == 1)
{
if (buttons & JP_DOWN)
{
cursorpos++;
if (cursorpos == NUMMENUITEMS)
cursorpos = 0;
}
if (buttons & JP_UP)
{
cursorpos--;
if (cursorpos == -1)
cursorpos = NUMMENUITEMS-1;
}
if (buttons & JP_RIGHT)
{
if (cursorpos == controls)
{
controltype++;
if(controltype == NUMCONTROLOPTIONS)
controltype = (NUMCONTROLOPTIONS - 1);
}
}
if (buttons & JP_LEFT)
{
if (cursorpos == controls)
{
controltype--;
if(controltype == -1)
controltype = 0;
}
}
}
}
}
void O_Drawer (void)
{
int i;
int offset;
/* Erase old and Draw new cursor frame */
EraseBlock(56, 40, o_cursor1->width, 200);
if(cursorframe)
DrawJagobj(o_cursor1, 60, menuitem[cursorpos].y - 2);
else
DrawJagobj(o_cursor2, 60, menuitem[cursorpos].y - 2);
/* Draw menu */
print(104, 10, "Options");
for (i = 0; i < NUMMENUITEMS; i++)
{
print(menuitem[i].x, menuitem[i].y, menuitem[i].name);
if(menuitem[i].hasslider == true)
{
DrawJagobj(o_slidertrack , menuitem[i].x + 2, menuitem[i].y + 20);
offset = (slider[i].curval * SLIDEWIDTH) / slider[i].maxval;
DrawJagobj(o_slider, menuitem[i].x + 7 + offset, menuitem[i].y + 20);
/* ST_Num(menuitem[i].x + o_slider->width + 10, */
/* menuitem[i].y + 20,slider[i].curval); */
}
}
/* Draw control info */
print(menuitem[controls].x + 10, menuitem[controls].y + 20, "A");
print(menuitem[controls].x + 10, menuitem[controls].y + 40, "B");
print(menuitem[controls].x + 10, menuitem[controls].y + 60, "C");
O_DrawControl();
/* debug stuff */
#if 0
cx = 30;
cy = 40;
D_printf("Speed = %d", BT_SPEED);
cy = 60;
D_printf("Use/Strafe = %d", BT_SPEED);
cy = 80;
D_printf("Fire = %d", BT_SPEED);
#endif
/* end of debug stuff */
UpdateBuffer ();
}