mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
InputConfigDiag: Update for the new expression language
Modify the buttons and editor interface for the new expression language, like the new op name for add, the new device name syntax, and add new editing features, like simple selection behavior on unary ops.
This commit is contained in:
parent
a42388d061
commit
03a835ec07
@ -239,10 +239,7 @@ void GamepadPage::UpdateGUI()
|
||||
std::vector<ControlButton*>::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<PadSetting*>::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<std::recursive_mutex> 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<std::recursive_mutex> 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);
|
||||
|
@ -113,6 +113,7 @@ private:
|
||||
GamepadPage* const m_parent;
|
||||
wxStaticText* m_bound_label;
|
||||
DeviceQualifier m_devq;
|
||||
bool GetExpressionForSelectedControl(wxString &expr);
|
||||
};
|
||||
|
||||
class ExtensionButton : public wxButton
|
||||
|
Loading…
Reference in New Issue
Block a user