Compare commits

...

3 Commits

Author SHA1 Message Date
3wc
8a803b9cdc TODO updates 2024-02-18 14:00:22 -03:00
3wc
e1bdd74100 Working option selection 🎉 2024-02-18 13:56:45 -03:00
3wc
610d107e60 Abandon ScaleGrid bg for now, working though! 2024-02-18 13:38:32 -03:00
5 changed files with 81 additions and 104 deletions

28
TODO.md
View File

@ -2,26 +2,26 @@
## Features ## Features
- Saving and loading games - [ ] Saving and loading games
- Character select - [ ] Character select
- Stats - [ ] Stats
- Better open / closed state graphics for rooms - [ ] Better open / closed state graphics for rooms
- Displaying sprites (characters, objects) - [ ] Displaying sprites (characters, objects)
- Inventory - [ ] Inventory
- Room labels - [ ] Room labels
- Background music - [ ] Background music
- Sound effects - [ ] Sound effects
## Bugs ## Bugs
- Fix console rendering issues - [ ] Fix console rendering issues
### Dialogue ### Dialogue
- Text formatting - [ ] Text formatting
- Character profiles / speaker ID - [ ] Character profiles / speaker ID
## Code architecture ## Code architecture
- Move dialogue- and option-drawing out of `Game.hx` - [x] Move dialogue- and option-drawing out of `Game.hx`
- Use domkit for dialogue - [x] Use domkit for dialogue

View File

@ -56,18 +56,31 @@ menubutton:active {
flow.dialogue-container { flow.dialogue-container {
fill-width: true; fill-width: true;
height: 20; height: 20;
debug: true; layout: vertical;
} }
dialogue-box { dialogue-box {
fill-width: true; fill-width: true;
height: 20; height: 20;
/* background: tile("ui.png", 5, 5); */
/* background-tile-pos: 1 1; */
background: blue;
padding: 10;
alpha: 0.9;
} }
scale-grid#dialogueBackground { dialogue-options {
/* fill-width: true; */ fill-width: true;
layout: vertical;
} }
/* text#dialogueText { */ dialogue-option {
/* font : url("res/font/minecraftia_regular_6.fnt"); */ fill-width: true;
/* } */ background: green;
padding: 10;
alpha: 0.9;
}
dialogue-option.disabled {
alpha: 0.5;
}

View File

