Browse Source

Extract current input mode into its own library

Removes a transitive dependency on the entire plrctrl from options.
pull/7670/head
Gleb Mazovetskiy 1 year ago
parent
commit
3bb1d685af
  1. 9
      Source/CMakeLists.txt
  2. 1
      Source/DiabloUI/diabloui.cpp
  3. 1
      Source/DiabloUI/hero/selhero.cpp
  4. 1
      Source/control.cpp
  5. 16
      Source/controls/control_mode.cpp
  6. 30
      Source/controls/control_mode.hpp
  7. 10
      Source/controls/controller_buttons.cpp
  8. 9
      Source/controls/controller_buttons.h
  9. 1
      Source/controls/controller_motion.cpp
  10. 1
      Source/controls/game_controls.cpp
  11. 7
      Source/controls/game_controls.h
  12. 1
      Source/controls/menu_controls.cpp
  13. 10
      Source/controls/plrctrls.cpp
  14. 22
      Source/controls/plrctrls.h
  15. 1
      Source/cursor.cpp
  16. 1
      Source/diablo.cpp
  17. 1
      Source/engine/demomode.cpp
  18. 1
      Source/engine/dx.cpp
  19. 1
      Source/engine/render/scrollrt.cpp
  20. 1
      Source/inv.cpp
  21. 5
      Source/items.cpp
  22. 1
      Source/levels/trigs.cpp
  23. 1
      Source/missiles.cpp
  24. 1
      Source/movie.cpp
  25. 10
      Source/options.cpp
  26. 1
      Source/panels/spell_list.cpp
  27. 1
      Source/player.cpp
  28. 1
      Source/stores.cpp
  29. 1
      Source/track.cpp

9
Source/CMakeLists.txt

