public static void RunOption(PowerUI.MouseEvent e) { Dom.Node targetNode = (e.target as Dom.Node); // Get the unique ID: int uniqueId; if (!int.TryParse(targetNode.getAttribute("unique-id"), out uniqueId)) { Dom.Log.Add("A dialogue option did not have an unique-id attribute."); return; } // Get the widget: DialogueWidget dw = e.targetWidget as DialogueWidget; if (dw == null) { Dom.Log.Add("A dialogue option tried to run but it's not inside a DialogueWidget."); return; } // Great ok - we can now grab the active options entry. // Select the active slide with that unique ID: PowerSlide.DialogueSlide slide = dw.getSlide(uniqueId) as PowerSlide.DialogueSlide; if (slide == null) { Dom.Log.Add("Unable to resolve a DialogueSlide from a unique-id."); return; } // Get the GOTO: string gotoUrl = slide.slidesToGoTo; if (string.IsNullOrEmpty(gotoUrl)) { // Acts just like a continue does. // Just cue it: dw.timeline.cue(); return; } // Load it now (into the existing timeline): PowerSlide.Timeline.open(gotoUrl, PowerSlide.Dialogue.basePath, dw.timeline).then(delegate(object o){ // Successfully opened it! Should already be running, but just incase: PowerSlide.Timeline timeline = o as PowerSlide.Timeline; // Start: timeline.start(); }, delegate(object failure){ // Failed! Dom.Log.Add("Failed to load a timeline from an option URI: " + failure); }); // dw.timeline.document.startDialogue(gotoUrl,dw.Timeline.template); // Kill the event: e.stopPropagation(); }
/// <summary>Called when the template is ready.</summary> public override void Goto(string url, Dictionary <string, object> globals) { // Just get the timeline: object timelineObj; if (globals.TryGetValue("timeline", out timelineObj)) { // Get the timeline: timeline = timelineObj as PowerSlide.Timeline; } }
public static void Cue(PowerUI.MouseEvent me) { // The widget: Widgets.Widget widget = me.htmlTarget.widget; // Get the timeline: PowerSlide.Timeline tl = PowerSlide.Timeline.get(widget); // Cue it: if (tl != null) { tl.cue(); } }
/// <summary> /// Starts the dialogue at the given path. It's relative to resources://Dialogue/ by default /// and ".json" is appended if it contains no dot. /// E.g. "joey" => "resources://Dialogue/joey.json". /// "Hello/joey" => "resources://Dialogue/Hello/joey.json". /// "cdn://...joey.json" => as is. /// Use {language} in your path to localise the file. /// </summary> /// <param name="template">The widget template to use. /// Note that the widget doesn't need to be visual - it could, for example, /// manage a bunch of WorldUI's instead.</param> /// <param name="killRunning">Kills any open dialogue in the document.</param> /// <returns>A promise which runs when the dialogue loaded and started up.</returns> public Promise startDialogue(string startPath, string template, bool killRunning) { if (killRunning) { // Find all timelines in the document itself (and marked with 'isDialogue') and stop them: PowerSlide.Timeline current = PowerSlide.Timeline.first; while (current != null) { if (current.isDialogue && current.document == this) { // Kill it! current.stop(false); } current = current.after; } } Promise p = new Promise(); // Load the slides: PowerSlide.Dialogue.open(startPath).then(delegate(object o){ // It's a timeline: PowerSlide.Timeline timeline = o as PowerSlide.Timeline; // Set the default template/doc: timeline.isDialogue = true; timeline.template = template; timeline.document = this; // Start it (which may open widgets): timeline.start(); // Just resolve the promise here: p.resolve(timeline); }, p); return(p); }
/// <summary> /// The same as startDialogue, only the promise this one returns runs when the dialogue is over. /// (It hooks up to the timelineend event triggered on the timeline itself). /// </summary> /// <param name="template">The widget template to use. /// Note that the widget doesn't need to be visual - it could, for example, /// manage a bunch of WorldUI's instead.</param> /// <param name="killRunning">Kills any open dialogue in the document.</param> /// <returns>A promise which runs when the dialogue finished.</returns> public Promise playDialogue(string startPath, string template, bool killRunning) { Promise p = new Promise(); startDialogue(startPath, template, killRunning).then(delegate(object o){ PowerSlide.Timeline timeline = (o as PowerSlide.Timeline); // Add a done event handler: timeline.addEventListener("timelineend", delegate(PowerSlide.SlideEvent e){ // Ok! p.resolve(timeline); }); // Catch the slides cancel event (called when it was quit early): timeline.addEventListener("timelinecancel", delegate(PowerSlide.SlideEvent se){ // Resolve it now: p.reject(timeline); }); }, p); return(p); }