summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorstormcone <48624099+stormcone@users.noreply.github.com>2021-03-23 20:16:27 +0100
committerMichael Lutz <michi@icosahedron.de>2021-04-02 10:12:47 +0200
commitbde5396d118371c16db57cfd2ad0b15e4e606cd3 (patch)
tree92f13751d6423e38ba25b23460c8f38e028b87cf /src
parentc56e9a546dda44d90cb397334897a8e4dfda9bf1 (diff)
downloadopenttd-bde5396d118371c16db57cfd2ad0b15e4e606cd3.tar.xz
Add: Hotkey to focus the build object class name filter editbox.
Diffstat (limited to 'src')
-rw-r--r--src/object.h2
-rw-r--r--src/object_gui.cpp53
2 files changed, 50 insertions, 5 deletions
diff --git a/src/object.h b/src/object.h
index e3f0c84ff..c374ba950 100644
--- a/src/object.h
+++ b/src/object.h
@@ -18,6 +18,6 @@ void UpdateCompanyHQ(TileIndex tile, uint score);
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner = OWNER_NONE, struct Town *town = nullptr, uint8 view = 0);
-void ShowBuildObjectPicker();
+Window *ShowBuildObjectPicker();
#endif /* OBJECT_H */
diff --git a/src/object_gui.cpp b/src/object_gui.cpp
index 7fab0b194..69857895e 100644
--- a/src/object_gui.cpp
+++ b/src/object_gui.cpp
@@ -9,9 +9,11 @@
#include "stdafx.h"
#include "command_func.h"
+#include "hotkeys.h"
#include "newgrf.h"
#include "newgrf_object.h"
#include "newgrf_text.h"
+#include "object.h"
#include "querystring_gui.h"
#include "sortlist_type.h"
#include "stringfilter_type.h"
@@ -33,6 +35,11 @@ static ObjectClassID _selected_object_class; ///< Currently selected available o
static int _selected_object_index; ///< Index of the currently selected object if existing, else \c -1.
static uint8 _selected_object_view; ///< the view of the selected object
+/** Enum referring to the Hotkeys in the build object window */
+enum BuildObjectHotkeys {
+ BOHK_FOCUS_FILTER_BOX, ///< Focus the edit box for editing the filter string
+};
+
/** The window used for building objects. */
class BuildObjectWindow : public Window {
typedef GUIList<ObjectClassID, StringFilter &> GUIObjectClassList; ///< Type definition for the list to hold available object classes.
@@ -88,7 +95,7 @@ class BuildObjectWindow : public Window {
}
public:
- BuildObjectWindow(WindowDesc *desc, WindowNumber number) : Window(desc), info_height(1), filter_editbox(EDITBOX_MAX_SIZE)
+ BuildObjectWindow(WindowDesc *desc, WindowNumber number) : Window(desc), info_height(1), filter_editbox(EDITBOX_MAX_SIZE * MAX_CHAR_LENGTH, EDITBOX_MAX_SIZE)
{
this->CreateNestedTree();
@@ -544,6 +551,21 @@ public:
this->UpdateButtons(_selected_object_class, -1, _selected_object_view);
}
+ EventState OnHotkey(int hotkey) override
+ {
+ switch (hotkey) {
+ case BOHK_FOCUS_FILTER_BOX:
+ this->SetFocusedWidget(WID_BO_FILTER);
+ SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
+ break;
+
+ default:
+ return ES_NOT_HANDLED;
+ }
+
+ return ES_HANDLED;
+ }
+
void OnEditboxChanged(int wid) override
{
string_filter.SetFilterTerm(this->filter_editbox.text.buf);
@@ -597,7 +619,28 @@ public:
}
this->SelectOtherObject(-1);
}
+
+ static HotkeyList hotkeys;
+};
+
+/**
+ * Handler for global hotkeys of the BuildObjectWindow.
+ * @param hotkey Hotkey
+ * @return ES_HANDLED if hotkey was accepted.
+ */
+static EventState BuildObjectGlobalHotkeys(int hotkey)
+{
+ if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
+ Window *w = ShowBuildObjectPicker();
+ if (w == nullptr) return ES_NOT_HANDLED;
+ return w->OnHotkey(hotkey);
+}
+
+static Hotkey buildobject_hotkeys[] = {
+ Hotkey('F', "focus_filter_box", BOHK_FOCUS_FILTER_BOX),
+ HOTKEY_LIST_END
};
+HotkeyList BuildObjectWindow::hotkeys("buildobject", buildobject_hotkeys, BuildObjectGlobalHotkeys);
Listing BuildObjectWindow::last_sorting = { false, 0 };
Filtering BuildObjectWindow::last_filtering = { false, 0 };
@@ -661,16 +704,18 @@ static WindowDesc _build_object_desc(
WDP_AUTO, "build_object", 0, 0,
WC_BUILD_OBJECT, WC_BUILD_TOOLBAR,
WDF_CONSTRUCTION,
- _nested_build_object_widgets, lengthof(_nested_build_object_widgets)
+ _nested_build_object_widgets, lengthof(_nested_build_object_widgets),
+ &BuildObjectWindow::hotkeys
);
/** Show our object picker. */
-void ShowBuildObjectPicker()
+Window *ShowBuildObjectPicker()
{
/* Don't show the place object button when there are no objects to place. */
if (ObjectClass::GetUIClassCount() > 0) {
- AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
+ return AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
}
+ return nullptr;
}
/** Reset all data of the object GUI. */