@ -220,6 +220,13 @@ target_link_dependencies(libdevilutionx_controller_buttons
DevilutionX::SDL
)
add_devilutionx_object_library(libdevilutionx_control_mode
controls/control_mode.cpp
)
target_link_dependencies(libdevilutionx_control_mode PUBLIC
libdevilutionx_controller_buttons
)
add_devilutionx_object_library(libdevilutionx_padmapper
controls/padmapper.cpp
)
@ -428,6 +435,7 @@ target_link_dependencies(libdevilutionx_options PUBLIC
fmt::fmt
tl
libdevilutionx_controller_buttons
libdevilutionx_control_mode
libdevilutionx_logged_fstream
libdevilutionx_quick_messages
libdevilutionx_strings
@ -654,6 +662,7 @@ target_link_dependencies(libdevilutionx PUBLIC
libdevilutionx_codec
libdevilutionx_config
libdevilutionx_controller_buttons
libdevilutionx_control_mode
libdevilutionx_crawl
libdevilutionx_direction
libdevilutionx_surface

1
Source/DiabloUI/diabloui.cpp

@ -10,6 +10,7 @@
#include "DiabloUI/dialogs.h"
#include "DiabloUI/scrollbar.h"
#include "DiabloUI/text_input.hpp"
#include "controls/control_mode.hpp"
#include "controls/controller.h"
#include "controls/input.h"
#include "controls/menu_controls.h"

1
Source/DiabloUI/hero/selhero.cpp

@ -14,6 +14,7 @@
#include "DiabloUI/selok.h"
#include "DiabloUI/selyesno.h"
#include "control.h"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "engine/assets.hpp"
#include "game_mode.hpp"

1
Source/control.cpp

@ -17,6 +17,7 @@
#include "DiabloUI/text_input.hpp"
#include "automap.h"
#include "controls/control_mode.hpp"
#include "controls/modifier_hints.h"
#include "controls/plrctrls.h"
#include "cursor.h"

16
Source/controls/control_mode.cpp

@ -0,0 +1,16 @@
#include "controls/control_mode.hpp"
namespace devilution {
ControlTypes ControlMode = ControlTypes::None;
ControlTypes ControlDevice = ControlTypes::None;
GamepadLayout GamepadType =
#if defined(DEVILUTIONX_GAMEPAD_TYPE)
GamepadLayout::
DEVILUTIONX_GAMEPAD_TYPE;
#else
GamepadLayout::Generic;
#endif
} // namespace devilution

30
Source/controls/control_mode.hpp

@ -0,0 +1,30 @@
#pragma once
#include <cstdint>
#include "controls/controller_buttons.h"
namespace devilution {
enum class ControlTypes : uint8_t {
None,
KeyboardAndMouse,
Gamepad,
VirtualGamepad,
};
extern ControlTypes ControlMode;
/**
* @brief Controlling device type.
*
* While simulating a mouse, `ControlMode` is set to `KeyboardAndMouse`,
* even though a gamepad is used to control it.
*
* This value is always set to the actual active device type.
*/
extern ControlTypes ControlDevice;
extern GamepadLayout GamepadType;
} // namespace devilution

10
Source/controls/controller_buttons.cpp

@ -1,7 +1,5 @@
#include "controller_buttons.h"
#include "controls/game_controls.h"
namespace devilution {
namespace {
namespace controller_button_icon {
@ -280,13 +278,9 @@ std::string_view ToXboxIcon(ControllerButton button)
} // namespace
// Defined in `plrctrls.cpp`.
// Declared here to avoid having to depend on it in tests.
extern GamepadLayout GamepadType;
std::string_view ToString(ControllerButton button)
std::string_view ToString(GamepadLayout gamepadType, ControllerButton button)
{
switch (GamepadType) {
switch (gamepadType) {
case GamepadLayout::PlayStation:
return ToPlayStationIcon(button);
case GamepadLayout::Nintendo:

9
Source/controls/controller_buttons.h

@ -74,6 +74,13 @@ inline bool IsDPadButton(ControllerButton button)
|| button == ControllerButton_BUTTON_DPAD_RIGHT;
}
std::string_view ToString(ControllerButton button);
enum class GamepadLayout : uint8_t {
Generic,
Nintendo,
PlayStation,
Xbox,
};
[[nodiscard]] std::string_view ToString(GamepadLayout gamepadType, ControllerButton button);
} // namespace devilution

1
Source/controls/controller_motion.cpp

@ -3,6 +3,7 @@
#include <cmath>
#include "control.h"
#include "controls/control_mode.hpp"
#include "controls/controller.h"
#ifndef USE_SDL1
#include "controls/devices/game_controller.h"

1
Source/controls/game_controls.cpp

@ -2,6 +2,7 @@
#include <cstdint>
#include "controls/control_mode.hpp"
#include "controls/controller_motion.h"
#ifndef USE_SDL1
#include "controls/devices/game_controller.h"

7
Source/controls/game_controls.h

@ -8,13 +8,6 @@
namespace devilution {
enum class GamepadLayout : uint8_t {
Generic,
Nintendo,
PlayStation,
Xbox,
};
enum GameActionType : uint8_t {
GameActionType_NONE,
GameActionType_USE_HEALTH_POTION,

1
Source/controls/menu_controls.cpp

@ -2,6 +2,7 @@
#include "DiabloUI/diabloui.h"
#include "controls/axis_direction.h"
#include "controls/control_mode.hpp"
#include "controls/controller.h"
#include "controls/controller_motion.h"
#include "controls/plrctrls.h"

10
Source/controls/plrctrls.cpp

@ -15,6 +15,7 @@
#ifndef USE_SDL1
#include "controls/devices/game_controller.h"
#endif
#include "controls/control_mode.hpp"
#include "controls/game_controls.h"
#include "controls/touch/gamepad.h"
#include "cursor.h"
@ -44,16 +45,7 @@
namespace devilution {
ControlTypes ControlMode = ControlTypes::None;
ControlTypes ControlDevice = ControlTypes::None;
GameActionType ControllerActionHeld = GameActionType_NONE;
GamepadLayout GamepadType =
#if defined(DEVILUTIONX_GAMEPAD_TYPE)
GamepadLayout::
DEVILUTIONX_GAMEPAD_TYPE;
#else
GamepadLayout::Generic;
#endif
bool StandToggle = false;

22
Source/controls/plrctrls.h

@ -17,29 +17,7 @@ enum class BeltItemType : uint8_t {
Mana,
};
enum class ControlTypes : uint8_t {
None,
KeyboardAndMouse,
Gamepad,
VirtualGamepad,
};
extern ControlTypes ControlMode;
/**
* @brief Controlling device type.
*
* While simulating a mouse, `ControlMode` is set to `KeyboardAndMouse`,
* even though a gamepad is used to control it.
*
* This value is always set to the actual active device type.
*/
extern ControlTypes ControlDevice;
extern GameActionType ControllerActionHeld;
extern GamepadLayout GamepadType;
extern bool StandToggle;
// Runs every frame.

1
Source/cursor.cpp

@ -15,6 +15,7 @@
#include "DiabloUI/diabloui.h"
#include "control.h"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "doom.h"
#include "engine/backbuffer_state.hpp"

1
Source/diablo.cpp

@ -22,6 +22,7 @@
#include "debug.h"
#endif
#include "DiabloUI/diabloui.h"
#include "controls/control_mode.hpp"
#include "controls/keymapper.hpp"
#include "controls/plrctrls.h"
#include "controls/remap_keyboard.h"

1
Source/engine/demomode.cpp

@ -11,6 +11,7 @@
#include "utils/sdl2_to_1_2_backports.h"
#endif
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "engine/events.hpp"
#include "gmenu.h"

1
Source/engine/dx.cpp

@ -8,6 +8,7 @@
#include <SDL.h>
#include <cstdint>
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "engine/render/primitive_render.hpp"
#include "headless_mode.hpp"

1
Source/engine/render/scrollrt.cpp

@ -13,6 +13,7 @@
#include "DiabloUI/ui_flags.hpp"
#include "automap.h"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "cursor.h"
#include "dead.h"

1
Source/inv.cpp

@ -12,6 +12,7 @@
#include <fmt/format.h>
#include "DiabloUI/ui_flags.hpp"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "cursor.h"
#include "engine/backbuffer_state.hpp"

5
Source/items.cpp

@ -16,6 +16,7 @@
#include <fmt/format.h>
#include "DiabloUI/ui_flags.hpp"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "cursor.h"
#include "doom.h"
@ -1800,8 +1801,8 @@ void printItemMiscGamepad(const Item &item, bool isOil, bool isCastOnTarget)
printItemMiscGenericGamepad(item, isOil, isCastOnTarget);
return;
}
const std::string_view activateButton = ToString(ControllerButton_BUTTON_Y);
const std::string_view castButton = ToString(ControllerButton_BUTTON_X);
const std::string_view activateButton = ToString(GamepadType, ControllerButton_BUTTON_Y);
const std::string_view castButton = ToString(GamepadType, ControllerButton_BUTTON_X);
if (item._iMiscId == IMISC_MAPOFDOOM) {
AddInfoBoxString(fmt::format(fmt::runtime(_("{} to view")), activateButton));

1
Source/levels/trigs.cpp

@ -11,6 +11,7 @@
#include <fmt/format.h>
#include "control.h"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "cursor.h"
#include "diablo_msg.hpp"

1
Source/missiles.cpp

@ -10,6 +10,7 @@
#include <cstdint>
#include "control.h"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "crawl.hpp"
#include "cursor.h"

1
Source/movie.cpp

@ -6,6 +6,7 @@
#include <cstdint>
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "diablo.h"
#include "effects.h"

10
Source/options.cpp

@ -21,11 +21,8 @@
#include <function_ref.hpp>
#include "appfat.h"
#include "control.h"
#include "controls/controller.h"
#include "controls/control_mode.hpp"
#include "controls/controller_buttons.h"
#include "controls/game_controls.h"
#include "controls/plrctrls.h"
#include "engine/assets.hpp"
#include "engine/sound_defs.hpp"
#include "platform/locale.hpp"
@ -33,7 +30,6 @@
#include "utils/algorithm/container.hpp"
#include "utils/file_util.h"
#include "utils/ini.hpp"
#include "utils/is_of.hpp"
#include "utils/language.h"
#include "utils/log.hpp"
#include "utils/logged_fstream.hpp"
@ -1444,13 +1440,13 @@ void PadmapperOptions::Action::UpdateValueDescription() const
boundInputShortDescription = "";
return;
}
std::string_view buttonName = ToString(boundInput.button);
std::string_view buttonName = ToString(GamepadType, boundInput.button);
if (boundInput.modifier == ControllerButton_NONE) {
boundInputDescription = std::string(buttonName);
boundInputShortDescription = std::string(Shorten(buttonName));
return;
}
std::string_view modifierName = ToString(boundInput.modifier);
std::string_view modifierName = ToString(GamepadType, boundInput.modifier);
boundInputDescription = StrCat(modifierName, "+", buttonName);
boundInputShortDescription = StrCat(Shorten(modifierName), "+", Shorten(buttonName));
}

1
Source/panels/spell_list.cpp

@ -5,6 +5,7 @@
#include <fmt/format.h>
#include "control.h"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "engine/backbuffer_state.hpp"
#include "engine/palette.h"

1
Source/player.cpp

@ -10,6 +10,7 @@
#include <fmt/core.h>
#include "control.h"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "cursor.h"
#include "dead.h"

1
Source/stores.cpp

@ -11,6 +11,7 @@
#include <fmt/format.h>
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"
#include "cursor.h"
#include "engine/backbuffer_state.hpp"

1
Source/track.cpp

@ -7,6 +7,7 @@
#include <SDL.h>
#include "controls/control_mode.hpp"
#include "controls/game_controls.h"
#include "controls/plrctrls.h"
#include "cursor.h"

Loading…
Cancel
Save