]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/serverlist.qh
Restore white tos text
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / serverlist.qh
1 #pragma once
2
3 #include "listbox.qh"
4 CLASS(XonoticServerList, XonoticListBox)
5         METHOD(XonoticServerList, configureXonoticServerList, void(entity));
6         ATTRIB(XonoticServerList, rowsPerItem, float, 1);
7         METHOD(XonoticServerList, draw, void(entity));
8         METHOD(XonoticServerList, drawListBoxItem, void(entity, int, vector, bool, bool));
9         METHOD(XonoticServerList, doubleClickListBoxItem, void(entity, float, vector));
10         METHOD(XonoticServerList, resizeNotify, void(entity, vector, vector, vector, vector));
11         METHOD(XonoticServerList, keyDown, float(entity, float, float, float));
12         METHOD(XonoticServerList, toggleFavorite, void(entity, string));
13
14         ATTRIB(XonoticServerList, iconsSizeFactor, float, 0.85);
15         METHOD(XonoticServerList, mouseMove, float(entity, vector));
16         ATTRIB(XonoticServerList, mouseOverIcons, bool, false);
17         METHOD(XonoticServerList, focusedItemChangeNotify, void(entity));
18
19         ATTRIB(XonoticServerList, realFontSize, vector, '0 0 0');
20         ATTRIB(XonoticServerList, realUpperMargin, float, 0);
21         ATTRIB(XonoticServerList, columnIconsOrigin, float, 0);
22         ATTRIB(XonoticServerList, columnIconsSize, float, 0);
23         ATTRIB(XonoticServerList, columnPingOrigin, float, 0);
24         ATTRIB(XonoticServerList, columnPingSize, float, 0);
25         ATTRIB(XonoticServerList, columnNameOrigin, float, 0);
26         ATTRIB(XonoticServerList, columnNameSize, float, 0);
27         ATTRIB(XonoticServerList, columnMapOrigin, float, 0);
28         ATTRIB(XonoticServerList, columnMapSize, float, 0);
29         ATTRIB(XonoticServerList, columnTypeOrigin, float, 0);
30         ATTRIB(XonoticServerList, columnTypeSize, float, 0);
31         ATTRIB(XonoticServerList, columnPlayersOrigin, float, 0);
32         ATTRIB(XonoticServerList, columnPlayersSize, float, 0);
33         ATTRIB(XonoticServerList, lockedSelectedItem, bool, true); // initially keep selected the first item of the list to avoid unwanted scrolling
34
35         ATTRIB(XonoticServerList, selectedServer, string); // to restore selected server when needed
36         METHOD(XonoticServerList, setSelected, void(entity, float));
37         METHOD(XonoticServerList, setSortOrder, void(entity, float, float));
38         ATTRIB(XonoticServerList, filterShowEmpty, float, 1);
39         ATTRIB(XonoticServerList, filterShowFull, float, 1);
40         ATTRIB(XonoticServerList, filterShowLaggy, float, 0);
41         ATTRIB(XonoticServerList, filterString, string);
42         ATTRIB(XonoticServerList, controlledTextbox, entity);
43         ATTRIB(XonoticServerList, ipAddressBox, entity);
44         ATTRIB(XonoticServerList, favoriteButton, entity);
45         ATTRIB(XonoticServerList, nextRefreshTime, float, 0);
46         METHOD(XonoticServerList, refreshServerList, void(entity, float));  // refresh mode: REFRESHSERVERLIST_*
47         ATTRIB(XonoticServerList, needsRefresh, float, 1);
48         METHOD(XonoticServerList, focusEnter, void(entity));
49         METHOD(XonoticServerList, positionSortButton, void(entity, entity, float, float, string, void(entity, entity)));
50         ATTRIB(XonoticServerList, sortButton1, entity);
51         ATTRIB(XonoticServerList, sortButton2, entity);
52         ATTRIB(XonoticServerList, sortButton3, entity);
53         ATTRIB(XonoticServerList, sortButton4, entity);
54         ATTRIB(XonoticServerList, sortButton5, entity);
55         ATTRIB(XonoticServerList, connectButton, entity);
56         //ATTRIB(XonoticServerList, disconnectButton, entity);
57         ATTRIB(XonoticServerList, infoButton, entity);
58         ATTRIB(XonoticServerList, currentSortOrder, float, 0);
59         ATTRIB(XonoticServerList, currentSortField, float, -1);
60
61         ATTRIB(XonoticServerList, ipAddressBoxFocused, float, -1);
62
63         ATTRIB(XonoticServerList, seenIPv4, float, 0);
64         ATTRIB(XonoticServerList, seenIPv6, float, 0);
65         ATTRIB(XonoticServerList, categoriesHeight, float, 1.25);
66         ATTRIB(XonoticServerList, serversHeight, float, 1.0);
67
68         METHOD(XonoticServerList, getTotalHeight, float(entity));
69         METHOD(XonoticServerList, getItemAtPos, float(entity, float));
70         METHOD(XonoticServerList, getItemStart, float(entity, float));
71         METHOD(XonoticServerList, getItemHeight, float(entity, float));
72 ENDCLASS(XonoticServerList)
73 entity makeXonoticServerList();
74
75 void RegisterSLCategories();
76 float CategoryForEntry(float entry);
77 void ServerList_Filter_Change(entity box, entity me);
78 void ServerList_Categories_Click(entity box, entity me);
79 void ServerList_ShowEmpty_Click(entity box, entity me);
80 void ServerList_ShowFull_Click(entity box, entity me);
81 void ServerList_ShowLaggy_Click(entity box, entity me);
82 void ServerList_Connect_Click(entity btn, entity me);
83 void ServerList_Update_favoriteButton(entity btn, entity me);
84 void ServerList_Favorite_Click(entity btn, entity me);
85 void ServerList_Info_Click(entity btn, entity me);
86
87 // server cache fields
88 #define SLIST_FIELDS \
89         SLIST_FIELD(CNAME,       "cname") \
90         SLIST_FIELD(PING,        "ping") \
91         SLIST_FIELD(GAME,        "game") \
92         SLIST_FIELD(MOD,         "mod") \
93         SLIST_FIELD(MAP,         "map") \
94         SLIST_FIELD(NAME,        "name") \
95         SLIST_FIELD(MAXPLAYERS,  "maxplayers") \
96         SLIST_FIELD(NUMPLAYERS,  "numplayers") \
97         SLIST_FIELD(NUMHUMANS,   "numhumans") \
98         SLIST_FIELD(NUMBOTS,     "numbots") \
99         SLIST_FIELD(PROTOCOL,    "protocol") \
100         SLIST_FIELD(FREESLOTS,   "freeslots") \
101         SLIST_FIELD(PLAYERS,     "players") \
102         SLIST_FIELD(QCSTATUS,    "qcstatus") \
103         SLIST_FIELD(CATEGORY,    "category") \
104         SLIST_FIELD(ISFAVORITE,  "isfavorite")
105
106 #define SLIST_FIELD(suffix,name) float SLIST_FIELD_##suffix;
107 SLIST_FIELDS
108 #undef SLIST_FIELD
109
110 float autocvar_menu_slist_categories;
111 float autocvar_menu_slist_categories_onlyifmultiple;
112 float autocvar_menu_slist_purethreshold;
113 float autocvar_menu_slist_modimpurity;
114 float autocvar_menu_slist_maxping = 300;
115 float autocvar_menu_slist_recommendations;
116 float autocvar_menu_slist_recommendations_maxping;
117 float autocvar_menu_slist_recommendations_minfreeslots;
118 float autocvar_menu_slist_recommendations_minhumans;
119 float autocvar_menu_slist_recommendations_purethreshold;
120
121 const float REFRESHSERVERLIST_RESORT = 0;    // sort the server list again to update for changes to e.g. favorite status, categories
122 const float REFRESHSERVERLIST_REFILTER = 1;  // ..., also update filter and sort criteria
123 const float REFRESHSERVERLIST_ASK = 2;       // ..., also suggest querying servers now
124 const float REFRESHSERVERLIST_RESET = 3;     // ..., also clear the list first
125
126 // function declarations
127 float IsServerInList(string list, string srv);
128
129 entity RetrieveCategoryEnt(float catnum);
130
131 float CategoryOverride(float cat);
132 float m_gethostcachecategory(float entry);
133
134
135 // fields for category entities
136 const int MAX_CATEGORIES = 9;
137 const int CATEGORY_FIRST = 1;
138 entity categories[MAX_CATEGORIES];
139 int category_ent_count;
140 .string cat_name;
141 .string cat_string;
142 .string cat_enoverride_string;
143 .string cat_dioverride_string;
144 .float cat_enoverride;
145 .float cat_dioverride;
146
147 // fields for drawing categories
148 int category_name[MAX_CATEGORIES];
149 int category_item[MAX_CATEGORIES];
150 int category_draw_count;
151
152 #define SLIST_CATEGORIES \
153         SLIST_CATEGORY(CAT_FAVORITED,    "",            "",             CTX(_("SLCAT^Favorites"))) \
154         SLIST_CATEGORY(CAT_RECOMMENDED,  "",            "",             CTX(_("SLCAT^Recommended"))) \
155         SLIST_CATEGORY(CAT_NORMAL,       "",            "CAT_SERVERS",  CTX(_("SLCAT^Normal Servers"))) \
156         SLIST_CATEGORY(CAT_SERVERS,      "CAT_NORMAL",  "CAT_SERVERS",  CTX(_("SLCAT^Servers"))) \
157         SLIST_CATEGORY(CAT_XPM,          "CAT_NORMAL",  "CAT_SERVERS",  CTX(_("SLCAT^Competitive Mode"))) \
158         SLIST_CATEGORY(CAT_MODIFIED,     "",            "CAT_SERVERS",  CTX(_("SLCAT^Modified Servers"))) \
159         SLIST_CATEGORY(CAT_OVERKILL,     "",            "CAT_SERVERS",  CTX(_("SLCAT^Overkill"))) \
160         SLIST_CATEGORY(CAT_INSTAGIB,     "",            "CAT_SERVERS",  CTX(_("SLCAT^InstaGib"))) \
161         SLIST_CATEGORY(CAT_DEFRAG,       "",            "CAT_SERVERS",  CTX(_("SLCAT^Defrag Mode")))
162
163 #define SLIST_CATEGORY_AUTOCVAR(name) autocvar_menu_slist_categories_##name##_override
164 #define SLIST_CATEGORY(name,enoverride,dioverride,str) \
165         int name; \
166         string SLIST_CATEGORY_AUTOCVAR(name) = enoverride;
167 SLIST_CATEGORIES
168 #undef SLIST_CATEGORY