annotate gamelib/toolbar.py @ 569:3ec614e6fd4a

Replace monolithic sell equipment tool with a tool for each type of equipment.
author Simon Cross <hodgestar@gmail.com>
date Sat, 28 Nov 2009 19:59:46 +0000
parents e813365af567
children 40eee9e1246c
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
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
486
8897a436a8cb Factor out save game logic and (new, simplified) dialogs into their own module. Add preferences folder to concept to config. Save games under preferences folder.
Simon Cross <hodgestar@gmail.com>
parents: 484
diff changeset
9 import savegame
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
10 import misc
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
11
472
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
12 class RinkhalsTool(gui.Tool):
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
13 def __init__(self, group, label, value, func, **params):
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
14 gui.Tool.__init__(self, group, label, value, **params)
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
15 self.func = func
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
16
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
17 def click(self):
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
18 gui.Tool.click(self)
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
19 if not self.func():
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
20 # Don't hightlight if the function says so
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
21 self.group.value = None
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
22
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
23 class OpaqueLabel(gui.Label):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
24 def __init__(self, value, **params):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
25 gui.Label.__init__(self, value, **params)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
26 if 'width' in params:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
27 self._width = params['width']
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
28 if 'height' in params:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
29 self._height = params['height']
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
30 self._set_size()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
31
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
32 def _set_size(self):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
33 width, height = self.font.size(self.value)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
34 width = getattr(self, '_width', width)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
35 height = getattr(self, '_height', height)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
36 self.style.width, self.style.height = width, height
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 paint(self, s):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
39 s.fill(self.style.background)
545
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
40 r = s.get_rect()
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
41 w, _ = self.font.size(self.value)
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
42 if self.style.align > 0: # Right align
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
43 s = s.subsurface(r.move((r.w-w, 0)).clip(r))
545
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
44 elif self.style.align == 0: # Centre align
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
45 s = s.subsurface(r.move(((r.w-w)/2, 0)).clip(r))
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
46 else: # Left align
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
47 pass
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
48 gui.Label.paint(self, s)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
49
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
50 def update_value(self, value):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
51 self.value = value
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
52 self._set_size()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
53 self.repaint()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
54
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
55 def mklabel(text="", **params):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
56 params.setdefault('color', constants.FG_COLOR)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
57 params.setdefault('width', constants.TOOLBAR_WIDTH/2)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
58 return OpaqueLabel(text, **params)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
59
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
60 def mkcountupdate(counter):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
61 def update_counter(self, value):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
62 getattr(self, counter).update_value("%s " % value)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
63 self.repaint()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
64 return update_counter
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
65
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
66 class BaseToolBar(gui.Table):
483
25e8c57189c3 toggling move/select from subtoolbar no longer crashes
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 482
diff changeset
67
25e8c57189c3 toggling move/select from subtoolbar no longer crashes
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 482
diff changeset
68 IS_DEFAULT = False
503
4c281ce4fc5f Make MOVE_SELECTED_PERMITTED default, as seems the right thing
Neil Muller <drnlmuller@gmail.com>
parents: 494
diff changeset
69 MOVE_SELECT_PERMITTED = True
483
25e8c57189c3 toggling move/select from subtoolbar no longer crashes
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 482
diff changeset
70
434
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
71 def __init__(self, gameboard, **params):
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
72 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
73 self.group = gui.Group(name='base_toolbar', value=None)
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
74 self._next_tool_value = 0
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
75 self.gameboard = gameboard
545
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
76 self.cash_counter = mklabel(align=0)
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
77 self.wood_counter = mklabel(align=0)
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
78 self.chicken_counter = mklabel(align=0)
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
79 self.egg_counter = mklabel(align=0)
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
80 self.day_counter = mklabel(align=0)
56a3a3f54e3d Centre counter values, by means of the power of MATHS!
Jeremy Thurgood <firxen@gmail.com>
parents: 544
diff changeset
81 self.killed_foxes = mklabel(align=0)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
82 self.add_labels()
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
83
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
84 def add_labels(self):
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
85 self.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
86 self.td(gui.Spacer(self.rect.w/2, 0))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
87 self.td(gui.Spacer(self.rect.w/2, 0))
544
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
88 self._counter_col = 0
459
e9393970b5f6 picture icons for all counters
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 458
diff changeset
89 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
90 self.add_counter(icons.WOOD_ICON, self.wood_counter)
544
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
91 self.add_counter(icons.CHKN_ICON, self.chicken_counter)
459
e9393970b5f6 picture icons for all counters
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 458
diff changeset
92 self.add_counter(icons.EGG_ICON, self.egg_counter)
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
93 self.add_counter(icons.KILLED_FOX, self.killed_foxes)
544
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
94 self.add_counter(icons.DAY_ICON, self.day_counter)
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
95 self.add_spacer(5)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
96
434
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
97 def start_night(self):
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
98 self.clear_tool()
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
99 self._set_all_disabled(True)
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
100 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
101 self.fin_tool.resize()
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
102 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
103 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
104
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
105 def start_day(self):
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
106 self.clear_tool()
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
107 self._set_all_disabled(False)
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
108 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
109 self.fin_tool.resize()
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
110
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
111 def _set_all_disabled(self, state):
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
112 """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
113 for td in self.widgets:
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
114 for widget in td.widgets:
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
115 if hasattr(widget, 'group'): # Tool
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
116 widget.disabled = state
f2a55e5e24db Disable non-selectable toolbar widgets at night
Neil Muller <drnlmuller@gmail.com>
parents: 433
diff changeset
117 widget.focusable = not state
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
118
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
119 def show_prices(self):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
120 """Popup dialog of prices"""
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']:
534
d16ed2a8a33e Make price and control reference dialogs a little shinier.
Simon Cross <hodgestar@gmail.com>
parents: 529
diff changeset
127 doc.add(misc.make_box("<b>%s</b>" % header, markup=True))
433
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:
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
130 doc.add(misc.make_box(building.NAME))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
131 doc.add(misc.make_box('%d planks' % building.BUY_PRICE))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
132 doc.add(misc.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:
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
134 doc.add(misc.make_box('%d planks' % building.REPAIR_PRICE))
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
135 else:
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
136 doc.add(misc.make_box('N/A'))
433
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:
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
139 doc.add(misc.make_box(equip.NAME))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
140 doc.add(misc.make_box('%d groats' % equip.BUY_PRICE))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
141 doc.add(misc.make_box('%d groats' % equip.SELL_PRICE))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
142 doc.add(misc.make_box('N/A'))
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
143 doc.br(space[1])
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
144 doc.add(misc.make_box("5 planks"))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
145 doc.add(misc.make_box('%d groats' % self.gameboard.wood_buy_price))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
146 doc.add(misc.make_box('%d groats' % self.gameboard.wood_sell_price))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
147 doc.add(misc.make_box('N/A'))
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
148 doc.br(space[1])
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
149
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
150 misc.fix_widths(doc)
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
151 for word in "Damaged equipment or buildings will be sold for" \
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
152 " less than the sell price.".split():
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
153 doc.add(gui.Label(word))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
154 doc.space(space)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
155 close_button = gui.Button("Close")
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
156 tbl.td(doc)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
157 tbl.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
158 tbl.td(close_button, align=1)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
159 dialog = gui.Dialog(gui.Label('Price Reference'), tbl)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
160 close_button.connect(gui.CLICK, dialog.close)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
161 dialog.open()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
162
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
163 def show_controls(self):
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
164 """Popup dialog of controls"""
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
165
529
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
166 COMBOS = [
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
167 ('Select Multiple chickens', 'Shift & Left Click'),
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
168 ('Move selected chickens', 'Ctrl & Left Click'),
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
169 ('Toggle between select and move', 'Right Click'),
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
170 ('Unselect current tool and chickens', 'Middle Click'),
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
171 ('Save selection', 'Ctrl & 0 .. 9'),
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
172 (' or', 'Alt & 0 .. 9'),
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
173 ('Recall saved selection', '0 .. 9'),
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
174 ('Exit game', 'Esc'),
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
175 ]
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
176
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
177 tbl = gui.Table()
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
178 tbl.tr()
520
3e19a7f5333e Tweak controls dialog
Neil Muller <drnlmuller@gmail.com>
parents: 519
diff changeset
179 doc = gui.Document(width=610)
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
180 space = doc.style.font.size(" ")
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
181 for header in ['Action', 'Combination']:
534
d16ed2a8a33e Make price and control reference dialogs a little shinier.
Simon Cross <hodgestar@gmail.com>
parents: 529
diff changeset
182 doc.add(misc.make_box("<b>%s</b>" % header, markup=True))
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
183 doc.br(space[1])
529
93eab01a1e57 Updated (but no prettier) control dialog.
Jeremy Thurgood <firxen@gmail.com>
parents: 520
diff changeset
184 for command, combo in COMBOS:
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
185 doc.add(misc.make_box(command))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
186 doc.add(misc.make_box(combo))
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
187 doc.br(space[1])
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
188 doc.br(space[1])
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
189
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
190 misc.fix_widths(doc)
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
191 close_button = gui.Button("Close")
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
192 tbl.td(doc)
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
193 tbl.tr()
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
194 tbl.td(close_button, align=1)
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
195 dialog = gui.Dialog(gui.Label('Command Reference'), tbl)
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
196 close_button.connect(gui.CLICK, dialog.close)
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
197 dialog.open()
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
198
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
199
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
200 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
201 """Save game 'dialog'."""
486
8897a436a8cb Factor out save game logic and (new, simplified) dialogs into their own module. Add preferences folder to concept to config. Save games under preferences folder.
Simon Cross <hodgestar@gmail.com>
parents: 484
diff changeset
202 savegame.SaveDialog(self.gameboard).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
203
feb9b7a23ef2 Support for saving and loading games (toolbar entries commented out for lack of space).
Simon Cross <hodgestar@gmail.com>
parents: 434
diff changeset
204 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
205 """Load game 'dialog'."""
512
b112bcf4d435 Add restore game button to main menu.
Simon Cross <hodgestar@gmail.com>
parents: 503
diff changeset
206 savegame.RestoreDialog(self.gameboard.restore_game).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
207
568
e813365af567 Add quit button to toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 566
diff changeset
208 def quit_game(self):
e813365af567 Add quit button to toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 566
diff changeset
209 self.gameboard._do_quit()
e813365af567 Add quit button to toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 566
diff changeset
210
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
211 update_cash_counter = mkcountupdate('cash_counter')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
212 update_wood_counter = mkcountupdate('wood_counter')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
213 update_fox_counter = mkcountupdate('killed_foxes')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
214 update_chicken_counter = mkcountupdate('chicken_counter')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
215 update_egg_counter = mkcountupdate('egg_counter')
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
216 update_day_counter = mkcountupdate('day_counter')
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_spacer(self, height):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
219 self.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
220 self.td(gui.Spacer(0, height), colspan=2)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
221
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
222 def add_heading(self, text):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
223 self.tr()
546
e57a0cf38cc7 And fix headings, now that it's easy to do so.
Jeremy Thurgood <firxen@gmail.com>
parents: 545
diff changeset
224 self.td(mklabel(text, width=constants.TOOLBAR_WIDTH, align=0), colspan=2)
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
225
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
226 def add_tool_button(self, text, tool, price=None, cursor=None):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
227 if price is not None:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
228 text = "%s (%s)" % (text, price)
482
cab751de93cc selected button switches when you toggle select/move
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 472
diff changeset
229 return self.add_tool(text, lambda: self.gameboard.set_selected_tool(tool,
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
230 cursor))
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
231
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
232 def add_tool(self, text, func):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
233 label = gui.basic.Label(text)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
234 value = self._next_tool_value
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
235 self._next_tool_value += 1
472
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
236 tool = RinkhalsTool(self.group, label, value, func, width=self.rect.w,
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
237 style={"padding_left": 0})
67574723427e Partially working (but much less crashy) multiple select support
Neil Muller <drnlmuller@gmail.com>
parents: 466
diff changeset
238 #tool.connect(gui.CLICK, func)
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
239 self.tr()
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
240 self.td(tool, align=-1, colspan=2)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
241 return tool
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
242
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
243 def clear_tool(self):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
244 self.group.value = None
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
245 for item in self.group.widgets:
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
246 item.pcls = ""
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
247
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
248 def add_counter(self, icon, label):
544
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
249 if self._counter_col == 0:
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
250 self.add_spacer(5)
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
251 self.tr()
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
252 tbl = gui.Table()
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
253 tbl.tr()
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
254 tbl.td(icon, width=self.rect.w/2)
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
255 tbl.tr()
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
256 tbl.td(label, width=self.rect.w/2)
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
257 self.td(tbl)
84964077626a Counter display more compact, although not as pretty as it should be.
Jeremy Thurgood <firxen@gmail.com>
parents: 541
diff changeset
258 self._counter_col = (self._counter_col + 1) % 2
433
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
259
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
260 def resize(self, width=None, height=None):
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
261 width, height = gui.Table.resize(self, width, height)
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
262 width = constants.TOOLBAR_WIDTH
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
263 return width, height
8643893635e7 Seperate toolbar and gameboard
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
264
541
450de9dfa106 Move gameboard event prodding into the widgets - better matches pgu internals
Neil Muller <drnlmuller@gmail.com>
parents: 538
diff changeset
265
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
266 class DefaultToolBar(BaseToolBar):
483
25e8c57189c3 toggling move/select from subtoolbar no longer crashes
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 482
diff changeset
267
25e8c57189c3 toggling move/select from subtoolbar no longer crashes
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 482
diff changeset
268 IS_DEFAULT = True
492
e8430f93b23a toggling select/move can now be initiated from no selected tool and in any toolbar where select/move is allowed
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 487
diff changeset
269 MOVE_SELECT_PERMITTED = True
483
25e8c57189c3 toggling move/select from subtoolbar no longer crashes
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 482
diff changeset
270
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
271 def __init__(self, gameboard, **params):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
272 BaseToolBar.__init__(self, gameboard, **params)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
273 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
274 self.make_toolbar()
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
275
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
276 def make_toolbar(self):
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
277 self._select_tool = self.add_tool_button("Select / Move", constants.TOOL_SELECT_CHICKENS,
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
278 None, cursors.cursors['select'])
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
279
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
280 self.add_spacer(5)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
281
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
282 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
283
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
284 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
285
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
286 self.add_tool('Trade wood', self.add_wood_toolbar)
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
287
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
288 self.add_spacer(5)
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
289
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
290 self.add_heading("Buildings")
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
291
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
292 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
293
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
294 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
295 None, cursors.cursors['sell'])
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
296
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
297 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
298
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
299 self.add_spacer(5)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
300 self.add_heading("Help")
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
301 self.add_tool("Price Reference", self.show_prices)
519
f84ad10a9625 Remove move tool. Add basic controls reference dialog
Neil Muller <drnlmuller@gmail.com>
parents: 512
diff changeset
302 self.add_tool("Controls", self.show_controls)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
303
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
304 self.add_spacer(5)
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
305 self.add_heading("Game")
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
306 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
307 self.add_tool("Load Game", self.load_game)
568
e813365af567 Add quit button to toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 566
diff changeset
308 self.add_tool("Quit", self.quit_game)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
309
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
310 self.add_heading(" ")
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
311 ## Dear pgu, is there a better way to get the current height?
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
312 #_cur_width, cur_height = self.resize()
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
313 #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
314 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
315
538
ec5276cfe98b put back code to highlight move/select button appropriately
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 534
diff changeset
316 if self.gameboard.selected_tool in [constants.TOOL_PLACE_ANIMALS, constants.TOOL_SELECT_CHICKENS]:
ec5276cfe98b put back code to highlight move/select button appropriately
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 534
diff changeset
317 self.highlight_move_select_button()
ec5276cfe98b put back code to highlight move/select button appropriately
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 534
diff changeset
318
ec5276cfe98b put back code to highlight move/select button appropriately
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 534
diff changeset
319 def highlight_move_select_button(self):
ec5276cfe98b put back code to highlight move/select button appropriately
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 534
diff changeset
320 self._select_tool.group.value = self._select_tool.value
ec5276cfe98b put back code to highlight move/select button appropriately
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 534
diff changeset
321 self._select_tool.pcls = "down"
ec5276cfe98b put back code to highlight move/select button appropriately
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 534
diff changeset
322
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
323 def add_building_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
324 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
325 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
326
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
327 def add_sell_toolbar(self):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
328 self.gameboard.change_toolbar(SellToolBar(self.gameboard,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
329 width=self.style.width))
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
330
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
331 def add_wood_toolbar(self):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
332 self.gameboard.change_toolbar(WoodToolBar(self.gameboard,
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
333 width=self.style.width))
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
334
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
335 def add_equipment_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
336 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
337 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
338
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
339 def day_done(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
340 if self.gameboard.day:
566
a8dde729000a Add 'Save and Quit' option to quit dialog. Move game events from engine to constants to ease 'import engine' fun
Neil Muller <drnlmuller@gmail.com>
parents: 548
diff changeset
341 pygame.event.post(constants.START_NIGHT)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
342 else:
566
a8dde729000a Add 'Save and Quit' option to quit dialog. Move game events from engine to constants to ease 'import engine' fun
Neil Muller <drnlmuller@gmail.com>
parents: 548
diff changeset
343 pygame.event.post(constants.FAST_FORWARD)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
344
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
345 class BuildingToolBar(BaseToolBar):
494
efb5ce9d1a89 allowing select/move in building toolbar; doesn't hurt and can be helpful
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 493
diff changeset
346
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
347 def __init__(self, gameboard, **params):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
348 BaseToolBar.__init__(self, gameboard, **params)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
349 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
350 self.make_toolbar()
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
351
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
352 def make_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
353 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
354 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
355 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
356 self.add_spacer(15)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
357 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
358
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
359 def add_default_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
360 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
361 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
362
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
363 class EquipmentToolBar(BaseToolBar):
492
e8430f93b23a toggling select/move can now be initiated from no selected tool and in any toolbar where select/move is allowed
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 487
diff changeset
364
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
365 def __init__(self, gameboard, **params):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
366 BaseToolBar.__init__(self, gameboard, **params)
484
d3381e722839 gave toolbars unique groups
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 483
diff changeset
367 self.group = gui.Group(name='equipment_toolbar', value=None)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
368 self.make_toolbar()
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
369
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
370 def make_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
371 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
372 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
373 equipment_cls,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
374 equipment_cls.BUY_PRICE,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
375 cursors.cursors.get('buy', None))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
376 self.add_spacer(15)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
377 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
378
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
379 def add_default_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
380 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
381 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
382
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
383 class SellToolBar(BaseToolBar):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
384 def __init__(self, gameboard, **params):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
385 BaseToolBar.__init__(self, gameboard, **params)
484
d3381e722839 gave toolbars unique groups
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 483
diff changeset
386 self.group = gui.Group(name='sell_toolbar', value=None)
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
387 self.make_toolbar()
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
388
569
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
389 @staticmethod
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
390 def make_equip_tool(equipment_cls):
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
391 tool = ("sell_tool", equipment_cls)
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
392 return tool
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
393
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
394 @staticmethod
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
395 def is_equip_tool(tool):
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
396 return type(tool) == tuple and tool[0] == "sell_tool"
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
397
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
398 @staticmethod
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
399 def get_equip_cls(tool):
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
400 return tool[1]
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
401
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
402 def make_toolbar(self):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
403 self.add_heading("Sell ...")
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
404 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
405 self.gameboard.level.sell_price_chicken, cursors.cursors['sell'])
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
406 self.add_tool_button("Egg", constants.TOOL_SELL_EGG,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
407 self.gameboard.level.sell_price_egg, cursors.cursors['sell'])
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
408 self.add_spacer(15)
569
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
409
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
410 for equipment_cls in equipment.EQUIPMENT:
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
411 tool = self.make_equip_tool(equipment_cls)
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
412 self.add_tool_button(equipment_cls.NAME.title(),
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
413 tool,
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
414 equipment_cls.SELL_PRICE,
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
415 cursors.cursors.get('sell', None))
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
416 self.add_spacer(15)
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
417
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
418 #self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT,
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
419 # None, cursors.cursors['sell'])
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
420
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
421 self.add_tool('Done', self.add_default_toolbar)
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
422
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
423 def add_default_toolbar(self):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
424 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
425 width=self.style.width))
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
426
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
427 class WoodToolBar(BaseToolBar):
492
e8430f93b23a toggling select/move can now be initiated from no selected tool and in any toolbar where select/move is allowed
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 487
diff changeset
428
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
429 def __init__(self, gameboard, **params):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
430 BaseToolBar.__init__(self, gameboard, **params)
484
d3381e722839 gave toolbars unique groups
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 483
diff changeset
431 self.group = gui.Group(name='wood_toolbar', value=None)
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
432 self.make_toolbar()
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
433
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
434 def make_toolbar(self):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
435 self.add_heading("Trade...")
461
279caa00f3fa exchange rate should be per tree, not per plank
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 460
diff changeset
436 self.add_tool("Buy 5 planks (%s)" % self.gameboard.wood_buy_price, self.buy_wood)
279caa00f3fa exchange rate should be per tree, not per plank
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 460
diff changeset
437 self.add_tool("Sell 5 planks (%s)" % self.gameboard.wood_sell_price, self.sell_wood)
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
438
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
439 self.add_spacer(15)
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
440 self.add_tool('Done', self.add_default_toolbar)
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
441
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
442 def add_default_toolbar(self):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
443 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard,
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
444 width=self.style.width))
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
445
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
446 def buy_wood(self):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
447 if self.gameboard.cash >= self.gameboard.wood_buy_price:
461
279caa00f3fa exchange rate should be per tree, not per plank
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 460
diff changeset
448 self.gameboard.add_wood(5)
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
449 self.gameboard.add_cash(-self.gameboard.wood_buy_price)
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
450
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
451 def sell_wood(self):
461
279caa00f3fa exchange rate should be per tree, not per plank
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 460
diff changeset
452 if self.gameboard.wood >= 5:
279caa00f3fa exchange rate should be per tree, not per plank
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 460
diff changeset
453 self.gameboard.add_wood(-5)
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
454 self.gameboard.add_cash(self.gameboard.wood_sell_price)