Mercurial > rinkhals
annotate gamelib/toolbar.py @ 447:f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 19:58:49 +0000 |
parents | 0c523d384681 |
children | 92e7a641b4a6 |
rev | line source |
---|---|
433
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
1 import pygame |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
2 from pgu import gui |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
3 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
4 import icons |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
5 import constants |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
6 import buildings |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
7 import equipment |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
8 import cursors |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
9 import engine |
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
|
10 try: |
feb9b7a23ef2
Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents:
434
diff
changeset
|
11 import json |
feb9b7a23ef2
Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents:
434
diff
changeset
|
12 except ImportError: |
feb9b7a23ef2
Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents:
434
diff
changeset
|
13 import simplejson as json |
433
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
14 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
15 class OpaqueLabel(gui.Label): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
16 def __init__(self, value, **params): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
17 gui.Label.__init__(self, value, **params) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
18 if 'width' in params: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
19 self._width = params['width'] |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
20 if 'height' in params: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
21 self._height = params['height'] |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
22 self._set_size() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
23 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
24 def _set_size(self): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
25 width, height = self.font.size(self.value) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
26 width = getattr(self, '_width', width) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
27 height = getattr(self, '_height', height) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
28 self.style.width, self.style.height = width, height |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
29 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
30 def paint(self, s): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
31 s.fill(self.style.background) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
32 if self.style.align > 0: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
33 r = s.get_rect() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
34 w, _ = self.font.size(self.value) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
35 s = s.subsurface(r.move((r.w-w, 0)).clip(r)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
36 gui.Label.paint(self, s) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
37 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
38 def update_value(self, value): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
39 self.value = value |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
40 self._set_size() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
41 self.repaint() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
42 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
43 def mklabel(text="", **params): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
44 params.setdefault('color', constants.FG_COLOR) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
45 params.setdefault('width', constants.TOOLBAR_WIDTH/2) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
46 return OpaqueLabel(text, **params) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
47 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
48 def mkcountupdate(counter): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
49 def update_counter(self, value): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
50 getattr(self, counter).update_value("%s " % value) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
51 self.repaint() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
52 return update_counter |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
53 |
447
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
54 class BaseToolBar(gui.Table): |
434
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
55 def __init__(self, gameboard, **params): |
433
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
56 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
|
57 self.group = gui.Group(name='base_toolbar', value=None) |
433
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
58 self._next_tool_value = 0 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
59 self.gameboard = gameboard |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
60 self.cash_counter = mklabel(align=1) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
61 self.wood_counter = mklabel(align=1) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
62 self.chicken_counter = mklabel(align=1) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
63 self.egg_counter = mklabel(align=1) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
64 self.day_counter = mklabel(align=1) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
65 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
|
66 self.add_labels() |
433
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
67 |
447
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
68 def add_labels(self): |
433
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
69 self.tr() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
70 self.td(gui.Spacer(self.rect.w/2, 0)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
71 self.td(gui.Spacer(self.rect.w/2, 0)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
72 self.add_counter(mklabel("Day:"), self.day_counter) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
73 self.add_counter(mklabel("Groats:"), self.cash_counter) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
74 self.add_counter(mklabel("Planks:"), self.wood_counter) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
75 self.add_counter(mklabel("Eggs:"), self.egg_counter) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
76 self.add_counter(icons.CHKN_ICON, self.chicken_counter) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
77 self.add_counter(icons.KILLED_FOX, self.killed_foxes) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
78 self.add_spacer(5) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
79 |
434
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
80 def start_night(self): |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
81 self.clear_tool() |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
82 self._set_all_disabled(True) |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
83 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
|
84 self.fin_tool.resize() |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
85 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
|
86 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
|
87 |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
88 def start_day(self): |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
89 self.clear_tool() |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
90 self._set_all_disabled(False) |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
91 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
|
92 self.fin_tool.resize() |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
93 |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
94 def _set_all_disabled(self, state): |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
95 """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
|
96 for td in self.widgets: |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
97 for widget in td.widgets: |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
98 if hasattr(widget, 'group'): # Tool |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
99 widget.disabled = state |
f2a55e5e24db
Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents:
433
diff
changeset
|
100 widget.focusable = not state |
433
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
101 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
102 def show_prices(self): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
103 """Popup dialog of prices""" |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
104 def make_box(text): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
105 style = { |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
106 'border' : 1 |
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 word = gui.Label(text, style=style) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
109 return word |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
110 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
111 def fix_widths(doc): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
112 """Loop through all the widgets in the doc, and set the |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
113 width of the labels to max + 10""" |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
114 # We need to do this because of possible font issues |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
115 max_width = 0 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
116 for thing in doc.widgets: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
117 if hasattr(thing, 'style'): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
118 # A label |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
119 if thing.style.width > max_width: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
120 max_width = thing.style.width |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
121 for thing in doc.widgets: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
122 if hasattr(thing, 'style'): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
123 thing.style.width = max_width + 10 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
124 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
125 tbl = gui.Table() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
126 tbl.tr() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
127 doc = gui.Document(width=510) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
128 space = doc.style.font.size(" ") |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
129 for header in ['Item', 'Buy Price', 'Sell Price', 'Repair Price']: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
130 doc.add(make_box(header)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
131 doc.br(space[1]) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
132 for building in buildings.BUILDINGS: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
133 doc.add(make_box(building.NAME)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
134 doc.add(make_box('%d' % building.BUY_PRICE)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
135 doc.add(make_box('%d' % building.SELL_PRICE)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
136 if building.BREAKABLE: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
137 doc.add(make_box('%d' % building.REPAIR_PRICE)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
138 else: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
139 doc.add(make_box('N/A')) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
140 doc.br(space[1]) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
141 for equip in equipment.EQUIPMENT: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
142 doc.add(make_box(equip.NAME)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
143 doc.add(make_box('%d' % equip.BUY_PRICE)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
144 doc.add(make_box('%d' % equip.SELL_PRICE)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
145 doc.add(make_box('N/A')) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
146 doc.br(space[1]) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
147 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
148 fix_widths(doc) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
149 for word in "Damaged equipment or buildings will be sold for" \ |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
150 " less than the sell price.".split(): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
151 doc.add(gui.Label(word)) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
152 doc.space(space) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
153 close_button = gui.Button("Close") |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
154 tbl.td(doc) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
155 tbl.tr() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
156 tbl.td(close_button, align=1) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
157 dialog = gui.Dialog(gui.Label('Price Reference'), tbl) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
158 close_button.connect(gui.CLICK, dialog.close) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
159 dialog.open() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
160 |
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
|
161 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
|
162 """Save game 'dialog'.""" |
446
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
163 dialog = gui.FileDialog("Save game ...", button_txt="Save") |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
164 |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
165 def save(): |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
166 if dialog.value is None: |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
167 return |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
168 data = self.gameboard.save_game() |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
169 open(dialog.value, "wb").write(json.dumps(data)) |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
170 |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
171 dialog.connect(gui.CHANGE, save) |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
172 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
|
173 |
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 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
|
175 """Load game 'dialog'.""" |
446
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
176 dialog = gui.FileDialog("Load game ...", button_txt="Load") |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
177 |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
178 def restore(): |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
179 if dialog.value is None: |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
180 return |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
181 data = json.loads(open(dialog.value, "rb").read()) |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
182 self.gameboard.restore_game(data) |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
183 |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
184 dialog.connect(gui.CHANGE, restore) |
0c523d384681
Basic load and save dialogs.
Simon Cross <hodgestar@gmail.com>
parents:
444
diff
changeset
|
185 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
|
186 |
433
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
187 update_cash_counter = mkcountupdate('cash_counter') |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
188 update_wood_counter = mkcountupdate('wood_counter') |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
189 update_fox_counter = mkcountupdate('killed_foxes') |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
190 update_chicken_counter = mkcountupdate('chicken_counter') |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
191 update_egg_counter = mkcountupdate('egg_counter') |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
192 update_day_counter = mkcountupdate('day_counter') |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
193 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
194 def add_spacer(self, height): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
195 self.tr() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
196 self.td(gui.Spacer(0, height), colspan=2) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
197 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
198 def add_heading(self, text): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
199 self.tr() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
200 self.td(mklabel(text), colspan=2) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
201 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
202 def add_tool_button(self, text, tool, price=None, cursor=None): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
203 if price is not None: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
204 text = "%s (%s)" % (text, price) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
205 self.add_tool(text, lambda: self.gameboard.set_selected_tool(tool, |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
206 cursor)) |
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_tool(self, text, func): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
209 label = gui.basic.Label(text) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
210 value = self._next_tool_value |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
211 self._next_tool_value += 1 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
212 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
|
213 tool.connect(gui.CLICK, func) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
214 self.tr() |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
215 self.td(tool, align=-1, colspan=2) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
216 return tool |
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 clear_tool(self): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
219 self.group.value = None |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
220 for item in self.group.widgets: |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
221 item.pcls = "" |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
222 |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
223 def add_counter(self, icon, label): |
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(icon, width=self.rect.w/2) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
226 self.td(label, width=self.rect.w/2) |
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 resize(self, width=None, height=None): |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
229 width, height = gui.Table.resize(self, width, height) |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
230 width = constants.TOOLBAR_WIDTH |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
231 return width, height |
8643893635e7
Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
232 |
447
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
233 class DefaultToolBar(BaseToolBar): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
234 def __init__(self, gameboard, **params): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
235 BaseToolBar.__init__(self, gameboard, **params) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
236 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
|
237 self.make_toolbar() |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
238 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
239 def make_toolbar(self): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
240 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
|
241 None, cursors.cursors['select']) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
242 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
243 self.add_spacer(5) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
244 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
245 self.add_heading("Sell ...") |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
246 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN, |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
247 self.gameboard.level.sell_price_chicken, cursors.cursors['sell']) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
248 self.add_tool_button("Egg", constants.TOOL_SELL_EGG, |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
249 self.gameboard.level.sell_price_egg, cursors.cursors['sell']) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
250 self.add_tool_button("Building", constants.TOOL_SELL_BUILDING, |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
251 None, cursors.cursors['sell']) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
252 self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT, |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
253 None, cursors.cursors['sell']) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
254 self.add_spacer(5) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
255 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
256 self.add_heading(" ") |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
257 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
258 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
|
259 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
260 self.add_heading("For selection, ...") |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
261 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
262 self.add_tool('Buy equipment', self.add_equipment_toolbar) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
263 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
264 self.add_tool_button("Move selected hen", constants.TOOL_PLACE_ANIMALS, |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
265 None, cursors.cursors['select']) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
266 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
267 self.add_heading(" ") |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
268 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
|
269 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
270 self.add_heading("Help") |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
271 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
|
272 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
273 self.add_spacer(5) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
274 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
|
275 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
|
276 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
277 self.add_heading(" ") |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
278 self.add_spacer(10) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
279 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
|
280 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
281 def add_building_toolbar(self): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
282 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
|
283 width=self.style.width)) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
284 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
285 def add_equipment_toolbar(self): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
286 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
|
287 width=self.style.width)) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
288 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
289 def day_done(self): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
290 if self.gameboard.day: |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
291 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
|
292 else: |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
293 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
|
294 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
295 class BuildingToolBar(BaseToolBar): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
296 def __init__(self, gameboard, **params): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
297 BaseToolBar.__init__(self, gameboard, **params) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
298 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
|
299 self.make_toolbar() |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
300 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
301 def make_toolbar(self): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 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
|
306 self.add_spacer(15) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
307 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
|
308 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
309 def add_default_toolbar(self): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
310 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
|
311 width=self.style.width)) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
312 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
313 class EquipmentToolBar(BaseToolBar): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
314 def __init__(self, gameboard, **params): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
315 BaseToolBar.__init__(self, gameboard, **params) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
316 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
|
317 self.make_toolbar() |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
318 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
319 def make_toolbar(self): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 equipment_cls, |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
324 equipment_cls.BUY_PRICE, |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
325 cursors.cursors.get('buy', None)) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
326 self.add_spacer(15) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
327 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
|
328 |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
329 def add_default_toolbar(self): |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
330 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
|
331 width=self.style.width)) |
f04a2490c35f
The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents:
446
diff
changeset
|
332 |