Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search/filter functionality to object selection window #1837

Merged
merged 19 commits into from Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1f9bae7
TextInput: fix handleInput when no input length limit is set
AaronVanGeffen Feb 12, 2023
7b4b17e
ObjectSelectionWindow: add full text input functionality
AaronVanGeffen Feb 12, 2023
2f12968
ObjectSelectionWindow: rename _tabInformation to _tabPositions
AaronVanGeffen Feb 12, 2023
fdac3e7
ObjectSelectionWindow: rename _50D144 to _objectSelection
AaronVanGeffen Feb 12, 2023
b7a8990
ObjectSelectionWindow: rename _52334{A,C} to _mousePos{X,Y}
AaronVanGeffen Feb 12, 2023
2aa7bd8
ObjectSelectionWindow: rename sub_472BBC to getFirstAvailableSelected…
AaronVanGeffen Feb 12, 2023
3d770e8
ObjectSelectionWindow: cache vector with object list for current tab
AaronVanGeffen Feb 12, 2023
08190bf
ObjectSelectionWindow: implement case-insensitive filtering
AaronVanGeffen Feb 12, 2023
33e647a
ObjectSelectionWindow: keep visibility into account in getObjectFromS…
AaronVanGeffen Feb 12, 2023
cbb177d
ObjectSelectionWindow: only count visible objects for getScrollSize
AaronVanGeffen Feb 12, 2023
e148476
Amend changelog
AaronVanGeffen Feb 12, 2023
150239c
Keyboard: allow using screenshot shortcut in object selection window,…
AaronVanGeffen Feb 12, 2023
73d3494
drawSearchBox: reuse rather than shadow a local
AaronVanGeffen Feb 12, 2023
6a151b9
Add 'Clear' button next to text input
AaronVanGeffen Feb 15, 2023
f353bce
Construct pattern directly from buffer, no need to go through c_str
AaronVanGeffen Feb 15, 2023
e597e4e
Apply suggestions from code review
AaronVanGeffen Feb 15, 2023
a3d4118
Reserve space in vector before iterating over objects
AaronVanGeffen Feb 15, 2023
620c306
populateTabObjectList: apply std::move to entry
AaronVanGeffen Feb 16, 2023
f76660f
Use enum class to denote visibility
AaronVanGeffen Feb 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
23.01+ (???)
------------------------------------------------------------------------
- Feature: [#1837]: Add search/filter functionality to object selection window.
- Fix: [#1763] Title music does not stop when unchecked in options window.
- Fix: [#1772] Toggling edge scrolling option does not work.
- Fix: [#1798] Memory leak when resizing the window.
Expand Down
1 change: 1 addition & 0 deletions data/language/en-GB.yml
Expand Up @@ -2326,3 +2326,4 @@ strings:
2271: "Disable town expansion"
2272: "{SMALLFONT}{COLOUR BLACK}When enabled, towns will not renew or expand over time"
2273: "Complete scenario challenge"
2274: "Clear"
10 changes: 10 additions & 0 deletions src/OpenLoco/src/Input/Keyboard.cpp
Expand Up @@ -342,6 +342,16 @@ namespace OpenLoco::Input
}
}

ti = WindowManager::find(WindowType::objectSelection);
if (ti != nullptr)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should start handling these through the window manager, ideally passing through to an event for the active window only. Something for a future PR though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i was a bit confused as to what this was about.

{
if (tryShortcut(Shortcut::screenshot, nextKey->keyCode, _keyModifier))
continue;

Ui::Windows::ObjectSelectionWindow::handleInput(nextKey->charCode, nextKey->keyCode);
continue;
}

ti = WindowManager::find(WindowType::editKeyboardShortcut);
if (ti != nullptr)
{
Expand Down
1 change: 1 addition & 0 deletions src/OpenLoco/src/Localisation/StringIds.h
Expand Up @@ -1840,6 +1840,7 @@ namespace OpenLoco::StringIds
constexpr string_id disableTownExpansion = 2271;
constexpr string_id disableTownExpansion_tip = 2272;
constexpr string_id completeChallenge = 2273;
constexpr string_id clearInput = 2274;

constexpr string_id temporary_object_load_str_0 = 8192;
constexpr string_id temporary_object_load_str_1 = 8193;
Expand Down
10 changes: 9 additions & 1 deletion src/OpenLoco/src/Ui/TextInput.cpp
Expand Up @@ -14,7 +14,7 @@ namespace OpenLoco::Ui::TextInput
{
if ((charCode >= SDLK_SPACE && charCode < SDLK_DELETE) || (charCode >= 159 && charCode <= 255))
{
if (buffer.length() == inputLenLimit)
if (inputLenLimit > 0 && buffer.length() == inputLenLimit)
{
return false;
}
Expand Down Expand Up @@ -136,6 +136,14 @@ namespace OpenLoco::Ui::TextInput
xOffset = std::clamp<int16_t>(xOffset, minOffset, maxOffset);
}

void InputSession::clearInput()
{
buffer.clear();
cursorPosition = 0;
cursorFrame = 0;
xOffset = 0;
}

// 0x004CEBFB
void InputSession::sanitizeInput()
{
Expand Down
1 change: 1 addition & 0 deletions src/OpenLoco/src/Ui/TextInput.h
Expand Up @@ -30,6 +30,7 @@ namespace OpenLoco::Ui::TextInput
bool handleInput(uint32_t charCode, uint32_t keyCode);
bool needsReoffsetting(int16_t containerWidth);
void calculateTextOffset(int16_t containerWidth);
void clearInput();
void sanitizeInput();
};
}
1 change: 1 addition & 0 deletions src/OpenLoco/src/Ui/WindowManager.h
Expand Up @@ -263,6 +263,7 @@ namespace OpenLoco::Ui::Windows
{
Window* open();
bool tryCloseWindow();
void handleInput(uint32_t charCode, uint32_t keyCode);
}

namespace Options
Expand Down