1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

* improved Layout

* small bug fixes


git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@23 39dd0a4e-7c14-0410-91b3-c4f2d318f732
This commit is contained in:
skomoroh 2006-07-21 21:04:39 +00:00
parent 2c7c722413
commit 9c2e477746
23 changed files with 134 additions and 74 deletions

View file

@ -1964,6 +1964,7 @@ for %d moves.
self.__storeMove(am)
am.do(self)
# for ArbitraryStack
def singleCardMove(self, from_stack, to_stack, position, frames=-1, shadow=-1):
am = ASingleCardMove(from_stack, to_stack, position, frames, shadow)
self.__storeMove(am)
@ -1971,7 +1972,6 @@ for %d moves.
self.hints.list = None
# Finish the current move.
def finishMove(self):
current, moves, stats = self.moves.current, self.moves, self.stats

View file

@ -131,6 +131,7 @@ class Braid(Game):
def createGame(self):
# create layout
l, s = Layout(self), self.s
font=self.app.getFont("canvas_default")
# set window
# (piles up to 20 cards are playable - needed for Braid_BraidStack)
@ -161,9 +162,8 @@ class Braid(Game):
s.talon = WasteTalonStack(x, y, self, max_rounds=3)
l.createText(s.talon, "ss")
s.talon.texts.rounds = MfxCanvasText(self.canvas,
x + l.CW / 2, y - l.YM,
anchor="s",
font=self.app.getFont("canvas_default"))
x + l.CW / 2, y - l.TEXT_MARGIN,
anchor="s", font=font)
x = x - l.XS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, "ss")
@ -174,10 +174,9 @@ class Braid(Game):
s.foundations.append(cl(x, y, self, suit=i))
x += l.XS
y = y + l.YS
x = 8*l.XS+decks*l.XS/2+l.XM/2
x = l.XM+8*l.XS+decks*l.XS/2
self.texts.info = MfxCanvasText(self.canvas,
x, y, anchor="n",
font=self.app.getFont("canvas_default"))
x, y, anchor="n", font=font)
# define stack-groups
self.sg.talonstacks = [s.talon] + [s.waste]

View file

@ -142,8 +142,8 @@ class Canfield(Game):
tx, ty, ta, tf = l.getTextAttr(None, "se")
tx, ty = x + tx + l.XM, y + ty
else:
tx, ty, ta, tf = l.getTextAttr(None, "s")
tx, ty = x + tx, y + ty + l.YM
tx, ty, ta, tf = l.getTextAttr(None, "ss")
tx, ty = x + tx, y + ty
font = self.app.getFont("canvas_default")
self.texts.info = MfxCanvasText(self.canvas, tx, ty, anchor=ta, font=font)
x, y = l.XM, l.YM + l.YS + l.TEXT_HEIGHT

View file

@ -162,7 +162,7 @@ class Dumfries(Game):
# create layout
l, s = Layout(self), self.s
kwdefault(layout, rows=8, waste=0, texts=1, playcards=20)
apply(Layout.klondikeLayout, (l,), layout)
l.klondikeLayout(**layout)
self.setSize(l.size[0], l.size[1])
# create stacks
s.talon = Dumfries_TalonStack(l.s.talon.x, l.s.talon.y, self)

View file

@ -81,15 +81,16 @@ class Fan(Game):
self.setSize(l.XM + max(rows)*w, l.YM + (1+len(rows))*l.YS)
# create stacks
decks = self.gameinfo.decks
if reserves:
x, y = l.XM, l.YM
for r in range(reserves):
s.reserves.append(self.ReserveStack_Class(x, y, self))
x += l.XS
x = (self.width - self.gameinfo.decks*4*l.XS - 2*l.XS) / 2
x = (self.width - decks*4*l.XS - 2*l.XS) / 2
dx = l.XS
else:
dx = (self.width - self.gameinfo.decks*4*l.XS)/(self.gameinfo.decks*4+1)
dx = (self.width - decks*4*l.XS)/(decks*4+1)
x, y = l.XM + dx, l.YM
dx += l.XS
for fnd_cls in self.Foundation_Classes:

View file

