diff --git a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp index ae52c7dbf1..a8be1b56a4 100644 --- a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp @@ -239,10 +239,7 @@ void GamepadPage::UpdateGUI() std::vector::const_iterator i = (*g)->control_buttons.begin() , e = (*g)->control_buttons.end(); for (; i!=e; ++i) - //if (std::string::npos == (*i)->control_reference->expression.find_first_of("`|&!#")) - (*i)->SetLabel(StrToWxStr((*i)->control_reference->expression)); - //else - //(*i)->SetLabel(wxT("...")); + (*i)->SetLabel(StrToWxStr((*i)->control_reference->expression)); // cboxes std::vector::const_iterator si = (*g)->options.begin() @@ -323,23 +320,45 @@ void ControlDialog::ClearControl(wxCommandEvent&) UpdateGUI(); } -void ControlDialog::SetSelectedControl(wxCommandEvent&) +inline bool IsAlphabetic(wxString &str) +{ + for (wxString::const_iterator it = str.begin(); it != str.end(); ++it) + if (!isalpha(*it)) + return false; + return true; +} + +bool ControlDialog::GetExpressionForSelectedControl(wxString &expr) { const int num = control_lbox->GetSelection(); if (num < 0) - return; + return false; - wxString expr; + expr = ""; // non-default device - if (false == (m_devq == m_parent->controller->default_device)) - expr.append(wxT('`')).append(StrToWxStr(m_devq.ToString())).append(wxT('`')); + if (!(m_devq == m_parent->controller->default_device)) + expr += m_devq.ToString(); // append the control name expr += control_lbox->GetString(num); - control_reference->expression = WxStrToStr(expr); + if (!IsAlphabetic(expr)) + expr = wxString::Format("`%s`", expr); + + return true; +} + +void ControlDialog::SetSelectedControl(wxCommandEvent&) +{ + wxString expr; + + if (!GetExpressionForSelectedControl(expr)) + return; + + textctrl->WriteText(expr); + control_reference->expression = textctrl->GetValue(); std::lock_guard lk(m_plugin.controls_lock); g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device); @@ -349,28 +368,30 @@ void ControlDialog::SetSelectedControl(wxCommandEvent&) void ControlDialog::AppendControl(wxCommandEvent& event) { - const int num = control_lbox->GetSelection(); + wxString device_expr, expr; - if (num < 0) + const wxString lbl = ((wxButton*)event.GetEventObject())->GetLabel(); + char op = lbl[0]; + + if (!GetExpressionForSelectedControl(device_expr)) return; - // o boy!, hax - const wxString lbl = ((wxButton*)event.GetEventObject())->GetLabel(); + // Unary ops (that is, '!') are a special case. When there's a selection, + // put parens around it and prepend it with a '!', but when there's nothing, + // just add a '!device'. + if (op == '!') + { + wxString selection = textctrl->GetStringSelection(); + if (selection == "") + expr = wxString::Format("%c%s", op, device_expr); + else + expr = wxString::Format("%c(%s)", op, selection); + } + else + expr = wxString::Format(" %c %s", op, device_expr); - wxString expr = textctrl->GetValue(); - - // append the operator to the expression - if (wxT('!') == lbl[0] || false == expr.empty()) - expr += lbl[0]; - - // non-default device - if (false == (m_devq == m_parent->controller->default_device)) - expr.append(wxT('`')).append(StrToWxStr(m_devq.ToString())).append(wxT('`')); - - // append the control name - expr += control_lbox->GetString(num); - - control_reference->expression = WxStrToStr(expr); + textctrl->WriteText(expr); + control_reference->expression = textctrl->GetValue(); std::lock_guard lk(m_plugin.controls_lock); g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device); @@ -478,6 +499,9 @@ wxStaticBoxSizer* ControlDialog::CreateControlChooser(GamepadPage* const parent) wxButton* const select_button = new wxButton(this, -1, _("Select")); select_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::SetSelectedControl, this); + wxButton* const not_button = new wxButton(this, -1, _("! NOT"), wxDefaultPosition); + not_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this); + wxButton* const or_button = new wxButton(this, -1, _("| OR"), wxDefaultPosition); or_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this); @@ -492,11 +516,9 @@ wxStaticBoxSizer* ControlDialog::CreateControlChooser(GamepadPage* const parent) { // TODO: check if && is good on other OS wxButton* const and_button = new wxButton(this, -1, _("&& AND"), wxDefaultPosition); - wxButton* const not_button = new wxButton(this, -1, _("! NOT"), wxDefaultPosition); - wxButton* const add_button = new wxButton(this, -1, _("^ ADD"), wxDefaultPosition); + wxButton* const add_button = new wxButton(this, -1, _("+ ADD"), wxDefaultPosition); and_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this); - not_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this); add_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this); button_sizer->Add(and_button, 1, 0, 5); diff --git a/Source/Core/DolphinWX/Src/InputConfigDiag.h b/Source/Core/DolphinWX/Src/InputConfigDiag.h index a11cea2cb3..475fa9ed5e 100644 --- a/Source/Core/DolphinWX/Src/InputConfigDiag.h +++ b/Source/Core/DolphinWX/Src/InputConfigDiag.h @@ -113,6 +113,7 @@ private: GamepadPage* const m_parent; wxStaticText* m_bound_label; DeviceQualifier m_devq; + bool GetExpressionForSelectedControl(wxString &expr); }; class ExtensionButton : public wxButton