mirror of https://github.com/OpenTTD/OpenTTD
Add: Hotkey to focus the build object class name filter editbox.
parent
c56e9a546d
commit
bde5396d11
|
@ -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 BuildObject(ObjectType type, TileIndex tile, CompanyID owner = OWNER_NONE, struct Town *town = nullptr, uint8 view = 0);
|
||||||
|
|
||||||
void ShowBuildObjectPicker();
|
Window *ShowBuildObjectPicker();
|
||||||
|
|
||||||
#endif /* OBJECT_H */
|
#endif /* OBJECT_H */
|
||||||
|
|
|
@ -9,9 +9,11 @@
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
|
#include "hotkeys.h"
|
||||||
#include "newgrf.h"
|
#include "newgrf.h"
|
||||||
#include "newgrf_object.h"
|
#include "newgrf_object.h"
|
||||||
#include "newgrf_text.h"
|
#include "newgrf_text.h"
|
||||||
|
#include "object.h"
|
||||||
#include "querystring_gui.h"
|
#include "querystring_gui.h"
|
||||||
#include "sortlist_type.h"
|
#include "sortlist_type.h"
|
||||||
#include "stringfilter_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 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
|
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. */
|
/** The window used for building objects. */
|
||||||
class BuildObjectWindow : public Window {
|
class BuildObjectWindow : public Window {
|
||||||
typedef GUIList<ObjectClassID, StringFilter &> GUIObjectClassList; ///< Type definition for the list to hold available object classes.
|
typedef GUIList<ObjectClassID, StringFilter &> GUIObjectClassList; ///< Type definition for the list to hold available object classes.
|
||||||
|
@ -88,7 +95,7 @@ class BuildObjectWindow : public Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
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();
|
this->CreateNestedTree();
|
||||||
|
|
||||||
|
@ -544,6 +551,21 @@ public:
|
||||||
this->UpdateButtons(_selected_object_class, -1, _selected_object_view);
|
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
|
void OnEditboxChanged(int wid) override
|
||||||
{
|
{
|
||||||
string_filter.SetFilterTerm(this->filter_editbox.text.buf);
|
string_filter.SetFilterTerm(this->filter_editbox.text.buf);
|
||||||
|
@ -597,8 +619,29 @@ public:
|
||||||
}
|
}
|
||||||
this->SelectOtherObject(-1);
|
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 };
|
Listing BuildObjectWindow::last_sorting = { false, 0 };
|
||||||
Filtering BuildObjectWindow::last_filtering = { false, 0 };
|
Filtering BuildObjectWindow::last_filtering = { false, 0 };
|
||||||
|
|
||||||
|
@ -661,16 +704,18 @@ static WindowDesc _build_object_desc(
|
||||||
WDP_AUTO, "build_object", 0, 0,
|
WDP_AUTO, "build_object", 0, 0,
|
||||||
WC_BUILD_OBJECT, WC_BUILD_TOOLBAR,
|
WC_BUILD_OBJECT, WC_BUILD_TOOLBAR,
|
||||||
WDF_CONSTRUCTION,
|
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. */
|
/** Show our object picker. */
|
||||||
void ShowBuildObjectPicker()
|
Window *ShowBuildObjectPicker()
|
||||||
{
|
{
|
||||||
/* Don't show the place object button when there are no objects to place. */
|
/* Don't show the place object button when there are no objects to place. */
|
||||||
if (ObjectClass::GetUIClassCount() > 0) {
|
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. */
|
/** Reset all data of the object GUI. */
|
||||||
|
|
Loading…
Reference in New Issue