annotate gamelib/toolbar.py @ 573:ffdaac5d6cf8

Select is the default tool.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 28 Nov 2009 20:29:33 +0000
parents 40eee9e1246c
children 2a913d34c95a
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
573
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
276 def toggle_move(self):
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
277 if self.gameboard.selected_tool == constants.TOOL_PLACE_ANIMALS:
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
278 self.gameboard.set_selected_tool(None, None)
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
279 return False
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
280 else:
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
281 self.gameboard.set_selected_tool(constants.TOOL_PLACE_ANIMALS, cursors.cursors['chicken'])
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
282 return True
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
283
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
284 def make_toolbar(self):
573
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
285 self._move_tool = self.add_tool("Move", self.toggle_move)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
286
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
287 self.add_spacer(5)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
288
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
289 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
290
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
291 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
292
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
293 self.add_tool('Trade wood', self.add_wood_toolbar)
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
294
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
295 self.add_spacer(5)
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
296
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
297 self.add_heading("Buildings")
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
298
572
40eee9e1246c extended help; renamed building-related buttons.
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 569
diff changeset
299 self.add_tool('Build', self.add_building_toolbar)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
300
572
40eee9e1246c extended help; renamed building-related buttons.
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 569
diff changeset
301 self.add_tool_button("Demolish", constants.TOOL_SELL_BUILDING,
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
302 None, cursors.cursors['sell'])
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_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
305
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
306 self.add_spacer(5)
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
307 self.add_heading("Help")
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
308 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
309 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
310
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
311 self.add_spacer(5)
458
7e4ea53d8b10 Reorder toolbar. Fix 'Finished Day' position
Neil Muller <drnlmuller@gmail.com>
parents: 454
diff changeset
312 self.add_heading("Game")
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
313 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
314 self.add_tool("Load Game", self.load_game)
568
e813365af567 Add quit button to toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 566
diff changeset
315 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
316
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
317 self.add_heading(" ")
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
318 ## 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
319 #_cur_width, cur_height = self.resize()
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
320 #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
321 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
322
573
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
323 if self.gameboard.selected_tool == constants.TOOL_PLACE_ANIMALS:
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
324 self.highlight_move_button()
538
ec5276cfe98b put back code to highlight move/select button appropriately
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 534
diff changeset
325
573
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
326 def unhighlight_move_button(self):
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
327 self._move_tool.group.value = None
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
328 self._move_tool.pcls = "up"
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
329
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
330 def highlight_move_button(self):
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
331 self._move_tool.group.value = self._move_tool.value
ffdaac5d6cf8 Select is the default tool.
Jeremy Thurgood <firxen@gmail.com>
parents: 572
diff changeset
332 self._move_tool.pcls = "down"
538
ec5276cfe98b put back code to highlight move/select button appropriately
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 534
diff changeset
333
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
334 def add_building_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
335 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
336 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
337
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
338 def add_sell_toolbar(self):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
339 self.gameboard.change_toolbar(SellToolBar(self.gameboard,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
340 width=self.style.width))
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
341
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
342 def add_wood_toolbar(self):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
343 self.gameboard.change_toolbar(WoodToolBar(self.gameboard,
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
344 width=self.style.width))
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
345
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
346 def add_equipment_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
347 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
348 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
349
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
350 def day_done(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
351 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
352 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
353 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
354 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
355
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
356 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
357
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
358 def __init__(self, gameboard, **params):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
359 BaseToolBar.__init__(self, gameboard, **params)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
360 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
361 self.make_toolbar()
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 def make_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
364 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
365 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
366 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
367 self.add_spacer(15)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
368 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
369
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
370 def add_default_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
371 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
372 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
373
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
374 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
375
447
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
376 def __init__(self, gameboard, **params):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
377 BaseToolBar.__init__(self, gameboard, **params)
484
d3381e722839 gave toolbars unique groups
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 483
diff changeset
378 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
379 self.make_toolbar()
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
380
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
381 def make_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
382 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
383 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
384 equipment_cls,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
385 equipment_cls.BUY_PRICE,
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
386 cursors.cursors.get('buy', None))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
387 self.add_spacer(15)
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
388 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
389
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
390 def add_default_toolbar(self):
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
391 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
392 width=self.style.width))
f04a2490c35f The sub-toolbar rewrite, the finally not crashing version
Neil Muller <drnlmuller@gmail.com>
parents: 446
diff changeset
393
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
394 class SellToolBar(BaseToolBar):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
395 def __init__(self, gameboard, **params):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
396 BaseToolBar.__init__(self, gameboard, **params)
484
d3381e722839 gave toolbars unique groups
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 483
diff changeset
397 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
398 self.make_toolbar()
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
399
569
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
400 @staticmethod
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
401 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
402 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
403 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
404
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
405 @staticmethod
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
406 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
407 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
408
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
409 @staticmethod
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
410 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
411 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
412
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
413 def make_toolbar(self):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
414 self.add_heading("Sell ...")
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
415 self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
416 self.gameboard.level.sell_price_chicken, cursors.cursors['sell'])
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
417 self.add_tool_button("Egg", constants.TOOL_SELL_EGG,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
418 self.gameboard.level.sell_price_egg, cursors.cursors['sell'])
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
419 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
420
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
421 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
422 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
423 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
424 tool,
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
425 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
426 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
427 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
428
3ec614e6fd4a Replace monolithic sell equipment tool with a tool for each type of equipment.
Simon Cross <hodgestar@gmail.com>
parents: 568
diff changeset
429 #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
430 # 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
431
454
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
432 self.add_tool('Done', self.add_default_toolbar)
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
433
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
434 def add_default_toolbar(self):
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
435 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard,
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
436 width=self.style.width))
30e6d6097b12 Make selling things sub-toolbar
Neil Muller <drnlmuller@gmail.com>
parents: 450
diff changeset
437
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
438 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
439
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
440 def __init__(self, gameboard, **params):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
441 BaseToolBar.__init__(self, gameboard, **params)
484
d3381e722839 gave toolbars unique groups
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 483
diff changeset
442 self.group = gui.Group(name='wood_toolbar', value=None)
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
443 self.make_toolbar()
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
444
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
445 def make_toolbar(self):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
446 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
447 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
448 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
449
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
450 self.add_spacer(15)
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
451 self.add_tool('Done', self.add_default_toolbar)
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
452
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
453 def add_default_toolbar(self):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
454 self.gameboard.change_toolbar(DefaultToolBar(self.gameboard,
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
455 width=self.style.width))
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
456
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
457 def buy_wood(self):
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
458 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
459 self.gameboard.add_wood(5)
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
460 self.gameboard.add_cash(-self.gameboard.wood_buy_price)
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
461
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
462 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
463 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
464 self.gameboard.add_wood(-5)
460
7204c16ab64d Wood market!
Adrianna Pińska <adrianna.pinska@gmail.com>
parents: 459
diff changeset
465 self.gameboard.add_cash(self.gameboard.wood_sell_price)