]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/gametypebutton.qc
Header police
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / gametypebutton.qc
1 #include "gametypebutton.qh"
2 #ifndef GAMETYPEBUTTON_H
3 #define GAMETYPEBUTTON_H
4 #include "../item/radiobutton.qc"
5 CLASS(XonoticGametypeButton, RadioButton)
6         METHOD(XonoticGametypeButton, configureXonoticGametypeButton, void(entity, float, string, string));
7         METHOD(XonoticGametypeButton, setChecked, void(entity, float));
8         ATTRIB(XonoticGametypeButton, fontSize, float, SKINFONTSIZE_NORMAL)
9         ATTRIB(XonoticGametypeButton, image, string, SKINGFX_BUTTON_BIG)
10         ATTRIB(XonoticGametypeButton, color, vector, SKINCOLOR_BUTTON_N)
11         ATTRIB(XonoticGametypeButton, colorC, vector, SKINCOLOR_BUTTON_C)
12         ATTRIB(XonoticGametypeButton, colorF, vector, SKINCOLOR_BUTTON_F)
13         ATTRIB(XonoticGametypeButton, colorD, vector, SKINCOLOR_BUTTON_D)
14         ATTRIB(XonoticGametypeButton, srcMulti, float, 1)
15         ATTRIB(XonoticGametypeButton, useDownAsChecked, float, 1)
16
17         ATTRIB(XonoticGametypeButton, cvarName, string, string_null)
18         METHOD(XonoticGametypeButton, loadCvars, void(entity));
19         METHOD(XonoticGametypeButton, saveCvars, void(entity));
20
21         ATTRIB(XonoticGametypeButton, alpha, float, SKINALPHA_TEXT)
22         ATTRIB(XonoticGametypeButton, disabledAlpha, float, SKINALPHA_DISABLED)
23 ENDCLASS(XonoticGametypeButton)
24 entity makeXonoticGametypeButton(float, string, string);
25 #endif
26
27 #ifdef IMPLEMENTATION
28 void GameTypeButton_Click(entity me, entity other);
29 entity makeXonoticGametypeButton(float theGroup, string theCvar, string theText)
30 {
31         entity me;
32         me = NEW(XonoticGametypeButton);
33         me.configureXonoticGametypeButton(me, theGroup, theCvar, theText, theTooltip);
34         return me;
35 }
36 void XonoticGametypeButton_configureXonoticGametypeButton(entity me, float theGroup, string theCvar, string theText, string theTooltip)
37 {
38         me.cvarName = (theCvar) ? theCvar : string_null;
39         me.loadCvars(me);
40         setZonedTooltip(me, theTooltip, theCvar);
41         me.configureRadioButton(me, theText, me.fontSize, me.image, theGroup, 0);
42         me.align = 0.5;
43         me.onClick = GameTypeButton_Click;
44         me.onClickEntity = NULL;
45 }
46 void XonoticGametypeButton_setChecked(entity me, float val)
47 {
48         if(val != me.checked)
49         {
50                 me.checked = val;
51                 me.saveCvars(me);
52         }
53 }
54 void XonoticGametypeButton_loadCvars(entity me)
55 {
56         if (!me.cvarName)
57                 return;
58
59         me.checked = cvar(me.cvarName);
60 }
61 void XonoticGametypeButton_saveCvars(entity me)
62 {
63         if (!me.cvarName)
64                 return;
65
66         cvar_set(me.cvarName, ftos(me.checked));
67 }
68 void GameTypeButton_Click(entity me, entity other)
69 {
70         RadioButton_Click(me, other);
71         me.parent.gameTypeChangeNotify(me.parent);
72 }
73 #endif