File: uipulldownmenucontainer.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 (300 lines) | stat: -rw-r--r-- 9,299 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
/*
===========================================================================
Copyright (C) 2015 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 "ui_local.h"

Event EV_UIPulldownMenuContainer_AddPopup
(
    "addpopup",
    EV_DEFAULT,
    "ssss",
    "menuname title type string",
    "Adds a popup to the list box.\n"
    "menuname - the name of the menu to add this to\n"
    "title - the string to display\n"
    "type - type of item this is (command,cvar,event_name)\n"
    "string - the data that corresponds to the correct type\n"
);

Event EV_UIPulldownMenuContainer_MenuShader
(
    "menushader",
    EV_DEFAULT,
    "ss",
    "menuname shader",
    "Adds a menu to the container and sets the shader.\n"
    "menuname - the name of the menu to add this to\n"
    "shader - the string to display"
);

Event EV_UIPulldownMenuContainer_SelectedMenuShader
(
    "selmenushader",
    EV_DEFAULT,
    "ss",
    "menuname shader",
    "Adds a menu to the container and sets the shader when it's selected.\n"
    "menuname - the name of the menu to add this to\n"
    "shader - the string to display"
);

Event EV_UIPulldownMenuContainer_PopupHighlightFGColor
(
    "popup_highlight_fgcolor",
    EV_DEFAULT,
    "sffff",
    "menu r g b a",
    "Set the highlight background color of the popup menu\n"
    "menu - the name of the popup menu to color\n"
);

Event EV_UIPulldownMenuContainer_HighlightBGColor
(
    "highlight_bgcolor",
    EV_DEFAULT,
    "sffff",
    "menu r g b a",
    "Set the highlight foreground color of the pulldown menu\n"
    "menu - the name of the popup menu to color\n"
);

Event EV_UIPulldownMenuContainer_HighlightFGColor
(
    "highlight_fgcolor",
    EV_DEFAULT,
    "sffff",
    "menu r g b a",
    "Set the highlight background color of the pulldown menu\n"
    "menu - the name of the popup menu to color\n"
);

Event EV_UIPulldownMenuContainer_PopupHighlightBGColor
(
    "popup_highlight_bgcolor",
    EV_DEFAULT,
    "sffff",
    "menu r g b a",
    "Set the highlight foreground color of the popup menu\n"
    "menu - the name of the popup menu to color\n"
);

Event EV_UIPulldownMenuContainer_PopupFGColor
(
    "popup_fgcolor",
    EV_DEFAULT,
    "sffff",
    "menu r g b a",
    "Set the background color of the popup menu\n"
    "menu - the name of the popup menu to color\n"
);

Event EV_UIPulldownMenuContainer_PopupBGColor
(
    "popup_bgcolor",
    EV_DEFAULT,
    "sffff",
    "menu r g b a",
    "Set the foreground color of the popup menu\n"
    "menu - the name of the popup menu to color\n"
);

CLASS_DECLARATION(UIWidget, UIPulldownMenuContainer, NULL) {
    {&EV_UIPulldownMenuContainer_AddPopup,              &UIPulldownMenuContainer::AddPopup                },
    {&EV_UIPulldownMenuContainer_MenuShader,            &UIPulldownMenuContainer::SetMenuShader           },
    {&EV_UIPulldownMenuContainer_SelectedMenuShader,    &UIPulldownMenuContainer::SetSelectedMenuShader   },
    {&EV_UIPulldownMenuContainer_PopupHighlightFGColor, &UIPulldownMenuContainer::SetPopupHighlightFGColor},
    {&EV_UIPulldownMenuContainer_PopupHighlightBGColor, &UIPulldownMenuContainer::SetPopupHighlightBGColor},
    {&EV_UIPulldownMenuContainer_PopupFGColor,          &UIPulldownMenuContainer::SetPopupFGColor         },
    {&EV_UIPulldownMenuContainer_PopupBGColor,          &UIPulldownMenuContainer::SetPopupBGColor         },
    {&EV_UIPulldownMenuContainer_HighlightFGColor,      &UIPulldownMenuContainer::SetHighlightFGColor     },
    {&EV_UIPulldownMenuContainer_HighlightBGColor,      &UIPulldownMenuContainer::SetHighlightBGColor     },
    {&EV_Layout_VirtualRes,                             &UIPulldownMenuContainer::PulldownVirtualRes      },
    {NULL,                                              NULL                                              }
};

UIPulldownMenuContainer::UIPulldownMenuContainer()
{
    m_menu = new UIPulldownMenu();
    m_menu->CreateAligned(this, this);
}

UIPulldownMenuContainer::~UIPulldownMenuContainer()
{
    for (int i = m_popups.NumObjects(); i > 0; i--) {
        uipopup_describe *uipd = m_popups.ObjectAt(i);
        m_popups.RemoveObjectAt(i);
        delete uipd;
    }

    for (int i = m_dataContainer.NumObjects(); i > 0; i--) {
        char *data = m_dataContainer.ObjectAt(i);
        m_dataContainer.RemoveObjectAt(i);
        delete data;
    }

    // FIXME: m_menu isn't deleted, possible memory leak!
}

void UIPulldownMenuContainer::FrameInitialized(void)
{
    AllowActivate(qfalse);
    m_menu->setBackgroundColor(m_background_color, qtrue);
    m_menu->setForegroundColor(m_foreground_color);
}

void UIPulldownMenuContainer::setBackgroundAlpha(float f)
{
    m_alpha = f;
    m_menu->setBackgroundAlpha(f);
}

void UIPulldownMenuContainer::setBackgroundColor(const UColor& color, bool setbordercolor)
{
    UIWidget::setBackgroundColor(color, setbordercolor);
    m_menu->setBackgroundColor(color, setbordercolor);
}

void UIPulldownMenuContainer::setForegroundColor(const UColor& color)
{
    UIWidget::setForegroundColor(color);
    m_menu->setForegroundColor(color);
}

void UIPulldownMenuContainer::SetPopupHighlightFGColor(Event *ev)
{
    str   menu = ev->GetString(1);
    float r    = ev->GetFloat(2);
    float g    = ev->GetFloat(3);
    float b    = ev->GetFloat(4);
    float a    = ev->GetFloat(5);

    m_menu->setPopupHighlightFGColor(menu, UColor(r, g, b, a));
}

void UIPulldownMenuContainer::SetPopupHighlightBGColor(Event *ev)
{
    str   menu = ev->GetString(1);
    float r    = ev->GetFloat(2);
    float g    = ev->GetFloat(3);
    float b    = ev->GetFloat(4);
    float a    = ev->GetFloat(5);

    m_menu->setPopupHighlightBGColor(menu, UColor(r, g, b, a));
}

void UIPulldownMenuContainer::SetPopupFGColor(Event *ev)
{
    str   menu = ev->GetString(1);
    float r    = ev->GetFloat(2);
    float g    = ev->GetFloat(3);
    float b    = ev->GetFloat(4);
    float a    = ev->GetFloat(5);

    m_menu->setPopupFGColor(menu, UColor(r, g, b, a));
}

void UIPulldownMenuContainer::SetPopupBGColor(Event *ev)
{
    str   menu = ev->GetString(1);
    float r    = ev->GetFloat(2);
    float g    = ev->GetFloat(3);
    float b    = ev->GetFloat(4);
    float a    = ev->GetFloat(5);

    m_menu->setPopupBGColor(menu, UColor(r, g, b, a));
}

void UIPulldownMenuContainer::SetHighlightFGColor(Event *ev)
{
    // original game goes 1-4 for some reason
    float r = ev->GetFloat(2);
    float g = ev->GetFloat(3);
    float b = ev->GetFloat(4);
    float a = ev->GetFloat(5);

    m_menu->setHighlightFGColor(UColor(r, g, b, a));
}

void UIPulldownMenuContainer::SetHighlightBGColor(Event *ev)
{
    // original game goes 1-4 for some reason
    float r = ev->GetFloat(2);
    float g = ev->GetFloat(3);
    float b = ev->GetFloat(4);
    float a = ev->GetFloat(5);

    m_menu->setHighlightBGColor(UColor(r, g, b, a));
}

void UIPulldownMenuContainer::SetMenuShader(Event *ev)
{
    str               menu   = ev->GetString(1);
    str               shader = ev->GetString(2);
    UIReggedMaterial *mat    = uWinMan.RegisterShader(shader);
    m_menu->setPulldownShader(menu, mat);
}

void UIPulldownMenuContainer::SetSelectedMenuShader(Event *ev)
{
    str               menu   = ev->GetString(1);
    str               shader = ev->GetString(2);
    UIReggedMaterial *mat    = uWinMan.RegisterShader(shader);
    m_menu->setSelectedPulldownShader(menu, mat);
}

void UIPulldownMenuContainer::Realign(void)
{
    UIWidget::Realign();
    m_menu->Realign();
}

void UIPulldownMenuContainer::PulldownVirtualRes(Event *ev)
{
    LayoutVirtualRes(ev);

    if (m_bVirtual) {
        Event *newEv = new Event(EV_Layout_VirtualRes);
        newEv->AddInteger(1);
        m_menu->ProcessEvent(newEv);
    }
}

void UIPulldownMenuContainer::AddPopup(Event *ev)
{
    str menu  = ev->GetString(1);
    str title = ev->GetString(2);
    str t     = ev->GetString(3);
    str d     = ev->GetString(4);

    uipopup_type type = UI_PopupTypeStringToInt(t);

    // Make sure to create a duplicate of the original string,
    // otherwise `data` will point to junk when `d` is destroyed.
    // This only seems to run for each popup menu during game startup,
    // so it doesn't appear to leak memory continuously,
    // but it's being cleaned up in uipopup_describe's dtor anyway.
    void *data = strdup(d);

    uipopup_describe *uipd = new uipopup_describe(title, type, data, NULL);
    m_popups.AddObject(uipd);
    m_menu->AddUIPopupDescribe(menu, uipd);
}