@ -103,18 +103,18 @@ class FortyThieves(Game):
s.rows.append(self.RowStack_Class(x, y, self, max_move=self.ROW_MAX_MOVE))
x = x + l.XS
x = self.width - l.XS
y = self.height - l.YS - l.TEXT_HEIGHT
y = self.height - l.YS
s.talon = WasteTalonStack(x, y, self, max_rounds=max_rounds, num_deal=num_deal)
l.createText(s.talon, "s")
l.createText(s.talon, "n")
if max_rounds > 1:
s.talon.texts.rounds = MfxCanvasText(self.canvas,
x + l.CW / 2, y - l.YM,
x + l.CW / 2, y - l.TEXT_HEIGHT,
anchor="s",
font=self.app.getFont("canvas_default"))
x = x - l.XS
s.waste = WasteStack(x, y, self)
s.waste.CARD_XOFFSET = -l.XOFFSET
l.createText(s.waste, "s")
l.createText(s.waste, "n")
# define stack-groups
l.defaultStackGroups()

View file

@ -79,7 +79,7 @@ class DoubleKlondike(Game):
assert s.talon.texts.rounds is None
tx, ty, ta, tf = l.getTextAttr(s.talon, "nn")
if layout.get("texts"):
ty = ty - 2*l.YM
ty = ty - 2*l.TEXT_MARGIN
s.talon.texts.rounds = MfxCanvasText(self.canvas, tx, ty,
anchor=ta,
font=self.app.getFont("canvas_default"))
@ -243,6 +243,10 @@ class BigDeal(DoubleKlondike):
x += l.XS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, 'n')
if max_rounds > 1:
tx, ty, ta, tf = l.getTextAttr(s.waste, 'se')
font = self.app.getFont('canvas_default')
s.talon.texts.rounds = MfxCanvasText(self.canvas, tx, ty, anchor=ta, font=font)
self.setRegion(s.rows, (-999, -999, l.XM+rows*l.XS-l.CW/2, 999999), priority=1)
l.defaultStackGroups()

View file

@ -486,7 +486,7 @@ class FlowerGarden(Stonewall):
# // Brigade
# ************************************************************************/
class KingAlbertOld(Klondike):
class KingAlbert(Klondike):
Talon_Class = InitialDealTalonStack
RowStack_Class = StackWrapper(AC_RowStack, max_move=1)
Hint_Class = CautiousDefaultHint
@ -511,17 +511,17 @@ class KingAlbertOld(Klondike):
self.s.talon.dealRow(rows=self.s.reserves)
class KingAlbert(KingAlbertOld):
## class KingAlbertNew(KingAlbert):
def createGame(self):
l = Klondike.createGame(self, max_rounds=1, rows=self.ROWS, waste=0, texts=0)
self.setSize(self.width+l.XM+l.XS, self.height)
self.s.reserves.append(ArbitraryStack(self.width-l.XS, l.YM, self))
l.defaultStackGroups()
## def createGame(self):
## l = Klondike.createGame(self, max_rounds=1, rows=self.ROWS, waste=0, texts=0)
## self.setSize(self.width+l.XM+l.XS, self.height)
## self.s.reserves.append(ArbitraryStack(self.width-l.XS, l.YM, self))
## l.defaultStackGroups()
def startGame(self):
Klondike.startGame(self, flip=1, reverse=0)
self.s.talon.dealRow(rows=self.s.reserves*7)
## def startGame(self):
## Klondike.startGame(self, flip=1, reverse=0)
## self.s.talon.dealRow(rows=self.s.reserves*7)
class Raglan(KingAlbert):

View file

@ -174,7 +174,9 @@ class Matriarchy(Game):
self.setSize(10*l.XS+l.XM, h + l.YM + h)
# create stacks
center, c1, c2 = self.height / 2, h, self.height - h
##center, c1, c2 = self.height / 2, h, self.height - h
center = self.height / 2
c1, c2 = center-l.TEXT_HEIGHT/2, center+l.TEXT_HEIGHT/2
x, y = l.XM, c1 - l.CH
for i in range(8):
s.rows.append(Matriarchy_UpRowStack(x, y, self, i/2))
@ -186,10 +188,10 @@ class Matriarchy(Game):
x, y = x + l.XS / 2, c1 - l.CH / 2 - l.CH
tx = x + l.CW / 2
s.waste = Matriarchy_Waste(x, y, self)
l.createText(s.waste, "ss")
l.createText(s.waste, "s")
y = c2 + l.CH / 2
s.talon = Matriarchy_Talon(x, y, self, max_rounds=VARIABLE_REDEALS)
l.createText(s.talon, "nn")
l.createText(s.talon, "n")
s.talon.texts.rounds = MfxCanvasText(self.canvas,
tx, y + l.YS, anchor="n",
font=self.app.getFont("canvas_default"))

