Compare commits
12 Commits
c768073503
...
main
Author | SHA1 | Date | |
---|---|---|---|
2a63c748f1 | |||
216f1ecd4c | |||
035f69d9fc | |||
624b538ad8 | |||
e375d0028e | |||
d308ce7231 | |||
8a803b9cdc | |||
e1bdd74100 | |||
610d107e60 | |||
2ad54aa613 | |||
ed8bc13402 | |||
d6b042f2a4 |
34
TODO.md
34
TODO.md
@ -2,22 +2,30 @@
|
||||
|
||||
## Features
|
||||
|
||||
- Saving and loading games
|
||||
- Character select
|
||||
- Stats
|
||||
- Better open / closed state graphics for rooms
|
||||
- Displaying sprites (characters, objects)
|
||||
- Inventory
|
||||
- Room labels
|
||||
- Background music
|
||||
- Sound effects
|
||||
- [ ] Saving and loading games
|
||||
- [ ] Character select
|
||||
- [ ] Stats
|
||||
- [ ] Better open / closed state graphics for rooms
|
||||
- [ ] Displaying sprites (characters, objects)
|
||||
- [ ] Inventory
|
||||
- [ ] Room labels
|
||||
- [ ] Background music
|
||||
- [ ] Sound effects
|
||||
- [ ] Custom debug console commands
|
||||
|
||||
## Bugs
|
||||
|
||||
- [x] Console rendering issues
|
||||
- [ ] DOM tree rendering issues
|
||||
- [x] Inconsistent text formatting
|
||||
|
||||
### Dialogue
|
||||
|
||||
- Text formatting
|
||||
- Character profiles / speaker ID
|
||||
- [x] Text formatting
|
||||
- [ ] Character profiles / speaker ID
|
||||
- [ ] Scrollable dialogue pane (like Citizen Sleeper / Disco Elysium)
|
||||
|
||||
## Code architecture
|
||||
|
||||
- Move dialogue- and option-drawing out of `Game.hx`
|
||||
- Use domkit for dialogue
|
||||
- [x] Move dialogue- and option-drawing out of `Game.hx`
|
||||
- [x] Use domkit for dialogue
|
||||
|
@ -3,5 +3,5 @@
|
||||
-lib heaps:git:https://github.com/HeapsIO/heaps.git
|
||||
-lib tiledhx
|
||||
-lib hxyarn
|
||||
-main Main
|
||||
-main Game
|
||||
-lib domkit
|
||||
|
@ -2,4 +2,4 @@ compile-common.hxml
|
||||
|
||||
-D windowTitle=StoneInAGlasshouse
|
||||
-lib hlsdl
|
||||
-hl bin/rewild.hl
|
||||
-hl bin/glasshouse.hl
|
||||
|
10
makefile
10
makefile
@ -1,23 +1,23 @@
|
||||
.PHONY: watch run
|
||||
|
||||
default: bin/rewild.hl
|
||||
default: bin/glasshouse.hl
|
||||
|
||||
SOURCES := $(shell find . -name \*.hx -print)
|
||||
|
||||
bin/rewild.hl: $(SOURCES)
|
||||
bin/glasshouse.hl: $(SOURCES)
|
||||
haxe compile-hl.hxml
|
||||
|
||||
bin/rewild.js: $(SOURCES)
|
||||
bin/glasshouse.js: $(SOURCES)
|
||||
haxe compile-js.hxml
|
||||
|
||||
debug: $(SOURCES)
|
||||
haxe --debug compile-hl.hxml
|
||||
|
||||
clean:
|
||||
rm -f bin/rewild.hl bin/rewild.js
|
||||
rm -f bin/glasshouse.hl bin/glasshouse.js
|
||||
|
||||
watch:
|
||||
@inotifywait --recursive --monitor --event modify,move,create,delete --include '.*.hx$$' ./ | while read changed; do echo $$changed; make debug; done
|
||||
|
||||
run:
|
||||
hl bin/rewild.hl
|
||||
hl bin/glasshouse.hl
|
||||
|
@ -52,3 +52,33 @@ menubutton:hover text {
|
||||
menubutton:active {
|
||||
background: #666;
|
||||
}
|
||||
|
||||
flow.dialogue-container {
|
||||
fill-width: true;
|
||||
min-height: 20;
|
||||
layout: vertical;
|
||||
}
|
||||
|
||||
dialogue-box {
|
||||
fill-width: true;
|
||||
background: blue;
|
||||
padding: 10;
|
||||
alpha: 0.9;
|
||||
min-height: 20;
|
||||
}
|
||||
|
||||
dialogue-options {
|
||||
fill-width: true;
|
||||
layout: vertical;
|
||||
}
|
||||
|
||||
dialogue-option {
|
||||
fill-width: true;
|
||||
background: green;
|
||||
padding: 10;
|
||||
alpha: 0.9;
|
||||
}
|
||||
|
||||
dialogue-option.disabled {
|
||||
alpha: 0.5;
|
||||
}
|
||||
|
@ -1,37 +1,42 @@
|
||||
title: Room:quarters
|
||||
---
|
||||
<<declare $roll = 0>>
|
||||
<<declare $quartersIntroSeen = false>>
|
||||
<<declare $hangarKeyFound = false>>
|
||||
<<declare $sleepingMatSetUp = false>>
|
||||
You: It's the crew quarters.
|
||||
<<if not $quartersIntroSeen>>
|
||||
You: It's the [room]crew quarters[/room].
|
||||
You: Well, it will be. Set-up hasn't started yet.
|
||||
You: That was meant to be one of my first jobs after defrost...
|
||||
You: ...but it doesn't exactly seem like a priority now.
|
||||
<<set $quartersIntroSeen to true>>
|
||||
<<endif>>
|
||||
You: Maybe there's something useful here?
|
||||
-> Search the lockers (perception) <<if not $hangarKeyFound>>
|
||||
-> Search the lockers [ability](perception)[/ability] <<if not $hangarKeyFound>>
|
||||
<<set $roll to dice(6)>>
|
||||
<<if $roll > 2>>
|
||||
You: Aha! A small piece of paper with the **hangar access code**.
|
||||
<<if $roll > 0>>
|
||||
You: Aha! A small piece of paper with the [item]access code[/item] for the [room]hangar[/room].
|
||||
<<room hangar>>
|
||||
<<set $hangarKeyFound to true>>
|
||||
<<else>>
|
||||
You: Just some dust bunnies. Guess they stowed away from Earth.
|
||||
<<endif>>
|
||||
-> Set up a sleeping mat (ingenuity) <<if not $sleepingMatSetUp>>
|
||||
-> Set up a sleeping mat [ability](ingenuity)[/ability] <<if not $sleepingMatSetUp>>
|
||||
<<set $roll to dice(6)>>
|
||||
<<if $roll > 2>>
|
||||
You: Nice, at least I have somewhere to crash now.
|
||||
<<set $sleepingMatSetUp to true>>
|
||||
<<else>>
|
||||
You: Hmm, I was never good at this camping stuff. Maybe I can find somewhere else to rest.
|
||||
You: [failure]Hmm, I was never good at this camping stuff. Maybe I can find somewhere else to rest.[/failure]
|
||||
<<endif>>
|
||||
-> Leave
|
||||
===
|
||||
title: Room:hangar
|
||||
---
|
||||
You: The **hangar** seems eerily deserted.
|
||||
You: The [room]hangar[/room] seems eerily deserted.
|
||||
===
|
||||
title: Room not open
|
||||
---
|
||||
You: Hmm, that part of the ship is still inaccessible. I wonder how to get in?
|
||||
<<room hangar>>
|
||||
===
|
||||
|
110
src/Game.hx
110
src/Game.hx
@ -7,13 +7,8 @@ import scene.GameScene;
|
||||
import event.EventBus;
|
||||
import event.ChangeSceneEvent;
|
||||
import Const;
|
||||
import dialogue.DialogueBox;
|
||||
import listeners.DialogueBoxController;
|
||||
import dialogue.DialogueManager;
|
||||
import dialogue.event.LineShown;
|
||||
import dialogue.event.OptionsShown;
|
||||
import dialogue.event.OptionSelected;
|
||||
import dialogue.event.DialogueComplete;
|
||||
import dialogue.event.NextLine;
|
||||
import dialogue.command.OpenRoomCommand;
|
||||
|
||||
@:uiComp("game-container")
|
||||
@ -27,28 +22,26 @@ class GameContainer extends h2d.Flow implements h2d.domkit.Object {
|
||||
public function new(?parent) {
|
||||
super(parent);
|
||||
initComponent();
|
||||
this.maxWidth = Const.W;
|
||||
this.minWidth = Const.W;
|
||||
}
|
||||
}
|
||||
|
||||
class Game extends hxd.App {
|
||||
public var font:h2d.Font;
|
||||
public var curDialogue:h2d.Object;
|
||||
public var options:Array<h2d.ScaleGrid> = [];
|
||||
public var dialogueManager:DialogueManager;
|
||||
|
||||
public var globalEventBus:EventBus;
|
||||
|
||||
public static var loader = new tiled.Tiled();
|
||||
public static var current:Game; // Current Game (singleton)
|
||||
|
||||
var layer:Layers;
|
||||
|
||||
public var font:h2d.Font;
|
||||
public var options:Array<h2d.ScaleGrid> = [];
|
||||
public var dialogueManager:DialogueManager;
|
||||
public var root:GameContainer;
|
||||
public var console:Console;
|
||||
public var globalEventBus:EventBus;
|
||||
|
||||
var dialogueBoxController:DialogueBoxController;
|
||||
var layer:Layers;
|
||||
var style = null;
|
||||
|
||||
public static var loader = new tiled.Tiled();
|
||||
|
||||
override function init() {
|
||||
s2d.scaleMode = Stretch(Const.W, Const.H);
|
||||
layer = new Layers(s2d);
|
||||
@ -62,7 +55,6 @@ class Game extends hxd.App {
|
||||
|
||||
root = new GameContainer();
|
||||
root.horizontalAlign = root.verticalAlign = Middle;
|
||||
// s2d.add(root);
|
||||
layer.addChildAt(root, 1);
|
||||
onResize();
|
||||
|
||||
@ -72,14 +64,13 @@ class Game extends hxd.App {
|
||||
style.addObject(root);
|
||||
|
||||
font = Res.font.minecraftia_regular_6.toFont();
|
||||
font.resizeTo(18);
|
||||
|
||||
#if debug
|
||||
console = new Console(font);
|
||||
layer.addChildAt(console, 4);
|
||||
#end
|
||||
|
||||
font.resizeTo(20);
|
||||
|
||||
globalEventBus = new EventBus(console);
|
||||
globalEventBus.subscribe(ChangeSceneEvent, onChangeScene);
|
||||
|
||||
@ -89,12 +80,15 @@ class Game extends hxd.App {
|
||||
var yarnFileNames = [hxd.Res.text.intro.entry.name, hxd.Res.text.rooms.entry.name,];
|
||||
dialogueManager.load(yarnText, yarnFileNames);
|
||||
|
||||
globalEventBus.subscribe(LineShown, dialogue);
|
||||
globalEventBus.subscribe(OptionsShown, renderOptions);
|
||||
globalEventBus.subscribe(OptionSelected, onOptionSelected);
|
||||
globalEventBus.subscribe(DialogueComplete, onDialogueComplete);
|
||||
dialogueManager.addCommandHandler(new OpenRoomCommand(globalEventBus));
|
||||
|
||||
var dialogueParent = new h2d.Flow();
|
||||
dialogueParent.dom = domkit.Properties.create("flow", dialogueParent);
|
||||
dialogueParent.dom.addClass('dialogue-container');
|
||||
layer.addChildAt(dialogueParent, 2);
|
||||
style.addObject(dialogueParent);
|
||||
dialogueBoxController = new DialogueBoxController(globalEventBus, dialogueParent, style);
|
||||
|
||||
#if debug
|
||||
setGameScene(new WorldMapScene(root));
|
||||
#else
|
||||
@ -116,70 +110,6 @@ class Game extends hxd.App {
|
||||
style.sync();
|
||||
}
|
||||
|
||||
function dialogue(event:LineShown) {
|
||||
if (curDialogue != null) {
|
||||
curDialogue.remove();
|
||||
}
|
||||
var d = new DialogueBox(Const.W, 100, event.line());
|
||||
d.y = 0;
|
||||
d.onClick = function() {
|
||||
globalEventBus.publishEvent(new NextLine());
|
||||
};
|
||||
|
||||
curDialogue = d;
|
||||
}
|
||||
|
||||
function renderOptions(event:OptionsShown) {
|
||||
for (option in event.options) {
|
||||
addOption(option.text, option.enabled, function() {
|
||||
if (option.enabled) {
|
||||
globalEventBus.publishEvent(new OptionSelected(option.index));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
curDialogue.remove();
|
||||
}
|
||||
|
||||
public function onChangeScene(event:ChangeSceneEvent) {
|
||||
setGameScene(event.newScene);
|
||||
}
|
||||
@ -196,4 +126,8 @@ class Game extends hxd.App {
|
||||
root.scene = gs;
|
||||
style.addObject(gs.getH2dObject());
|
||||
}
|
||||
|
||||
static function main() {
|
||||
new Game();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
class Main {
|
||||
static function main() {
|
||||
new Game();
|
||||
}
|
||||
}
|
218
src/components/DialogueBoxComponent.hx
Normal file
218
src/components/DialogueBoxComponent.hx
Normal file
@ -0,0 +1,218 @@
|
||||
package components;
|
||||
|
||||
import h2d.HtmlText;
|
||||
import hxyarn.dialogue.markup.MarkupParseResult;
|
||||
|
||||
import dialogue.event.NextLine;
|
||||
import dialogue.event.LineShown;
|
||||
import dialogue.event.OptionSelected;
|
||||
import dialogue.event.OptionsShown.OptionChoice;
|
||||
|
||||
@: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;
|
||||
}
|
||||
|
||||
var choice:OptionChoice;
|
||||
|
||||
public function new(choice:OptionChoice, ?parent) {
|
||||
super(parent);
|
||||
initComponent();
|
||||
this.choice = choice;
|
||||
this.label = choice.text;
|
||||
if (!choice.enabled) {
|
||||
this.dom.addClass('disabled');
|
||||
}
|
||||
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() {
|
||||
if (this.choice.enabled)
|
||||
Game.current.globalEventBus.publishEvent(new OptionSelected(this.choice.index));
|
||||
}
|
||||
}
|
||||
|
||||
@:uiComp("dialogue-options")
|
||||
class DialogueOptionsComponent extends h2d.Flow implements h2d.domkit.Object {
|
||||
static var SRC = <dialogue-options>
|
||||
${options}
|
||||
</dialogue-options>;
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
override function onRemove() {
|
||||
for (option in this.options)
|
||||
option.remove();
|
||||
super.onRemove();
|
||||
}
|
||||
}
|
||||
|
||||
@: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;
|
||||
public var lineMarkup:MarkupParseResult;
|
||||
|
||||
static var SRC = <dialogue-box>
|
||||
<html-text text={displayedText} public font={Game.current.font} id="dialogueText" />
|
||||
</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(lineShown:LineShown, ?parent) {
|
||||
this.game = Game.current;
|
||||
super(parent);
|
||||
initComponent();
|
||||
this.lineMarkup = lineShown.markUpResults;
|
||||
this.internalText = lineShown.line();
|
||||
|
||||
enableInteractive = true;
|
||||
interactive.onClick = function(_) onClick();
|
||||
}
|
||||
|
||||
function updateText() {
|
||||
if (textPos == internalText.length) {
|
||||
timer.stop();
|
||||
// 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 = applyTextAttributes(internalText.substr(0, textPos));
|
||||
}
|
||||
|
||||
function applyTextAttributes(text:String):String {
|
||||
var characterOffset = 0;
|
||||
var characterAttribute = lineMarkup.tryGetAttributeWithName("character");
|
||||
if (characterAttribute != null)
|
||||
characterOffset = -characterAttribute.length;
|
||||
|
||||
var htmlTagsByIndex = new Map<Int, String>();
|
||||
|
||||
for (attribute in lineMarkup.attributes) {
|
||||
var startTagIndex = attribute.position + characterOffset;
|
||||
if (startTagIndex < text.length) {
|
||||
var currrentStartTag = "";
|
||||
var currentEndTag = "";
|
||||
var endTagIndex = Std.int(Math.min(text.length, startTagIndex + attribute.length));
|
||||
if (htmlTagsByIndex.exists(startTagIndex))
|
||||
currrentStartTag = htmlTagsByIndex.get(startTagIndex);
|
||||
|
||||
if (htmlTagsByIndex.exists(endTagIndex))
|
||||
currentEndTag = htmlTagsByIndex.get(endTagIndex);
|
||||
|
||||
if (attribute.name == "room") {
|
||||
var openTag = '$currrentStartTag<font color="#00FF00">';
|
||||
var closeTag = '</font>$currentEndTag';
|
||||
htmlTagsByIndex.set(startTagIndex, openTag);
|
||||
htmlTagsByIndex.set(endTagIndex, closeTag);
|
||||
} else if (attribute.name == "item") {
|
||||
var openTag = '$currrentStartTag<font color="#CD853F">';
|
||||
var closeTag = '</font>$currentEndTag';
|
||||
htmlTagsByIndex.set(startTagIndex, openTag);
|
||||
htmlTagsByIndex.set(endTagIndex, closeTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sb = new StringBuf();
|
||||
|
||||
for (i in 0...text.length) {
|
||||
var char = text.charAt(i);
|
||||
if (htmlTagsByIndex.exists(i)) {
|
||||
sb.add(htmlTagsByIndex.get(i));
|
||||
}
|
||||
|
||||
sb.add(char);
|
||||
}
|
||||
|
||||
if (htmlTagsByIndex.exists(text.length)) {
|
||||
sb.add(htmlTagsByIndex.get(text.length));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
override function onRemove() {
|
||||
super.onRemove();
|
||||
// if (chan != null)
|
||||
// chan.stop();
|
||||
// timer.stop();
|
||||
}
|
||||
|
||||
public dynamic function onClick() {
|
||||
if (textPos == internalText.length)
|
||||
Game.current.globalEventBus.publishEvent(new NextLine());
|
||||
else if (textPos < internalText.length) {
|
||||
textPos = internalText.length;
|
||||
displayedText = applyTextAttributes(internalText);
|
||||
updateText();
|
||||
};
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
package dialogue;
|
||||
|
||||
class DialogueBox extends h2d.Object {
|
||||
var game:Game;
|
||||
var bg:h2d.ScaleGrid;
|
||||
var tf:h2d.Text;
|
||||
var timer:haxe.Timer;
|
||||
var int:h2d.Interactive;
|
||||
|
||||
public var width(default, set):Int;
|
||||
public var height(default, set):Int;
|
||||
public var text(default, set):String;
|
||||
|
||||
var textPos:Int = 0;
|
||||
var chan:hxd.snd.Channel;
|
||||
|
||||
public function new(width:Int, height:Int, text:String) {
|
||||
super();
|
||||
if (text == null)
|
||||
text = "NULL";
|
||||
game = Game.current;
|
||||
cast(game.root, h2d.Object).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();
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
override function onRemove() {
|
||||
super.onRemove();
|
||||
if (chan != null)
|
||||
chan.stop();
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
function updateText() {
|
||||
if (textPos == text.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++;
|
||||
tf.text = text.substr(0, textPos);
|
||||
}
|
||||
|
||||
public function click() {
|
||||
if (textPos == text.length)
|
||||
onClick()
|
||||
else if (textPos < text.length) {
|
||||
textPos = text.length;
|
||||
tf.text = text;
|
||||
updateText();
|
||||
};
|
||||
}
|
||||
|
||||
public dynamic function onClick() {}
|
||||
|
||||
public dynamic function onReady() {}
|
||||
|
||||
function set_text(t) {
|
||||
text = t;
|
||||
timer = new haxe.Timer(30);
|
||||
timer.run = updateText;
|
||||
tf.text = "";
|
||||
textPos = 0;
|
||||
return t;
|
||||
}
|
||||
|
||||
function set_width(w:Int) {
|
||||
bg.width = w;
|
||||
int.width = w;
|
||||
tf.maxWidth = w - 14;
|
||||
tf.text = text;
|
||||
return width = w;
|
||||
}
|
||||
|
||||
function set_height(h:Int) {
|
||||
bg.height = h;
|
||||
int.height = h;
|
||||
return height = h;
|
||||
}
|
||||
}
|
@ -40,6 +40,7 @@ class EventBus {
|
||||
#end
|
||||
return;
|
||||
}
|
||||
trace('Publishing event $type');
|
||||
|
||||
for (func in listeners.get(type))
|
||||
func(event);
|
||||
|
68
src/listeners/DialogueBoxController.hx
Normal file
68
src/listeners/DialogueBoxController.hx
Normal file
@ -0,0 +1,68 @@
|
||||
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, this.parent);
|
||||
style.addObject(d);
|
||||
dialogueBox = d;
|
||||
} else {
|
||||
dialogueBox.lineMarkup = event.markUpResults;
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user