glasshouse/src/listeners/DialogueBoxController.hx

68 lines
1.6 KiB
Haxe

package listeners;
import Game;
import event.EventBus;
import dialogue.DialogueManager;
import dialogue.event.LineShown;
import dialogue.event.OptionsShown;
import dialogue.event.OptionSelected;
import dialogue.event.DialogueComplete;
import dialogue.event.NextLine;
import components.DialogueBoxComponent;
class DialogueBoxController {
public var dialogueBox:DialogueBoxComponent;
public var dialogueOptions:DialogueOptionsComponent;
var game:Game;
var bg:h2d.ScaleGrid;
var tf:h2d.Text;
var int:h2d.Interactive;
var eventBus:EventBus;
var parent:h2d.Object;
var style:h2d.domkit.Style;
public function new(eventBus:EventBus, parent:h2d.Object, style:h2d.domkit.Style) {
this.parent = parent;
this.style = style;
eventBus.subscribe(LineShown, onLineShown);
eventBus.subscribe(OptionsShown, onOptionsShown);
eventBus.subscribe(OptionSelected, onOptionSelected);
eventBus.subscribe(DialogueComplete, onDialogueComplete);
}
public dynamic function onClick() {}
public dynamic function onReady() {}
function onLineShown(event:LineShown) {
if (dialogueBox == null) {
var d = new DialogueBoxComponent(event.line(), this.parent);
style.addObject(d);
dialogueBox = d;
} else {
dialogueBox.internalText = event.line();
}
}
function onOptionsShown(event:OptionsShown) {
dialogueOptions = new DialogueOptionsComponent(event.options, this.parent);
}
function onOptionSelected(event:OptionSelected) {
dialogueOptions.remove();
}
function onDialogueComplete(event:DialogueComplete) {
dialogueBox.remove();
if (dialogueOptions != null)
dialogueOptions.remove();
dialogueBox = null;
}
}