]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/serverlist.qh
Merge branch 'master' into Mario/overkill
[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, avoiding an 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, filterString, string);
41         ATTRIB(XonoticServerList, controlledTextbox, entity);
42         ATTRIB(XonoticServerList, ipAddressBox, entity);
43         ATTRIB(XonoticServerList, favoriteButton, entity);
44         ATTRIB(XonoticServerList, nextRefreshTime, float, 0);
45         METHOD(XonoticServerList, refreshServerList, void(entity, float));  // refresh mode: REFRESHSERVERLIST_*
46         ATTRIB(XonoticServerList, needsRefresh, float, 1);
47         METHOD(XonoticServerList, focusEnter, void(entity));
48         METHOD(XonoticServerList, positionSortButton, void(entity, entity, float, float, string, void(entity, entity)));
49         ATTRIB(XonoticServerList, sortButton1, entity);
50         ATTRIB(XonoticServerList, sortButton2, entity);
51         ATTRIB(XonoticServerList, sortButton3, entity);
52         ATTRIB(XonoticServerList, sortButton4, entity);
53         ATTRIB(XonoticServerList, sortButton5, entity);
54         ATTRIB(XonoticServerList, connectButton, entity);
55         ATTRIB(XonoticServerList, infoButton, entity);
56         ATTRIB(XonoticServerList, currentSortOrder, float, 0);
57         ATTRIB(XonoticServerList, currentSortField, float, -1);
58
59         ATTRIB(XonoticServerList, ipAddressBoxFocused, float, -1);
60
61         ATTRIB(XonoticServerList, seenIPv4, float, 0);
62         ATTRIB(XonoticServerList, seenIPv6, float, 0);
63         ATTRIB(XonoticServerList, categoriesHeight, float, 1.25);
64
65         METHOD(XonoticServerList, getTotalHeight, float(entity));
66         METHOD(XonoticServerList, getItemAtPos, float(entity, float));
67         METHOD(XonoticServerList, getItemStart, float(entity, float));
68         METHOD(XonoticServerList, getItemHeight, float(entity, float));
69 ENDCLASS(XonoticServerList)
70 entity makeXonoticServerList();
71
72 void RegisterSLCategories();
73 float CheckCategoryForEntry(float entry);
74 void ServerList_Filter_Change(entity box, entity me);
75 void ServerList_Categories_Click(entity box, entity me);
76 void ServerList_ShowEmpty_Click(entity box, entity me);
77 void ServerList_ShowFull_Click(entity box, entity me);
78 void ServerList_Connect_Click(entity btn, entity me);
79 void ServerList_Update_favoriteButton(entity btn, entity me);
80 void ServerList_Favorite_Click(entity btn, entity me);
81 void ServerList_Info_Click(entity btn, entity me);
82
83 // server cache fields
84 #define SLIST_FIELDS \
85         SLIST_FIELD(CNAME,       "cname") \
86         SLIST_FIELD(PING,        "ping") \
87         SLIST_FIELD(GAME,        "game") \
88         SLIST_FIELD(MOD,         "mod") \
89         SLIST_FIELD(MAP,         "map") \
90         SLIST_FIELD(NAME,        "name") \
91         SLIST_FIELD(MAXPLAYERS,  "maxplayers") \
92         SLIST_FIELD(NUMPLAYERS,  "numplayers") \
93         SLIST_FIELD(NUMHUMANS,   "numhumans") \
94         SLIST_FIELD(NUMBOTS,     "numbots") \
95         SLIST_FIELD(PROTOCOL,    "protocol") \
96         SLIST_FIELD(FREESLOTS,   "freeslots") \
97         SLIST_FIELD(PLAYERS,     "players") \
98         SLIST_FIELD(QCSTATUS,    "qcstatus") \
99         SLIST_FIELD(CATEGORY,    "category") \
100         SLIST_FIELD(ISFAVORITE,  "isfavorite")
101
102 #define SLIST_FIELD(suffix,name) float SLIST_FIELD_##suffix;
103 SLIST_FIELDS
104 #undef SLIST_FIELD
105
106 float autocvar_menu_slist_categories;
107 float autocvar_menu_slist_categories_onlyifmultiple;
108 float autocvar_menu_slist_purethreshold;
109 float autocvar_menu_slist_modimpurity;
110 float autocvar_menu_slist_recommendations;
111 float autocvar_menu_slist_recommendations_maxping;
112 float autocvar_menu_slist_recommendations_minfreeslots;
113 float autocvar_menu_slist_recommendations_minhumans;
114 float autocvar_menu_slist_recommendations_purethreshold;
115
116 const float REFRESHSERVERLIST_RESORT = 0;    // sort the server list again to update for changes to e.g. favorite status, categories
117 const float REFRESHSERVERLIST_REFILTER = 1;  // ..., also update filter and sort criteria
118 const float REFRESHSERVERLIST_ASK = 2;       // ..., also suggest querying servers now
119 const float REFRESHSERVERLIST_RESET = 3;     // ..., also clear the list first
120
121 // function declarations
122 float IsServerInList(string list, string srv);
123 #define IsFavorite(srv) IsServerInList(cvar_string("net_slist_favorites"), srv)
124 #define IsPromoted(srv) IsServerInList(_Nex_ExtResponseSystem_PromotedServers, srv)
125 #define IsRecommended(srv) IsServerInList(_Nex_ExtResponseSystem_RecommendedServers, srv)
126
127 entity RetrieveCategoryEnt(float catnum);
128
129 float CheckCategoryOverride(float cat);
130 float m_gethostcachecategory(float entry) { return CheckCategoryOverride(CheckCategoryForEntry(entry)); }
131
132
133 // fields for category entities
134 const int MAX_CATEGORIES = 9;
135 const int CATEGORY_FIRST = 1;
136 entity categories[MAX_CATEGORIES];
137 int category_ent_count;
138 .string cat_name;
139 .string cat_string;
140 .string cat_enoverride_string;
141 .string cat_dioverride_string;
142 .float cat_enoverride;
143 .float cat_dioverride;
144
145 // fields for drawing categories
146 int category_name[MAX_CATEGORIES];
147 int category_item[MAX_CATEGORIES];
148 int category_draw_count;
149
150 #define SLIST_CATEGORIES \
151         SLIST_CATEGORY(CAT_FAVORITED,    "",            "",             CTX(_("SLCAT^Favorites"))) \
152         SLIST_CATEGORY(CAT_RECOMMENDED,  "",            "",             CTX(_("SLCAT^Recommended"))) \
153         SLIST_CATEGORY(CAT_NORMAL,       "",            "CAT_SERVERS",  CTX(_("SLCAT^Normal Servers"))) \
154         SLIST_CATEGORY(CAT_SERVERS,      "CAT_NORMAL",  "CAT_SERVERS",  CTX(_("SLCAT^Servers"))) \
155         SLIST_CATEGORY(CAT_XPM,          "CAT_NORMAL",  "CAT_SERVERS",  CTX(_("SLCAT^Competitive Mode"))) \
156         SLIST_CATEGORY(CAT_MODIFIED,     "",            "CAT_SERVERS",  CTX(_("SLCAT^Modified Servers"))) \
157         SLIST_CATEGORY(CAT_OVERKILL,     "",            "CAT_SERVERS",  CTX(_("SLCAT^Overkill"))) \
158         SLIST_CATEGORY(CAT_INSTAGIB,     "",            "CAT_SERVERS",  CTX(_("SLCAT^InstaGib"))) \
159         SLIST_CATEGORY(CAT_DEFRAG,       "",            "CAT_SERVERS",  CTX(_("SLCAT^Defrag Mode")))
160
161 #define SLIST_CATEGORY_AUTOCVAR(name) autocvar_menu_slist_categories_##name##_override
162 #define SLIST_CATEGORY(name,enoverride,dioverride,str) \
163         int name; \
164         string SLIST_CATEGORY_AUTOCVAR(name) = enoverride;
165 SLIST_CATEGORIES
166 #undef SLIST_CATEGORY