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);
@@ -171,6 +164,7 @@ wxBEGIN_EVENT_TABLE(EditMoveDialog, wxDialog) EVT_BUTTON(wxID_OK, EditMoveDialog
171164 if (p_infoset->IsChanceInfoset ()) {
172165 m_player->Append (_ (" Chance" ));
173166 m_player->SetSelection (0 );
167+ m_player->Disable ();
174168 }
175169 else {
176170 for (const auto &player : p_infoset->GetGame ()->GetPlayers ()) {
@@ -189,18 +183,13 @@ wxBEGIN_EVENT_TABLE(EditMoveDialog, wxDialog) EVT_BUTTON(wxID_OK, EditMoveDialog
189183 actionBoxSizer->Add (m_actionSheet, 1 , wxALL | wxEXPAND, 5 );
190184 topSizer->Add (actionBoxSizer, 0 , wxALL | wxEXPAND, 5 );
191185
192- auto *buttonSizer = new wxBoxSizer (wxHORIZONTAL);
193- buttonSizer->Add (new wxButton (this , wxID_CANCEL, _ (" Cancel" )), 0 , wxALL, 5 );
194- auto *okButton = new wxButton (this , wxID_OK, _ (" OK" ));
195- okButton->SetDefault ();
196- buttonSizer->Add (okButton, 0 , wxALL, 5 );
197- topSizer->Add (buttonSizer, 0 , wxALL | wxALIGN_RIGHT, 5 );
198-
199- SetSizer (topSizer);
200- topSizer->Fit (this );
201- topSizer->SetSizeHints (this );
202- wxTopLevelWindowBase::Layout ();
186+ if (auto *buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL)) {
187+ topSizer->Add (buttons, 0 , wxALL | wxEXPAND, 5 );
188+ }
189+ SetSizerAndFit (topSizer);
203190 CenterOnParent ();
191+
192+ Bind (wxEVT_BUTTON, &EditMoveDialog::OnOK, this , wxID_OK);
204193}
205194
206195void EditMoveDialog::OnOK (wxCommandEvent &p_event)
@@ -209,23 +198,16 @@ void EditMoveDialog::OnOK(wxCommandEvent &p_event)
209198 p_event.Skip ();
210199 return ;
211200 }
212- auto probs = m_actionSheet->GetActionProbs ();
213- if (std::any_of (probs.begin (), probs.end (),
214- [](const Number &p) { return static_cast <Rational>(p) < Rational (0 ); })) {
215- wxMessageBox (" Action probabilities must be non-negative numbers." , " Error" );
216- return ;
217- }
218- if (std::accumulate (probs.begin (), probs.end (), Rational (0 ),
219- [](const Rational &s, const Number &p) {
220- return s + static_cast <Rational>(p);
221- }) != Rational (1 )) {
222- p_event.Skip ();
201+ try {
202+ ValidateDistribution (m_actionSheet->GetActionProbs ());
223203 }
224- else {
225- 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" ,
226206 wxOK | wxCENTRE | wxICON_ERROR)
227207 .ShowModal ();
208+ return ;
228209 }
210+ p_event.Skip ();
229211}
230212
231213int EditMoveDialog::NumActions () const { return m_actionSheet->NumActions (); }
0 commit comments