1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00
- Added notifications for save and load commands
- some fixes
This commit is contained in:
lufebe16 2023-11-28 11:45:27 +01:00
parent 492acd6961
commit 2520934d35
5 changed files with 56 additions and 25 deletions

View file

@ -1455,7 +1455,7 @@ class Game(object):
c0 = cards[0] c0 = cards[0]
dx, dy = (x - c0.x), (y - c0.y) dx, dy = (x - c0.x), (y - c0.y)
base = float(self.app.opt.animations) base = float(self.app.opt.animations)
duration = base*base/40.0 + 0.05 duration = base*base/20.0 + 0.05
for card in cards: for card in cards:
card.animatedMove(dx, dy, duration) card.animatedMove(dx, dy, duration)
# self.top.waitAnimation(swallow=True, pickup=True) # self.top.waitAnimation(swallow=True, pickup=True)
@ -3267,6 +3267,7 @@ class Game(object):
def saveGame(self, filename, protocol=-1): def saveGame(self, filename, protocol=-1):
self.finishMove() # just in case self.finishMove() # just in case
self.setCursor(cursor=CURSOR_WATCH) self.setCursor(cursor=CURSOR_WATCH)
rval = False
try: try:
self._saveGame(filename, protocol) self._saveGame(filename, protocol)
except Exception as ex: except Exception as ex:
@ -3274,8 +3275,10 @@ class Game(object):
MfxExceptionDialog(self.top, ex, title=_("Save game error"), MfxExceptionDialog(self.top, ex, title=_("Save game error"),
text=_("Error while saving game")) text=_("Error while saving game"))
else: else:
rval = True
self.filename = filename self.filename = filename
self.setCursor(cursor=self.app.top_cursor) self.setCursor(cursor=self.app.top_cursor)
return rval
# #
# low level load/save # low level load/save

View file

@ -152,10 +152,10 @@ class LAnimationMgr(object):
self.animations.remove(anim) self.animations.remove(anim)
if not self.checkRunning(): if not self.checkRunning():
# print('LAnimationMgr: animEnd -> do callbacks') # print('LAnimationMgr: animEnd ->', len(self.callbacks), 'callbacks') # noqa
for cb in self.callbacks: for cb in self.callbacks:
cb() cb()
print('LAnimationMgr: animEnd -> callbacks done') # print('LAnimationMgr: animEnd -> callbacks done')
self.callbacks = [] self.callbacks = []
print('Clock.get_fps() ->', Clock.get_fps()) print('Clock.get_fps() ->', Clock.get_fps())
@ -1557,15 +1557,18 @@ class LMainWindow(BoxLayout, LTkBase):
# self.touches = [] # self.touches = []
# beispiel zu canvas (hintergrund) # beispiel zu canvas (hintergrund)
# with self.canvas.before: '''
# Color(0, 1, 0.7, 0.5) with self.canvas.before:
# self.rect = Rectangle(pos=self.pos, size=self.size) Color(0, 1, 0.7, 0.5)
# self.bind(pos=self.update_rect) self.rect = Rectangle(pos=self.pos, size=self.size)
# self.bind(size=self.update_rect) self.bind(pos=self.update_rect)
self.bind(size=self.update_rect)
# def update_rect(self, *args): '''
# self.rect.pos = self.pos '''
# self.rect.size = self.size def update_rect(self, *args):
self.rect.pos = self.pos
self.rect.size = self.size
'''
def on_motion(self, m): def on_motion(self, m):
print('on_motion', m) print('on_motion', m)
@ -1773,6 +1776,7 @@ class LApp(App):
self.baseWindow.add_widget(self.mainWindow) self.baseWindow.add_widget(self.mainWindow)
logging.info('top = %s' % str(self.mainWindow)) logging.info('top = %s' % str(self.mainWindow))
Cache.register('LAppCache', limit=10) Cache.register('LAppCache', limit=10)
Cache.append('LAppCache', 'baseWindow', self.baseWindow, timeout=0)
Cache.append('LAppCache', 'mainWindow', self.mainWindow, timeout=0) Cache.append('LAppCache', 'mainWindow', self.mainWindow, timeout=0)
Cache.append('LAppCache', 'mainApp', self, timeout=0) Cache.append('LAppCache', 'mainApp', self, timeout=0)
self.startCode = 0 self.startCode = 0

View file

@ -200,12 +200,12 @@ class LImage(Widget, LBase):
self.make_format(self.size, p) self.make_format(self.size, p)
def on_fit_mode(self, a, m): def on_fit_mode(self, a, m):
print('on_fit_mode', m) # print('on_fit_mode', m)
self.fit_num_update(self.fit_mode) self.fit_num_update(self.fit_mode)
self.make_format(self.size, self.pos) self.make_format(self.size, self.pos)
def on_texture(self, a, texture): def on_texture(self, a, texture):
print('on_texture', texture) # print('on_texture', texture)
self.tex_coord_update(self.texture) self.tex_coord_update(self.texture)
self.make_format(self.size, self.pos) self.make_format(self.size, self.pos)

View file

@ -26,6 +26,8 @@ import math
import os import os
import re import re
from kivy.cache import Cache
from kivy.clock import Clock
from kivy.event import EventDispatcher from kivy.event import EventDispatcher
from kivy.properties import BooleanProperty from kivy.properties import BooleanProperty
from kivy.properties import NumericProperty from kivy.properties import NumericProperty
@ -48,6 +50,7 @@ from pysollib.kivy.tkconst import CURSOR_WATCH, EVENT_HANDLED, EVENT_PROPAGATE
from pysollib.kivy.tkconst import TOOLBAR_BUTTONS from pysollib.kivy.tkconst import TOOLBAR_BUTTONS
from pysollib.kivy.tkutil import after_idle from pysollib.kivy.tkutil import after_idle
from pysollib.kivy.tkutil import bind from pysollib.kivy.tkutil import bind
from pysollib.kivy.toast import Toast
from pysollib.mfxutil import Struct from pysollib.mfxutil import Struct
from pysollib.mygettext import _ from pysollib.mygettext import _
from pysollib.pysoltk import MfxMessageDialog from pysollib.pysoltk import MfxMessageDialog
@ -229,6 +232,12 @@ class FileMenuDialog(LMenuDialog):
command(key) command(key)
return game_command return game_command
def make_command(self, command):
def _command():
self.closeWindow(0)
command()
return _command
def buildTree(self, tv, node): def buildTree(self, tv, node):
rg = tv.add_node( rg = tv.add_node(
LTreeNode(text=_('Recent games'))) LTreeNode(text=_('Recent games')))
@ -263,9 +272,9 @@ class FileMenuDialog(LMenuDialog):
LTreeNode(text=gi.name, command=command), rg) LTreeNode(text=gi.name, command=command), rg)
tv.add_node(LTreeNode( tv.add_node(LTreeNode(
text=_('Load'), command=self.menubar.mOpen)) text=_('Load'), command=self.make_command(self.menubar.mOpen)))
tv.add_node(LTreeNode( tv.add_node(LTreeNode(
text=_('Save'), command=self.menubar.mSaveAs)) text=_('Save'), command=self.make_command(self.menubar.mSaveAs)))
tv.add_node(LTreeNode( tv.add_node(LTreeNode(
text=_('Quit'), command=self.menubar.mHoldAndQuit)) text=_('Quit'), command=self.menubar.mHoldAndQuit))
@ -1372,6 +1381,7 @@ class PysolMenubarTk:
self.__keybindings = {} self.__keybindings = {}
self._createMenubar() self._createMenubar()
self.top = top self.top = top
self.app = app
if self.progress: if self.progress:
self.progress.update(step=1) self.progress.update(step=1)
@ -2047,9 +2057,12 @@ class PysolMenubarTk:
print('filename = %s' % filename) print('filename = %s' % filename)
if filename: if filename:
filename = os.path.normpath(filename) filename = os.path.normpath(filename)
# filename = os.path.normcase(filename)
if os.path.isfile(filename): if os.path.isfile(filename):
self.game.loadGame(filename) baseWindow = Cache.get('LAppCache', 'baseWindow')
text = _("loading game from:")+filename
toast = Toast(text=text)
toast.show(parent=baseWindow, duration=4.0)
Clock.schedule_once(lambda dt: self.game.loadGame(filename), 1.0) # noqa
def mSaveAs(self, *event): def mSaveAs(self, *event):
if self._cancelDrag(break_pause=False): if self._cancelDrag(break_pause=False):
@ -2070,16 +2083,16 @@ class PysolMenubarTk:
idir, ifile = os.path.split(os.path.normpath(filename)) idir, ifile = os.path.split(os.path.normpath(filename))
if not idir: if not idir:
idir = self.app.dn.savegames idir = self.app.dn.savegames
# print self.game.filename, ifile
# d = tkFileDialog.SaveAs()
# filename = d.show(filetypes=self.FILETYPES,
# defaultextension=self.DEFAULTEXTENSION,
# initialdir=idir, initialfile=ifile)
filename = idir + "/" + ifile filename = idir + "/" + ifile
if filename: if filename:
filename = os.path.normpath(filename) filename = os.path.normpath(filename)
# filename = os.path.normcase(filename) # filename = os.path.normcase(filename)
self.game.saveGame(filename) if self.game.saveGame(filename):
baseWindow = Cache.get('LAppCache', 'baseWindow')
text = _("game saved to:")+filename
toast = Toast(text=text)
toast.show(parent=baseWindow, duration=5.0)
self.updateMenus() self.updateMenus()
def mPause(self, *args): def mPause(self, *args):

View file

@ -163,13 +163,17 @@ class MfxCanvasGroup():
return return
imgs = self._imglist(self) imgs = self._imglist(self)
# print('number of imaages:', len(imgs)) if len(imgs) == 0:
return
if position is not None: if position is not None:
# In self.canvas suchen: das oberste image, welches zu position # In self.canvas suchen: das oberste image, welches zu position
# gehört und liste der images oberhalb einfüllen u.a.a.O weglassen. # gehört und liste der images oberhalb einfüllen u.a.a.O weglassen.
pimgs = self._imglist(position) pimgs = self._imglist(position)
if len(pimgs) == 0:
return
ws = [] ws = []
for c in reversed(self.canvas.children): for c in reversed(self.canvas.children):
if c not in imgs: if c not in imgs:
@ -207,8 +211,14 @@ class MfxCanvasGroup():
return return
imgs = self._imglist(self) imgs = self._imglist(self)
if len(imgs) == 0:
return
if position is not None: if position is not None:
pimgs = self._imglist(position) pimgs = self._imglist(position)
if len(pimgs) == 0:
return
ws = [] ws = []
for c in reversed(self.canvas.children): for c in reversed(self.canvas.children):
if c == pimgs[0]: if c == pimgs[0]:
@ -663,6 +673,7 @@ class MfxCanvas(LImage):
self.update_widget(posorobj, size) self.update_widget(posorobj, size)
def update_widget(self, posorobj, size): def update_widget(self, posorobj, size):
logging.info('MfxCanvas: update_widget')
# print('MfxCanvas: update_widget size=(%s, %s)' % # print('MfxCanvas: update_widget size=(%s, %s)' %
# (self.size[0], self.size[1])) # (self.size[0], self.size[1]))