1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Move keybinding settings to (Lua-based) setting menu (#15791)

This commit is contained in:
y5nw 2025-04-20 20:20:49 +02:00 committed by GitHub
parent c1d2124102
commit 23bfb2db72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 591 additions and 782 deletions

75
src/gui/guiButtonKey.h Normal file
View file

@ -0,0 +1,75 @@
// Luanti
// SPDX-License-Identifier: LGPL-2.1-or-later
#pragma once
#include "guiButton.h"
#include "client/keycode.h"
#include "util/string.h"
#include "gettext.h"
using namespace irr;
class GUIButtonKey : public GUIButton
{
using super = GUIButton;
public:
//! Constructor
GUIButtonKey(gui::IGUIEnvironment *environment, gui::IGUIElement *parent,
s32 id, core::rect<s32> rectangle, ISimpleTextureSource *tsrc,
bool noclip = false)
: GUIButton(environment, parent, id, rectangle, tsrc, noclip) {}
//! Sets the text for the key field
virtual void setText(const wchar_t *text) override
{
setKey(wide_to_utf8(text));
}
//! Gets the value for the key field
virtual const wchar_t *getText() const override
{
return keysym.c_str();
}
//! Do not drop returned handle
static GUIButtonKey *addButton(gui::IGUIEnvironment *environment,
const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc,
IGUIElement *parent, s32 id, const wchar_t *text = L"",
const wchar_t *tooltiptext = L"");
//! Called if an event happened
virtual bool OnEvent(const SEvent &event) override;
private:
void sendKey();
//! Start key capture
void startCapture()
{
if (nostart) {
nostart = false;
return;
}
capturing = true;
super::setText(wstrgettext("Press Button").c_str());
}
//! Cancel key capture
// inhibit_restart: whether the next call to startCapture should be inhibited
void cancelCapture(bool inhibit_restart = false)
{
capturing = false;
nostart |= inhibit_restart;
super::setText(wstrgettext(key_value.name()).c_str());
}
//! Sets the captured key and stop capturing
void setKey(KeyPress key);
bool capturing = false;
bool nostart = false;
KeyPress key_value = {};
std::wstring keysym;
};