summaryrefslogtreecommitdiff
path: root/src/network/network_gui.cpp
diff options
context:
space:
mode:
authorRubidium <rubidium@openttd.org>2021-04-18 20:29:46 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-04-21 21:12:08 +0200
commitbf4fe19a6684231d04764c3bee5ed51e4124a925 (patch)
treec8b7d662f3ed0ecc236ea894c9a51279e80dfbc2 /src/network/network_gui.cpp
parentb3495f1a1323eb6d236c6fecb1127a0bd716a4d5 (diff)
downloadopenttd-bf4fe19a6684231d04764c3bee5ed51e4124a925.tar.xz
Codechange: merge duplicated logic to scroll in lists by key into a single function
Diffstat (limited to 'src/network/network_gui.cpp')
-rw-r--r--src/network/network_gui.cpp39
1 files changed, 4 insertions, 35 deletions
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 78b0d9dfc..1c80f7f3c 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -66,8 +66,8 @@ void UpdateNetworkGameWindow()
}
typedef GUIList<NetworkGameList*, StringFilter&> GUIGameServerList;
-typedef uint16 ServerListPosition;
-static const ServerListPosition SLP_INVALID = 0xFFFF;
+typedef int ServerListPosition;
+static const ServerListPosition SLP_INVALID = -1;
/** Full blown container to make it behave exactly as we want :) */
class NWidgetServerListHeader : public NWidgetContainer {
@@ -771,39 +771,8 @@ public:
EventState state = ES_NOT_HANDLED;
/* handle up, down, pageup, pagedown, home and end */
- if (keycode == WKC_UP || keycode == WKC_DOWN || keycode == WKC_PAGEUP || keycode == WKC_PAGEDOWN || keycode == WKC_HOME || keycode == WKC_END) {
- if (this->servers.size() == 0) return ES_HANDLED;
- switch (keycode) {
- case WKC_UP:
- /* scroll up by one */
- if (this->list_pos == SLP_INVALID) return ES_HANDLED;
- if (this->list_pos > 0) this->list_pos--;
- break;
- case WKC_DOWN:
- /* scroll down by one */
- if (this->list_pos == SLP_INVALID) return ES_HANDLED;
- if (this->list_pos < this->servers.size() - 1) this->list_pos++;
- break;
- case WKC_PAGEUP:
- /* scroll up a page */
- if (this->list_pos == SLP_INVALID) return ES_HANDLED;
- this->list_pos = (this->list_pos < this->vscroll->GetCapacity()) ? 0 : this->list_pos - this->vscroll->GetCapacity();
- break;
- case WKC_PAGEDOWN:
- /* scroll down a page */
- if (this->list_pos == SLP_INVALID) return ES_HANDLED;
- this->list_pos = std::min(this->list_pos + this->vscroll->GetCapacity(), (int)this->servers.size() - 1);
- break;
- case WKC_HOME:
- /* jump to beginning */
- this->list_pos = 0;
- break;
- case WKC_END:
- /* jump to end */
- this->list_pos = (ServerListPosition)this->servers.size() - 1;
- break;
- default: NOT_REACHED();
- }
+ if (this->vscroll->UpdateListPositionOnKeyPress(this->list_pos, keycode) == ES_HANDLED) {
+ if (this->list_pos == SLP_INVALID) return ES_HANDLED;
this->server = this->servers[this->list_pos];