mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Improvements to random logic to prevent choosing an option where there are no possible games.
This commit is contained in:
parent
ef404e3fc1
commit
4f2f874d26
8 changed files with 49 additions and 6 deletions
|
@ -4669,6 +4669,9 @@ msgstr "Zu&fallsspiel auswählen"
|
|||
msgid "&All games"
|
||||
msgstr "&Alle Spiele"
|
||||
|
||||
msgid "&Games played"
|
||||
msgstr "&Gespielte Spiele"
|
||||
|
||||
#: pysollib/ui/tktile/menubar.py:309
|
||||
msgid "Games played and &won"
|
||||
msgstr "Gespielt: ge&wonnen/verloren"
|
||||
|
|
|
@ -4721,6 +4721,9 @@ msgstr "Jeu au hasa&rd"
|
|||
msgid "&All games"
|
||||
msgstr "&Tous les jeux"
|
||||
|
||||
msgid "&Games played"
|
||||
msgstr "J&eux joués"
|
||||
|
||||
#: pysollib/ui/tktile/menubar.py:309
|
||||
msgid "Games played and &won"
|
||||
msgstr "Jeux finis et &gagnés"
|
||||
|
|
|
@ -4786,6 +4786,9 @@ msgstr "Un gioco a &caso"
|
|||
msgid "&All games"
|
||||
msgstr "&Tutti i giochi"
|
||||
|
||||
msgid "&Games played"
|
||||
msgstr "&Giocati"
|
||||
|
||||
#: pysollib/ui/tktile/menubar.py:309
|
||||
msgid "Games played and &won"
|
||||
msgstr "Giocati e &vinti"
|
||||
|
|
|
@ -4844,6 +4844,9 @@ msgstr "Wybie&rz grę losowo"
|
|||
msgid "&All games"
|
||||
msgstr "Wszystkie gry"
|
||||
|
||||
msgid "&Games played"
|
||||
msgstr "&Gry rozegrane"
|
||||
|
||||
#: pysollib/ui/tktile/menubar.py:309
|
||||
msgid "Games played and &won"
|
||||
msgstr "Gry rozegrane i &wygrane"
|
||||
|
|
|
@ -4476,6 +4476,9 @@ msgstr ""
|
|||
msgid "&All games"
|
||||
msgstr ""
|
||||
|
||||
msgid "&Games played"
|
||||
msgstr ""
|
||||
|
||||
#: pysollib/ui/tktile/menubar.py:309
|
||||
msgid "Games played and &won"
|
||||
msgstr ""
|
||||
|
|
|
@ -4810,6 +4810,9 @@ msgstr "С&лучайная игра"
|
|||
msgid "&All games"
|
||||
msgstr "&Все игры"
|
||||
|
||||
msgid "&Games played"
|
||||
msgstr "&Играли игры"
|
||||
|
||||
#: pysollib/ui/tktile/menubar.py:309
|
||||
msgid "Games played and &won"
|
||||
msgstr "&Выигранные игры"
|
||||
|
|
|
@ -65,6 +65,10 @@ class PysolMenubar(PysolMenubarTk):
|
|||
save=0,
|
||||
save_as=0,
|
||||
hold_and_quit=0,
|
||||
rndplayed=0,
|
||||
rndwon=0,
|
||||
rndnotwon=0,
|
||||
rndnotplayed=0,
|
||||
undo=0,
|
||||
redo=0,
|
||||
restart=0,
|
||||
|
@ -123,6 +127,10 @@ class PysolMenubar(PysolMenubarTk):
|
|||
opt = self.app.opt
|
||||
ms = self.menustate
|
||||
# 0 = DISABLED, 1 = ENABLED
|
||||
ms.rndplayed = len(self._mGetPossibleRandomGames("played")) > 0
|
||||
ms.rndwon = len(self._mGetPossibleRandomGames("won")) > 0
|
||||
ms.rndnotwon = len(self._mGetPossibleRandomGames("not won")) > 0
|
||||
ms.rndnotplayed = len(self._mGetPossibleRandomGames("not played")) > 0
|
||||
ms.save_as = game.canSaveGame()
|
||||
ms.hold_and_quit = ms.save_as
|
||||
if game.filename and ms.save_as:
|
||||
|
@ -174,6 +182,12 @@ class PysolMenubar(PysolMenubarTk):
|
|||
# File menu
|
||||
self.setMenuState(ms.save, "file.save")
|
||||
self.setMenuState(ms.save_as, "file.saveas")
|
||||
self.setMenuState(ms.rndplayed, "file.selectrandomgame.gamesplayed")
|
||||
self.setMenuState(ms.rndwon, "file.selectrandomgame.gamesplayedandwon")
|
||||
self.setMenuState(ms.rndnotwon,
|
||||
"file.selectrandomgame.gamesplayedandnotwon")
|
||||
self.setMenuState(ms.rndnotplayed,
|
||||
"file.selectrandomgame.gamesnotplayed")
|
||||
self.setMenuState(ms.hold_and_quit, "file.holdandquit")
|
||||
# Edit menu
|
||||
self.setMenuState(ms.undo, "edit.undo")
|
||||
|
@ -325,6 +339,14 @@ class PysolMenubar(PysolMenubarTk):
|
|||
if not self.game.areYouSure(_("Select random game")):
|
||||
return
|
||||
game_id = None
|
||||
games = self._mGetPossibleRandomGames(type)
|
||||
if games:
|
||||
game_id = self.app.chooseRandomOutOfGames(games)
|
||||
if game_id and game_id != self.game.id:
|
||||
self.game.endGame()
|
||||
self.game.quitGame(game_id)
|
||||
|
||||
def _mGetPossibleRandomGames(self, type='all'):
|
||||
games = []
|
||||
for g in self.app.gdb.getGamesIdSortedById():
|
||||
gi = self.app.getGameInfo(g)
|
||||
|
@ -337,17 +359,15 @@ class PysolMenubar(PysolMenubarTk):
|
|||
won, lost = self.app.stats.getStats(self.app.opt.player, gi.id)
|
||||
if type == 'all':
|
||||
games.append(gi.id)
|
||||
elif type == 'played' and won + lost > 0:
|
||||
games.append(gi.id)
|
||||
elif type == 'won' and won > 0:
|
||||
games.append(gi.id)
|
||||
elif type == 'not won' and won == 0 and lost > 0:
|
||||
games.append(gi.id)
|
||||
elif type == 'not played' and won+lost == 0:
|
||||
elif type == 'not played' and won + lost == 0:
|
||||
games.append(gi.id)
|
||||
if games:
|
||||
game_id = self.app.chooseRandomOutOfGames(games)
|
||||
if game_id and game_id != self.game.id:
|
||||
self.game.endGame()
|
||||
self.game.quitGame(game_id)
|
||||
return games
|
||||
|
||||
def _mSelectNextGameFromList(self, gl, step):
|
||||
if self._cancelDrag():
|
||||
|
@ -747,6 +767,7 @@ class PysolMenubar(PysolMenubarTk):
|
|||
self.game.updateStatus(player=self.app.opt.player)
|
||||
self.game.updateStatus(stats=self.app.stats.getStats(
|
||||
self.app.opt.player, self.game.id))
|
||||
self.updateMenus()
|
||||
|
||||
def mOptColors(self, *args):
|
||||
if self._cancelDrag(break_pause=False):
|
||||
|
|
|
@ -383,6 +383,10 @@ class PysolMenubarTkCommon:
|
|||
submenu.add_command(
|
||||
label=n_("&All games"), command=lambda:
|
||||
self.mSelectRandomGame('all'), accelerator=m+"R")
|
||||
submenu.add_separator()
|
||||
submenu.add_command(
|
||||
label=n_("&Games played"),
|
||||
command=lambda: self.mSelectRandomGame('played'))
|
||||
submenu.add_command(
|
||||
label=n_("Games played and &won"),
|
||||
command=lambda: self.mSelectRandomGame('won'))
|
||||
|
|
Loading…
Add table
Reference in a new issue