3232#include " renratio.h"
3333
3434namespace Gambit ::GUI {
35+
3536class ActionSheet final : public wxSheet {
36- GameInfoset m_infoset;
37+ GameInfoset m_infoset{nullptr };
38+ wxSheetCellAttr m_labelAttr;
39+ wxFont m_labelFont, m_cellFont;
3740
3841 // Overriding wxSheet members
3942 wxSheetCellAttr GetAttr (const wxSheetCoords &p_coords, wxSheetAttr_Type) const override ;
@@ -48,8 +51,17 @@ class ActionSheet final : public wxSheet {
4851};
4952
5053ActionSheet::ActionSheet (wxWindow *p_parent, const GameInfoset &p_infoset)
51- : wxSheet(p_parent, wxID_ANY), m_infoset(p_infoset)
54+ : wxSheet(p_parent, wxID_ANY), m_infoset(p_infoset), m_labelFont(GetFont()),
55+ m_cellFont (GetFont())
5256{
57+ m_labelFont.MakeBold ();
58+
59+ m_labelAttr = GetSheetRefData ()->m_defaultRowLabelAttr ;
60+ m_labelAttr.SetFont (m_labelFont);
61+ m_labelAttr.SetAlignment (wxALIGN_CENTER, wxALIGN_CENTER);
62+ m_labelAttr.SetOrientation (wxHORIZONTAL);
63+ m_labelAttr.SetReadOnly (true );
64+
5365 CreateGrid (p_infoset->GetActions ().size (), (p_infoset->IsChanceInfoset ()) ? 2 : 1 );
5466 SetRowLabelWidth (40 );
5567 SetColLabelHeight (25 );
@@ -103,29 +115,12 @@ Array<Number> ActionSheet::GetActionProbs()
103115
104116wxSheetCellAttr ActionSheet::GetAttr (const wxSheetCoords &p_coords, wxSheetAttr_Type) const
105117{
106- if (IsRowLabelCell (p_coords)) {
107- wxSheetCellAttr attr (GetSheetRefData ()->m_defaultRowLabelAttr );
108- attr.SetFont (wxFont (10 , wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
109- attr.SetAlignment (wxALIGN_CENTER, wxALIGN_CENTER);
110- attr.SetOrientation (wxHORIZONTAL);
111- attr.SetReadOnly (true );
112- return attr;
113- }
114- else if (IsColLabelCell (p_coords)) {
115- wxSheetCellAttr attr (GetSheetRefData ()->m_defaultColLabelAttr );
116- attr.SetFont (wxFont (10 , wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
117- attr.SetAlignment (wxALIGN_CENTER, wxALIGN_CENTER);
118- attr.SetOrientation (wxHORIZONTAL);
119- attr.SetReadOnly (true );
120- return attr;
121- }
122- else if (IsCornerLabelCell (p_coords)) {
123- const wxSheetCellAttr attr (GetSheetRefData ()->m_defaultCornerLabelAttr );
124- return attr;
118+ if (IsLabelCell (p_coords)) {
119+ return m_labelAttr;
125120 }
126121
127122 wxSheetCellAttr attr (GetSheetRefData ()->m_defaultGridCellAttr );
128- attr.SetFont (wxFont ( 10 , wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL) );
123+ attr.SetFont (m_cellFont );
129124 attr.SetAlignment (wxALIGN_CENTER, wxALIGN_CENTER);
130125 attr.SetOrientation (wxHORIZONTAL);
131126 attr.SetReadOnly (false );
@@ -143,9 +138,7 @@ wxSheetCellAttr ActionSheet::GetAttr(const wxSheetCoords &p_coords, wxSheetAttr_
143138// class EditMoveDialog
144139// ======================================================================
145140
146- wxBEGIN_EVENT_TABLE (EditMoveDialog, wxDialog) EVT_BUTTON(wxID_OK, EditMoveDialog::OnOK)
147- wxEND_EVENT_TABLE () EditMoveDialog::EditMoveDialog(wxWindow *p_parent,
148- const GameInfoset &p_infoset)
141+ EditMoveDialog::EditMoveDialog (wxWindow *p_parent, const GameInfoset &p_infoset)
149142 : wxDialog(p_parent, wxID_ANY, _(" Move properties" ), wxDefaultPosition), m_infoset(p_infoset)
150143{
151144 auto *topSizer = new wxBoxSizer (wxVERTICAL);
@@ -158,10 +151,11 @@ wxBEGIN_EVENT_TABLE(EditMoveDialog, wxDialog) EVT_BUTTON(wxID_OK, EditMoveDialog
158151 labelSizer->Add (m_infosetName, 1 , wxALL | wxEXPAND, 5 );
159152 topSizer->Add (labelSizer, 0 , wxALL | wxEXPAND, 0 );
160153
161- topSizer->Add (new wxStaticText (
162- this , wxID_STATIC,
163- wxString::Format (_ (" Number of members: %d" ), p_infoset->GetMembers ().size ())),
164- 0 , wxALL | wxALIGN_CENTER, 5 );
154+ {
155+ wxString label;
156+ label << _ (" Number of members: " ) << p_infoset->GetMembers ().size ();
157+ topSizer->Add (new wxStaticText (this , wxID_STATIC, label), 0 , wxALL | wxALIGN_CENTER, 5 );
158+ }
165159
166160 auto *playerSizer = new wxBoxSizer (wxHORIZONTAL);
167161 playerSizer->Add (new wxStaticText (this , wxID_STATIC, _ (" Belongs to player" )), 0 ,
@@ -170,11 +164,13 @@ wxBEGIN_EVENT_TABLE(EditMoveDialog, wxDialog) EVT_BUTTON(wxID_OK, EditMoveDialog
170164 if (p_infoset->IsChanceInfoset ()) {
171165 m_player->Append (_ (" Chance" ));
172166 m_player->SetSelection (0 );
167+ m_player->Disable ();
173168 }
174169 else {
175170 for (const auto &player : p_infoset->GetGame ()->GetPlayers ()) {
176- m_player->Append (wxString::Format (_T (" %d: " ), player->GetNumber ()) +
177- wxString (player->GetLabel ().c_str (), *wxConvCurrent));
171+ wxString label;
172+ label << player->GetNumber () << " : " << player->GetLabel ();
173+ m_player->Append (label);
178174 }
179175 m_player->SetSelection (p_infoset->GetPlayer ()->GetNumber () - 1 );
180176 }
@@ -187,18 +183,13 @@ wxBEGIN_EVENT_TABLE(EditMoveDialog, wxDialog) EVT_BUTTON(wxID_OK, EditMoveDialog
187183 actionBoxSizer->Add (m_actionSheet, 1 , wxALL | wxEXPAND, 5 );
188184 topSizer->Add (actionBoxSizer, 0 , wxALL | wxEXPAND, 5 );
189185
190- auto *buttonSizer = new wxBoxSizer (wxHORIZONTAL);
191- buttonSizer->Add (new wxButton (this , wxID_CANCEL, _ (" Cancel" )), 0 , wxALL, 5 );
192- auto *okButton = new wxButton (this , wxID_OK, _ (" OK" ));
193- okButton->SetDefault ();
194- buttonSizer->Add (okButton, 0 , wxALL, 5 );
195- topSizer->Add (buttonSizer, 0 , wxALL | wxALIGN_RIGHT, 5 );
196-
197- SetSizer (topSizer);
198- topSizer->Fit (this );
199- topSizer->SetSizeHints (this );
200- wxTopLevelWindowBase::Layout ();
186+ if (auto *buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL)) {
187+ topSizer->Add (buttons, 0 , wxALL | wxEXPAND, 5 );
188+ }
189+ SetSizerAndFit (topSizer);
201190 CenterOnParent ();
191+
192+ Bind (wxEVT_BUTTON, &EditMoveDialog::OnOK, this , wxID_OK);
202193}
203194
204195void EditMoveDialog::OnOK (wxCommandEvent &p_event)
@@ -207,23 +198,16 @@ void EditMoveDialog::OnOK(wxCommandEvent &p_event)
207198 p_event.Skip ();
208199 return ;
209200 }
210- auto probs = m_actionSheet->GetActionProbs ();
211- if (std::any_of (probs.begin (), probs.end (),
212- [](const Number &p) { return static_cast <Rational>(p) < Rational (0 ); })) {
213- wxMessageBox (" Action probabilities must be non-negative numbers." , " Error" );
214- return ;
215- }
216- if (std::accumulate (probs.begin (), probs.end (), Rational (0 ),
217- [](const Rational &s, const Number &p) {
218- return s + static_cast <Rational>(p);
219- }) != Rational (1 )) {
220- p_event.Skip ();
201+ try {
202+ ValidateDistribution (m_actionSheet->GetActionProbs ());
221203 }
222- else {
223- wxRichMessageDialog (this , " Action probabilities must sum to exactly one" , " Error" ,
204+ catch (ValueException &) {
205+ wxRichMessageDialog (this , " Probabilities must be nonnegative numbers summing to one. " , " Error" ,
224206 wxOK | wxCENTRE | wxICON_ERROR)
225207 .ShowModal ();
208+ return ;
226209 }
210+ p_event.Skip ();
227211}
228212
229213int EditMoveDialog::NumActions () const { return m_actionSheet->NumActions (); }
0 commit comments