]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/gametypelist.qc
Update notifications.cfg
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / gametypelist.qc
1 #include "gametypelist.qh"
2
3 #include "dialog_multiplayer_create.qh"
4 #include <common/mapinfo.qh>
5
6 entity makeXonoticGametypeList()
7 {
8         entity me;
9         me = NEW(XonoticGametypeList);
10         me.configureXonoticGametypeList(me);
11         return me;
12 }
13 void XonoticGametypeList_configureXonoticGametypeList(entity me)
14 {
15         me.configureXonoticListBox(me);
16         me.nItems = GameType_GetCount();
17
18         if(SKINBOOL_GAMETYPELIST_ICON_BLUR)
19         {
20                 for(int i = 0; i < GameType_GetTotalCount(); ++i)
21                         draw_PreloadPictureWithFlags(GameType_GetIcon(i), PRECACHE_PIC_MIPMAP);
22         }
23
24         me.loadCvars(me);
25 }
26 void XonoticGametypeList_setSelected(entity me, float i)
27 {
28         SUPER(XonoticGametypeList).setSelected(me, i);
29         me.saveCvars(me);
30 }
31 void XonoticGametypeList_loadCvars(entity me)
32 {
33         Gametype t = MapInfo_CurrentGametype();
34         float i;
35         for(i = 0; i < GameType_GetCount(); ++i)
36                 if(t == GameType_GetID(i))
37                         break;
38         if(i >= GameType_GetCount())
39         {
40                 for(i = 0; i < GameType_GetCount(); ++i)
41                         if(t == MAPINFO_TYPE_DEATHMATCH)
42                                 break;
43                 if(i >= GameType_GetCount())
44                         i = 0;
45         }
46         me.setSelected(me, i);
47         // do we need this: me.parent.gameTypeChangeNotify(me.parent); // to make sure
48 }
49 void XonoticGametypeList_saveCvars(entity me)
50 {
51         Gametype t = GameType_GetID(me.selectedItem);
52         if (t == MapInfo_CurrentGametype()) {
53                 return;
54         }
55         MapInfo_SwitchGameType(t);
56         entity owner = me.parent;
57         if (owner) { // not set immediately
58                 owner.gameTypeChangeNotify(owner);
59         }
60 }
61 void XonoticGametypeList_draw(entity me)
62 {
63         if(me.nItems != GameType_GetCount())
64         {
65                 me.nItems = GameType_GetCount();
66                 me.setSelected(me, 0);
67         }
68         SUPER(XonoticGametypeList).draw(me);
69 }
70 void XonoticGametypeList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
71 {
72         string s1, s2;
73
74         if(isSelected)
75                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
76         else if(isFocused)
77         {
78                 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
79                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
80         }
81
82         draw_Picture(me.columnIconOrigin * eX, GameType_GetIcon(i), me.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
83         s1 = GameType_GetName(i);
84
85         if(_MapInfo_GetTeamPlayBool(GameType_GetID(i)))
86                 s2 = _("teamplay");
87         else
88                 s2 = _("free for all");
89
90         vector save_fontscale = draw_fontscale;
91         float f = draw_CondensedFontFactor(strcat(s1, " ", s2), false, me.realFontSize, 1);
92         draw_fontscale.x *= f;
93         vector fs = me.realFontSize;
94         fs.x *= f;
95         draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s1, fs, '1 1 1', SKINALPHA_TEXT, 0);
96         draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 1.0 * (me.columnNameSize - draw_TextWidth(s2, 0, fs))) * eX, s2, fs, SKINCOLOR_TEXT, SKINALPHA_TEXT, 0);
97         draw_fontscale = save_fontscale;
98 }
99 void XonoticGametypeList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
100 {
101         me.itemAbsSize = '0 0 0';
102         SUPER(XonoticGametypeList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
103
104         me.itemAbsSize.y = absSize.y * me.itemHeight;
105         me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
106         me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
107         me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
108         me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
109         me.columnIconOrigin = 0;
110         me.columnIconSize = me.itemAbsSize.y / me.itemAbsSize.x;
111         me.columnNameOrigin = me.columnIconOrigin + me.columnIconSize + (0.5 * me.realFontSize.x);
112         me.columnNameSize = 1 - me.columnIconSize - (1.5 * me.realFontSize.x);
113 }
114 float XonoticGametypeList_keyDown(entity me, float scan, float ascii, float shift)
115 {
116         if(scan == K_ENTER || scan == K_KP_ENTER)
117         {
118                 m_play_click_sound(MENU_SOUND_EXECUTE);
119                 me.parent.gameTypeSelectNotify(me.parent);
120                 return 1;
121         }
122
123         return SUPER(XonoticGametypeList).keyDown(me, scan, ascii, shift);
124 }
125 void XonoticGametypeList_clickListBoxItem(entity me, float i, vector where)
126 {
127         m_play_click_sound(MENU_SOUND_SELECT);
128 }
129 void XonoticGametypeList_focusedItemChangeNotify(entity me)
130 {
131         if(me.focusedItem >= 0)
132                 setZonedTooltip(me, MapInfo_Type_Description(GameType_GetID(me.focusedItem)), string_null);
133         else
134                 clearTooltip(me);
135 }