From 8583a2f4f7cda0351d27f3406ebcc3fbef553591 Mon Sep 17 00:00:00 2001 From: Inusaito Sayori Date: Thu, 10 Jul 2014 22:38:30 -0400 Subject: [PATCH] Idea!: Set to defaults flyout button with options for all styles of joystick controller The button portion does nothing if there is an unknown or no controller connected, otherwise it sets defaults for the controller's identified type. Joystick buttons are still configured based on identification, however. DS3 users will likely find that using Motion in Joy switchboards is much more effective, however. --- indra/newview/llfloaterjoystick.cpp | 16 ++++++------- indra/newview/llfloaterjoystick.h | 3 +-- indra/newview/llviewerjoystick.cpp | 24 +++++++++++++------ indra/newview/llviewerjoystick.h | 2 +- .../default/xui/en-us/floater_joystick.xml | 9 +++++-- .../skins/default/xui/es/floater_joystick.xml | 1 - .../skins/default/xui/fr/floater_joystick.xml | 10 ++++---- .../skins/default/xui/it/floater_joystick.xml | 1 - .../skins/default/xui/pt/floater_joystick.xml | 1 - 9 files changed, 40 insertions(+), 27 deletions(-) diff --git a/indra/newview/llfloaterjoystick.cpp b/indra/newview/llfloaterjoystick.cpp index c067b78a7..2795ce016 100644 --- a/indra/newview/llfloaterjoystick.cpp +++ b/indra/newview/llfloaterjoystick.cpp @@ -126,7 +126,7 @@ BOOL LLFloaterJoystick::postBuild() mCheckFlycamEnabled = getChild("JoystickFlycamEnabled"); childSetCommitCallback("JoystickFlycamEnabled",onCommitJoystickEnabled,this); - childSetAction("SpaceNavigatorDefaults", onClickRestoreSNDefaults, this); + getChild("Default")->setCommitCallback(boost::bind(&LLFloaterJoystick::onClickDefault, this, _2)); childSetAction("cancel_btn", onClickCancel, this); childSetAction("ok_btn", onClickOK, this); @@ -301,9 +301,14 @@ void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel) } } -void LLFloaterJoystick::onClickRestoreSNDefaults(void *joy_panel) +S32 get_joystick_type(); +void LLFloaterJoystick::onClickDefault(const LLSD& val) { - setSNDefaults(); + S32 type(val.asInteger()); + if (val.isUndefined()) // If button portion, set to default for device. + if ((type = get_joystick_type()) == -1) // Invalid/No device + return; + LLViewerJoystick::getInstance()->setSNDefaults(type); } void LLFloaterJoystick::onClickCancel(void *joy_panel) @@ -332,8 +337,3 @@ void LLFloaterJoystick::onClickOK(void *joy_panel) } } } - -void LLFloaterJoystick::setSNDefaults() -{ - LLViewerJoystick::getInstance()->setSNDefaults(); -} diff --git a/indra/newview/llfloaterjoystick.h b/indra/newview/llfloaterjoystick.h index 3ce647e5b..07b4b49c7 100644 --- a/indra/newview/llfloaterjoystick.h +++ b/indra/newview/llfloaterjoystick.h @@ -49,11 +49,10 @@ public: virtual void apply(); // Apply the changed values. virtual void cancel(); // Cancel the changed values. virtual void draw(); - static void setSNDefaults(); private: static void onCommitJoystickEnabled(LLUICtrl*, void*); - static void onClickRestoreSNDefaults(void*); + void onClickDefault(const LLSD& val); static void onClickCancel(void*); static void onClickOK(void*); diff --git a/indra/newview/llviewerjoystick.cpp b/indra/newview/llviewerjoystick.cpp index 8113310a0..c30a3af80 100644 --- a/indra/newview/llviewerjoystick.cpp +++ b/indra/newview/llviewerjoystick.cpp @@ -109,6 +109,15 @@ enum DS3Keys DS3_START_KEY, DS3_LOGO_KEY }; + +S32 get_joystick_type() +{ + if (sType == SPACE_NAV) return 0; + if (sType == XBOX) return isOUYA(LLViewerJoystick::getInstance()->getDescription()) ? 1 : 2; + if (sType == DS3) return 3; + + return -1; // sType == NONE || sType == UNKNOWN +} // // These constants specify the maximum absolute value coming in from the device. @@ -312,11 +321,12 @@ void LLViewerJoystick::init(bool autoenable) { sType = XBOX; // It's an Xbox controller, we have defaults for it. - std::string controller = isOUYA(desc) ? "OUYA" : "XboxController"; + bool ouya(isOUYA(desc)); + std::string controller = ouya ? "OUYA" : "XboxController"; if (gSavedSettings.getString("JoystickInitialized") != controller) { // Only set the defaults if we haven't already (in case they were overridden) - setSNDefaults(); + setSNDefaults(ouya ? 1 : 2); gSavedSettings.setString("JoystickInitialized", controller); } } @@ -327,7 +337,7 @@ void LLViewerJoystick::init(bool autoenable) if (gSavedSettings.getString("JoystickInitialized") != "DualShock3") { // Only set the defaults if we haven't already (in case they were overridden) - setSNDefaults(); + setSNDefaults(3); gSavedSettings.setString("JoystickInitialized", "DualShock3"); } } @@ -1366,7 +1376,7 @@ bool LLViewerJoystick::isLikeSpaceNavigator() const } // ----------------------------------------------------------------------------- -void LLViewerJoystick::setSNDefaults() +void LLViewerJoystick::setSNDefaults(S32 type) { #if LL_DARWIN || LL_LINUX const float platformScale = 20.f; @@ -1380,9 +1390,9 @@ void LLViewerJoystick::setSNDefaults() #endif //gViewerWindow->alertXml("CacheWillClear"); - const bool xbox = sType == XBOX; - const bool ouya = xbox && isOUYA(getDescription()); - const bool ds3 = sType == DS3; + const bool ouya = type == 1; + const bool xbox = ouya || type == 2; + const bool ds3 = type == 3; llinfos << "restoring " << (xbox ? ouya ? "OUYA Game Controller" : "Xbox Controller" : ds3 ? "Dual Shock 3" : "SpaceNavigator") << " defaults..." << llendl; /* diff --git a/indra/newview/llviewerjoystick.h b/indra/newview/llviewerjoystick.h index 308f52bc6..058821bcd 100644 --- a/indra/newview/llviewerjoystick.h +++ b/indra/newview/llviewerjoystick.h @@ -67,7 +67,7 @@ public: bool getOverrideCamera() { return mOverrideCamera; } void setOverrideCamera(bool val); bool toggleFlycam(); - void setSNDefaults(); + void setSNDefaults(S32 type = 0); std::string getDescription(); protected: diff --git a/indra/newview/skins/default/xui/en-us/floater_joystick.xml b/indra/newview/skins/default/xui/en-us/floater_joystick.xml index d8a068948..5b32f1780 100644 --- a/indra/newview/skins/default/xui/en-us/floater_joystick.xml +++ b/indra/newview/skins/default/xui/en-us/floater_joystick.xml @@ -92,8 +92,13 @@ Zoom Dead Zone -