Mercurial > rinkhals
comparison gamelib/misc.py @ 548:27c09c58d89d
Remove gameboard and dialog event flow hacks.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 28 Nov 2009 11:25:56 +0000 |
parents | d16ed2a8a33e |
children | 7963fc09fac2 |
comparison
equal
deleted
inserted
replaced
547:1456bf2ff02e | 548:27c09c58d89d |
---|---|
80 if roll < weight: | 80 if roll < weight: |
81 return item | 81 return item |
82 roll -= weight | 82 roll -= weight |
83 | 83 |
84 class CheckDialog(gui.Dialog): | 84 class CheckDialog(gui.Dialog): |
85 def __init__(self, **params): | 85 def __init__(self, sure_func, **params): |
86 self._sure_func = sure_func | |
86 title = gui.Label('Are You Sure?') | 87 title = gui.Label('Are You Sure?') |
87 self.do_quit = False | |
88 self.running = True | |
89 tbl = gui.Table() | 88 tbl = gui.Table() |
90 tbl.tr() | 89 tbl.tr() |
91 tbl.td(gui.Label("Do you REALLY want to exit this game?"), colspan=2) | 90 tbl.td(gui.Label("Do you REALLY want to exit this game?"), colspan=2) |
92 tbl.tr() | 91 tbl.tr() |
93 tbl.td(gui.Spacer(0, 15), colspan=2) | 92 tbl.td(gui.Spacer(0, 15), colspan=2) |
99 tbl.td(no_button, align=-1) | 98 tbl.td(no_button, align=-1) |
100 tbl.td(yes_button, align=1) | 99 tbl.td(yes_button, align=1) |
101 gui.Dialog.__init__(self, title, tbl, **params) | 100 gui.Dialog.__init__(self, title, tbl, **params) |
102 | 101 |
103 def clicked(self, val): | 102 def clicked(self, val): |
104 self.do_quit = val | 103 self._sure_func(val) |
105 self.running = False | |
106 self.close() | 104 self.close() |
107 | 105 |
108 def event(self, e): | 106 def event(self, e): |
109 if e.type == KEYDOWN and e.key == K_ESCAPE: | 107 if e.type == KEYDOWN and e.key == K_ESCAPE: |
110 self.clicked(False) | 108 self.clicked(False) |
111 return True | 109 return True |
112 return gui.Dialog.event(self, e) | 110 return gui.Dialog.event(self, e) |
113 | 111 |
114 def check_exit(): | |
115 dialog = CheckDialog() | |
116 dialog.open() | |
117 return dialog | |
118 | 112 |
119 # Utility layout functions | 113 # Utility layout functions |
120 | 114 |
121 def make_box(text, markup=False): | 115 def make_box(text, markup=False): |
122 style = { | 116 style = { |