View file

@ -167,7 +167,7 @@ class Montana(Game):
def createGame(self):
# create layout
l, s = Layout(self, XM=4), self.s
l, s = Layout(self, card_x_space=4), self.s
# set window
self.setSize(l.XM + self.RSTEP*l.XS, l.YM + 5*l.YS)

View file

@ -702,7 +702,7 @@ class DerLetzteMonarch(Game):
def createGame(self):
# create layout
l, s = Layout(self, XM=4), self.s
l, s = Layout(self, card_x_space=4), self.s
# set window
self.setSize(l.XM + 13*l.XS, l.YM + 5*l.YS)

View file

@ -161,7 +161,7 @@ class PasDeDeux(Game):
def createGame(self):
# create layout
l, s = Layout(self, XM=4), self.s
l, s = Layout(self, card_x_space=4), self.s
# set window
self.setSize(l.XM + 13*l.XS, l.YM + 5*l.YS)

View file

@ -108,12 +108,16 @@ class PictureGallery_Hint(AbstractHint):
if not self.hints:
for r in game.s.rows:
pile = r.getPile()
lp = len(pile)
lr = len(r.cards)
assert 1 <= lp <= lr
rpile = r.cards[ : (lr-lp) ] # remaining pile
if not pile or len(pile) != 1 or len(pile) == len(r.cards):
continue
base_score = 60000
# find a stack that would accept this card
for t in game.s.rows:
if t is not r and t.acceptsCards(r, pile):
if self.shallMovePile(r, t, pile, rpile):
score = base_score + 100 * (self.K - pile[0].rank)
self.addHint(score, 1, r, t)
break
@ -289,6 +293,10 @@ class PictureGallery(Game):
# // Great Wheel
# ************************************************************************/
class GreatWheel_Hint(PictureGallery_Hint):
shallMovePile = PictureGallery_Hint._cautiousShallMovePile
class GreatWheel_Foundation(PictureGallery_Foundation):
def acceptsCards(self, from_stack, cards):
if not PictureGallery_Foundation.acceptsCards(self, from_stack, cards):
@ -313,9 +321,9 @@ class GreatWheel_RowStack(BasicRowStack):
return self.game.app.images.getTalonBottom()
class GreatWheel(PictureGallery):
Hint_Class = GreatWheel_Hint
Foundation_Class = GreatWheel_Foundation
TableauStack_Classes = [
StackWrapper(PictureGallery_TableauStack, base_rank=2, max_cards=5, dir=2),
@ -325,7 +333,7 @@ class GreatWheel(PictureGallery):
Talon_Class = StackWrapper(WasteTalonStack, max_rounds=1)
def createGame(self):
PictureGallery.createGame(self, rows=2, waste=True, dir=2)
PictureGallery.createGame(self, waste=True)
def fillStack(self, stack):
if stack is self.s.waste and not stack.cards :

View file

@ -76,7 +76,7 @@ class PileOn(Game):
# set window
# (set size so that at least 4 cards are fully playable)
#w = max(2*l.XS, l.XS+(self.PLAYCARDS-1)*l.XOFFSET+2*l.XM)
w = l.XS+(self.PLAYCARDS-1)*l.XOFFSET+3*l.XM
w = l.XS+(self.PLAYCARDS-1)*l.XOFFSET+3*l.XOFFSET
twidth, theight = self.TWIDTH, int((self.NSTACKS-1)/self.TWIDTH+1)
self.setSize(l.XM+twidth*w, l.YM+theight*l.YS)

View file

@ -195,7 +195,7 @@ class Maze(Game):
def createGame(self):
# create layout
l, s = Layout(self, XM=4, YM=4), self.s
l, s = Layout(self, card_x_space=4, card_y_space=4), self.s
# set window
self.setSize(l.XM + 9*l.XS, l.YM + 6*l.YS)

View file

@ -271,7 +271,7 @@ class Concentration(Memory24):
def createGame(self):
# create layout
l, s = Layout(self, XM=4), self.s
l, s = Layout(self, card_x_space=4), self.s
# game extras
self.other_stack = None

View file

@ -288,7 +288,7 @@ class IdleAces(Game):
def createGame(self):
l, s = Layout(self), self.s
self.setSize(l.XM+8*l.XS, l.YM+4*l.YS)
self.setSize(l.XM+7*l.XS, l.YM+4*l.YS)
x, y = l.XM, l.YM
s.talon = WasteTalonStack(x, y, self, max_rounds=3)
@ -296,7 +296,7 @@ class IdleAces(Game):
x += l.XS
s.waste = WasteStack(x, y, self)
l.createText(s.waste, 'ss')
x0, y0 = l.XM+l.XS, l.YM
x0, y0 = l.XM+2*l.XS, l.YM
k = 0
for i, j in((2, 0), (0, 1.5), (4, 1.5), (2, 3)):
x, y = x0+i*l.XS, y0+j*l.YS

View file

@ -97,7 +97,7 @@ class UnionSquare(Game):
def createGame(self, rows=16):
# create layout
l, s = Layout(self, YM=18), self.s
l, s = Layout(self, card_y_space=20), self.s
# set window
self.setSize(l.XM + (5+rows/4)*l.XS, l.YM + 4*l.YS)

View file

@ -75,7 +75,7 @@ class Windmill(Game):
def createGame(self):
# create layout
l, s = Layout(self, XM=20), self.s
l, s = Layout(self, card_x_space=20), self.s
# set window
self.setSize(7*l.XS+l.XM, 5*l.YS+l.YM+l.YM)
@ -153,7 +153,7 @@ class NapoleonsTomb(Windmill):
def createGame(self):
# create layout
l, s = Layout(self, XM=20, YM=20), self.s
l, s = Layout(self, card_x_space=20, card_y_space=20), self.s
# set window
self.setSize(5*l.XS+l.XM, 3*l.YS+l.YM+l.YM)
@ -205,7 +205,7 @@ class Corners(Game):
def createGame(self, max_rounds=3):
# create layout
l, s = Layout(self, XM=20, YM=20), self.s
l, s = Layout(self, card_x_space=20, card_y_space=20), self.s
# set window
self.setSize(5*l.XS+l.XM, 4*l.YS+3*l.YM)

View file

@ -40,6 +40,7 @@ import sys
# PySol imports
from mfxutil import destruct, Struct, SubclassResponsibility
from pysoltk import MfxCanvasText
from resource import CSI
# /***********************************************************************
@ -65,7 +66,7 @@ class _LayoutStack:
class Layout:
def __init__(self, game, XM=10, YM=10, **kw):
def __init__(self, game, card_x_space=None, card_y_space=None, **kw):
self.game = game
self.canvas = self.game.canvas
self.size = None
@ -80,15 +81,51 @@ class Layout:
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.XM = XM # XMARGIN
self.YM = YM # YMARGIN
self.XS = self.CW + XM # XSPACE
self.YS = self.CH + YM # YSPACE
self.XOFFSET = images.CARD_XOFFSET
self.YOFFSET = images.CARD_YOFFSET
self.TEXT_HEIGHT = 30
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
self.TEXT_MARGIN = 10
##self.TEXT_HEIGHT = 30
font = game.app.getFont("canvas_default")
self.TEXT_HEIGHT = 18+font[1]
self.__dict__.update(kw)
if self.game.preview > 1:
if kw.has_key("XOFFSET"):
@ -116,26 +153,26 @@ class Layout:
if stack is not None:
x, y = stack.x, stack.y
if anchor == "n":
return (x + self.CW / 2, y - self.YM, "center", "%d")
return (x+self.CW/2, y-4, "s", "%d")
if anchor == "nn":
return (x + self.CW / 2, y - self.YM, "s", "%d")
return (x+self.CW/2, y-self.TEXT_MARGIN, "s", "%d")
if anchor == "s":
return (x + self.CW / 2, y + self.YS, "center", "%d")
return (x+self.CW/2, y+self.CH+4, "n", "%d")
if anchor == "ss":
return (x + self.CW / 2, y + self.YS, "n", "%d")
return (x+self.CW/2, y+self.CH+self.TEXT_MARGIN, "n", "%d")
if anchor == "nw":
return (x - self.XM, y, "ne", "%d")
return (x-self.TEXT_MARGIN, y, "ne", "%d")
if anchor == "sw":
return (x - self.XM, y + self.CH, "se", "%d")
return (x-self.TEXT_MARGIN, y+self.CH, "se", "%d")
f = "%2d"
if self.game.gameinfo.decks > 1:
f = "%3d"
if anchor == "ne":
return (x + self.XS, y, "nw", f)
return (x+self.CW+self.TEXT_MARGIN, y, "nw", f)
if anchor == "se":
return (x + self.XS, y + self.CH, "sw", f)
return (x+self.CW+self.TEXT_MARGIN, y+self.CH, "sw", f)
if anchor == "e":
return (x + self.XS, y + self.CH / 2, "w", f)
return (x+self.CW+self.TEXT_MARGIN, y+self.CH/2, "w", f)
raise Exception, anchor
def createText(self, stack, anchor, dx=0, dy=0, text_format=""):
@ -344,7 +381,7 @@ class Layout:
self.s.waste = s = S(x, y)
if texts:
# place text left of stack
s.setText(x - XM, y + CH, anchor="se", format="%3d")
s.setText(x - self.TEXT_MARGIN, y + CH, anchor="se", format="%3d")
# set window
self.size = (XM + (rows+decks)*XS, h)
@ -391,12 +428,12 @@ class Layout:
self.s.waste = s = S(x, y)
if texts:
# place text above stack
s.setText(x + CW / 2, y - YM, anchor="s")
s.setText(x + CW / 2, y - self.TEXT_MARGIN, anchor="s")
x = w - XS
self.s.talon = s = S(x, y)
if texts:
# place text above stack
s.setText(x + CW / 2, y - YM, anchor="s")
s.setText(x + CW / 2, y - self.TEXT_MARGIN, anchor="s")
# set window
self.size = (w, YM + h + YS)

View file

@ -46,4 +46,3 @@ if os.name == "mac":
TOP_SIZE = 10
TOP_TITLE = n_("Top 10")

View file

@ -1030,10 +1030,10 @@ class Stack:
##sx, sy = 0, 0
sx, sy = -images.SHADOW_XOFFSET, -images.SHADOW_YOFFSET
dx, dy = 0, 0
if self.game.app.opt.sticky_mouse:
if game.app.opt.sticky_mouse:
# return cards under mouse
dx = event.x - (x_offset+images.CARDW+sx)
dy = event.y - (y_offset+images.CARDH+sy)
dx = event.x - (x_offset+images.CARDW+sx) - game.canvas.xmargin
dy = event.y - (y_offset+images.CARDH+sy) - game.canvas.ymargin
if dx < 0: dx = 0
if dy < 0: dy = 0
for s in drag.shadows:
@ -1043,8 +1043,8 @@ class Stack:
for card in drag.cards:
card.tkraise()
card.moveBy(sx+dx, sy+dy)
if self.game.app.opt.dragcursor:
self.game.canvas.config(cursor=CURSOR_DRAG)
if game.app.opt.dragcursor:
game.canvas.config(cursor=CURSOR_DRAG)
# continue a drag operation
def keepDrag(self, event):

View file

@ -117,6 +117,8 @@ class MfxCanvas(Tkinter.Canvas):
self._text_color = "#000000"
self._stretch_bg_image = 0
self._text_items = []
#
self.xmargin, self.ymargin = 10, 10
# resize bg image
self.bind('<Configure>', lambda e: self.set_bg_image())
@ -155,8 +157,8 @@ class MfxCanvas(Tkinter.Canvas):
#sh = max(self.winfo_screenheight(), 768)
sw = max(self.winfo_width(), int(self.cget('width')))
sh = max(self.winfo_height(), int(self.cget('height')))
for x in range(0, sw - 1, iw):
for y in range(0, sh - 1, ih):
for x in range(-self.xmargin, sw, iw):
for y in range(-self.ymargin, sh, ih):
id = self._x_create("image", x, y, image=image, anchor="nw")
self.tag_lower(id) # also see tag_lower above
self.__tiles.append(id)
@ -198,8 +200,15 @@ class MfxCanvas(Tkinter.Canvas):
def setInitialSize(self, width, height):
##print 'setInitialSize:', width, height
self.config(width=width, height=height)
self.config(scrollregion=(0, 0, width, height))
if self.preview:
self.config(width=width, height=height)
self.config(scrollregion=(0, 0, width, height))
else:
# add margins
##dx, dy = 40, 40
dx, dy = self.xmargin, self.ymargin
self.config(width=dx+width+dx, height=dy+height+dy)
self.config(scrollregion=(-dx, -dy, width+dx, height+dy))
#
@ -226,7 +235,8 @@ class MfxCanvas(Tkinter.Canvas):
## for i in range(len(stack.cards)):
## if stack.cards[i].item.id in current:
## return i
x, y = event.x, event.y
x, y = event.x-self.xmargin, event.y-self.ymargin
##x, y = event.x, event.y
items = list(self.find_overlapping(x,y,x,y))
items.reverse()
for item in items: