diff --git a/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp b/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp index cec8849d91f4..459b54e3a541 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp @@ -39,10 +39,34 @@ void BalanceBoardExt::BuildDesiredExtensionState(DesiredExtensionState* target_s const double total_weight = DEFAULT_WEIGHT * weight; // kilograms - const auto top_right = total_weight * (1 + balance_state.x + balance_state.y) / 4; - const auto bottom_right = total_weight * (1 + balance_state.x - balance_state.y) / 4; - const auto top_left = total_weight * (1 - balance_state.x + balance_state.y) / 4; - const auto bottom_left = total_weight * (1 - balance_state.x - balance_state.y) / 4; + auto top_right = total_weight * (1 + balance_state.x + balance_state.y) / 4; + auto bottom_right = total_weight * (1 + balance_state.x - balance_state.y) / 4; + auto top_left = total_weight * (1 - balance_state.x + balance_state.y) / 4; + auto bottom_left = total_weight * (1 - balance_state.x - balance_state.y) / 4; + + if (m_input_override_function) + { + if (const std::optional top_right_override = + m_input_override_function(BALANCE_GROUP, TOP_RIGHT_SENSOR, top_right)) + { + top_right = *top_right_override; + } + if (const std::optional bottom_right_override = + m_input_override_function(BALANCE_GROUP, BOTTOM_RIGHT_SENSOR, bottom_right)) + { + bottom_right = *bottom_right_override; + } + if (const std::optional top_left_override = + m_input_override_function(BALANCE_GROUP, TOP_LEFT_SENSOR, top_left)) + { + top_left = *top_left_override; + } + if (const std::optional bottom_left_override = + m_input_override_function(BALANCE_GROUP, BOTTOM_LEFT_SENSOR, bottom_left)) + { + bottom_left = *bottom_left_override; + } + } DataFormat bb_data = {}; diff --git a/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h b/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h index b907298f4999..9fc6335975ba 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h +++ b/Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h @@ -33,6 +33,13 @@ class BalanceBoardExt : public Extension1stParty }; static_assert(sizeof(DataFormat) == 12, "Wrong size"); + static constexpr const char* BALANCE_GROUP = "Balance"; + + static constexpr const char* TOP_RIGHT_SENSOR = "TR"; + static constexpr const char* BOTTOM_RIGHT_SENSOR = "BR"; + static constexpr const char* TOP_LEFT_SENSOR = "TL"; + static constexpr const char* BOTTOM_LEFT_SENSOR = "BL"; + BalanceBoardExt(BalanceBoard* owner); static constexpr float DEFAULT_WEIGHT = 63.5; // kilograms; no specific meaning to this value diff --git a/Source/Core/DolphinQt/TAS/TASInputWindow.cpp b/Source/Core/DolphinQt/TAS/TASInputWindow.cpp index 1a09084875b1..dedf4e7d4234 100644 --- a/Source/Core/DolphinQt/TAS/TASInputWindow.cpp +++ b/Source/Core/DolphinQt/TAS/TASInputWindow.cpp @@ -235,6 +235,25 @@ TASSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int defaul return value; } +QDoubleSpinBox* TASInputWindow::CreateWeightSliderValuePair(std::string_view group_name, + std::string_view control_name, + InputOverrider* overrider, + QBoxLayout* layout, int min, int max, + QKeySequence shortcut_key_sequence, + QWidget* shortcut_widget) +{ + QDoubleSpinBox* value = + CreateWeightSliderValuePair(layout, min, max, shortcut_key_sequence, shortcut_widget); + + InputOverrider::OverrideFunction func = [this, value](ControlState controller_state) { + return GetSpinBox(value, controller_state); + }; + + overrider->AddFunction(group_name, control_name, std::move(func)); + + return value; +} + // The shortcut_widget argument needs to specify the container widget that will be hidden/shown. // This is done to avoid ambigous shortcuts QDoubleSpinBox* TASInputWindow::CreateWeightSliderValuePair(QBoxLayout* layout, int min, int max, @@ -302,3 +321,24 @@ std::optional TASInputWindow::GetSpinBox(TASSpinBox* spin, int zer return (spin->GetValue() - zero) / scale; } + +std::optional TASInputWindow::GetSpinBox(QDoubleSpinBox* spin, + ControlState controller_state) +{ + if (m_use_controller->isChecked()) + { + if (!m_spinbox_most_recent_values_double.count(spin) || + m_spinbox_most_recent_values_double[spin] != controller_state) + { + QueueOnObjectBlocking(spin, [spin, controller_state] { spin->setValue(controller_state); }); + } + + m_spinbox_most_recent_values_double[spin] = controller_state; + } + else + { + m_spinbox_most_recent_values_double.clear(); + } + + return spin->value(); +} diff --git a/Source/Core/DolphinQt/TAS/TASInputWindow.h b/Source/Core/DolphinQt/TAS/TASInputWindow.h index fb26916eb5f5..8f5cb6becbdd 100644 --- a/Source/Core/DolphinQt/TAS/TASInputWindow.h +++ b/Source/Core/DolphinQt/TAS/TASInputWindow.h @@ -67,6 +67,11 @@ class TASInputWindow : public QDialog TASSpinBox* CreateSliderValuePair(QBoxLayout* layout, int default_, int max, QKeySequence shortcut_key_sequence, Qt::Orientation orientation, QWidget* shortcut_widget); + QDoubleSpinBox* CreateWeightSliderValuePair(std::string_view group_name, + std::string_view control_name, + InputOverrider* overrider, QBoxLayout* layout, + int min, int max, QKeySequence shortcut_key_sequence, + QWidget* shortcut_widget); QDoubleSpinBox* CreateWeightSliderValuePair(QBoxLayout* layout, int min, int max, QKeySequence shortcut_key_sequence, QWidget* shortcut_widget); @@ -82,4 +87,7 @@ class TASInputWindow : public QDialog ControlState controller_state); std::optional GetSpinBox(TASSpinBox* spin, int zero, ControlState controller_state, ControlState scale); + std::optional GetSpinBox(QDoubleSpinBox* spin, ControlState controller_state); + + std::map m_spinbox_most_recent_values_double; }; diff --git a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp index 13cf9083432f..dcbe4323a031 100644 --- a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp +++ b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp @@ -120,15 +120,23 @@ WiiTASInputWindow::WiiTASInputWindow(QWidget* parent, int num) : TASInputWindow( auto* bal_top_layout = new QHBoxLayout; m_top_left_balance_value = CreateWeightSliderValuePair( - bal_top_layout, -34, 68, balance_tl_shortcut_key_sequence, m_balance_board_box); + WiimoteEmu::BalanceBoardExt::BALANCE_GROUP, WiimoteEmu::BalanceBoardExt::TOP_LEFT_SENSOR, + &m_balance_board_overrider, bal_top_layout, -34, 68, balance_tl_shortcut_key_sequence, + m_balance_board_box); m_top_right_balance_value = CreateWeightSliderValuePair( - bal_top_layout, -34, 68, balance_tr_shortcut_key_sequence, m_balance_board_box); + WiimoteEmu::BalanceBoardExt::BALANCE_GROUP, WiimoteEmu::BalanceBoardExt::TOP_RIGHT_SENSOR, + &m_balance_board_overrider, bal_top_layout, -34, 68, balance_tr_shortcut_key_sequence, + m_balance_board_box); auto* bal_bottom_layout = new QHBoxLayout; m_bottom_left_balance_value = CreateWeightSliderValuePair( - bal_bottom_layout, -34, 68, balance_bl_shortcut_key_sequence, m_balance_board_box); + WiimoteEmu::BalanceBoardExt::BALANCE_GROUP, WiimoteEmu::BalanceBoardExt::BOTTOM_LEFT_SENSOR, + &m_balance_board_overrider, bal_bottom_layout, -34, 68, balance_bl_shortcut_key_sequence, + m_balance_board_box); m_bottom_right_balance_value = CreateWeightSliderValuePair( - bal_bottom_layout, -34, 68, balance_br_shortcut_key_sequence, m_balance_board_box); + WiimoteEmu::BalanceBoardExt::BALANCE_GROUP, WiimoteEmu::BalanceBoardExt::BOTTOM_RIGHT_SENSOR, + &m_balance_board_overrider, bal_bottom_layout, -34, 68, balance_br_shortcut_key_sequence, + m_balance_board_box); auto* bal_weight_layout = new QHBoxLayout; m_total_weight_value = CreateWeightSliderValuePair( @@ -572,35 +580,6 @@ void WiiTASInputWindow::showEvent(QShowEvent* event) if (m_active_extension == WiimoteEmu::ExtensionNumber::CLASSIC) GetExtension()->SetInputOverrideFunction(m_classic_overrider.GetInputOverrideFunction()); - /* - if (rpt.HasExt() && m_balance_board_box->isVisible()) - { - using WiimoteEmu::BalanceBoard; - - u8* const ext_data = rpt.GetExtDataPtr(); - BalanceBoard::DataFormat bb_data = Common::BitCastPtr(ext_data); - - // TODO: Reading the existing values, but then just clobbering them instead of using them if - // controller input is enabled - double top_right = BalanceBoard::ConvertToKilograms(Common::swap16(bb_data.top_right)); - double bottom_right = BalanceBoard::ConvertToKilograms(Common::swap16(bb_data.bottom_right)); - double top_left = BalanceBoard::ConvertToKilograms(Common::swap16(bb_data.top_left)); - double bottom_left = BalanceBoard::ConvertToKilograms(Common::swap16(bb_data.bottom_left)); - - top_right = m_top_right_balance_value->value(); - bottom_right = m_bottom_right_balance_value->value(); - top_left = m_top_left_balance_value->value(); - bottom_left = m_bottom_left_balance_value->value(); - - bb_data.top_right = Common::swap16(BalanceBoard::ConvertToSensorWeight(top_right)); - bb_data.bottom_right = Common::swap16(BalanceBoard::ConvertToSensorWeight(bottom_right)); - bb_data.top_left = Common::swap16(BalanceBoard::ConvertToSensorWeight(top_left)); - bb_data.bottom_left = Common::swap16(BalanceBoard::ConvertToSensorWeight(bottom_left)); - bb_data.temperature = BalanceBoard::TEMPERATURE; - bb_data.battery = 0x83; - - Common::BitCastPtr(ext_data) = bb_data; - key.Encrypt(ext_data, 0, sizeof(BalanceBoard::DataFormat)); - } -*/ + if (m_active_extension == WiimoteEmu::ExtensionNumber::BALANCE_BOARD) + GetExtension()->SetInputOverrideFunction(m_balance_board_overrider.GetInputOverrideFunction()); } diff --git a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.h b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.h index 128b02fcc1c2..1c1418d8cc9f 100644 --- a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.h +++ b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.h @@ -42,6 +42,7 @@ class WiiTASInputWindow : public TASInputWindow InputOverrider m_wiimote_overrider; InputOverrider m_nunchuk_overrider; InputOverrider m_classic_overrider; + InputOverrider m_balance_board_overrider; TASCheckBox* m_a_button; TASCheckBox* m_b_button;