@ -22,6 +22,8 @@ class GameContainer extends h2d.Flow implements h2d.domkit.Object {
public function new(?parent) { public function new(?parent) {
super(parent); super(parent);
initComponent(); initComponent();
this.maxWidth = Const.W;
this.minWidth = Const.W;
} }
} }
@ -83,8 +85,8 @@ class Game extends hxd.App {
var dialogueParent = new h2d.Flow(); var dialogueParent = new h2d.Flow();
dialogueParent.dom = domkit.Properties.create("flow", dialogueParent); dialogueParent.dom = domkit.Properties.create("flow", dialogueParent);
dialogueParent.dom.addClass('dialogue-container'); dialogueParent.dom.addClass('dialogue-container');
style.addObject(dialogueParent);
layer.addChildAt(dialogueParent, 2); layer.addChildAt(dialogueParent, 2);
style.addObject(dialogueParent);
dialogueBoxController = new DialogueBoxController(globalEventBus, dialogueParent, style); dialogueBoxController = new DialogueBoxController(globalEventBus, dialogueParent, style);
#if debug #if debug

View File

@ -1,6 +1,8 @@
package components; package components;
import dialogue.event.NextLine; import dialogue.event.NextLine;
import dialogue.event.OptionSelected;
import dialogue.event.OptionsShown.OptionChoice;
@:uiComp("dialogue-option") @:uiComp("dialogue-option")
class DialogueOptionComponent extends h2d.Flow implements h2d.domkit.Object { class DialogueOptionComponent extends h2d.Flow implements h2d.domkit.Object {
@ -18,9 +20,16 @@ class DialogueOptionComponent extends h2d.Flow implements h2d.domkit.Object {
return s; return s;
} }
public function new(label:String, ?parent) { var choice:OptionChoice;
public function new(choice:OptionChoice, ?parent) {
super(parent); super(parent);
initComponent(); initComponent();
this.choice = choice;
this.label = choice.text;
if (!choice.enabled) {
this.dom.addClass('disabled');
}
enableInteractive = true; enableInteractive = true;
interactive.onClick = function(_) onClick(); interactive.onClick = function(_) onClick();
interactive.onOver = function(_) { interactive.onOver = function(_) {
@ -37,7 +46,10 @@ class DialogueOptionComponent extends h2d.Flow implements h2d.domkit.Object {
}; };
} }
public dynamic function onClick() {} public dynamic function onClick() {
if (this.choice.enabled)
Game.current.globalEventBus.publishEvent(new OptionSelected(this.choice.index));
}
} }
@:uiComp("dialogue-options") @:uiComp("dialogue-options")
@ -46,7 +58,17 @@ class DialogueOptionsComponent extends h2d.Flow implements h2d.domkit.Object {
${options} ${options}
</dialogue-options>; </dialogue-options>;
public var options:Array<DialogueOptionComponent>; public var options = new Array<DialogueOptionComponent>();
public function new(options:Array<OptionChoice>, ?parent) {
super(parent);
initComponent();
for (option in options) {
this.options.push(
new DialogueOptionComponent(option, this)
);
}
}
} }
@:uiComp("dialogue-box") @:uiComp("dialogue-box")
@ -57,9 +79,7 @@ class DialogueBoxComponent extends h2d.Flow implements h2d.domkit.Object {
var game:Game; var game:Game;
static var SRC = <dialogue-box> static var SRC = <dialogue-box>
<scale-grid id="dialogueBackground"> <text text={displayedText} public font={Game.current.font} id="dialogueText" />
<text text={displayedText} public font={Game.current.font} id="dialogueText" />
</scale-grid>
</dialogue-box> </dialogue-box>
public var displayedText(get, set):String; public var displayedText(get, set):String;
@ -88,13 +108,6 @@ class DialogueBoxComponent extends h2d.Flow implements h2d.domkit.Object {
super(parent); super(parent);
initComponent(); initComponent();
internalText = text; 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; enableInteractive = true;
interactive.onClick = function(_) onClick(); interactive.onClick = function(_) onClick();

View File

@ -15,7 +15,8 @@ import dialogue.event.NextLine;
import components.DialogueBoxComponent; import components.DialogueBoxComponent;
class DialogueBoxController { class DialogueBoxController {
public var curDialogue:DialogueBoxComponent; public var dialogueBox:DialogueBoxComponent;
public var dialogueOptions:DialogueOptionsComponent;
var game:Game; var game:Game;
var bg:h2d.ScaleGrid; var bg:h2d.ScaleGrid;
@ -28,25 +29,10 @@ class DialogueBoxController {
public function new(eventBus:EventBus, parent:h2d.Object, style:h2d.domkit.Style) { public function new(eventBus:EventBus, parent:h2d.Object, style:h2d.domkit.Style) {
this.parent = parent; this.parent = parent;
this.style = style; this.style = style;
// game = Game.current;
// parent.getScene().add(this, 1);
// bg = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5, this);
// bg.colorKey = 0xFF00FF;
// tf = new h2d.Text(game.font, this);
// tf.y = 5;
// tf.x = 7;
// tf.dropShadow = {
// dx: 0,
// dy: 1,
// color: 0,
// alpha: 0.3
// };
// int = new h2d.Interactive(0, 0, this);
// int.onClick = function(_) click();
eventBus.subscribe(LineShown, dialogue); eventBus.subscribe(LineShown, onLineShown);
// eventBus.subscribe(OptionsShown, renderOptions); eventBus.subscribe(OptionsShown, onOptionsShown);
// eventBus.subscribe(OptionSelected, onOptionSelected); eventBus.subscribe(OptionSelected, onOptionSelected);
eventBus.subscribe(DialogueComplete, onDialogueComplete); eventBus.subscribe(DialogueComplete, onDialogueComplete);
} }
@ -61,65 +47,28 @@ class DialogueBoxController {
public dynamic function onReady() {} public dynamic function onReady() {}
function dialogue(event:LineShown) { function onLineShown(event:LineShown) {
if (curDialogue != null) { if (dialogueBox != null) {
curDialogue.remove(); dialogueBox.remove();
} }
var d = new DialogueBoxComponent(event.line(), this.parent); var d = new DialogueBoxComponent(event.line(), this.parent);
style.addObject(d); style.addObject(d);
curDialogue = d; dialogueBox = d;
} }
// function renderOptions(event:OptionsShown) { function onOptionsShown(event:OptionsShown) {
// for (option in event.options) { dialogueOptions = new DialogueOptionsComponent(event.options, this.parent);
// addOption(option.text, option.enabled, function() { }
// if (option.enabled) {
// globalEventBus.publishEvent(new OptionSelected(option.index)); function onOptionSelected(event:OptionSelected) {
// } dialogueOptions.remove();
// }); }
// }
// }
//
// 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 addOption(o:String, enabled:Bool, callback:() -> Void) {
// var spr = newPanel(Const.W, 60);
// curDialogue.addChild(spr);
// var tf = new h2d.Text(font, spr);
// if (!enabled) {
// tf.color = new Vector4(0.5, 0.5, 0.5, 1);
// }
// tf.text = o;
// tf.x = 10;
// tf.y = 10;
// spr.x = 0;
// spr.y = 100 + options.length * 60;
// var int = new h2d.Interactive(spr.width, spr.height, spr);
// int.onClick = function(_) {
// callback();
// }
// int.cursor = Button;
// options.push(spr);
// return spr;
// }
//
// function onOptionSelected(event:OptionSelected) {
// for (o in options) {
// o.remove();
// }
// options.splice(0, options.length);
// }
function onDialogueComplete(event:DialogueComplete) { function onDialogueComplete(event:DialogueComplete) {
curDialogue.remove(); dialogueBox.remove();
if (dialogueOptions != null)
dialogueOptions.remove();
} }
} }