File: cl_uibind.cpp

package info (click to toggle)
openmohaa 0.82.1%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 34,192 kB
  • sloc: cpp: 315,720; ansic: 275,789; sh: 312; xml: 246; asm: 141; makefile: 7
file content (401 lines) | stat: -rw-r--r-- 13,300 bytes parent folder | download
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*
===========================================================================
Copyright (C) 2023 the OpenMoHAA team

This file is part of OpenMoHAA source code.

OpenMoHAA source code 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 of the License,
or (at your option) any later version.

OpenMoHAA source code 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/

#include "cl_ui.h"

bind_t::bind_t()
{
    int i;

    commandwidth       = 100;
    commandheight      = 20;
    primarykeywidth    = 100;
    primarykeyheight   = 20;
    alternatekeywidth  = 100;
    alternatekeyheight = 20;
    fillwidth          = 16;
    fillmaterial       = NULL;

    for (i = 0; i < ARRAY_LEN(headermats); i++) {
        headermats[i] = NULL;
    }
}

bind_t::~bind_t()
{
    Clear();
}

void bind_t::Clear(void)
{
    for (int i = binds.NumObjects(); i > 0; i--) {
        bind_item_t *bi;

        bi = binds.ObjectAt(i);
        binds.RemoveObjectAt(i);

        if (bi) {
            delete bi;
        }
    }
}

Event EV_Bind_Header("header", EV_DEFAULT, "iss", "column_num name material", "Set the header of each column");
Event EV_Bind_Width("bind_width", EV_DEFAULT, "i", "width", "Width of the bind menu");
Event EV_Bind_Height("bind_height", EV_DEFAULT, "i", "height", "Height of the bind menu");
Event EV_Bind_FillWidth("bind_fillwidth", EV_DEFAULT, "iS", "width material", "Width of the filling between widgets");
Event EV_Bind_CommandWidth("bind_commandwidth", EV_DEFAULT, "i", "width", "Width of the command item");
Event EV_Bind_CommandHeight("bind_commandheight", EV_DEFAULT, "i", "height", "Height of the command item");
Event EV_Bind_PrimaryKeyWidth("bind_primarykeywidth", EV_DEFAULT, "i", "width", "Width of the primary key item");
Event EV_Bind_PrimaryKeyHeight("bind_primarykeyheight", EV_DEFAULT, "i", "height", "Height of the primary key item");
Event EV_Bind_AlternateKeyWidth("bind_alternatekeywidth", EV_DEFAULT, "i", "width", "Width of the alternate key item");
Event EV_Bind_AlternateKeyHeight(
    "bind_alternatekeyheight", EV_DEFAULT, "i", "height", "Height of the alternate key item"
);
Event EV_Bind_NewItem("binditem", EV_DEFAULT, "ss", "name command", "Create a new bind item in the interface");
Event
    EV_Bind_Align("align", EV_DEFAULT, "sSSSSS", "arg1 arg2 arg3 arg4 arg5 arg6", "Set the alignment on the bind menu");
Event EV_Bind_TitleForegroundColor(
    "titleforegroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the title foreground"
);
Event EV_Bind_TitleBackgroundColor(
    "titlebackgroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the title background"
);
Event EV_Bind_InactiveForegroundColor(
    "inactiveforegroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the inactive button foreground"
);
Event EV_Bind_InactiveBackgroundColor(
    "inactivebackgroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the inactive button background"
);
Event EV_Bind_ActiveForegroundColor(
    "activeforegroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the active button foreground"
);
Event EV_Bind_ActiveBackgroundColor(
    "activebackgroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the active button background"
);
Event EV_Bind_ActiveBorderColor(
    "activebordercolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the active button border"
);
Event EV_Bind_HighlightForegroundColor(
    "highlightforegroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the highlighted button foreground"
);
Event EV_Bind_HighlightBackgroundColor(
    "highlightbackgroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the highlighted button background"
);
Event EV_Bind_SelectForegroundColor(
    "selectforegroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the selected button foreground"
);
Event EV_Bind_SelectBackgroundColor(
    "selectbackgroundcolor", EV_DEFAULT, "ffff", "r g b a", "Set the color for the selected button background"
);
Event EV_Bind_ChangeSound(
    "changesound", EV_DEFAULT, "s", "soundname", "Set the name of the sound to play when the highlighted item changes"
);
Event EV_Bind_ActiveSound(
    "activesound", EV_DEFAULT, "s", "soundname", "Set the name of the sound to play when the item is made active"
);
Event EV_Bind_EnterSound(
    "entersound", EV_DEFAULT, "s", "soundname", "Set the name of the sound to play when the key is entered"
);

