From 0fbe4cf62a236ea24f383818bf81b933f87380d8 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 9 Jul 2020 23:59:38 +0300 Subject: SL-5894 #2 WIP Changes to display multiple joystick devices --- indra/newview/llfloaterjoystick.cpp | 69 +++++++-- indra/newview/llfloaterjoystick.h | 6 +- .../skins/default/xui/en/floater_joystick.xml | 165 +++++++++++---------- 3 files changed, 147 insertions(+), 93 deletions(-) diff --git a/indra/newview/llfloaterjoystick.cpp b/indra/newview/llfloaterjoystick.cpp index 2b672bc890..4538d34c95 100644 --- a/indra/newview/llfloaterjoystick.cpp +++ b/indra/newview/llfloaterjoystick.cpp @@ -41,6 +41,7 @@ #include "llappviewer.h" #include "llviewerjoystick.h" #include "llcheckboxctrl.h" +#include "llcombobox.h" static LLTrace::SampleStatHandle<> sJoystickAxis0("Joystick axis 0"), sJoystickAxis1("Joystick axis 1"), @@ -59,7 +60,8 @@ static LLTrace::SampleStatHandle<>* sJoystickAxes[6] = }; LLFloaterJoystick::LLFloaterJoystick(const LLSD& data) - : LLFloater(data) + : LLFloater(data), + mHasDeviceList(false) { if (!LLViewerJoystick::getInstance()->isJoystickInitialized()) { @@ -71,14 +73,13 @@ LLFloaterJoystick::LLFloaterJoystick(const LLSD& data) void LLFloaterJoystick::draw() { - bool joystick_inited = LLViewerJoystick::getInstance()->isJoystickInitialized(); - getChildView("enable_joystick")->setEnabled(joystick_inited); - getChildView("joystick_type")->setEnabled(joystick_inited); - std::string desc = LLViewerJoystick::getInstance()->getDescription(); - if (desc.empty()) desc = getString("NoDevice"); - getChild("joystick_type")->setValue(desc); - - LLViewerJoystick* joystick(LLViewerJoystick::getInstance()); + LLViewerJoystick* joystick(LLViewerJoystick::getInstance()); + bool joystick_inited = joystick->isJoystickInitialized(); + if (joystick_inited != mHasDeviceList) + { + refreshListOfDevices(); + } + for (U32 i = 0; i < 6; i++) { F32 value = joystick->getJoystickAxis(i); @@ -115,8 +116,8 @@ BOOL LLFloaterJoystick::postBuild() } } - mCheckJoystickEnabled = getChild("enable_joystick"); - childSetCommitCallback("enable_joystick",onCommitJoystickEnabled,this); + mJoysticksCombo = getChild("joystick_combo"); + childSetCommitCallback("joystick_combo",onCommitJoystickEnabled,this); mCheckFlycamEnabled = getChild("JoystickFlycamEnabled"); childSetCommitCallback("JoystickFlycamEnabled",onCommitJoystickEnabled,this); @@ -125,6 +126,7 @@ BOOL LLFloaterJoystick::postBuild() childSetAction("ok_btn", onClickOK, this); refresh(); + refreshListOfDevices(); return TRUE; } @@ -210,9 +212,36 @@ void LLFloaterJoystick::initFromSettings() void LLFloaterJoystick::refresh() { LLFloater::refresh(); + initFromSettings(); } +void LLFloaterJoystick::refreshListOfDevices() +{ + mJoysticksCombo->removeall(); + mJoysticksCombo->add(getString("JoystickDisabled"), LLSD(LLSD::Integer(0)), ADD_BOTTOM, 1); + + mHasDeviceList = false; + std::string desc = LLViewerJoystick::getInstance()->getDescription(); + if (!desc.empty()) + { + mJoysticksCombo->add(desc, LLSD(LLSD::Integer(1)), ADD_BOTTOM, 1); + mHasDeviceList = true; + } + + //todo: load list of devices + + if (gSavedSettings.getBOOL("JoystickEnabled") && mHasDeviceList) + { + // todo: select device according to data from LLViewerJoystick + mJoysticksCombo->selectByValue(LLSD::Integer(1)); + } + else + { + mJoysticksCombo->selectByValue(LLSD::Integer(0)); + } +} + void LLFloaterJoystick::cancel() { gSavedSettings.setBOOL("JoystickEnabled", mJoystickEnabled); @@ -285,7 +314,21 @@ void LLFloaterJoystick::cancel() void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel) { LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel; - BOOL joystick_enabled = self->mCheckJoystickEnabled->get(); + + LLSD value = self->mJoysticksCombo->getValue(); + bool joystick_enabled = true; + if (value.isInteger()) + { + joystick_enabled = value.asInteger(); + // ndof already has a device selected, we are just setting it enabled or disabled + } + else + { + // else joystick is enabled, because combobox holds id of device + joystick_enabled = true; + // todo: make LLViewerJoystick select a device based on value + } + gSavedSettings.setBOOL("JoystickEnabled", joystick_enabled); BOOL flycam_enabled = self->mCheckFlycamEnabled->get(); if (!joystick_enabled || !flycam_enabled) @@ -297,6 +340,8 @@ void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel) joystick->toggleFlycam(); } } + + self->refreshListOfDevices(); } void LLFloaterJoystick::onClickRestoreSNDefaults(void *joy_panel) diff --git a/indra/newview/llfloaterjoystick.h b/indra/newview/llfloaterjoystick.h index a1b5951389..b3d879b233 100644 --- a/indra/newview/llfloaterjoystick.h +++ b/indra/newview/llfloaterjoystick.h @@ -31,6 +31,7 @@ #include "llstatview.h" class LLCheckBoxCtrl; +class LLComboBox; class LLFloaterJoystick : public LLFloater { @@ -47,6 +48,7 @@ public: protected: + void refreshListOfDevices(); void onClose(bool app_quitting); void onClickCloseBtn(bool app_quitting); @@ -85,8 +87,10 @@ private: F32 mFlycamFeathering; // Controls that can disable the flycam - LLCheckBoxCtrl *mCheckJoystickEnabled; LLCheckBoxCtrl *mCheckFlycamEnabled; + LLComboBox *mJoysticksCombo; + + bool mHasDeviceList; // stats view LLStatBar* mAxisStatsBar[6]; diff --git a/indra/newview/skins/default/xui/en/floater_joystick.xml b/indra/newview/skins/default/xui/en/floater_joystick.xml index 3dfdf8e1a5..7d2cea1fe5 100644 --- a/indra/newview/skins/default/xui/en/floater_joystick.xml +++ b/indra/newview/skins/default/xui/en/floater_joystick.xml @@ -8,27 +8,32 @@ title="JOYSTICK CONFIGURATION" width="569"> - no device detected + name="JoystickDisabled"> + None - - + Joystick: + + + name="joystick_combo" + top="19" + left_pad="4" + width="300"/> Control Modes: