def __init__(self): Struct.__init__( self, # line[0] version=1, ext=".gif", type=CSI.TYPE_FRENCH, ncards=-1, styles=[], year=0, # line[1] ident="", name="", # line[2] CARDW=0, CARDH=0, CARDD=0, # line[3] CARD_XOFFSET=0, CARD_YOFFSET=0, SHADOW_XOFFSET=0, SHADOW_YOFFSET=0, # line[4] backindex=0, # line[5] backnames=(), # other CARD_DX=0, # relative pos of real card image within Card CARD_DY=0, )
def update(self, gameid, value, game_number, game_start_time): # update min & max if not self.min or value < self.min: self.min = value if not self.max or value > self.max: self.max = value # calculate position & update top position = None n = 0 for i in self.top: if value < i.value: position = n + 1 v = Struct(gameid=gameid, value=value, game_number=game_number, game_start_time=game_start_time) self.top.insert(n, v) del self.top[TOP_SIZE:] break n += 1 if not position and len(self.top) < TOP_SIZE: v = Struct(gameid=gameid, value=value, game_number=game_number, game_start_time=game_start_time) self.top.append(v) position = len(self.top) # update average self.total += value self.num += 1 self.average = float(self.total) / self.num return position
def playeroptionsdialog_main(args): from pysollib.ui.tktile.tkutil import wm_withdraw opt = Struct(player="Test", update_player_stats=1) app = Struct(opt=opt) tk = tkinter.Tk() wm_withdraw(tk) tk.update() d = PlayerOptionsDialog(tk, "Player options", app) print(d.status, d.button, ":", d.player, d.update_stats) return 0
def __init__(self, **kw): kw = KwStruct(kw, name = "", filename = "", basename = "", # basename of filename absname = "", # absolute filename # implicit index = -1, error = 0, # error while loading this resource ) Struct.__init__(self, **kw.getKw())
def __init__(self, **kw): kw = KwStruct( kw, name="", filename="", basename="", # basename of filename absname="", # absolute filename # implicit index=-1, error=0, # error while loading this resource ) Struct.__init__(self, **kw.getKw())
def __init__(self, parent, app=None, home=None): self.parent = parent self.app = app self.home = home self.url = None self.history = Struct( list = [], index = 0, ) self.visited_urls = [] self.images = {} # need to keep a reference because of garbage collection self.defcursor = parent["cursor"] ##self.defcursor = 'xterm' self.handcursor = "hand2" # create buttons button_width = 8 self.homeButton = Tkinter.Button(parent, text=_("Index"), width=button_width, command=self.goHome) self.homeButton.grid(row=0, column=0, sticky='w') self.backButton = Tkinter.Button(parent, text=_("Back"), width=button_width, command=self.goBack) self.backButton.grid(row=0, column=1, sticky='w') self.forwardButton = Tkinter.Button(parent, text=_("Forward"), width=button_width, command=self.goForward) self.forwardButton.grid(row=0, column=2, sticky='w') self.closeButton = Tkinter.Button(parent, text=_("Close"), width=button_width, command=self.destroy) self.closeButton.grid(row=0, column=3, sticky='e') # create text widget text_frame = Tkinter.Frame(parent) text_frame.grid(row=1, column=0, columnspan=4, sticky='nsew') text_frame.grid_propagate(False) vbar = Tkinter.Scrollbar(text_frame) vbar.pack(side='right', fill='y') self.text = Tkinter.Text(text_frame, fg='black', bg='white', bd=1, relief='sunken', cursor=self.defcursor, wrap='word', padx=10) self.text.pack(side='left', fill='both', expand=True) self.text["yscrollcommand"] = vbar.set vbar["command"] = self.text.yview # statusbar self.statusbar = HtmlStatusbar(parent, row=2, column=0, columnspan=4) parent.columnconfigure(2, weight=1) parent.rowconfigure(1, weight=1) # load images for name, fn in self.symbols_fn.items(): self.symbols_img[name] = self.getImage(fn) self.initBindings()
def __init__(self, app, top, progress=None): self.app = app self.top = top self.game = None # enabled/disabled - this is set by updateMenuState() self.menustate = Struct( save=0, save_as=0, hold_and_quit=0, undo=0, redo=0, restart=0, deal=0, hint=0, autofaceup=0, autodrop=0, shuffle=0, autodeal=0, quickplay=0, demo=0, highlight_piles=0, find_card=0, rules=0, pause=0, custom_game=0, ) PysolMenubarTk.__init__(self, app, top, progress)
def __init__(self, game, card_x_space=None, card_y_space=None, **kw): self.game = game self.canvas = self.game.canvas self.size = None self.s = Struct( talon=None, waste=None, foundations=[], rows=[], reserves=[], ) self.stackmap = {} self.regions = [] # set visual constants images = self.game.app.images layout_x_margin = images.CARDW // 9 layout_y_margin = layout_x_margin layout_card_x_space = images.CARDW // 9 layout_card_y_space = images.CARDH // 8 self.CW = images.CARDW self.CH = images.CARDH self.XOFFSET = images.CARD_XOFFSET self.YOFFSET = images.CARD_YOFFSET self.XM = layout_x_margin # XMARGIN self.YM = layout_y_margin # YMARGIN if card_x_space is None: self.XS = self.CW + layout_card_x_space # XSPACE else: self.XS = self.CW + card_x_space if card_y_space is None: self.YS = self.CH + layout_card_y_space # YSPACE else: self.YS = self.CH + card_y_space # self.CARD_X_SPACE = layout_card_x_space # self.CARD_Y_SPACE = layout_card_y_space # self.RIGHT_MARGIN = layout_x_margin-layout_card_x_space # self.BOTTOM_MARGIN = layout_y_margin-layout_card_y_space font = game.app.getFont("canvas_default") # self.TEXT_MARGIN = 10 self.TEXT_MARGIN = font[1] # self.TEXT_HEIGHT = 30 self.TEXT_HEIGHT = 18 + font[1] self.__dict__.update(kw) if self.game.preview > 1: if "XOFFSET" in kw: self.XOFFSET //= self.game.preview if "YOFFSET" in kw: self.YOFFSET //= self.game.preview self.TEXT_HEIGHT = 10
def __init__(self, **kw): # start with all fields from CardsetConfig config = CardsetConfig() kw = KwStruct(config.__dict__, **kw) # si is the SelectionInfo struct that will be queried by # the "select cardset" dialogs. It can be freely modified. si = Struct(type=0, size=0, styles=[], nationalities=[], dates=[]) kw = KwStruct( kw, # essentials ranks=(), suits=(), trumps=(), nbottoms=7, nletters=4, nshadows=1 + 13, # selection criteria si=si, # implicit backname=None, dir="", ) Resource.__init__(self, **kw.getKw())
def __init__(self): self.gdb = GAME_DB self.opt = Options() self.startup_opt = self.opt.copy() self.stats = Statistics() self.splashscreen = 1 # visual components self.top = None # the root toplevel window self.top_bg = None # default background self.top_cursor = None # default cursor self.menubar = None self.toolbar = None self.canvas = None # MfxCanvas self.scrolled_canvas = None # MfxScrolledCanvas self.statusbar = None # self.game = None self.dataloader = None self.audio = None self.images = None self.subsampled_images = None self.gimages = Struct( # global images demo=[], # demo logos pause=[], # pause logos logos=[], redeal=[], ) # self.progress_bg = None self.progress_images = [] self.cardset_manager = CardsetManager() self.cardset = None # current cardset self.cardsets_cache = {} self.tabletile_manager = TileManager() self.tabletile_index = 0 # current table tile self.sample_manager = SampleManager() self.music_manager = MusicManager() self.music_playlist = [] self.intro = Struct( progress=None, # progress bar ) # directory names config = os.path.normpath(getprefdir(PACKAGE)) self.dn = Struct( config=config, plugins=os.path.join(config, "plugins"), savegames=os.path.join(config, "savegames"), maint=os.path.join(config, "maint"), # debug ) for k, v in self.dn.__dict__.items(): # if os.name == "nt": # v = os.path.normcase(v) v = os.path.normpath(v) self.dn.__dict__[k] = v # file names self.fn = Struct( opt=os.path.join(self.dn.config, "options.dat"), opt_cfg=os.path.join(self.dn.config, "options.cfg"), stats=os.path.join(self.dn.config, "statistics.dat"), holdgame=os.path.join(self.dn.config, "holdgame.dat"), comments=os.path.join(self.dn.config, "comments.dat"), ) for k, v in self.dn.__dict__.items(): if os.name == "nt": v = os.path.normcase(v) v = os.path.normpath(v) self.fn.__dict__[k] = v # random generators self.gamerandom = PysolRandom() self.miscrandom = PysolRandom() # player player = getusername() if not player: player = "unknown" player = player[:30] self.opt.player = player # misc self.nextgame = Struct( id=0, # start this game random=None, # use this random generator loadedgame=None, # data for loaded game startdemo=0, # start demo ? cardset=None, # use this cardset holdgame=0, # hold this game on exit ? bookmark=None, # goto this bookmark (load new cardset) ) self.commandline = Struct( loadgame=None, # load a game ? game=None, gameid=None, deal=None, ) self.demo_counter = 0
def __init__(self, game, card_x_space=None, card_y_space=None, **kw): self.game = game self.canvas = self.game.canvas self.size = None self.s = Struct( talon=None, waste=None, foundations=[], rows=[], reserves=[], ) self.stackmap = {} self.regions = [] # set visual constants images = self.game.app.images cardset_size = images.cs.si.size if cardset_size in (CSI.SIZE_TINY, CSI.SIZE_SMALL): layout_x_margin = 6 layout_y_margin = 6 layout_card_x_space = 6 layout_card_y_space = 10 elif cardset_size in (CSI.SIZE_MEDIUM, ): layout_x_margin = 8 layout_y_margin = 8 layout_card_x_space = 8 layout_card_y_space = 12 else: # CSI.SIZE_LARGE, CSI.SIZE_XLARGE layout_x_margin = 10 layout_y_margin = 10 layout_card_x_space = 10 layout_card_y_space = 14 self.CW = images.CARDW self.CH = images.CARDH self.XOFFSET = images.CARD_XOFFSET self.YOFFSET = images.CARD_YOFFSET self.XM = layout_x_margin # XMARGIN self.YM = layout_y_margin # YMARGIN if card_x_space is None: self.XS = self.CW + layout_card_x_space # XSPACE else: self.XS = self.CW + card_x_space if card_y_space is None: self.YS = self.CH + layout_card_y_space # YSPACE else: self.YS = self.CH + card_y_space ##self.CARD_X_SPACE = layout_card_x_space ##self.CARD_Y_SPACE = layout_card_y_space ##self.RIGHT_MARGIN = layout_x_margin-layout_card_x_space ##self.BOTTOM_MARGIN = layout_y_margin-layout_card_y_space font = game.app.getFont("canvas_default") ##self.TEXT_MARGIN = 10 self.TEXT_MARGIN = font[1] ##self.TEXT_HEIGHT = 30 self.TEXT_HEIGHT = 18 + font[1] self.__dict__.update(kw) if self.game.preview > 1: if "XOFFSET" in kw: self.XOFFSET = self.XOFFSET / self.game.preview if "YOFFSET" in kw: self.YOFFSET = self.YOFFSET / self.game.preview self.TEXT_HEIGHT = 10
def updatePreview(self, gameid, animations=10): if gameid == self.preview_key: return self.deletePreview() canvas = self.preview # gi = self.app.gdb.get(gameid) if not gi: self.preview_key = -1 return # if self.preview_app is None: self.preview_app = Struct( # variables audio=self.app.audio, canvas=canvas, cardset=self.app.cardset.copy(), gamerandom=self.app.gamerandom, gdb=self.app.gdb, gimages=self.app.gimages, images=None, menubar=None, miscrandom=self.app.miscrandom, opt=self.app.opt.copy(), startup_opt=self.app.startup_opt, stats=self.app.stats.new(), top=None, top_cursor=self.app.top_cursor, toolbar=None, # methods constructGame=self.app.constructGame, getFont=self.app.getFont, ) self.preview_app.opt.shadow = 0 self.preview_app.opt.shade = 0 # c = self.app.cardsets_cache.get(gi.category) if not c: cardset = self.app.cardset_manager.getByName( self.app.opt.cardset[gi.category][0]) self.app.loadCardset(cardset, id=gi.category, tocache=True, noprogress=True) c = self.app.cardsets_cache.get(gi.category) if c: self.preview_app.images = c[2] else: self.preview_app.images = self.app.subsampled_images self.preview_app.audio = None # turn off audio for initial dealing if animations >= 0: self.preview_app.opt.animations = animations # if self.preview_game: self.preview_game.endGame() self.preview_game.destruct() # self.top.wm_title( # "Select Game - " + self.app.getGameTitleName(gameid)) title = self.app.getGameTitleName(gameid) self.set_title(_("Select Game - %(game)s") % {'game': title}) # self.preview_game = gi.gameclass(gi) self.preview_game.createPreview(self.preview_app) # tx, ty = 0, 0 # gw, gh = self.preview_game.width, self.preview_game.height # ~ canvas.config(scrollregion=(-tx, -ty, -tx, -ty)) # ~ canvas.xview_moveto(0) # ~ canvas.yview_moveto(0) # random = None if gameid == self.gameid: random = self.app.game.random.copy() if gameid == self.gameid and self.bookmark: self.preview_game.restoreGameFromBookmark(self.bookmark) else: self.preview_game.newGame(random=random, autoplay=1) # ~ canvas.config(scrollregion=(-tx, -ty, gw, gh)) # self.preview_app.audio = self.app.audio if self.app.opt.animations: self.preview_app.opt.animations = 10 else: self.preview_app.opt.animations = 0 # save seed self.random = self.preview_game.random.copy() self.random.origin = self.random.ORIGIN_PREVIEW self.preview_key = gameid # self.updateInfo(gameid) # rules_button = self.buttons[1] if self.app.getGameRulesFilename(gameid): rules_button.set_sensitive(True) else: rules_button.set_sensitive(False)
def __init__(self, parent, app=None, home=None): self.parent = parent self.app = app self.home = home self.url = None self.history = Struct( list=[], index=0, ) self.visited_urls = [] self.images = {} # need to keep a reference because of garbage collection self.defcursor = "default" # self.defcursor = parent["cursor"] # self.defcursor = 'xterm' self.handcursor = "hand2" self.title = "Browser" self.window = None self.running = False # prüfen ob noch aktiv. if parent.workStack.peek(self.title) is not None: parent.popWork(self.title) pc = self.make_pop_command(parent, self.title) cc = self.make_close_command(parent, self.title) # neuen Dialog aufbauen. window = LTopLevel(app.top, self.title, size_hint=(1.8, 1.0)) window.titleline.bind(on_press=cc) self.parent.pushWork(self.title, window) self.window = window self.running = True content = BoxLayout(orientation='vertical') # buttonline = # BoxLayout(orientation='horizontal', size_hint=(1.0, 0.1)) # create buttons self.homeButton = HTMLButton(text="Index", on_release=self.goHome) self.backButton = HTMLButton(text="Back", on_release=self.goBack) self.forwardButton = HTMLButton( text="Forward", on_release=self.goForward) self.closeButton = HTMLButton(text="Close", on_release=self.goHome) ''' buttonline.add_widget(self.homeButton) buttonline.add_widget(self.backButton) buttonline.add_widget(self.forwardButton) buttonline.add_widget(self.closeButton) content.add_widget(buttonline) ''' ''' self.homeButton = Tkinter.Button(parent, text=_("Index"), width=button_width, command=self.goHome) self.homeButton.grid(row=0, column=0, sticky='w') self.backButton = Tkinter.Button(parent, text=_("Back"), width=button_width, command=self.goBack) self.backButton.grid(row=0, column=1, sticky='w') self.forwardButton = Tkinter.Button(parent, text=_("Forward"), width=button_width, command=self.goForward) self.forwardButton.grid(row=0, column=2, sticky='w') self.closeButton = Tkinter.Button(parent, text=_("Close"), width=button_width, command=self.destroy) self.closeButton.grid(row=0, column=3, sticky='e') ''' # create text widget self.text = HTMLText( pop_command=pc, text="hallo", size_hint=(1.0, 1.0)) self.text.label.bind(on_ref_press=self.refpress) content.add_widget(self.text) ''' text_frame = Tkinter.Frame(parent) text_frame.grid(row=1, column=0, columnspan=4, sticky='nsew') text_frame.grid_propagate(False) vbar = Tkinter.Scrollbar(text_frame) vbar.pack(side='right', fill='y') self.text = Tkinter.Text(text_frame, fg='black', bg='white', bd=1, relief='sunken', cursor=self.defcursor, wrap='word', padx=10) self.text.pack(side='left', fill='both', expand=True) self.text["yscrollcommand"] = vbar.set vbar["command"] = self.text.yview ''' self.window.content.add_widget(content) # statusbar # self.statusbar = HtmlStatusbar(parent, row=2, column=0, columnspan=4) # parent.columnconfigure(2, weight=1) # parent.rowconfigure(1, weight=1) # load images for name, fn in self.symbols_fn.items(): self.symbols_img[name] = self.getImage(fn)
def __init__( self, id, gameclass, name, game_type, decks, redeals, skill_level=None, # keyword arguments: si={}, category=0, short_name=None, altnames=(), suits=list(range(4)), ranks=list(range(13)), trumps=(), rules_filename=None, ): # def to_unicode(s): if isinstance(s, six.text_type): return s try: s = six.text_type(s, 'utf-8') except UnicodeDecodeError as err: print_err(err) s = six.text_type(s, 'utf-8', 'ignore') return s ncards = decks * (len(suits) * len(ranks) + len(trumps)) game_flags = game_type & ~1023 game_type = game_type & 1023 name = to_unicode(name) en_name = name # for app.getGameRulesFilename if pysollib.settings.TRANSLATE_GAME_NAMES: name = _(name) if not short_name: short_name = name else: short_name = to_unicode(short_name) if pysollib.settings.TRANSLATE_GAME_NAMES: short_name = _(short_name) if isinstance(altnames, six.string_types): altnames = (altnames, ) altnames = [to_unicode(n) for n in altnames] if pysollib.settings.TRANSLATE_GAME_NAMES: altnames = [_(n) for n in altnames] # if not (1 <= category <= 9): if game_type == GI.GT_HANAFUDA: category = GI.GC_HANAFUDA elif game_type == GI.GT_TAROCK: category = GI.GC_TAROCK elif game_type == GI.GT_MAHJONGG: category = GI.GC_MAHJONGG elif game_type == GI.GT_HEXADECK: category = GI.GC_HEXADECK elif game_type == GI.GT_MUGHAL_GANJIFA: category = GI.GC_MUGHAL_GANJIFA elif game_type == GI.GT_NAVAGRAHA_GANJIFA: category = GI.GC_NAVAGRAHA_GANJIFA elif game_type == GI.GT_DASHAVATARA_GANJIFA: category = GI.GC_DASHAVATARA_GANJIFA else: category = GI.GC_FRENCH # if not (1 <= id <= 999999): raise GameInfoException(name + ": invalid game ID " + str(id)) if category == GI.GC_MAHJONGG: if decks % 4: raise GameInfoException(name + ": invalid number of decks " + str(id)) else: if not (1 <= decks <= 4): raise GameInfoException(name + ": invalid number of decks " + str(id)) if not name: raise GameInfoException(name + ": invalid game name") if GI.PROTECTED_GAMES.get(id): raise GameInfoException(name + ": protected game ID " + str(id)) # for f, l in ((GI.GT_CHILDREN, GI._CHILDREN_GAMES), (GI.GT_OPEN, GI._OPEN_GAMES), (GI.GT_POPULAR, GI._POPULAR_GAMES)): if (game_flags & f) and (id not in l): l.append(id) elif not (game_flags & f) and (id in l): game_flags = game_flags | f # si is the SelectionInfo struct that will be queried by # the "select game" dialogs. It can be freely modified. gi_si = Struct(game_type=game_type, game_flags=game_flags, decks=decks, redeals=redeals, ncards=ncards) gi_si.update(si) # Struct.__init__(self, id=id, gameclass=gameclass, name=name, short_name=short_name, altnames=tuple(altnames), en_name=en_name, decks=decks, redeals=redeals, ncards=ncards, category=category, skill_level=skill_level, suits=tuple(suits), ranks=tuple(ranks), trumps=tuple(trumps), si=gi_si, rules_filename=rules_filename)
def __init__(self, parent, app=None, home=None): self.parent = parent self.app = app self.home = home self.url = None self.history = Struct( list=[], index=0, ) self.visited_urls = [] self.images = {} self.anchor_tags = {} # create buttons vbox = gtk.VBox() parent.table.attach(vbox, 0, 1, 0, 1, gtk.EXPAND | gtk.FILL, gtk.EXPAND | gtk.FILL | gtk.SHRINK, 0, 0) buttons_box = gtk.HBox() vbox.pack_start(buttons_box, fill=True, expand=False) for name, label, callback in (('homeButton', _('Index'), self.goHome), ('backButton', _('Back'), self.goBack), ('forwardButton', _('Forward'), self.goForward), ('closeButton', _('Close'), self.destroy)): button = gtk.Button(label) button.show() button.connect('clicked', callback) buttons_box.pack_start(button, fill=True, expand=False) button.set_property('can-focus', False) setattr(self, name, button) # create text widget self.textview = gtk.TextView() self.textview.show() self.textview.set_left_margin(10) self.textview.set_right_margin(10) self.textview.set_cursor_visible(False) self.textview.set_editable(False) self.textview.set_wrap_mode(gtk.WRAP_WORD) self.textbuffer = self.textview.get_buffer() sw = gtk.ScrolledWindow() sw.set_property('hscrollbar-policy', gtk.POLICY_AUTOMATIC) sw.set_property('vscrollbar-policy', gtk.POLICY_AUTOMATIC) sw.set_property('border-width', 0) sw.add(self.textview) sw.show() vbox.pack_start(sw, fill=True, expand=True) self.vadjustment = sw.get_vadjustment() self.hadjustment = sw.get_hadjustment() # statusbar self.statusbar = gtk.Statusbar() self.statusbar.show() vbox.pack_start(self.statusbar, fill=True, expand=False) # load images for name, fn in self.symbols_fn.items(): self.symbols_img[name] = self.getImage(fn) # bindings parent.connect('key-press-event', self.key_press_event) parent.connect('destroy', self.destroy) self.textview.connect('motion-notify-event', self.motion_notify_event) self.textview.connect('leave-notify-event', self.leave_event) self.textview.connect('enter-notify-event', self.motion_notify_event) self._changed_cursor = False self.createFontMap() # cursor self.defcursor = gdk.XTERM self.handcursor = gdk.HAND2 # self.textview.realize() # window = self.textview.get_window(gtk.TEXT_WINDOW_TEXT) # window.set_cursor(gdk.Cursor(self.defcursor)) parent.set_default_size(600, 440) parent.show_all() gobject.idle_add(gtk.main)
def createGame(self): tiles, max_tl, max_tx, max_ty = self.getTiles() # start layout l, s = Layout(self), self.s show_removed = self.app.opt.mahjongg_show_removed # dx, dy = 2, -2 # dx, dy = 3, -3 cs = self.app.cardset if cs.version >= 6: dx = l.XOFFSET dy = -l.YOFFSET d_x = cs.SHADOW_XOFFSET d_y = cs.SHADOW_YOFFSET if self.preview: # Fixme dx, dy, d_x, d_y = dx // 2, dy // 2, d_x // 2, d_y // 2 self._delta_x, self._delta_y = dx, -dy else: dx = 3 dy = -3 d_x = 0 d_y = 0 self._delta_x, self._delta_y = 0, 0 # print dx, dy, d_x, d_y, cs.version font = self.app.getFont("canvas_default") # width of self.texts.info # ti_width = Font(self.canvas, font).measure(_('Remaining')) ti_width = 80 # set window size dxx, dyy = abs(dx) * (max_tl + 1), abs(dy) * (max_tl + 1) # foundations dxx dyy if self.NCARDS > 144: fdxx = abs(dx) * 8 fdyy = abs(dy) * 8 else: fdxx = abs(dx) * 4 fdyy = abs(dy) * 4 cardw, cardh = l.CW - d_x, l.CH - d_y if show_removed: left_margin = l.XM + 4 * cardw + fdxx + d_x + l.XM else: left_margin = l.XM tableau_width = (max_tx + 2) * cardw // 2 + dxx + d_x right_margin = l.XM + ti_width + l.XM w = left_margin + tableau_width + right_margin h = l.YM + dyy + (max_ty + 2) * cardh // 2 + d_y + l.YM if show_removed: h = max(h, l.YM + fdyy + cardh * 9 + d_y + l.YM) self.setSize(w, h) # set game extras self.check_dist = l.CW * l.CW + l.CH * l.CH # see _getClosestStack() # sort tiles (for 3D) tiles.sort(key=lambda x: (x[0], x[2] - x[1])) # create a row stack for each tile and compute the tilemap tilemap = {} x0 = left_margin y0 = l.YM + dyy for level, tx, ty in tiles: # print level, tx, ty x = x0 + (tx * cardw) // 2 + level * dx y = y0 + (ty * cardh) // 2 + level * dy stack = self.RowStack_Class(x, y, self) # stack.G = (level, tx, ty) stack.CARD_XOFFSET = dx stack.CARD_YOFFSET = dy s.rows.append(stack) # tilemap - each tile covers 4 positions tilemap[(level, tx, ty)] = stack tilemap[(level, tx + 1, ty)] = stack tilemap[(level, tx, ty + 1)] = stack tilemap[(level, tx + 1, ty + 1)] = stack # compute blockmap for stack in s.rows: level, tx, ty = tiles[stack.id] above, below, left, right = {}, {}, {}, {} # above blockers for tl in range(level + 1, level + 2): above[tilemap.get((tl, tx, ty))] = 1 above[tilemap.get((tl, tx + 1, ty))] = 1 above[tilemap.get((tl, tx, ty + 1))] = 1 above[tilemap.get((tl, tx + 1, ty + 1))] = 1 # for tl in range(level): below[tilemap.get((tl, tx, ty))] = 1 below[tilemap.get((tl, tx + 1, ty))] = 1 below[tilemap.get((tl, tx, ty + 1))] = 1 below[tilemap.get((tl, tx + 1, ty + 1))] = 1 # left blockers left[tilemap.get((level, tx - 1, ty))] = 1 left[tilemap.get((level, tx - 1, ty + 1))] = 1 # right blockers right[tilemap.get((level, tx + 2, ty))] = 1 right[tilemap.get((level, tx + 2, ty + 1))] = 1 # up blockers # up[tilemap.get((level, tx, ty-1))] = 1 # up[tilemap.get((level, tx+1, ty-1))] = 1 # bottom blockers # bottom[tilemap.get((level, tx, ty+2))] = 1 # bottom[tilemap.get((level, tx+1, ty+2))] = 1 # sanity check - assert that there are no overlapping tiles assert tilemap.get((level, tx, ty)) is stack assert tilemap.get((level, tx + 1, ty)) is stack assert tilemap.get((level, tx, ty + 1)) is stack assert tilemap.get((level, tx + 1, ty + 1)) is stack # above = tuple([_f for _f in above.keys() if _f]) below = tuple([_f for _f in below.keys() if _f]) left = tuple([_f for _f in left.keys() if _f]) right = tuple([_f for _f in right.keys() if _f]) # up = tuple(filter(None, up.keys())) # bottom = tuple(filter(None, bottom.keys())) # assemble stack.blockmap = Struct( above=above, below=below, left=left, right=right, # up=up, # bottom=bottom, all_left=None, all_right=None, ) def get_all_left(s): if s.blockmap.all_left is None: s.blockmap.all_left = {} for t in s.blockmap.left: if t.blockmap.all_left is None: get_all_left(t) s.blockmap.all_left.update(t.blockmap.all_left) s.blockmap.all_left[t] = 1 def get_all_right(s): if s.blockmap.all_right is None: s.blockmap.all_right = {} for t in s.blockmap.right: if t.blockmap.all_right is None: get_all_right(t) s.blockmap.all_right.update(t.blockmap.all_right) s.blockmap.all_right[t] = 1 for r in s.rows: get_all_left(r) get_all_right(r) for r in s.rows: r.blockmap.all_left = tuple(r.blockmap.all_left.keys()) r.blockmap.all_right = tuple(r.blockmap.all_right.keys()) # create other stacks for i in range(4): for j in range(9): if show_removed: x = l.XM + i * cardw y = l.YM + fdyy + j * cardh else: if TOOLKIT == 'tk': x = -l.XS - self.canvas.xmargin y = l.YM + dyy elif TOOLKIT == 'gtk': # FIXME x = self.width - l.XS y = self.height - l.YS stack = Mahjongg_Foundation(x, y, self) if show_removed: stack.CARD_XOFFSET = dx stack.CARD_YOFFSET = dy s.foundations.append(stack) self.texts.info = MfxCanvasText(self.canvas, self.width - l.XM - ti_width, l.YM + dyy, anchor="nw", font=font) # the Talon is invisble s.talon = InitialDealTalonStack(-l.XS - self.canvas.xmargin, self.height - dyy, self) # Define stack groups l.defaultStackGroups()
def mPlayerStats(self, *args, **kw): wasPaused = False if not self.game.pause: self.game.doPause() wasPaused = True mode = kw.get("mode", 101) demo = 0 gameid = None while mode > 0: if mode > 1000: demo = not demo mode = mode % 1000 # d = Struct(status=-1, button=-1) if demo: player = None else: player = self.app.opt.player n = self.game.gameinfo.name # translation keywords transkw = { 'app': TITLE, 'player': player, 'game': n, 'tops': TOP_SIZE } # if mode == 100: d = Status_StatsDialog(self.top, game=self.game) elif mode == 101: header = (_("%(app)s Demo Statistics for %(game)s") if demo else _("Statistics for %(game)s")) % transkw d = SingleGame_StatsDialog(self.top, header, self.app, player, gameid=self.game.id) gameid = d.selected_game elif mode == 102: header = (_("%(app)s Demo Statistics") if demo else _("Statistics for %(player)s")) % transkw d = AllGames_StatsDialog(self.top, header, self.app, player) gameid = d.selected_game elif mode == 103: header = (_("%(app)s Demo Full log") if demo else _("Full log for %(player)s")) % transkw d = FullLog_StatsDialog(self.top, header, self.app, player) elif mode == 104: header = (_("%(app)s Demo Session log") if demo else _("Session log for %(player)s")) % transkw d = SessionLog_StatsDialog(self.top, header, self.app, player) elif mode == 105: # TRANSLATORS: eg. top 10 or top 5 results for a certain game header = (_("%(app)s Demo Top %(tops)d for %(game)s") if demo else _("Top %(tops)d for %(game)s")) % transkw d = Top_StatsDialog(self.top, header, self.app, player, gameid=self.game.id) elif mode == 106: header = _("Game Info") d = GameInfoDialog(self.top, header, self.app) elif mode == 107: header = _("Statistics progression") d = ProgressionDialog(self.top, header, self.app, player, gameid=self.game.id) elif mode == 202: # print stats to file write_method = FileStatsFormatter.writeStats self._mStatsSave(player, "stats", write_method) elif mode == 203: # print full log to file write_method = FileStatsFormatter.writeFullLog self._mStatsSave(player, "log", write_method) elif mode == 204: # print session log to file write_method = FileStatsFormatter.writeSessionLog self._mStatsSave(player, "log", write_method) elif mode == 301: # reset all player stats if self.game.areYouSure( _("Reset all statistics"), _("Reset ALL statistics and logs for player\n" + "%(player)s?") % transkw, confirm=1, default=1): self.app.stats.resetStats(player, 0) self.game.updateStatus(stats=self.app.stats.getStats( self.app.opt.player, self.game.id)) elif mode == 302: # reset player stats for current game if self.game.areYouSure( _("Reset game statistics"), _('Reset statistics and logs for player\n%(player)s\n' 'and game\n%(game)s?') % transkw, confirm=1, default=1): self.app.stats.resetStats(player, self.game.id) self.game.updateStatus(stats=self.app.stats.getStats( self.app.opt.player, self.game.id)) elif mode == 401: # start a new game with a gameid if gameid and gameid != self.game.id: self.game.endGame() self.game.quitGame(gameid) elif mode == 402: # start a new game with a gameid / gamenumber # TODO pass else: print_err("stats problem: %s %s %s" % (mode, demo, player)) pass if d.status != 0: break mode = d.button if self.game.pause: if wasPaused: self.game.doPause()
def updatePreview(self, gameid, animations=10): if gameid == self.preview_key: return self.deletePreview() canvas = self.preview.canvas # gi = self.app.gdb.get(gameid) if not gi: self.preview_key = -1 return # if self.preview_app is None: self.preview_app = Struct( # variables audio=self.app.audio, canvas=canvas, cardset=self.app.cardset.copy(), comments=self.app.comments.new(), gamerandom=self.app.gamerandom, gdb=self.app.gdb, gimages=self.app.gimages, images=self.app.subsampled_images, menubar=None, miscrandom=self.app.miscrandom, opt=self.app.opt.copy(), startup_opt=self.app.startup_opt, stats=self.app.stats.new(), top=None, top_cursor=self.app.top_cursor, toolbar=None, # methods constructGame=self.app.constructGame, getFont=self.app.getFont, ) self.preview_app.opt.shadow = 0 self.preview_app.opt.shade = 0 # self.preview_app.audio = None # turn off audio for intial dealing if animations >= 0: self.preview_app.opt.animations = animations # if self.preview_game: self.preview_game.endGame() self.preview_game.destruct() ##self.top.wm_title("Select Game - " + self.app.getGameTitleName(gameid)) title = self.app.getGameTitleName(gameid) self.top.wm_title(_("Playable Preview - ") + title) # self.preview_game = gi.gameclass(gi) self.preview_game.createPreview(self.preview_app) # random = None if gameid == self.gameid: random = self.app.game.random.copy() if gameid == self.gameid and self.bookmark: self.preview_game.restoreGameFromBookmark(self.bookmark) else: self.preview_game.newGame(random=random, autoplay=1) gw, gh = self.preview_game.width, self.preview_game.height canvas.config(scrollregion=(0, 0, gw, gh)) canvas.xview_moveto(0) canvas.yview_moveto(0) # self.preview_app.audio = self.app.audio if self.app.opt.animations: self.preview_app.opt.animations = 10 else: self.preview_app.opt.animations = 0 # save seed self.random = self.preview_game.random.copy() self.random.origin = self.random.ORIGIN_PREVIEW self.preview_key = gameid # self.updateInfo(gameid) # rules_button = self.buttons[1] if self.app.getGameRulesFilename(gameid): rules_button.config(state="normal") else: rules_button.config(state="disabled")
def mPlayerStats(self, *args, **kw): mode = kw.get("mode", 101) demo = 0 gameid = None while mode > 0: if mode > 1000: demo = not demo mode = mode % 1000 # d = Struct(status=-1, button=-1) if demo: player = None p0, p1, p2 = TITLE + _(" Demo"), TITLE + _(" Demo "), "" else: player = self.app.opt.player p0, p1, p2 = player, "", _(" for ") + player n = self.game.gameinfo.name # if mode == 100: d = Status_StatsDialog(self.top, game=self.game) elif mode == 101: header = p1 + _("Statistics for ") + n d = SingleGame_StatsDialog(self.top, header, self.app, player, gameid=self.game.id) gameid = d.selected_game elif mode == 102: header = p1 + _("Statistics") + p2 d = AllGames_StatsDialog(self.top, header, self.app, player) gameid = d.selected_game elif mode == 103: header = p1 + _("Full log") + p2 d = FullLog_StatsDialog(self.top, header, self.app, player) elif mode == 104: header = p1 + _("Session log") + p2 d = SessionLog_StatsDialog(self.top, header, self.app, player) elif mode == 105: header = p1 + TOP_TITLE + _(" for ") + n d = Top_StatsDialog(self.top, header, self.app, player, gameid=self.game.id) elif mode == 106: header = _("Game Info") d = GameInfoDialog(self.top, header, self.app) elif mode == 107: header = _("Statistics progression") d = ProgressionDialog(self.top, header, self.app, player, gameid=self.game.id) elif mode == 202: # print stats to file write_method = FileStatsFormatter.writeStats self._mStatsSave(player, "stats", write_method) elif mode == 203: # print full log to file write_method = FileStatsFormatter.writeFullLog self._mStatsSave(player, "log", write_method) elif mode == 204: # print session log to file write_method = FileStatsFormatter.writeSessionLog self._mStatsSave(player, "log", write_method) elif mode == 301: # reset all player stats if self.game.areYouSure( _("Reset all statistics"), _("Reset ALL statistics and logs for player\n%s ?") % p0, confirm=1, default=1): self.app.stats.resetStats(player, 0) self.game.updateStatus(stats=self.app.stats.getStats( self.app.opt.player, self.game.id)) elif mode == 302: # reset player stats for current game if self.game.areYouSure(_("Reset game statistics"), _('Reset statistics and logs ' + 'for player\n%s\nand game\n%s ?') % (p0, n), confirm=1, default=1): self.app.stats.resetStats(player, self.game.id) self.game.updateStatus(stats=self.app.stats.getStats( self.app.opt.player, self.game.id)) elif mode == 401: # start a new game with a gameid if gameid and gameid != self.game.id: self.game.endGame() self.game.quitGame(gameid) elif mode == 402: # start a new game with a gameid / gamenumber # TODO pass else: print_err("stats problem: %s %s %s" % (mode, demo, player)) pass if d.status != 0: break mode = d.button