CLASS_DECLARATION(Listener, bindlistener, NULL) {
    {&EV_Bind_Width,                    &bindlistener::Width                   },
    {&EV_Bind_Height,                   &bindlistener::Height                  },
    {&EV_Bind_FillWidth,                &bindlistener::FillWidth               },
    {&EV_Bind_CommandWidth,             &bindlistener::CommandWidth            },
    {&EV_Bind_CommandHeight,            &bindlistener::CommandHeight           },
    {&EV_Bind_PrimaryKeyWidth,          &bindlistener::PrimaryKeyWidth         },
    {&EV_Bind_PrimaryKeyHeight,         &bindlistener::PrimaryKeyHeight        },
    {&EV_Bind_AlternateKeyWidth,        &bindlistener::AlternateKeyWidth       },
    {&EV_Bind_AlternateKeyHeight,       &bindlistener::AlternateKeyHeight      },
    {&EV_Bind_Header,                   &bindlistener::Header                  },
    {&EV_Bind_NewItem,                  &bindlistener::NewItem                 },
    {&EV_Bind_Align,                    &bindlistener::Align                   },
    {&EV_Bind_TitleForegroundColor,     &bindlistener::TitleForegroundColor    },
    {&EV_Bind_TitleBackgroundColor,     &bindlistener::TitleBackgroundColor    },
    {&EV_Bind_InactiveForegroundColor,  &bindlistener::InactiveForegroundColor },
    {&EV_Bind_InactiveBackgroundColor,  &bindlistener::InactiveBackgroundColor },
    {&EV_Bind_ActiveForegroundColor,    &bindlistener::ActiveForegroundColor   },
    {&EV_Bind_ActiveBackgroundColor,    &bindlistener::ActiveBackgroundColor   },
    {&EV_Bind_ActiveBorderColor,        &bindlistener::ActiveBorderColor       },
    {&EV_Bind_HighlightForegroundColor, &bindlistener::HighlightForegroundColor},
    {&EV_Bind_HighlightBackgroundColor, &bindlistener::HighlightBackgroundColor},
    {&EV_Bind_SelectForegroundColor,    &bindlistener::SelectForegroundColor   },
    {&EV_Bind_SelectBackgroundColor,    &bindlistener::SelectBackgroundColor   },
    {&EV_Bind_ChangeSound,              &bindlistener::ChangeSound             },
    {&EV_Bind_ActiveSound,              &bindlistener::ActiveSound             },
    {&EV_Bind_EnterSound,               &bindlistener::EnterSound              },
    {NULL,                              NULL                                   }
};

bindlistener::bindlistener() {}

bindlistener::bindlistener(bind_t *b)
{
    bind = b;
}

void bindlistener::Header(Event *ev)
{
    int num;

    num = ev->GetInteger(1) - 1;
    if (num > ARRAY_LEN(bind_t::headers)) {
        return;
    }

    bind->headers[num] = ev->GetString(2);
    if (ev->NumArgs() > 2) {
        bind->headermats[num] = uWinMan.RegisterShader(ev->GetString(3));
    }
}

void bindlistener::ChangeSound(Event *ev)
{
    bind->changesound = ev->GetString(1);
}

void bindlistener::ActiveSound(Event *ev)
{
    bind->activesound = ev->GetString(1);
}

void bindlistener::EnterSound(Event *ev)
{
    bind->entersound = ev->GetString(1);
}

void bindlistener::SelectForegroundColor(Event *ev)
{
    bind->selectfgcolor.r = ev->GetFloat(1);
    bind->selectfgcolor.g = ev->GetFloat(2);
    bind->selectfgcolor.b = ev->GetFloat(3);
    bind->selectfgcolor.a = ev->GetFloat(4);
}

void bindlistener::SelectBackgroundColor(Event *ev)
{
    bind->selectbgcolor.r = ev->GetFloat(1);
    bind->selectbgcolor.g = ev->GetFloat(2);
    bind->selectbgcolor.b = ev->GetFloat(3);
    bind->selectbgcolor.a = ev->GetFloat(4);
}

void bindlistener::TitleForegroundColor(Event *ev)
{
    bind->titlefgcolor.r = ev->GetFloat(1);
    bind->titlefgcolor.g = ev->GetFloat(2);
    bind->titlefgcolor.b = ev->GetFloat(3);
    bind->titlefgcolor.a = ev->GetFloat(4);
}

void bindlistener::TitleBackgroundColor(Event *ev)
{
    bind->titlebgcolor.r = ev->GetFloat(1);
    bind->titlebgcolor.g = ev->GetFloat(2);
    bind->titlebgcolor.b = ev->GetFloat(3);
    bind->titlebgcolor.a = ev->GetFloat(4);
}

void bindlistener::ActiveBorderColor(Event *ev)
{
    bind->activebordercolor.r = ev->GetFloat(1);
    bind->activebordercolor.g = ev->GetFloat(2);
    bind->activebordercolor.b = ev->GetFloat(3);
    bind->activebordercolor.a = ev->GetFloat(4);
}

void bindlistener::ActiveForegroundColor(Event *ev)
{
    bind->activefgcolor.r = ev->GetFloat(1);
    bind->activefgcolor.g = ev->GetFloat(2);
    bind->activefgcolor.b = ev->GetFloat(3);
    bind->activefgcolor.a = ev->GetFloat(4);
}

