--- a/src/network/network_gui.cpp Mon May 26 20:45:25 2008 +0000
+++ b/src/network/network_gui.cpp Tue May 27 00:50:55 2008 +0000
@@ -190,7 +190,6 @@
this->field = NGWW_PLAYER;
this->server = NULL;
- this->servers.sort_list = NULL;
this->servers.flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE);
this->servers.sort_type = _ng_sorting.criteria;
@@ -199,7 +198,6 @@
~NetworkGameWindow()
{
- free(this->servers.sort_list);
}
/**
@@ -208,23 +206,17 @@
*/
void BuildNetworkGameList()
{
- NetworkGameList *ngl_temp;
- uint n = 0;
-
if (!(this->servers.flags & VL_REBUILD)) return;
- /* Count the number of games in the list */
- for (ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) n++;
- if (n == 0) return;
-
/* Create temporary array of games to use for listing */
- this->servers.sort_list = ReallocT(this->servers.sort_list, n);
- this->servers.list_length = n;
+ this->servers.Clear();
- for (n = 0, ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) {
- this->servers.sort_list[n++] = ngl_temp;
+ for (NetworkGameList *ngl = _network_game_list; ngl != NULL; ngl = ngl->next) {
+ *this->servers.Append() = ngl;
}
+ this->servers.Compact();
+
/* Force resort */
this->servers.flags &= ~VL_REBUILD;
this->servers.flags |= VL_RESORT;
@@ -242,17 +234,17 @@
uint i;
if (!(this->servers.flags & VL_RESORT)) return;
- if (this->servers.list_length == 0) return;
+ if (this->servers.Length() == 0) return;
_internal_sort_order = !!(this->servers.flags & VL_DESC);
- qsort(this->servers.sort_list, this->servers.list_length, sizeof(this->servers.sort_list[0]), ngame_sorter[this->servers.sort_type]);
+ qsort(this->servers.Begin(), this->servers.Length(), sizeof(this->servers.Begin()), ngame_sorter[this->servers.sort_type]);
/* After sorting ngl->sort_list contains the sorted items. Put these back
* into the original list. Basically nothing has changed, we are only
* shuffling the ->next pointers */
- _network_game_list = this->servers.sort_list[0];
- for (item = _network_game_list, i = 1; i != this->servers.list_length; i++) {
- item->next = this->servers.sort_list[i];
+ _network_game_list = this->servers[0];
+ for (item = _network_game_list, i = 1; i != this->servers.Length(); i++) {
+ item->next = this->servers[i];
item = item->next;
}
item->next = NULL;
@@ -300,7 +292,7 @@
if (this->servers.flags & VL_REBUILD) {
this->BuildNetworkGameList();
- SetVScrollCount(this, this->servers.list_length);
+ SetVScrollCount(this, this->servers.Length());
}
if (this->servers.flags & VL_RESORT) this->SortNetworkGameList();
@@ -543,9 +535,9 @@
this->SetDirty();
}
- virtual bool OnKeyPress(uint16 key, uint16 keycode)
+ virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- bool cont = true;
+ EventState state = ES_NOT_HANDLED;
if (this->field != NGWW_PLAYER) {
if (this->server != NULL) {
if (keycode == WKC_DELETE) { // Press 'delete' to remove servers
@@ -554,10 +546,10 @@
this->server = NULL;
}
}
- return cont;
+ return state;
}
- if (this->HandleEditBoxKey(NGWW_PLAYER, keycode, key, cont) == 1) return cont; // enter pressed
+ if (this->HandleEditBoxKey(NGWW_PLAYER, keycode, key, state) == 1) return state; // enter pressed
/* The name is only allowed when it starts with a letter! */
if (StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') {
@@ -565,7 +557,7 @@
} else {
ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name));
}
- return cont;
+ return state;
}
virtual void OnQueryTextFinished(char *str)
@@ -582,7 +574,7 @@
this->widget[NGWW_MATRIX].data = (this->vscroll.cap << 8) + 1;
- SetVScrollCount(this, this->servers.list_length);
+ SetVScrollCount(this, this->servers.Length());
int widget_width = this->widget[NGWW_FIND].right - this->widget[NGWW_FIND].left;
int space = (this->width - 4 * widget_width - 25) / 3;
@@ -642,7 +634,6 @@
WC_NETWORK_WINDOW, WC_NONE,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
_network_game_window_widgets,
- NULL,
};
void ShowNetworkGameWindow()
@@ -892,16 +883,16 @@
if (this->field == NSSW_GAMENAME) this->HandleEditBox(NSSW_GAMENAME);
}
- virtual bool OnKeyPress(uint16 key, uint16 keycode)
+ virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- bool cont = true;
+ EventState state = ES_NOT_HANDLED;
if (this->field == NSSW_GAMENAME) {
- if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, cont) == 1) return cont; // enter pressed
+ if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, state) == 1) return state; // enter pressed
ttd_strlcpy(_network_server_name, this->text.buf, sizeof(_network_server_name));
}
- return cont;
+ return state;
}
virtual void OnQueryTextFinished(char *str)
@@ -977,7 +968,6 @@
WC_NETWORK_WINDOW, WC_NONE,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_network_start_server_window_widgets,
- NULL,
};
static void ShowNetworkStartServerWindow()
@@ -1191,7 +1181,6 @@
WC_NETWORK_WINDOW, WC_NONE,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_network_lobby_window_widgets,
- NULL,
};
/* Show the networklobbywindow with the selected server
@@ -1237,12 +1226,11 @@
{ WIDGETS_END},
};
-static WindowDesc _client_list_desc = {
+static const WindowDesc _client_list_desc = {
WDP_AUTO, WDP_AUTO, 250, 1, 250, 1,
WC_CLIENT_LIST, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_client_list_widgets,
- NULL
};
// Finds the Xth client-info that is active
@@ -1321,7 +1309,7 @@
ClientList_Action_Proc *proc[MAX_CLIENTLIST_ACTION];
NetworkClientListPopupWindow(int x, int y, const Widget *widgets, int client_no) :
- Window(x, y, 150, 100, NULL, WC_TOOLBAR_MENU, widgets),
+ Window(x, y, 150, 100, WC_TOOLBAR_MENU, widgets),
sel_index(0), client_no(client_no)
{
/*
@@ -1346,7 +1334,7 @@
if (_network_own_client_index != ci->client_index) {
/* We are no spectator and the player we want to give money to is no spectator and money gifts are allowed */
- if (IsValidPlayer(_network_playas) && IsValidPlayer(ci->client_playas) && _patches.give_money) {
+ if (IsValidPlayer(_network_playas) && IsValidPlayer(ci->client_playas) && _settings.economy.give_money) {
GetString(this->action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY, lastof(this->action[i]));
this->proc[i++] = &ClientList_GiveMoney;
}
@@ -1665,7 +1653,6 @@
WC_NETWORK_STATUS_WINDOW, WC_NONE,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_MODAL,
_network_join_status_window_widget,
- NULL,
};
void ShowJoinStatusWindow()
@@ -1878,21 +1865,21 @@
this->HandleEditBox(2);
}
- virtual bool OnKeyPress(uint16 key, uint16 keycode)
+ virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- bool cont = true;
+ EventState state = ES_NOT_HANDLED;
if (keycode == WKC_TAB) {
ChatTabCompletion();
} else {
_chat_tab_completion_active = false;
- switch (this->HandleEditBoxKey(2, key, keycode, cont)) {
+ switch (this->HandleEditBoxKey(2, key, keycode, state)) {
case 1: /* Return */
SendChat(this->text.buf, this->dtype, this->dest);
/* FALLTHROUGH */
case 2: /* Escape */ delete this; break;
}
}
- return cont;
+ return state;
}
};
@@ -1909,7 +1896,6 @@
WC_SEND_NETWORK_MSG, WC_NONE,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
_chat_window_widgets,
- NULL
};
void ShowNetworkChatQueryWindow(DestType type, int dest)
@@ -1985,10 +1971,10 @@
this->HandleEditBox(4);
}
- virtual bool OnKeyPress(uint16 key, uint16 keycode)
+ virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- bool cont;
- switch (this->HandleEditBoxKey(4, key, keycode, cont)) {
+ EventState state;
+ switch (this->HandleEditBoxKey(4, key, keycode, state)) {
case 1: // Return
this->OnOk();
/* FALL THROUGH */
@@ -1997,7 +1983,7 @@
delete this;
break;
}
- return cont;
+ return state;
}
};
@@ -2018,7 +2004,6 @@
WC_COMPANY_PASSWORD_WINDOW, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
_ncp_window_widgets,
- NULL
};
void ShowNetworkCompanyPasswordWindow(Window *parent)