diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llwindow/llgamecontrol.cpp | 68 | ||||
-rw-r--r-- | indra/llwindow/llgamecontrol.h | 14 | ||||
-rw-r--r-- | indra/newview/llappviewer.cpp | 4 | ||||
-rw-r--r-- | indra/newview/llfloaterpreference.cpp | 55 | ||||
-rw-r--r-- | indra/newview/llfloaterpreference.h | 7 |
5 files changed, 104 insertions, 44 deletions
diff --git a/indra/llwindow/llgamecontrol.cpp b/indra/llwindow/llgamecontrol.cpp index 812c861370..c7a27c5558 100644 --- a/indra/llwindow/llgamecontrol.cpp +++ b/indra/llwindow/llgamecontrol.cpp @@ -356,6 +356,7 @@ public: void resetDeviceOptionsToDefaults(); void loadDeviceOptionsFromSettings(); void saveDeviceOptionsToSettings() const; + void setDeviceOptions(const std::string& guid, const LLGameControl::Options& options); void addController(SDL_JoystickID id, const std::string& guid, const std::string& name); void removeController(SDL_JoystickID id); @@ -457,6 +458,7 @@ namespace std::function<void(const std::string&, const std::string&)> s_saveString; std::function<LLSD(const std::string&)> s_loadObject; std::function<void(const std::string&, LLSD&)> s_saveObject; + std::function<void()> s_updateUI; std::string SETTING_ENABLE("EnableGameControl"); std::string SETTING_SENDTOSERVER("GameControlToServer"); @@ -549,7 +551,6 @@ LLGameControl::Options::Options() mAxisOptions.resize(NUM_AXES); mAxisMap.resize(NUM_AXES); mButtonMap.resize(NUM_BUTTONS); - resetToDefaults(); } @@ -560,7 +561,6 @@ void LLGameControl::Options::resetToDefaults() mAxisOptions[i].resetToDefaults(); mAxisMap[i] = (U8)i; } - for (size_t i = 0; i < NUM_BUTTONS; ++i) { mButtonMap[i] = (U8)i; @@ -595,18 +595,7 @@ S16 LLGameControl::Options::fixAxisValue(U8 axis, S16 value) const } else { - const AxisOptions& options = mAxisOptions[axis]; - S32 new_value = (S32)value + (S32)options.mOffset; - value = (S16)std::clamp(new_value , -32768, 32767); - if ((value > 0 && value < (S16)options.mDeadZone) || - (value < 0 && value > -(S16)options.mDeadZone)) - { - value = 0; - } - else if (options.mInvert) - { - value = -value; - } + value = mAxisOptions[axis].computeModifiedValue(value); } return value; } @@ -615,7 +604,7 @@ std::string LLGameControl::Options::AxisOptions::saveToString() const { std::list<std::string> options; - if (mInvert) + if (mMultiplier == -1) { options.push_back("invert:1"); } @@ -715,16 +704,17 @@ void LLGameControl::Options::AxisOptions::loadFromString(std::string options) LL_WARNS("SDL2") << "Invalid axis options: '" << options << "'" << LL_ENDL; } + mMultiplier = 1; std::string invert = pairs["invert"]; if (!invert.empty()) { - if (invert != "1") + if (invert == "1") { - LL_WARNS("SDL2") << "Invalid invert value: '" << invert << "'" << LL_ENDL; + mMultiplier = -1; } else { - mInvert = true; + LL_WARNS("SDL2") << "Invalid invert value: '" << invert << "'" << LL_ENDL; } } @@ -732,13 +722,13 @@ void LLGameControl::Options::AxisOptions::loadFromString(std::string options) if (!dead_zone.empty()) { size_t number = std::stoull(dead_zone); - if (number > MAX_AXIS_DEAD_ZONE || std::to_string(number) != dead_zone) + if (number <= MAX_AXIS_DEAD_ZONE && std::to_string(number) == dead_zone) { - LL_WARNS("SDL2") << "Invalid dead_zone value: '" << dead_zone << "'" << LL_ENDL; + mDeadZone = (U16)number; } else { - mDeadZone = (U16)number; + LL_WARNS("SDL2") << "Invalid dead_zone value: '" << dead_zone << "'" << LL_ENDL; } } @@ -764,11 +754,13 @@ std::string LLGameControl::Options::saveToString(const std::string& name, bool f bool LLGameControl::Options::loadFromString(std::string& name, std::string options) { + resetToDefaults(); return LLGameControl::parseDeviceOptions(options, name, mAxisOptions, mAxisMap, mButtonMap); } bool LLGameControl::Options::loadFromString(std::string options) { + resetToDefaults(); std::string dummy_name; return LLGameControl::parseDeviceOptions(options, dummy_name, mAxisOptions, mAxisMap, mButtonMap); } @@ -916,6 +908,19 @@ void LLGameControllerManager::saveDeviceOptionsToSettings() const } } +void LLGameControllerManager::setDeviceOptions(const std::string& guid, const LLGameControl::Options& options) +{ + // find Device by name + for (LLGameControl::Device& device : mDevices) + { + if (device.getGUID() == guid) + { + device.mOptions = options; + return; + } + } +} + void LLGameControllerManager::addController(SDL_JoystickID id, const std::string& guid, const std::string& name) { llassert(id >= 0); @@ -1468,6 +1473,10 @@ void onControllerDeviceAdded(const SDL_Event& event) } g_manager.addController(id, guid, name); + + // this event could happen while the preferences UI is open + // in which case we need to force it to update + s_updateUI(); } void onControllerDeviceRemoved(const SDL_Event& event) @@ -1476,6 +1485,10 @@ void onControllerDeviceRemoved(const SDL_Event& event) SDL_JoystickID id = event.cdevice.which; g_manager.removeController(id); + + // this event could happen while the preferences UI is open + // in which case we need to force it to update + s_updateUI(); } void onControllerButton(const SDL_Event& event) @@ -1524,7 +1537,8 @@ void LLGameControl::init(const std::string& gamecontrollerdb_path, std::function<std::string(const std::string&)> loadString, std::function<void(const std::string&, const std::string&)> saveString, std::function<LLSD(const std::string&)> loadObject, - std::function<void(const std::string&, const LLSD&)> saveObject) + std::function<void(const std::string&, const LLSD&)> saveObject, + std::function<void()> updateUI) { if (g_gameControl) return; @@ -1535,6 +1549,7 @@ void LLGameControl::init(const std::string& gamecontrollerdb_path, llassert(saveString); llassert(loadObject); llassert(saveObject); + llassert(updateUI); int result = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER); if (result < 0) @@ -1572,6 +1587,7 @@ void LLGameControl::init(const std::string& gamecontrollerdb_path, s_saveString = saveString; s_loadObject = loadObject; s_saveObject = saveObject; + s_updateUI = updateUI; loadFromSettings(); } @@ -1692,7 +1708,7 @@ LLGameControl::InputChannel LLGameControl::getActiveInputChannel() else { // scan axes - S16 threshold = std::numeric_limits<S16>::max() / 2; + constexpr S16 threshold = std::numeric_limits<S16>::max() / 2; for (U8 i = 0; i < 6; ++i) { if (abs(state.mAxes[i]) > threshold) @@ -2099,3 +2115,9 @@ void LLGameControl::saveToSettings() LLSD deviceOptions(g_deviceOptions, true); s_saveObject(SETTING_KNOWNCONTROLLERS, deviceOptions); } + +// static +void LLGameControl::setDeviceOptions(const std::string& guid, const Options& options) +{ + g_manager.setDeviceOptions(guid, options); +} diff --git a/indra/llwindow/llgamecontrol.h b/indra/llwindow/llgamecontrol.h index 9398fb7f66..9dfce4c287 100644 --- a/indra/llwindow/llgamecontrol.h +++ b/indra/llwindow/llgamecontrol.h @@ -178,17 +178,23 @@ public: public: struct AxisOptions { - bool mInvert { false }; + S32 mMultiplier = 1; U16 mDeadZone { 0 }; S16 mOffset { 0 }; void resetToDefaults() { - mInvert = false; + mMultiplier = 1; mDeadZone = 0; mOffset = 0; } + S16 computeModifiedValue(S16 raw_value) const + { + S32 new_value = ((S32)raw_value + S32(mOffset)) * mMultiplier; + return (S16)(std::clamp(new_value, -32768, 32767)); + } + std::string saveToString() const; void loadFromString(std::string options); }; @@ -265,7 +271,8 @@ public: std::function<std::string(const std::string&)> loadString, std::function<void(const std::string&, const std::string&)> saveString, std::function<LLSD(const std::string&)> loadObject, - std::function<void(const std::string&, const LLSD&)> saveObject); + std::function<void(const std::string&, const LLSD&)> saveObject, + std::function<void()> updateUI); static void terminate(); static const std::list<LLGameControl::Device>& getDevices(); @@ -333,5 +340,6 @@ public: static void initByDefault(); static void loadFromSettings(); static void saveToSettings(); + static void setDeviceOptions(const std::string& guid, const Options& options); }; diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 7eded9e174..475610be36 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -47,6 +47,7 @@ #include "llagentwearables.h" #include "lldirpicker.h" #include "llfloaterimcontainer.h" +#include "llfloaterpreference.h" #include "llimprocessing.h" #include "llwindow.h" #include "llviewerstats.h" @@ -1141,7 +1142,8 @@ bool LLAppViewer::init() [&](const std::string& name) -> std::string { return gSavedSettings.getString(name); }, [&](const std::string& name, const std::string& value) { gSavedSettings.setString(name, value); }, [&](const std::string& name) -> LLSD { return gSavedSettings.getLLSD(name); }, - [&](const std::string& name, const LLSD& value) { gSavedSettings.setLLSD(name, value); }); + [&](const std::string& name, const LLSD& value) { gSavedSettings.setLLSD(name, value); }, + [&]() { LLPanelPreferenceGameControl::updateDeviceList(); }); try { diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp index 7ea9f9b4c2..109db7e3d7 100644 --- a/indra/newview/llfloaterpreference.cpp +++ b/indra/newview/llfloaterpreference.cpp @@ -1001,7 +1001,8 @@ void LLFloaterPreference::onBtnOK(const LLSD& userdata) LLUIColorTable::instance().saveUserSettings(); gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), true); - LLGameControl::loadFromSettings(); + // save current config to settings + LLGameControl::saveToSettings(); // Only save once logged in and loaded per account settings if (mGotPersonalInfo) @@ -1048,6 +1049,9 @@ void LLFloaterPreference::onBtnCancel(const LLSD& userdata) cancel(); closeFloater(); } + + // restore config from settings + LLGameControl::loadFromSettings(); } //static @@ -2261,12 +2265,12 @@ void LLPanelPreference::cancel(const std::vector<std::string> settings_to_skip) { for (control_values_map_t::iterator iter = mSavedValues.begin(); iter != mSavedValues.end(); ++iter) -{ + { LLControlVariable* control = iter->first; LLSD ctrl_value = iter->second; if((control->getName() == "InstantMessageLogPath") && (ctrl_value.asString() == "")) - { + { continue; } @@ -3176,6 +3180,15 @@ static LLScrollListCtrl* gSelectedGrid { nullptr }; static LLScrollListItem* gSelectedItem { nullptr }; static LLScrollListCell* gSelectedCell { nullptr }; +// static +void LLPanelPreferenceGameControl::updateDeviceList() +{ + if (gGameControlPanel) + { + gGameControlPanel->updateDeviceListInternal(); + } +} + LLPanelPreferenceGameControl::LLPanelPreferenceGameControl() { gGameControlPanel = this; @@ -3424,34 +3437,39 @@ void LLPanelPreferenceGameControl::onAxisOptionsSelect() if (LLScrollListItem* row = mAxisOptions->getFirstSelected()) { - LLGameControl::Options& deviceOptions = getSelectedDeviceOptions(); + LLGameControl::Options& options = getSelectedDeviceOptions(); S32 row_index = mAxisOptions->getItemIndex(row); - S32 column_index = row->getSelectedCell(); - if (column_index == 1) + { - LLGameControl::Options& deviceOptions = getSelectedDeviceOptions(); - deviceOptions.getAxisOptions()[row_index].mInvert = - row->getColumn(column_index)->getValue().asBoolean(); + // always update invert checkbox value because even though it may have been clicked + // the row does not know its cell has been selected + constexpr S32 invert_checkbox_column = 1; + bool invert = row->getColumn(invert_checkbox_column)->getValue().asBoolean(); + options.getAxisOptions()[row_index].mMultiplier = invert ? -1 : 1; } - else if (column_index == 2 || column_index == 3) + + S32 column_index = row->getSelectedCell(); + if (column_index == 2 || column_index == 3) { fitInRect(mNumericValueEditor, mAxisOptions, row_index, column_index); if (column_index == 2) { mNumericValueEditor->setMinValue(0); mNumericValueEditor->setMaxValue(LLGameControl::MAX_AXIS_DEAD_ZONE); - mNumericValueEditor->setValue(deviceOptions.getAxisOptions()[row_index].mDeadZone); + mNumericValueEditor->setValue(options.getAxisOptions()[row_index].mDeadZone); } else // column_index == 3 { mNumericValueEditor->setMinValue(-LLGameControl::MAX_AXIS_OFFSET); mNumericValueEditor->setMaxValue(LLGameControl::MAX_AXIS_OFFSET); - mNumericValueEditor->setValue(deviceOptions.getAxisOptions()[row_index].mOffset); + mNumericValueEditor->setValue(options.getAxisOptions()[row_index].mOffset); } mNumericValueEditor->setVisible(true); } initCombobox(row, mAxisOptions); + + LLGameControl::setDeviceOptions(mSelectedDeviceGUID, options); } } @@ -3464,7 +3482,7 @@ void LLPanelPreferenceGameControl::onCommitNumericValue() S32 row_index = mAxisOptions->getItemIndex(row); S32 column_index = row->getSelectedCell(); llassert(column_index == 2 || column_index == 3); - if (column_index != 2 && column_index != 3) + if (column_index < 2 || column_index > 3) return; if (column_index == 2) @@ -3574,6 +3592,12 @@ void LLPanelPreferenceGameControl::onOpen(const LLSD& key) populateActionTableCells(); updateActionTableState(); + updateDeviceListInternal(); + updateEnable(); +} + +void LLPanelPreferenceGameControl::updateDeviceListInternal() +{ // Setup the 2nd tab mDeviceOptions.clear(); for (const auto& pair : LLGameControl::getDeviceOptions()) @@ -3590,11 +3614,8 @@ void LLPanelPreferenceGameControl::onOpen(const LLSD& key) mDeviceOptions[device.getGUID()] = { device.getName(), device.saveOptionsToString(true), device.getOptions() }; } } - mCheckShowAllDevices->setValue(false); populateDeviceTitle(); - - updateEnable(); } void LLPanelPreferenceGameControl::populateActionTableRows(const std::string& filename) @@ -3791,7 +3812,7 @@ void LLPanelPreferenceGameControl::populateOptionsTableCells() { LLScrollListItem* row = rows[i]; const LLGameControl::Options::AxisOptions& axis_options = all_axis_options[i]; - row->getColumn(1)->setValue(axis_options.mInvert); + row->getColumn(1)->setValue(axis_options.mMultiplier == -1 ? true : false); setNumericLabel(row->getColumn(2), axis_options.mDeadZone); setNumericLabel(row->getColumn(3), axis_options.mOffset); } diff --git a/indra/newview/llfloaterpreference.h b/indra/newview/llfloaterpreference.h index b3872958ac..57eaa193a3 100644 --- a/indra/newview/llfloaterpreference.h +++ b/indra/newview/llfloaterpreference.h @@ -389,12 +389,19 @@ public: TYPE_NONE }; + static void updateDeviceList(); + LLPanelPreferenceGameControl(); ~LLPanelPreferenceGameControl(); void onOpen(const LLSD& key) override; + + // This function squirrels away the current values of the controls so that + // cancel() can restore them. void saveSettings() override; + void updateDeviceListInternal(); + void onGridSelect(LLUICtrl* ctrl); void onCommitInputChannel(LLUICtrl* ctrl); |