From 6a75ea5653ec596b1a08e985e98fca0b05ccd6f7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 8 Feb 2017 22:15:43 -0500 Subject: ControllerEmu: Separate ControlGroup from ControllerEmu ControllerEmu, the class, is essentially acting like a namespace for ControlGroup. This makes it impossible to forward declare any of the internals. It also globs a bunch of classes together which is kind of a pain to manage. This splits ControlGroup and the classes it contains into their own source files and situates them all within a namespace, which gets them out of global scope. Since this allows forward declarations for the once-internal classes, it now requires significantly less files to be rebuilt if anything is changed in the ControllerEmu portion of code. It does not split out the settings classes yet, however, as it would be preferable to make a settings base class that all settings derive from, but this would be a functional change -- this commit only intends to move around existing code. Extracting the settings class will be done in another commit. --- .../ControlGroup/ModifySettingsButton.cpp | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp') diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp new file mode 100644 index 0000000000..b71b1ea2c1 --- /dev/null +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp @@ -0,0 +1,77 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h" + +#include +#include +#include +#include + +#include "Common/Common.h" +#include "InputCommon/ControlReference/ControlReference.h" +#include "InputCommon/ControllerEmu/Control/Control.h" +#include "InputCommon/ControllerEmu/Control/Input.h" +#include "VideoCommon/OnScreenDisplay.h" + +namespace ControllerEmu +{ +ModifySettingsButton::ModifySettingsButton(std::string button_name) + : Buttons(std::move(button_name)) +{ + numeric_settings.emplace_back(std::make_unique(_trans("Threshold"), 0.5)); +} + +void ModifySettingsButton::AddInput(std::string button_name, bool toggle) +{ + controls.emplace_back(new Input(std::move(button_name))); + threshold_exceeded.emplace_back(false); + associated_settings.emplace_back(false); + associated_settings_toggle.emplace_back(toggle); +} + +void ModifySettingsButton::GetState() +{ + for (size_t i = 0; i < controls.size(); ++i) + { + ControlState state = controls[i]->control_ref->State(); + + if (!associated_settings_toggle[i]) + { + // not toggled + associated_settings[i] = state > numeric_settings[0]->GetValue(); + } + else + { + // toggle (loading savestates does not en-/disable toggle) + // after we passed the threshold, we en-/disable. but after that, we don't change it + // anymore + if (!threshold_exceeded[i] && state > numeric_settings[0]->GetValue()) + { + associated_settings[i] = !associated_settings[i]; + + if (associated_settings[i]) + OSD::AddMessage(controls[i]->name + ": " + _trans("on")); + else + OSD::AddMessage(controls[i]->name + ": " + _trans("off")); + + threshold_exceeded[i] = true; + } + + if (state < numeric_settings[0]->GetValue()) + threshold_exceeded[i] = false; + } + } +} + +const std::vector& ModifySettingsButton::isSettingToggled() const +{ + return associated_settings_toggle; +} + +const std::vector& ModifySettingsButton::getSettingsModifier() const +{ + return associated_settings; +} +} // namespace ControllerEmu -- cgit v1.2.3