annotate gamelib/toolbar.py @ 459:e9393970b5f6

picture icons for all counters
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Mon, 23 Nov 2009 20:12:03 +0000
parents 7e4ea53d8b10
children 7204c16ab64d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
1 import pygame
450
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
2 import xmlrpclib
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
3 from pgu import gui
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
4
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
5 import icons
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
6 import constants
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
7 import buildings
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
8 import equipment
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
9 import cursors
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
10 import engine
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
11
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
12 class OpaqueLabel(gui.Label):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
13 def __init__(self, value, **params):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
14 gui.Label.__init__(self, value, **params)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
15 if 'width' in params:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
16 self._width = params['width']
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
17 if 'height' in params:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
18 self._height = params['height']
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
19 self._set_size()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
20
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
21 def _set_size(self):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
22 width, height = self.font.size(self.value)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
23 width = getattr(self, '_width', width)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
24 height = getattr(self, '_height', height)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
25 self.style.width, self.style.height = width, height
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
26
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
27 def paint(self, s):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
28 s.fill(self.style.background)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
29 if self.style.align > 0:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
30 r = s.get_rect()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
31 w, _ = self.font.size(self.value)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
32 s = s.subsurface(r.move((r.w-w, 0)).clip(r))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
33 gui.Label.paint(self, s)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
34
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
35 def update_value(self, value):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
36 self.value = value
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
37 self._set_size()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
38 self.repaint()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
39
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
40 def mklabel(text="", **params):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
41 params.setdefault('color', constants.FG_COLOR)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
42 params.setdefault('width', constants.TOOLBAR_WIDTH/2)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
43 return OpaqueLabel(text, **params)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
44
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
45 def mkcountupdate(counter):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
46 def update_counter(self, value):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
47 getattr(self, counter).update_value("%s " % value)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
48 self.repaint()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
49 return update_counter
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
50
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
51 class BaseToolBar(gui.Table):
434
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
52 def __init__(self, gameboard, **params):
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
53 gui.Table.__init__(self, **params)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
54 self.group = gui.Group(name='base_toolbar', value=None)
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
55 self._next_tool_value = 0
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
56 self.gameboard = gameboard
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
57 self.cash_counter = mklabel(align=1)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
58 self.wood_counter = mklabel(align=1)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
59 self.chicken_counter = mklabel(align=1)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
60 self.egg_counter = mklabel(align=1)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
61 self.day_counter = mklabel(align=1)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
62 self.killed_foxes = mklabel(align=1)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
63 self.add_labels()
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
64
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
65 def add_labels(self):
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
66 self.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
67 self.td(gui.Spacer(self.rect.w/2, 0))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
68 self.td(gui.Spacer(self.rect.w/2, 0))
459
e9393970b5f6 picture icons for all counters
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 458
diff changeset
69 self.add_counter(icons.DAY_ICON, self.day_counter)
e9393970b5f6 picture icons for all counters
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 458
diff changeset
70 self.add_counter(icons.GROATS_ICON, self.cash_counter)
e9393970b5f6 picture icons for all counters
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 458
diff changeset
71 self.add_counter(icons.WOOD_ICON, self.wood_counter)
e9393970b5f6 picture icons for all counters
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 458
diff changeset
72 self.add_counter(icons.EGG_ICON, self.egg_counter)
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
73 self.add_counter(icons.CHKN_ICON, self.chicken_counter)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
74 self.add_counter(icons.KILLED_FOX, self.killed_foxes)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
75 self.add_spacer(5)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
76
434
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
77 def start_night(self):
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
78 self.clear_tool()
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
79 self._set_all_disabled(True)
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
80 self.fin_tool.widget = gui.basic.Label('Fast Forward')
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
81 self.fin_tool.resize()
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
82 self.fin_tool.disabled = False # Can always select this
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
83 self.fin_tool.focusable = True # Can always select this
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
84
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
85 def start_day(self):
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
86 self.clear_tool()
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
87 self._set_all_disabled(False)
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
88 self.fin_tool.widget = gui.basic.Label('Finished Day')
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
89 self.fin_tool.resize()
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
90
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
91 def _set_all_disabled(self, state):
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
92 """Sets the disabled flag on all the buttons in the toolbar"""
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
93 for td in self.widgets:
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
94 for widget in td.widgets:
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
95 if hasattr(widget, 'group'): # Tool
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
96 widget.disabled = state
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
97 widget.focusable = not state
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
98
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
99 def show_prices(self):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
100 """Popup dialog of prices"""
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
101 def make_box(text):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
102 style = {
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
103 'border' : 1
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
104 }
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
105 word = gui.Label(text, style=style)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
106 return word
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
107
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
108 def fix_widths(doc):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
109 """Loop through all the widgets in the doc, and set the
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
110 width of the labels to max + 10"""
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
111 # We need to do this because of possible font issues
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
112 max_width = 0
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
113 for thing in doc.widgets:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
114 if hasattr(thing, 'style'):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
115 # A label
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
116 if thing.style.width > max_width:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
117 max_width = thing.style.width
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
118 for thing in doc.widgets:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
119 if hasattr(thing, 'style'):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
120 thing.style.width = max_width + 10
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
121
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
122 tbl = gui.Table()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
123 tbl.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
124 doc = gui.Document(width=510)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
125 space = doc.style.font.size(" ")
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
126 for header in ['Item', 'Buy Price', 'Sell Price', 'Repair Price']:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
127 doc.add(make_box(header))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
128 doc.br(space[1])
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
129 for building in buildings.BUILDINGS:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
130 doc.add(make_box(building.NAME))
448
92e7a641b4a6 added units to price list
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 447
diff changeset
131 doc.add(make_box('%d planks' % building.BUY_PRICE))
92e7a641b4a6 added units to price list
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 447
diff changeset
132 doc.add(make_box('%d planks' % building.SELL_PRICE))
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
133 if building.BREAKABLE:
448
92e7a641b4a6 added units to price list
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 447
diff changeset
134 doc.add(make_box('%d planks' % building.REPAIR_PRICE))
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
135 else:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
136 doc.add(make_box('N/A'))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
137 doc.br(space[1])
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
138 for equip in equipment.EQUIPMENT:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
139 doc.add(make_box(equip.NAME))
448
92e7a641b4a6 added units to price list
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 447
diff changeset
140 doc.add(make_box('%d groats' % equip.BUY_PRICE))
92e7a641b4a6 added units to price list
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 447
diff changeset
141 doc.add(make_box('%d groats' % equip.SELL_PRICE))
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
142 doc.add(make_box('N/A'))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
143 doc.br(space[1])
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
144
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
145 fix_widths(doc)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
146 for word in "Damaged equipment or buildings will be sold for" \
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
147 " less than the sell price.".split():
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
148 doc.add(gui.Label(word))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
149 doc.space(space)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
150 close_button = gui.Button("Close")
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
151 tbl.td(doc)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
152 tbl.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
153 tbl.td(close_button, align=1)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
154 dialog = gui.Dialog(gui.Label('Price Reference'), tbl)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
155 close_button.connect(gui.CLICK, dialog.close)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
156 dialog.open()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
157
444
feb9b7a23ef2 Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents: 434
diff changeset
158 def save_game(self):
feb9b7a23ef2 Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents: 434
diff changeset
159 """Save game 'dialog'."""
446
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
160 dialog = gui.FileDialog("Save game ...", button_txt="Save")
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
161
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
162 def save():
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
163 if dialog.value is None:
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
164 return
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
165 data = self.gameboard.save_game()
450
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
166 xml = xmlrpclib.dumps((data,), "foxassault")
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
167 try:
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
168 open(dialog.value, "wb").write(xml)
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
169 except Exception, e:
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
170 print "Failed to save game: %s" % (e,)
446
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
171
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
172 dialog.connect(gui.CHANGE, save)
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
173 dialog.open()
444
feb9b7a23ef2 Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents: 434
diff changeset
174
feb9b7a23ef2 Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents: 434
diff changeset
175 def load_game(self):
feb9b7a23ef2 Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents: 434
diff changeset
176 """Load game 'dialog'."""
446
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
177 dialog = gui.FileDialog("Load game ...", button_txt="Load")
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
178
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
179 def restore():
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
180 if dialog.value is None:
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
181 return
450
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
182 try:
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
183 xml = open(dialog.value, "rb").read()
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
184 params, methodname = xmlrpclib.loads(xml)
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
185 if methodname != "foxassault":
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
186 raise ValueError("Bad XML save game.")
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
187 data = params[0]
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
188 except Exception, e:
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
189 "Failed to load game: %s" % (e,)
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
190 return
5d74d0e4a4cc Switch to XML (RPC) for save game encoding.
Simon Cross <hodgestar@gmail.com>
parents: 448
diff changeset
191
446
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
192 self.gameboard.restore_game(data)
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
193
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
194 dialog.connect(gui.CHANGE, restore)
0c523d384681 Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents: 444
diff changeset
195 dialog.open()
444
feb9b7a23ef2 Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents: 434
diff changeset
196
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
197 update_cash_counter = mkcountupdate('cash_counter')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
198 update_wood_counter = mkcountupdate('wood_counter')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
199 update_fox_counter = mkcountupdate('killed_foxes')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
200 update_chicken_counter = mkcountupdate('chicken_counter')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
201 update_egg_counter = mkcountupdate('egg_counter')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
202 update_day_counter = mkcountupdate('day_counter')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
203
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
204 def add_spacer(self, height):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
205 self.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
206 self.td(gui.Spacer(0, height), colspan=2)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
207
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
208 def add_heading(self, text):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
209 self.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
210 self.td(mklabel(text), colspan=2)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
211
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
212 def add_tool_button(self, text, tool, price=None, cursor=None):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
213 if price is not None:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
214 text = "%s (%s)" % (text, price)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
215 self.add_tool(text, lambda: self.gameboard.set_selected_tool(tool,
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
216 cursor))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
217
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
218 def add_tool(self, text, func):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
219 label = gui.basic.Label(text)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
220 value = self._next_tool_value
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
221 self._next_tool_value += 1
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
222 tool = gui.Tool(self.group, label, value, width=self.rect.w, style={"padding_left": 0})
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
223 tool.connect(gui.CLICK, func)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
224 self.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
225 self.td(tool, align=-1, colspan=2)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
226 return tool
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
227
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
228 def clear_tool(self):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
229 self.group.value = None
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
230 for item in self.group.widgets:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
231 item.pcls = ""
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
232
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
233 def add_counter(self, icon, label):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
234 self.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
235 self.td(icon, width=self.rect.w/2)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
236 self.td(label, width=self.rect.w/2)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
237
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
238 def resize(self, width=None, height=None):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
239 width, height = gui.Table.resize(self, width, height)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
240 width = constants.TOOLBAR_WIDTH
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
241 return width, height
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
242
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
243 class DefaultToolBar(BaseToolBar):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
244 def __init__(self, gameboard, **params):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
245 BaseToolBar.__init__(self, gameboard, **params)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
246 self.group = gui.Group(name='default_toolbar', value=None)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
247 self.make_toolbar()
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
248
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
249 def make_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
250 self.add_tool_button("Select chicken", constants.TOOL_SELECT_CHICKENS,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
251 None, cursors.cursors['select'])
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
252
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
253 self.add_spacer(5)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
254
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
255 self.add_tool('Equip chickens', self.add_equipment_toolbar)
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
256
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
257 self.add_tool_button("Move chickens", constants.TOOL_PLACE_ANIMALS,
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
258 None, cursors.cursors['select'])
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
259
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
260 self.add_tool('Sell stuff', self.add_sell_toolbar)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
261
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
262 self.add_spacer(5)
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
263
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
264 self.add_heading("Buildings")
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
265
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
266 self.add_tool('Buy building', self.add_building_toolbar)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
267
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
268 self.add_tool_button("Sell building", constants.TOOL_SELL_BUILDING,
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
269 None, cursors.cursors['sell'])
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
270
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
271 self.add_tool_button("Repair", constants.TOOL_REPAIR_BUILDING, None, cursors.cursors['repair'])
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
272
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
273 self.add_spacer(5)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
274 self.add_heading("Help")
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
275 self.add_tool("Price Reference", self.show_prices)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
276
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
277 self.add_spacer(5)
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
278 self.add_heading("Game")
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
279 self.add_tool("Save Game", self.save_game)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
280 self.add_tool("Load Game", self.load_game)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
281
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
282 self.add_heading(" ")
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
283 # Dear pgu, is there a better way to get the current height?
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
284 _cur_width, cur_height = self.resize()
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
285 self.add_spacer(570-cur_height)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
286 self.fin_tool = self.add_tool("Finished Day", self.day_done)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
287
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
288 def add_building_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
289 self.gameboard.change_toolbar(BuildingToolBar(self.gameboard,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
290 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
291
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
292 def add_sell_toolbar(self):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
293 self.gameboard.change_toolbar(SellToolBar(self.gameboard,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
294 width=self.style.width))
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
295
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
296 def add_equipment_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
297 self.gameboard.change_toolbar(EquipmentToolBar(self.gameboard,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
298 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
299
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
300 def day_done(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
301 if self.gameboard.day:
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
302 pygame.event.post(engine.START_NIGHT)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
303 else:
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
304 pygame.event.post(engine.FAST_FORWARD)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
305
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
306 class BuildingToolBar(BaseToolBar):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
307 def __init__(self, gameboard, **params):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
308 BaseToolBar.__init__(self, gameboard, **params)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
309 self.group = gui.Group(name='building_toolbar', value=None)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
310 self.make_toolbar()
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
311
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
312 def make_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
313 self.gameboard.set_cursor(cursors.cursors['arrow'], None)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
314 for building_cls in buildings.BUILDINGS:
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
315 self.add_tool_button(building_cls.NAME.title(), building_cls,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
316 None, cursors.cursors.get('build', None))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
317 self.add_spacer(15)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
318 self.add_tool('Done', self.add_default_toolbar)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
319
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
320 def add_default_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
321 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
322 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
323
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
324 class EquipmentToolBar(BaseToolBar):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
325 def __init__(self, gameboard, **params):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
326 BaseToolBar.__init__(self, gameboard, **params)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
327 self.group = gui.Group(name='building_toolbar', value=None)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
328 self.make_toolbar()
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
329
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
330 def make_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
331 self.gameboard.set_cursor(cursors.cursors['arrow'], None)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
332 for equipment_cls in equipment.EQUIPMENT:
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
333 self.add_tool_button(equipment_cls.NAME.title(),
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
334 equipment_cls,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
335 equipment_cls.BUY_PRICE,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
336 cursors.cursors.get('buy', None))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
337 self.add_spacer(15)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
338 self.add_tool('Done', self.add_default_toolbar)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
339
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
340 def add_default_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
341 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
342 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
343
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
344 class SellToolBar(BaseToolBar):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
345 def __init__(self, gameboard, **params):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
346 BaseToolBar.__init__(self, gameboard, **params)
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
347 self.group = gui.Group(name='building_toolbar', value=None)
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
348 self.make_toolbar()
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
349
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
350 def make_toolbar(self):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
351 self.gameboard.set_cursor(cursors.cursors['arrow'], None)
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
352
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
353 self.add_heading("Sell ...")
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
354 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
355 self.gameboard.level.sell_price_chicken, cursors.cursors['sell'])
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
356 self.add_tool_button("Egg", constants.TOOL_SELL_EGG,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
357 self.gameboard.level.sell_price_egg, cursors.cursors['sell'])
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
358 self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
359 None, cursors.cursors['sell'])
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
360 self.add_spacer(15)
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
361 self.add_tool('Done', self.add_default_toolbar)
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
362
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
363 def add_default_toolbar(self):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
364 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
365 width=self.style.width))
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
366