Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
they do not require it. (#80)
- Clarified handling of .efg/.nfg/.gbt file types in graphical interface and refined warnings about
unsaved work. (#12)
- Created and documented right-click context menu in the normal form pivot table, which makes the
mechanism for deleting a strategy more clear. (#855)

### Removed
- Built-in plotting of logit QRE for strategic games has been removed in the GUI (#809)
Expand Down
11 changes: 8 additions & 3 deletions doc/gui.nfg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ presents such games by hierarchially listing the strategies of one or
more players on both rows and columns.

The hierarchical presentation of the table is similar to that of a
contingency table in a spreadsheet application.
pivot table.
Here, Alice,
shown in red, has her strategies listed on the rows of the table, and
Bob, shown in blue, has his strategies listed on the columns of the
Expand Down Expand Up @@ -109,8 +109,8 @@ common convention in print.



Adding players and strategies
-----------------------------
Changing players and strategies
-------------------------------

To add an additional player to the game, use the menu item
:menuselection:`Edit --> Add player`,
Expand All @@ -125,6 +125,11 @@ To edit the names of strategies, click on any cell in the strategic
game table where the strategy label appears, and edit the label using
the edit control.

Right-clicking a strategy label creates a popup context menu.
This menu offers the ability to delete the selected strategy
from the game. It is not possible to delete a player's only strategy.




Editing payoffs
Expand Down
46 changes: 44 additions & 2 deletions src/gui/nfgtable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,21 @@ void RowPlayerWidget::OnCellRightClick(wxSheetEvent &p_event)
}

const wxSheetCoords coords = p_event.GetCoords();
m_table->DeleteRowHeaderStrategy(coords.GetCol(), coords.GetRow());
if (IsLabelCell(coords)) {
p_event.Skip();
return;
}

wxMenu menu;
wxMenuItem *deleteItem = menu.Append(wxID_DELETE, _("Delete strategy"));
deleteItem->Enable(m_table->CanDeleteRowHeaderStrategy(coords.GetCol(), coords.GetRow()));
menu.Bind(
wxEVT_MENU,
[this, coords](wxCommandEvent &) {
m_table->DeleteRowHeaderStrategy(coords.GetCol(), coords.GetRow());
},
wxID_DELETE);
PopupMenu(&menu);
}

wxString RowPlayerWidget::GetCellValue(const wxSheetCoords &p_coords)
Expand Down Expand Up @@ -405,7 +419,23 @@ void ColPlayerWidget::OnCellRightClick(wxSheetEvent &p_event)
}

const wxSheetCoords coords = p_event.GetCoords();
m_table->DeleteColHeaderStrategy(coords.GetRow(), coords.GetCol());
if (IsLabelCell(coords)) {
p_event.Skip();
return;
}

wxMenu menu;
wxMenuItem *deleteItem = menu.Append(wxID_DELETE, _("Delete strategy"));
deleteItem->Enable(m_table->CanDeleteColHeaderStrategy(coords.GetRow(), coords.GetCol()));

menu.Bind(
wxEVT_MENU,
[this, coords](wxCommandEvent &) {
m_table->DeleteColHeaderStrategy(coords.GetRow(), coords.GetCol());
},
wxID_DELETE);

PopupMenu(&menu);
}

void ColPlayerWidget::OnUpdate()
Expand Down Expand Up @@ -1266,4 +1296,16 @@ GameStrategy TableWidget::GetStrategyByPlayerAndIndex(int player, int strategy)
return *std::next(strategies.begin(), strategy - 1);
}

bool TableWidget::CanDeleteRowHeaderStrategy(int headerCol, int) const
{
const int player = GetRowHeaderPlayer(headerCol);
return GetSupport().GetStrategies(GetSupport().GetGame()->GetPlayer(player)).size() > 1;
}

bool TableWidget::CanDeleteColHeaderStrategy(int headerRow, int) const
{
const int player = GetColHeaderPlayer(headerRow);
return GetSupport().GetStrategies(GetSupport().GetGame()->GetPlayer(player)).size() > 1;
}

} // namespace Gambit::GUI
4 changes: 4 additions & 0 deletions src/gui/nfgtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,12 @@ class TableWidget final : public wxPanel {
void RenderGame(wxDC &p_dc, int marginX, int marginY);
void RenameRowHeaderStrategy(int headerCol, int headerRow, const wxString &value);
void RenameColHeaderStrategy(int headerRow, int headerCol, const wxString &value);

bool CanDeleteRowHeaderStrategy(int headerCol, int headerRow) const;
bool CanDeleteColHeaderStrategy(int headerRow, int headerCol) const;
void DeleteRowHeaderStrategy(int headerCol, int headerRow);
void DeleteColHeaderStrategy(int headerRow, int headerCol);

void SetPayoffCellValue(const wxSheetCoords &coords, const wxString &value);
//@}
};
Expand Down
Loading