mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Add setting callbacks for Camera and TouchControls (#15700)
This commit is contained in:
parent
b5e084c9a5
commit
41dfac96c1
6 changed files with 71 additions and 25 deletions
|
@ -201,19 +201,40 @@ static EKEY_CODE id_to_keycode(touch_gui_button_id id)
|
|||
}
|
||||
|
||||
|
||||
static const char *setting_names[] = {
|
||||
"touchscreen_threshold", "touch_long_tap_delay",
|
||||
"fixed_virtual_joystick", "virtual_joystick_triggers_aux1",
|
||||
"touch_layout",
|
||||
};
|
||||
|
||||
TouchControls::TouchControls(IrrlichtDevice *device, ISimpleTextureSource *tsrc):
|
||||
m_device(device),
|
||||
m_guienv(device->getGUIEnvironment()),
|
||||
m_receiver(device->getEventReceiver()),
|
||||
m_texturesource(tsrc)
|
||||
{
|
||||
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
||||
m_button_size = ButtonLayout::getButtonSize(m_screensize);
|
||||
|
||||
readSettings();
|
||||
for (auto name : setting_names)
|
||||
g_settings->registerChangedCallback(name, settingChangedCallback, this);
|
||||
}
|
||||
|
||||
void TouchControls::settingChangedCallback(const std::string &name, void *data)
|
||||
{
|
||||
static_cast<TouchControls *>(data)->readSettings();
|
||||
}
|
||||
|
||||
void TouchControls::readSettings()
|
||||
{
|
||||
m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold");
|
||||
m_long_tap_delay = g_settings->getU16("touch_long_tap_delay");
|
||||
m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick");
|
||||
m_joystick_triggers_aux1 = g_settings->getBool("virtual_joystick_triggers_aux1");
|
||||
|
||||
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
||||
m_button_size = ButtonLayout::getButtonSize(m_screensize);
|
||||
// Note that "fixed_virtual_joystick" and "virtual_joystick_triggers_aux1"
|
||||
// also affect the layout.
|
||||
applyLayout(ButtonLayout::loadFromSettings());
|
||||
}
|
||||
|
||||
|
@ -314,6 +335,7 @@ void TouchControls::applyLayout(const ButtonLayout &layout)
|
|||
|
||||
TouchControls::~TouchControls()
|
||||
{
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
releaseAll();
|
||||
}
|
||||
|
||||
|
|
|
@ -120,19 +120,31 @@ public:
|
|||
bool isStatusTextOverriden() { return m_overflow_open; }
|
||||
IGUIStaticText *getStatusText() { return m_status_text.get(); }
|
||||
|
||||
ButtonLayout getLayout() { return m_layout; }
|
||||
void applyLayout(const ButtonLayout &layout);
|
||||
|
||||
private:
|
||||
IrrlichtDevice *m_device = nullptr;
|
||||
IGUIEnvironment *m_guienv = nullptr;
|
||||
IEventReceiver *m_receiver = nullptr;
|
||||
ISimpleTextureSource *m_texturesource = nullptr;
|
||||
bool m_visible = true;
|
||||
|
||||
// changes to these two values are handled in TouchControls::step
|
||||
v2u32 m_screensize;
|
||||
s32 m_button_size;
|
||||
|
||||
// cached settings
|
||||
double m_touchscreen_threshold;
|
||||
u16 m_long_tap_delay;
|
||||
bool m_visible = true;
|
||||
bool m_fixed_joystick;
|
||||
bool m_joystick_triggers_aux1;
|
||||
|
||||
static void settingChangedCallback(const std::string &name, void *data);
|
||||
void readSettings();
|
||||
|
||||
ButtonLayout m_layout;
|
||||
void applyLayout(const ButtonLayout &layout);
|
||||
|
||||
// not read from a setting, but set by Game via setUseCrosshair
|
||||
bool m_draw_crosshair = false;
|
||||
|
||||
std::unordered_map<u16, recti> m_hotbar_rects;
|
||||
std::optional<u16> m_hotbar_selection = std::nullopt;
|
||||
|
@ -165,9 +177,6 @@ private:
|
|||
float m_joystick_direction = 0.0f; // assume forward
|
||||
float m_joystick_speed = 0.0f; // no movement
|
||||
bool m_joystick_status_aux1 = false;
|
||||
bool m_fixed_joystick = false;
|
||||
bool m_joystick_triggers_aux1 = false;
|
||||
bool m_draw_crosshair = false;
|
||||
std::shared_ptr<IGUIImage> m_joystick_btn_off;
|
||||
std::shared_ptr<IGUIImage> m_joystick_btn_bg;
|
||||
std::shared_ptr<IGUIImage> m_joystick_btn_center;
|
||||
|
@ -237,8 +246,6 @@ private:
|
|||
|
||||
bool m_place_pressed = false;
|
||||
u64 m_place_pressed_until = 0;
|
||||
|
||||
ButtonLayout m_layout;
|
||||
};
|
||||
|
||||
extern TouchControls *g_touchcontrols;
|
||||
|
|
|
@ -23,10 +23,7 @@ GUITouchscreenLayout::GUITouchscreenLayout(gui::IGUIEnvironment* env,
|
|||
GUIModalMenu(env, parent, id, menumgr),
|
||||
m_tsrc(tsrc)
|
||||
{
|
||||
if (g_touchcontrols)
|
||||
m_layout = g_touchcontrols->getLayout();
|
||||
else
|
||||
m_layout = ButtonLayout::loadFromSettings();
|
||||
m_layout = ButtonLayout::loadFromSettings();
|
||||
|
||||
m_gui_help_text = grab_gui_element<IGUIStaticText>(Environment->addStaticText(
|
||||
L"", core::recti(), false, false, this, -1));
|
||||
|
@ -378,8 +375,6 @@ bool GUITouchscreenLayout::OnEvent(const SEvent& event)
|
|||
}
|
||||
|
||||
if (event.GUIEvent.Caller == m_gui_done_btn.get()) {
|
||||
if (g_touchcontrols)
|
||||
g_touchcontrols->applyLayout(m_layout);
|
||||
std::ostringstream oss;
|
||||
m_layout.serializeJson(oss);
|
||||
g_settings->set("touch_layout", oss.str());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue