changeset 285:71f15f6e9274

Hook up auto_next dialogue events.
author Simon Cross <hodgestar@gmail.com>
date Fri, 08 Apr 2011 20:52:47 +0200
parents 8cac6ff88a9d
children 0dbb50d07764
files skaapsteker/dialogue.py skaapsteker/widgets/bubble.py
diffstat 2 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/dialogue.py	Fri Apr 08 20:41:05 2011 +0200
+++ b/skaapsteker/dialogue.py	Fri Apr 08 20:52:47 2011 +0200
@@ -49,6 +49,9 @@
     def choice(self, i):
         self.event(DsmEvent(choice=i))
 
+    def auto_next(self):
+        self.event(DsmEvent(auto_next=True))
+
 
 class AttrDict(dict):
 
@@ -60,9 +63,10 @@
 
 class DsmEvent(object):
 
-    def __init__(self, choice=None):
+    def __init__(self, choice=None, auto_next=False):
         self.items = {
             "choice": choice,
+            "auto_next": auto_next,
         }
 
 
@@ -92,9 +96,12 @@
                                          pseudo_path))
 
         auto_next = state_src.get("auto_next", None)
+        self.auto_next = False
         if auto_next is not None:
+            self.auto_next = True
+            assert not self.choices, "%s: auto_next and choices are not compatible" % ":".join(base_path)
             pseudo_path = base_path + ["auto_next"]
-            self.triggers.append(Trigger("""True""", auto_next, pseudo_path))
+            self.triggers.append(Trigger("""auto_next""", auto_next, pseudo_path))
 
         on_entry = state_src.get("on_entry", None)
         if on_entry is not None:
--- a/skaapsteker/widgets/bubble.py	Fri Apr 08 20:41:05 2011 +0200
+++ b/skaapsteker/widgets/bubble.py	Fri Apr 08 20:52:47 2011 +0200
@@ -26,7 +26,10 @@
         else:
             self._text = None
         options = [(text, i) for (i, text) in state.choices]
-        options.append(("Leave", "L"))
+        if state.auto_next:
+            options.append(("Next", "N"))
+        else:
+            options.append(("Leave", "L"))
         pos = pos.move(0, 0) # copy
         self._text_choice = TextChoice(options, pos, wrap=True)
         self._text_choice.callbacks.append(self._selected)
@@ -34,6 +37,9 @@
     def _selected(self, i, data):
         if data == "L":
             CloseDialog.post(self.npc)
+        elif data == "N":
+            self.dsm.auto_next()
+            self._state_update()
         else:
             self.dsm.choice(i)
             self._state_update()