Mercurial > rinkhals
changeset 326:89f51d513606
Add TextDialog class and use it to warn about selling your last chicken.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 21:50:04 +0000 |
parents | b07ea17b8b4e |
children | 7ef352c66f07 |
files | gamelib/gameboard.py |
diffstat | 1 files changed, 30 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/gameboard.py Sat Sep 05 21:38:41 2009 +0000 +++ b/gamelib/gameboard.py Sat Sep 05 21:50:04 2009 +0000 @@ -464,7 +464,8 @@ if not chicken: return False # sanity check if len(self.chickens) == 1: - print "You can't sell your last chicken!" + msg = "You can't sell your last chicken!" + TextDialog("Squuaaawwwwwk!", msg).open() return False for item in list(chicken.equipment): self.add_cash(item.sell_price()) @@ -1061,3 +1062,31 @@ return True if len(self.chickens) == 0: return True + + +class TextDialog(gui.Dialog): + def __init__(self, title, text, **params): + title_label = gui.Label(title) + + doc = gui.Document() + + space = doc.style.font.size(" ") + + for paragraph in text.split('\n\n'): + doc.block(align=-1) + for word in paragraph.split(): + doc.add(gui.Label(word)) + doc.space(space) + doc.br(space[1]) + doc.br(space[1]) + + done_button = gui.Button("Close") + done_button.connect(gui.CLICK, self.close) + + tbl = gui.Table() + tbl.tr() + tbl.td(doc) + tbl.tr() + tbl.td(done_button, align=1) + + gui.Dialog.__init__(self, title_label, tbl, **params)