void bindlistener::ActiveBackgroundColor(Event *ev)
{
    bind->activebgcolor.r = ev->GetFloat(1);
    bind->activebgcolor.g = ev->GetFloat(2);
    bind->activebgcolor.b = ev->GetFloat(3);
    bind->activebgcolor.a = ev->GetFloat(4);
}

void bindlistener::InactiveForegroundColor(Event *ev)
{
    bind->inactivefgcolor.r = ev->GetFloat(1);
    bind->inactivefgcolor.g = ev->GetFloat(2);
    bind->inactivefgcolor.b = ev->GetFloat(3);
    bind->inactivefgcolor.a = ev->GetFloat(4);
}

void bindlistener::InactiveBackgroundColor(Event *ev)
{
    bind->inactivebgcolor.r = ev->GetFloat(1);
    bind->inactivebgcolor.g = ev->GetFloat(2);
    bind->inactivebgcolor.b = ev->GetFloat(3);
    bind->inactivebgcolor.a = ev->GetFloat(4);
}

void bindlistener::HighlightForegroundColor(Event *ev)
{
    bind->highlightfgcolor.r = ev->GetFloat(1);
    bind->highlightfgcolor.g = ev->GetFloat(2);
    bind->highlightfgcolor.b = ev->GetFloat(3);
    bind->highlightfgcolor.a = ev->GetFloat(4);
}

void bindlistener::HighlightBackgroundColor(Event *ev)
{
    bind->highlightbgcolor.r = ev->GetFloat(1);
    bind->highlightbgcolor.g = ev->GetFloat(2);
    bind->highlightbgcolor.b = ev->GetFloat(3);
    bind->highlightbgcolor.a = ev->GetFloat(4);
}

void bindlistener::Align(Event *ev)
{
    int i;

    for (i = 1; i <= ev->NumArgs(); i++) {
        str align = ev->GetString(i);

        if (!str::icmp(align, "left")) {
            bind->align |= WA_LEFT;
        } else if (!str::icmp(align, "right")) {
            bind->align |= WA_RIGHT;
        } else if (!str::icmp(align, "top")) {
            bind->align |= WA_TOP;
        } else if (!str::icmp(align, "bottom")) {
            bind->align |= WA_BOTTOM;
        } else if (!str::icmp(align, "centerx")) {
            bind->align |= WA_CENTERX;
        } else if (!str::icmp(align, "centery")) {
            bind->align |= WA_CENTERY;
        }
    }
}

void bindlistener::NewItem(Event *ev)
{
    bind_item_t      *bt;
    UIReggedMaterial *mat = NULL;

    if (ev->NumArgs() > 2) {
        mat = uWinMan.RegisterShader(ev->GetString(3));
    }

    str n = ev->GetString(1);
    str c = ev->GetString(2);

    bt               = new bind_item_t;
    bt->name         = n;
    bt->command      = c;
    bt->nameMaterial = mat;

    bind->binds.AddObject(bt);
}

void bindlistener::Width(Event *ev)
{
    bind->width = ev->GetInteger(1);
}

void bindlistener::Height(Event *ev)
{
    bind->height = ev->GetInteger(1);
}

void bindlistener::FillWidth(Event *ev)
{
    bind->fillwidth = ev->GetInteger(1);

    if (ev->NumArgs() > 1) {
        bind->fillmaterial = uWinMan.RegisterShader(ev->GetString(2));
    }
}

void bindlistener::CommandWidth(Event *ev)
{
    bind->commandwidth = ev->GetInteger(1);
}

void bindlistener::CommandHeight(Event *ev)
{
    bind->commandheight = ev->GetInteger(1);
}

void bindlistener::PrimaryKeyWidth(Event *ev)
{
    bind->primarykeywidth = ev->GetInteger(1);
}

void bindlistener::PrimaryKeyHeight(Event *ev)
{
    bind->primarykeyheight = ev->GetInteger(1);
}

void bindlistener::AlternateKeyWidth(Event *ev)
{
    bind->alternatekeywidth = ev->GetInteger(1);
}

void bindlistener::AlternateKeyHeight(Event *ev)
{
    bind->alternatekeyheight = ev->GetInteger(1);
}

bool bindlistener::Load(Script& script)
{
    str token;
    str errortext;

    while (script.TokenAvailable(true)) {
        token = script.GetToken(true);

        if (!token.length() || !ValidEvent(token)) {
            throw "invalid token";
        }

        Event *event = new Event(token);

        while (script.TokenAvailable(false)) {
            event->AddToken(script.GetToken(false));
        }

        ProcessEvent(event);
    }

    return true;
}

bool CL_LoadBind(const char *filename, bind_t *bind)
{
    Script script;

    bind->Clear();

    bindlistener listener(bind);
    script.LoadFile(filename);
    // Load the bind file
    return listener.Load(script);
}