applets/controller: Implement "Explain Text"

"Explain Text" is additional text that is shown for each player in the controller applet.
This commit is contained in:
Morph 2020-08-27 01:21:48 -04:00
parent 5219615418
commit 5ce3015945
6 changed files with 304 additions and 25 deletions

View File

@ -11,6 +11,7 @@
namespace Core::Frontend { namespace Core::Frontend {
using BorderColor = std::array<u8, 4>; using BorderColor = std::array<u8, 4>;
using ExplainText = std::array<char, 0x81>;
struct ControllerParameters { struct ControllerParameters {
s8 min_players{}; s8 min_players{};
@ -19,6 +20,8 @@ struct ControllerParameters {
bool enable_single_mode{}; bool enable_single_mode{};
bool enable_border_color{}; bool enable_border_color{};
std::vector<BorderColor> border_colors{}; std::vector<BorderColor> border_colors{};
bool enable_explain_text{};
std::vector<ExplainText> explain_text{};
bool allow_pro_controller{}; bool allow_pro_controller{};
bool allow_handheld{}; bool allow_handheld{};
bool allow_dual_joycons{}; bool allow_dual_joycons{};

View File

@ -19,8 +19,8 @@ namespace Service::AM::Applets {
[[maybe_unused]] constexpr ResultCode ERR_CONTROLLER_APPLET_3102{ErrorModule::HID, 3102}; [[maybe_unused]] constexpr ResultCode ERR_CONTROLLER_APPLET_3102{ErrorModule::HID, 3102};
static Core::Frontend::ControllerParameters ConvertToFrontendParameters( static Core::Frontend::ControllerParameters ConvertToFrontendParameters(
ControllerSupportArgPrivate private_arg, ControllerSupportArgHeader header, ControllerSupportArgPrivate private_arg, ControllerSupportArgHeader header, bool enable_text,
std::vector<IdentificationColor> identification_colors) { std::vector<IdentificationColor> identification_colors, std::vector<ExplainText> text) {
HID::Controller_NPad::NPadType npad_style_set; HID::Controller_NPad::NPadType npad_style_set;
npad_style_set.raw = private_arg.style_set; npad_style_set.raw = private_arg.style_set;
@ -31,6 +31,8 @@ static Core::Frontend::ControllerParameters ConvertToFrontendParameters(
.enable_single_mode = header.enable_single_mode, .enable_single_mode = header.enable_single_mode,
.enable_border_color = header.enable_identification_color, .enable_border_color = header.enable_identification_color,
.border_colors = identification_colors, .border_colors = identification_colors,
.enable_explain_text = enable_text,
.explain_text = text,
.allow_pro_controller = npad_style_set.pro_controller == 1, .allow_pro_controller = npad_style_set.pro_controller == 1,
.allow_handheld = npad_style_set.handheld == 1, .allow_handheld = npad_style_set.handheld == 1,
.allow_dual_joycons = npad_style_set.joycon_dual == 1, .allow_dual_joycons = npad_style_set.joycon_dual == 1,
@ -126,31 +128,38 @@ void Controller::Execute() {
case LibraryAppletVersion::Version5: case LibraryAppletVersion::Version5:
return ConvertToFrontendParameters( return ConvertToFrontendParameters(
controller_private_arg, controller_user_arg_old.header, controller_private_arg, controller_user_arg_old.header,
controller_user_arg_old.enable_explain_text,
std::vector<IdentificationColor>( std::vector<IdentificationColor>(
controller_user_arg_old.identification_colors.begin(), controller_user_arg_old.identification_colors.begin(),
controller_user_arg_old.identification_colors.end())); controller_user_arg_old.identification_colors.end()),
std::vector<ExplainText>(controller_user_arg_old.explain_text.begin(),
controller_user_arg_old.explain_text.end()));
case LibraryAppletVersion::Version7: case LibraryAppletVersion::Version7:
default: default:
return ConvertToFrontendParameters( return ConvertToFrontendParameters(
controller_private_arg, controller_user_arg_new.header, controller_private_arg, controller_user_arg_new.header,
controller_user_arg_new.enable_explain_text,
std::vector<IdentificationColor>( std::vector<IdentificationColor>(
controller_user_arg_new.identification_colors.begin(), controller_user_arg_new.identification_colors.begin(),
controller_user_arg_new.identification_colors.end())); controller_user_arg_new.identification_colors.end()),
std::vector<ExplainText>(controller_user_arg_new.explain_text.begin(),
controller_user_arg_new.explain_text.end()));
} }
}(); }();
is_single_mode = parameters.enable_single_mode; is_single_mode = parameters.enable_single_mode;
LOG_DEBUG( LOG_DEBUG(Service_HID,
Service_HID, "Controller Parameters: min_players={}, max_players={}, "
"Controller Parameters: min_players={}, max_players={}, keep_controllers_connected={}, " "keep_controllers_connected={}, enable_single_mode={}, enable_border_color={}, "
"enable_single_mode={}, enable_border_color={}, allow_pro_controller={}, " "enable_explain_text={}, allow_pro_controller={}, allow_handheld={}, "
"allow_handheld={}, allow_dual_joycons={}, allow_left_joycon={}, allow_right_joycon={}", "allow_dual_joycons={}, allow_left_joycon={}, allow_right_joycon={}",
parameters.min_players, parameters.max_players, parameters.keep_controllers_connected, parameters.min_players, parameters.max_players,
parameters.enable_single_mode, parameters.enable_border_color, parameters.keep_controllers_connected, parameters.enable_single_mode,
parameters.allow_pro_controller, parameters.allow_handheld, parameters.enable_border_color, parameters.enable_explain_text,
parameters.allow_dual_joycons, parameters.allow_left_joycon, parameters.allow_pro_controller, parameters.allow_handheld,
parameters.allow_right_joycon); parameters.allow_dual_joycons, parameters.allow_left_joycon,
parameters.allow_right_joycon);
frontend.ReconfigureControllers([this] { ConfigurationComplete(); }, parameters); frontend.ReconfigureControllers([this] { ConfigurationComplete(); }, parameters);
break; break;

View File

@ -16,6 +16,7 @@ class System;
namespace Service::AM::Applets { namespace Service::AM::Applets {
using IdentificationColor = std::array<u8, 4>; using IdentificationColor = std::array<u8, 4>;
using ExplainText = std::array<char, 0x81>;
enum class LibraryAppletVersion : u32_le { enum class LibraryAppletVersion : u32_le {
Version3 = 0x3, // 1.0.0 - 2.3.0 Version3 = 0x3, // 1.0.0 - 2.3.0
@ -65,7 +66,7 @@ struct ControllerSupportArgOld {
ControllerSupportArgHeader header{}; ControllerSupportArgHeader header{};
std::array<IdentificationColor, 4> identification_colors{}; std::array<IdentificationColor, 4> identification_colors{};
bool enable_explain_text{}; bool enable_explain_text{};
std::array<std::array<char, 0x81>, 4> explain_text{}; std::array<ExplainText, 4> explain_text{};
}; };
static_assert(sizeof(ControllerSupportArgOld) == 0x21C, static_assert(sizeof(ControllerSupportArgOld) == 0x21C,
"ControllerSupportArgOld has incorrect size."); "ControllerSupportArgOld has incorrect size.");
@ -75,7 +76,7 @@ struct ControllerSupportArgNew {
ControllerSupportArgHeader header{}; ControllerSupportArgHeader header{};
std::array<IdentificationColor, 8> identification_colors{}; std::array<IdentificationColor, 8> identification_colors{};
bool enable_explain_text{}; bool enable_explain_text{};
std::array<std::array<char, 0x81>, 8> explain_text{}; std::array<ExplainText, 8> explain_text{};
}; };
static_assert(sizeof(ControllerSupportArgNew) == 0x430, static_assert(sizeof(ControllerSupportArgNew) == 0x430,
"ControllerSupportArgNew has incorrect size."); "ControllerSupportArgNew has incorrect size.");

View File

@ -4,6 +4,7 @@
#include <algorithm> #include <algorithm>
#include "common/string_util.h"
#include "core/core.h" #include "core/core.h"
#include "core/hle/lock.h" #include "core/hle/lock.h"
#include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/npad.h"
@ -45,6 +46,7 @@ void UpdateController(Settings::ControllerType controller_type, std::size_t npad
npad.UpdateControllerAt(npad.MapSettingsTypeToNPad(controller_type), npad_index, connected); npad.UpdateControllerAt(npad.MapSettingsTypeToNPad(controller_type), npad_index, connected);
} }
// Returns true if the given controller type is compatible with the given parameters.
bool IsControllerCompatible(Settings::ControllerType controller_type, bool IsControllerCompatible(Settings::ControllerType controller_type,
Core::Frontend::ControllerParameters parameters) { Core::Frontend::ControllerParameters parameters) {
switch (controller_type) { switch (controller_type) {
@ -140,6 +142,12 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
ui->checkboxPlayer8LED4}, ui->checkboxPlayer8LED4},
}}; }};
explain_text_labels = {
ui->labelPlayer1Explain, ui->labelPlayer2Explain, ui->labelPlayer3Explain,
ui->labelPlayer4Explain, ui->labelPlayer5Explain, ui->labelPlayer6Explain,
ui->labelPlayer7Explain, ui->labelPlayer8Explain,
};
emulated_controllers = { emulated_controllers = {
ui->comboPlayer1Emulated, ui->comboPlayer2Emulated, ui->comboPlayer3Emulated, ui->comboPlayer1Emulated, ui->comboPlayer2Emulated, ui->comboPlayer3Emulated,
ui->comboPlayer4Emulated, ui->comboPlayer5Emulated, ui->comboPlayer6Emulated, ui->comboPlayer4Emulated, ui->comboPlayer5Emulated, ui->comboPlayer6Emulated,
@ -200,6 +208,8 @@ QtControllerSelectorDialog::QtControllerSelectorDialog(
Settings::ControllerType::Handheld); Settings::ControllerType::Handheld);
}); });
} }
SetExplainText(i);
} }
connect(ui->inputConfigButton, &QPushButton::clicked, this, connect(ui->inputConfigButton, &QPushButton::clicked, this,
@ -468,6 +478,16 @@ void QtControllerSelectorDialog::UpdateBorderColor(std::size_t player_index) {
.arg(parameters.border_colors[player_index][3]))); .arg(parameters.border_colors[player_index][3])));
} }
void QtControllerSelectorDialog::SetExplainText(std::size_t player_index) {
if (!parameters.enable_explain_text || player_index >= parameters.max_players) {
return;
}
explain_text_labels[player_index]->setText(QString::fromStdString(
Common::StringFromFixedZeroTerminatedBuffer(parameters.explain_text[player_index].data(),
parameters.explain_text[player_index].size())));
}
void QtControllerSelectorDialog::UpdateDockedState(bool is_handheld) { void QtControllerSelectorDialog::UpdateDockedState(bool is_handheld) {
// Disallow changing the console mode if the controller type is handheld. // Disallow changing the console mode if the controller type is handheld.
ui->radioDocked->setEnabled(!is_handheld); ui->radioDocked->setEnabled(!is_handheld);

View File

@ -59,6 +59,9 @@ private:
// Updates the border color per player. // Updates the border color per player.
void UpdateBorderColor(std::size_t player_index); void UpdateBorderColor(std::size_t player_index);
// Sets the "Explain Text" per player.
void SetExplainText(std::size_t player_index);
// Updates the console mode. // Updates the console mode.
void UpdateDockedState(bool is_handheld); void UpdateDockedState(bool is_handheld);
@ -94,6 +97,9 @@ private:
// LED patterns for currently connected controllers/players. // LED patterns for currently connected controllers/players.
std::array<std::array<QCheckBox*, 4>, 8> led_patterns_boxes; std::array<std::array<QCheckBox*, 4>, 8> led_patterns_boxes;
// Labels representing additional information known as "Explain Text" per player.
std::array<QLabel*, 8> explain_text_labels;
// Comboboxes with a list of emulated controllers per player. // Comboboxes with a list of emulated controllers per player.
std::array<QComboBox*, 8> emulated_controllers; std::array<QComboBox*, 8> emulated_controllers;

View File

@ -468,13 +468,43 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="fakeSpacerPlayer4" native="true"> <widget class="QWidget" name="Player4Explain" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>10</height> <height>10</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_39">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelPlayer4Explain">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -635,13 +665,43 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="fakeSpacerPlayer2" native="true"> <widget class="QWidget" name="Player2Explain" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>10</height> <height>10</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_37">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelPlayer2Explain">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -806,13 +866,43 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="fakeSpacerPlayer1" native="true"> <widget class="QWidget" name="Player1Explain" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>10</height> <height>10</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_36">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelPlayer1Explain">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -1086,13 +1176,43 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="fakeSpacerPlayer3" native="true"> <widget class="QWidget" name="Player3Explain" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>10</height> <height>10</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_38">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelPlayer3Explain">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -1296,13 +1416,43 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="fakeSpacerPlayer7" native="true"> <widget class="QWidget" name="Player7Explain" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>10</height> <height>10</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_42">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelPlayer7Explain">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -1463,13 +1613,43 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="fakeSpacerPlayer8" native="true"> <widget class="QWidget" name="Player8Explain" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>10</height> <height>10</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_35">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelPlayer8Explain">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -1634,13 +1814,43 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="fakeSpacerPlayer5" native="true"> <widget class="QWidget" name="Player5Explain" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>10</height> <height>10</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_40">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelPlayer5Explain">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -1801,13 +2011,43 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="fakeSpacerPlayer6" native="true"> <widget class="QWidget" name="Player6Explain" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>10</height> <height>10</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_41">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelPlayer6Explain">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -2395,7 +2635,7 @@
<item alignment="Qt::AlignBottom"> <item alignment="Qt::AlignBottom">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Ok</set>