summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.cpp
blob: 6dc200d1e17e0db159d8e2ba05607a9aaf6ee1c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h"

#include <cstddef>
#include <memory>
#include <string>
#include <utility>

#include "Common/Common.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
#include "VideoCommon/OnScreenDisplay.h"

namespace ControllerEmu
{
ModifySettingsButton::ModifySettingsButton(std::string button_name)
    : Buttons(std::move(button_name))
{
}

void ModifySettingsButton::AddInput(std::string button_name, bool toggle)
{
  ControlGroup::AddInput(Translate, 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)
  {
    const bool state = controls[i]->GetState<bool>();

    if (!associated_settings_toggle[i])
    {
      // not toggled
      associated_settings[i] = state;
    }
    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)
      {
        associated_settings[i] = !associated_settings[i];

        if (associated_settings[i])
          OSD::AddMessage(controls[i]->ui_name + ": on");
        else
          OSD::AddMessage(controls[i]->ui_name + ": off");

        threshold_exceeded[i] = true;
      }

      if (!state)
        threshold_exceeded[i] = false;
    }
  }
}

const std::vector<bool>& ModifySettingsButton::isSettingToggled() const
{
  return associated_settings_toggle;
}

const std::vector<bool>& ModifySettingsButton::getSettingsModifier() const
{
  return associated_settings;
}
}  // namespace ControllerEmu