Skip to content

Commit

Permalink
Add initial dialog for editing difficulty name
Browse files Browse the repository at this point in the history
Dialog appears on clicking the Edit button alongside the difficulty names
dropdown, and contains a simple text entry box initialised with the current
name which the user can edit. However, the changed name is not yet applied to
the map settings.
  • Loading branch information
Matthew Mott committed Mar 24, 2020
1 parent 6b02dc4 commit 70dc070
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions plugins/dm.difficulty/DifficultyDialog.cpp
Expand Up @@ -61,6 +61,37 @@ void DifficultyDialog::createDifficultyEditors()
}
}

namespace
{
// Simple dialog for editing a difficulty setting name
class EditNameDialog: public wxDialog
{
public:
EditNameDialog(wxWindow* parent, const wxString& initialText)
: wxDialog(parent, wxID_ANY, _("Difficulty name"))
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);

// Add the edit text box
wxTextCtrl* textBox = new wxTextCtrl(this, wxID_ANY, initialText);
mainSizer->Add(textBox, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 12);
mainSizer->AddSpacer(6);

// Add the buttons
wxSizer* buttons = CreateButtonSizer(wxOK | wxCANCEL);
mainSizer->Add(buttons, 0, wxEXPAND | wxBOTTOM, 12);

SetSizer(mainSizer);
Fit();

// Start with the text selected and focussed to save an extra mouse
// click
textBox->SelectAll();
textBox->SetFocus();
}
};
}

void DifficultyDialog::populateWindow()
{
SetSizer(new wxBoxSizer(wxVERTICAL));
Expand All @@ -75,6 +106,8 @@ void DifficultyDialog::populateWindow()
_notebook, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxBU_EXACTFIT | wxBU_NOTEXT
);
editBtn->Bind(wxEVT_BUTTON,
[&] (wxCommandEvent&) { editCurrentDifficultyName(); });
editBtn->SetBitmap(wxArtProvider::GetBitmap("darkradiant:edit.png"));
choiceSizer->Add(editBtn, 0, wxEXPAND);

Expand All @@ -100,6 +133,18 @@ void DifficultyDialog::populateWindow()
Fit();
}

void DifficultyDialog::editCurrentDifficultyName()
{
// Initialise an EditNameDialog with the current tab text as the initial
// name to edit
EditNameDialog dialog(this,
_notebook->GetPageText(_notebook->GetSelection()));
if (dialog.ShowModal() == wxID_OK)
{
// OK, change the difficulty name
}
}

void DifficultyDialog::save()
{
// Consistency check can go here
Expand Down
1 change: 1 addition & 0 deletions plugins/dm.difficulty/DifficultyDialog.h
Expand Up @@ -50,6 +50,7 @@ class DifficultyDialog :
void populateWindow(); // Main window
void createDifficultyEditors();

void editCurrentDifficultyName();
}; // class DifficultyDialog

} // namespace ui

0 comments on commit 70dc070

Please sign in to comment.