Make dialogue system work (hackily) with domkit

This commit is contained in:
3wc 2024-02-14 12:13:29 -03:00
parent 477b57e2a7
commit 021aac9914
2 changed files with 63 additions and 63 deletions

View File

@ -17,7 +17,7 @@ class DialogueBox extends h2d.Object {
if (text == null)
text = "NULL";
game = Game.current;
game.root.add(this, 1);
game.root.scene.getH2dObject().getScene().add(this, 1);
bg = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5, this);
bg.colorKey = 0xFF00FF;
tf = new h2d.Text(game.font, this);

View File

@ -8,9 +8,9 @@ import event.EventBus;
import event.ChangeSceneEvent;
import Const;
// import DialogueBox;
// import DialogueManager;
// import DialogueManager.Option;
import DialogueBox;
import DialogueManager;
import DialogueManager.Option;
@:uiComp("game-container")
class GameContainer extends h2d.Flow implements h2d.domkit.Object {
@ -69,19 +69,19 @@ class Game extends hxd.App {
setGameScene(new TitleScene(root));
#end
// font = Res.font.minecraftia_regular_6.toFont();
// font.resizeTo(24);
//
// dialogueManager = new DialogueManager(dialogue, renderActions);
//
// var yarnText = [
// hxd.Res.text.intro.entry.getText(),
// ];
// var yarnFileNames = [
// hxd.Res.text.intro.entry.name,
// ];
// dialogueManager.load(yarnText, yarnFileNames);
// dialogueManager.runNode("Intro");
font = Res.font.minecraftia_regular_6.toFont();
font.resizeTo(24);
dialogueManager = new DialogueManager(dialogue, renderActions);
var yarnText = [
hxd.Res.text.intro.entry.getText(),
];
var yarnFileNames = [
hxd.Res.text.intro.entry.name,
];
dialogueManager.load(yarnText, yarnFileNames);
dialogueManager.runNode("Intro");
}
public function new() {
@ -98,52 +98,52 @@ class Game extends hxd.App {
style.sync();
}
// function dialogue(manager:DialogueManager, t:String) {
// var d = new DialogueBox(Const.W, 100, t);
// d.y = 0;
// d.onClick = function() {
// manager.resume();
// };
//
// curDialogue = d;
// }
//
// function renderActions(manager:DialogueManager, t:Array<Option>) {
// for (action in t) {
// addAction(action.text, action.callback);
// }
// }
//
// function newPanel(w, h) {
// var g = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5);
// g.width = w;
// g.height = h;
// g.colorKey = 0xFF00FF;
// scene.add(g, 1);
// return g;
// }
//
// function addAction(a: String, callback: () -> Void) {
// var spr = newPanel(Const.W, 60);
// curDialogue.addChild(spr);
// var tf = new h2d.Text(font, spr);
// tf.text = a;
// tf.x = 10;
// tf.y = 10;
// spr.x = 0;
// spr.y = 100 + actions.length * 60;
// var int = new h2d.Interactive(spr.width, spr.height, spr);
// int.onClick = function(_) {
// for (action in actions) {
// action.remove();
// }
// callback();
// removeDialog();
// }
// int.cursor = Button;
// actions.push(spr);
// return spr;
// }
function dialogue(manager:DialogueManager, t:String) {
var d = new DialogueBox(Const.W, 100, t);
d.y = 0;
d.onClick = function() {
manager.resume();
};
curDialogue = d;
}
function renderActions(manager:DialogueManager, t:Array<Option>) {
for (action in t) {
addAction(action.text, action.callback);
}
}
function newPanel(w, h) {
var g = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5);
g.width = w;
g.height = h;
g.colorKey = 0xFF00FF;
root.scene.getH2dObject().getScene().add(g, 1);
return g;
}
function addAction(a: String, callback: () -> Void) {
var spr = newPanel(Const.W, 60);
curDialogue.addChild(spr);
var tf = new h2d.Text(font, spr);
tf.text = a;
tf.x = 10;
tf.y = 10;
spr.x = 0;
spr.y = 100 + actions.length * 60;
var int = new h2d.Interactive(spr.width, spr.height, spr);
int.onClick = function(_) {
for (action in actions) {
action.remove();
}
callback();
// removeDialog();
}
int.cursor = Button;
actions.push(spr);
return spr;
}
public function onChangeScene(event:ChangeSceneEvent) {
setGameScene(event.newScene);