136 lines
3.1 KiB
Haxe
136 lines
3.1 KiB
Haxe
package components;
|
|
|
|
import dialogue.event.NextLine;
|
|
|
|
@:uiComp("dialogue-option")
|
|
class DialogueOptionComponent extends h2d.Flow implements h2d.domkit.Object {
|
|
static var SRC = <dialogue-option>
|
|
<text text={label} public font={Game.current.font} id="labelTxt" />
|
|
</dialogue-option>;
|
|
|
|
public var label(get, set):String;
|
|
|
|
function get_label()
|
|
return labelTxt.text;
|
|
|
|
function set_label(s) {
|
|
labelTxt.text = s;
|
|
return s;
|
|
}
|
|
|
|
public function new(label:String, ?parent) {
|
|
super(parent);
|
|
initComponent();
|
|
enableInteractive = true;
|
|
interactive.onClick = function(_) onClick();
|
|
interactive.onOver = function(_) {
|
|
dom.hover = true;
|
|
};
|
|
interactive.onPush = function(_) {
|
|
dom.active = true;
|
|
};
|
|
interactive.onRelease = function(_) {
|
|
dom.active = false;
|
|
};
|
|
interactive.onOut = function(_) {
|
|
dom.hover = false;
|
|
};
|
|
}
|
|
|
|
public dynamic function onClick() {}
|
|
}
|
|
|
|
@:uiComp("dialogue-options")
|
|
class DialogueOptionsComponent extends h2d.Flow implements h2d.domkit.Object {
|
|
static var SRC = <dialogue-options>
|
|
${options}
|
|
</dialogue-options>;
|
|
|
|
public var options:Array<DialogueOptionComponent>;
|
|
}
|
|
|
|
@:uiComp("dialogue-box")
|
|
class DialogueBoxComponent extends h2d.Flow implements h2d.domkit.Object {
|
|
var timer:haxe.Timer;
|
|
var chan:hxd.snd.Channel;
|
|
var textPos:Int = 0;
|
|
var game:Game;
|
|
|
|
static var SRC = <dialogue-box>
|
|
<scale-grid id="dialogueBackground">
|
|
<text text={displayedText} public font={Game.current.font} id="dialogueText" />
|
|
</scale-grid>
|
|
</dialogue-box>
|
|
|
|
public var displayedText(get, set):String;
|
|
|
|
function get_displayedText()
|
|
return dialogueText.text;
|
|
|
|
function set_displayedText(s) {
|
|
dialogueText.text = s;
|
|
return s;
|
|
}
|
|
|
|
public var internalText(default, set):String;
|
|
|
|
function set_internalText(t) {
|
|
internalText = t;
|
|
timer = new haxe.Timer(30);
|
|
timer.run = updateText;
|
|
displayedText = "";
|
|
textPos = 0;
|
|
return t;
|
|
}
|
|
|
|
public function new(text:String, ?parent) {
|
|
this.game = Game.current;
|
|
super(parent);
|
|
initComponent();
|
|
internalText = text;
|
|
this.dialogueBackground.tile = Res.ui.toTile();
|
|
this.dialogueBackground.borderWidth = 5;
|
|
this.dialogueBackground.borderHeight = 5;
|
|
this.dialogueBackground.colorKey = 0xFF00FF;
|
|
this.dialogueBackground.width = this.innerWidth;
|
|
this.dialogueBackground.height = this.innerHeight;
|
|
// trace(this.dialogueBackground.width);
|
|
|
|
enableInteractive = true;
|
|
interactive.onClick = function(_) onClick();
|
|
}
|
|
|
|
function updateText() {
|
|
if (textPos == internalText.length) {
|
|
timer.stop();
|
|
// onReady();
|
|
// if (chan != null)
|
|
// chan.stop();
|
|
return;
|
|
}
|
|
// if (chan != null) {
|
|
// switch (text.charCodeAt(textPos)) {
|
|
// case " ".code, "\n".code:
|
|
// chan.volume = 0;
|
|
// default:
|
|
// if (chan.volume == 0)
|
|
// chan.volume = 1
|
|
// else
|
|
// chan.volume *= 0.9;
|
|
// }
|
|
// }
|
|
textPos++;
|
|
displayedText = internalText.substr(0, textPos);
|
|
}
|
|
|
|
public dynamic function onClick() {
|
|
if (textPos == internalText.length)
|
|
Game.current.globalEventBus.publishEvent(new NextLine());
|
|
else if (textPos < internalText.length) {
|
|
textPos = internalText.length;
|
|
displayedText = internalText;
|
|
updateText();
|
|
};
|
|
}
|
|
}
|