Implemented game info, play move, hover
This commit is contained in:
parent
8976349450
commit
f6d89e7ae2
|
@ -272,10 +272,10 @@ class Goban:
|
|||
code = 'w'
|
||||
|
||||
if pos == self.last_move:
|
||||
code = code + 'T'
|
||||
code += 'C'
|
||||
|
||||
if pos == self.ko:
|
||||
code = code + 'C'
|
||||
code += 'C'
|
||||
|
||||
return code
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 178 B |
|
@ -72,6 +72,8 @@ class GoGame(gtk.HBox):
|
|||
self.pack_start(self.board_area)
|
||||
self.pack_end(info_box, expand=False)
|
||||
|
||||
self.update_info()
|
||||
|
||||
|
||||
def do_hover(self, widget, event):
|
||||
x = event.x
|
||||
|
@ -87,12 +89,25 @@ class GoGame(gtk.HBox):
|
|||
if max(row,col) < board_size:
|
||||
if self.goban._real_pos((row,col)) != self.goban.hover:
|
||||
self.goban.set_hover((row,col))
|
||||
self.board_area.queue_draw()
|
||||
else:
|
||||
self.goban.clear_hover()
|
||||
self.board_area.queue_draw()
|
||||
|
||||
|
||||
def do_play(self, widget, event):
|
||||
print 'GoGame:do_play(): stub'
|
||||
x = event.x
|
||||
y = event.y
|
||||
width, height = widget.size_request()
|
||||
size = min(width, height)
|
||||
board_size = self.goban.board_size
|
||||
inc = size / board_size
|
||||
|
||||
row = int(y / inc)
|
||||
col = int(x / inc)
|
||||
|
||||
self.goban.play_move((row,col))
|
||||
self.update_info()
|
||||
|
||||
|
||||
# fixme: create a backbuffer pixmap and draw to *that* when we need to update
|
||||
|
@ -116,19 +131,42 @@ class GoGame(gtk.HBox):
|
|||
col = i % board_size
|
||||
drawable.draw_pixbuf(gc, img, 0, 0, inc * col, inc * row, inc, inc)
|
||||
|
||||
if i == self.goban.hover:
|
||||
if self.goban.to_move == goban.Goban.BLACK:
|
||||
code = 'bH'
|
||||
elif self.goban.to_move == goban.Goban.WHITE:
|
||||
code = 'wH'
|
||||
|
||||
base_img = GoGame.img_res[code]
|
||||
img = base_img.scale_simple(inc, inc, gtk.gdk.INTERP_BILINEAR)
|
||||
drawable.draw_pixbuf(gc, img, 0, 0, inc * col, inc * row, inc, inc)
|
||||
|
||||
|
||||
|
||||
|
||||
def on_pass(self, widget):
|
||||
print 'GoGame.on_pass(): stub'
|
||||
self.goban.pass_move()
|
||||
self.update_info()
|
||||
|
||||
|
||||
def on_resign(self, widget):
|
||||
print 'GoGame.on_resign(): stub'
|
||||
self.goban.resign()
|
||||
self.update_info()
|
||||
|
||||
|
||||
# fixme: Add a widget to show the outcome
|
||||
def update_info(self):
|
||||
if self.goban.to_move == goban.Goban.BLACK:
|
||||
move = 'Black'
|
||||
elif self.goban.to_move == goban.Goban.WHITE:
|
||||
move = 'White'
|
||||
else:
|
||||
move = 'None'
|
||||
self.to_move_value.set_text(move)
|
||||
self.black_cap_value.set_text(str(self.goban.black_captures))
|
||||
self.white_cap_value.set_text(str(self.goban.white_captures))
|
||||
|
||||
|
||||
# pixmap.draw_pixbuf(None, pixbuf, 0, 0, x, y, -1, -1, gtk.gdk.RGB_DITHER_NONE, 0, 0)
|
||||
|
||||
|
||||
|
||||
def _magnitude(vector):
|
||||
|
@ -142,26 +180,23 @@ def _build_img_res():
|
|||
triangle = _load_png('go_t.png')
|
||||
circle = _load_png('go_c.png')
|
||||
|
||||
ret['w'] = _load_png('go_w.png')
|
||||
ret['wT'] = _load_png('go_w.png')
|
||||
ret['wH'] = _load_png('go_w.png', 128)
|
||||
ret['wH'] = _load_png('go_wH.png')
|
||||
ret['bH'] = _load_png('go_bH.png')
|
||||
|
||||
ret['wT'] = _load_png('go_w.png')
|
||||
width = ret['wT'].get_width()
|
||||
height = ret['wT'].get_height()
|
||||
triangle.composite(ret['wT'], 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, 255)
|
||||
|
||||
ret['b'] = _load_png('go_b.png')
|
||||
ret['bT'] = _load_png('go_b.png')
|
||||
ret['bH'] = _load_png('go_b.png', 128)
|
||||
|
||||
width = ret['bT'].get_width()
|
||||
height = ret['bT'].get_height()
|
||||
triangle.composite(ret['bT'], 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, 255)
|
||||
|
||||
for d in ('u', 'd', 'l', 'r', 'm', 'dl', 'dr', 'ul', 'ur', 'h'):
|
||||
for d in ('u', 'd', 'l', 'r', 'm', 'dl', 'dr', 'ul', 'ur', 'h', 'w', 'b'):
|
||||
ret[d] = _load_png('go_' + d + '.png')
|
||||
ret[d + 'C'] = _load_png('go_' + d + '.png')
|
||||
|
||||
ret[d + 'C'] = _load_png('go_' + d + '.png')
|
||||
width = ret[d + 'C'].get_width()
|
||||
height = ret[d + 'C'].get_height()
|
||||
circle.composite(ret[d + 'C'], 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, 255)
|
||||
|
@ -169,36 +204,35 @@ def _build_img_res():
|
|||
return ret
|
||||
|
||||
|
||||
def _load_png(name, alpha=None):
|
||||
def _load_png(name):
|
||||
""" Load image and return image object"""
|
||||
fullname = os.path.join('ui/res/', name)
|
||||
image = gtk.gdk.pixbuf_new_from_file(fullname)
|
||||
|
||||
if alpha is not None:
|
||||
image = _set_alpha(image, alpha)
|
||||
# if alpha is not None:
|
||||
# image = _set_alpha(image, alpha)
|
||||
|
||||
return image
|
||||
|
||||
|
||||
# _trans_png = None
|
||||
|
||||
_trans_png = None
|
||||
# def _set_alpha(image, alpha):
|
||||
# """
|
||||
# change_opacity - changes the opacity of pixbuf by combining
|
||||
# the pixbuf with a pixbuf derived from a transparent .png
|
||||
|
||||
def _set_alpha(image, alpha):
|
||||
"""
|
||||
change_opacity - changes the opacity of pixbuf by combining
|
||||
the pixbuf with a pixbuf derived from a transparent .png
|
||||
# returns: a pixbuf of image made alpha more composite
|
||||
# """
|
||||
|
||||
arguments:
|
||||
alpha -
|
||||
returns: a pixbuf with the transperancy
|
||||
"""
|
||||
# global _trans_png
|
||||
|
||||
global _trans_png
|
||||
# if _trans_png == None:
|
||||
# _trans_png = _load_png('transparent.png')
|
||||
|
||||
if _trans_png is None:
|
||||
_trans_png = _load_png('transparent.png')
|
||||
# width = image.get_width()
|
||||
# height = image.get_height()
|
||||
|
||||
width = image.get_width()
|
||||
height = image.get_height()
|
||||
_trans_png = _trans_png.scale_simple(width,height,gtk.gdk.INTERP_NEAREST)
|
||||
image.composite(_trans_png, 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, alpha)
|
||||
# trans= _trans_png.scale_simple(width,height,gtk.gdk.INTERP_NEAREST)
|
||||
# trans.composite(image, 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, alpha)
|
||||
# return trans
|
||||
|
|
Loading…
Reference in New Issue
Block a user