omg working yarnspinner dialogue 😍
This commit is contained in:
parent
96c430c3c1
commit
51d10f430f
@ -2,6 +2,7 @@
|
||||
--macro Init.setup()
|
||||
-lib heaps
|
||||
-lib hlsdl
|
||||
-lib hxyarn
|
||||
-hl rewild.hl
|
||||
-main Main
|
||||
-lib domkit
|
||||
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
2058
res/font/pixel_unicode/Pixel-UniCode.fnt
Normal file
2058
res/font/pixel_unicode/Pixel-UniCode.fnt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
res/font/pixel_unicode/Pixel-UniCode.ttf
Normal file
BIN
res/font/pixel_unicode/Pixel-UniCode.ttf
Normal file
Binary file not shown.
BIN
res/font/pixel_unicode/Pixel-UniCode_0.png
Normal file
BIN
res/font/pixel_unicode/Pixel-UniCode_0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
4
res/font/pixel_unicode/license.txt
Normal file
4
res/font/pixel_unicode/license.txt
Normal file
@ -0,0 +1,4 @@
|
||||
The FontStruction “Pixel UniCode”
|
||||
(http://fontstruct.com/fontstructions/show/908795) by “ivancr72” is licensed
|
||||
under a Creative Commons Attribution license
|
||||
(http://creativecommons.org/licenses/by/3.0/).
|
26
res/font/pixel_unicode/readme.txt
Normal file
26
res/font/pixel_unicode/readme.txt
Normal file
@ -0,0 +1,26 @@
|
||||
The font file in this archive was created using Fontstruct the free, online
|
||||
font-building tool.
|
||||
This font was created by “ivancr72”.
|
||||
This font has a homepage where this archive and other versions may be found:
|
||||
http://fontstruct.com/fontstructions/show/908795
|
||||
|
||||
Try Fontstruct at http://fontstruct.com
|
||||
It’s easy and it’s fun.
|
||||
|
||||
NOTE FOR FLASH USERS: Fontstruct fonts (fontstructions) are optimized for Flash.
|
||||
If the font in this archive is a pixel font, it is best displayed at a font-size
|
||||
of 16.
|
||||
|
||||
Fontstruct is sponsored by FontShop.
|
||||
Visit them at http://fontshop.com
|
||||
FontShop is the original independent font retailer. We’ve been around since
|
||||
the dawn of digital type. Whether you need the right font or need to create the
|
||||
right font from scratch, let our 23 years of experience work for you.
|
||||
|
||||
Fontstruct is copyright ©2013-2014 Rob Meek
|
||||
|
||||
LEGAL NOTICE:
|
||||
In using this font you must comply with the licensing terms described in the
|
||||
file “license.txt” included with this archive.
|
||||
If you redistribute the font file in this archive, it must be accompanied by all
|
||||
the other files from this archive, including this one.
|
10
res/text/encounters.yarn
Normal file
10
res/text/encounters.yarn
Normal file
@ -0,0 +1,10 @@
|
||||
title: Intro
|
||||
---
|
||||
You: It's been 3 earth-days since I woke up from cryostasis, and I still don't know what's going on.
|
||||
You: Why is nobody else awake?
|
||||
You: What happened to the updates from mission control?
|
||||
-> Wow, some options!
|
||||
You got it, pal!
|
||||
-> Can I put text inside options?
|
||||
You sure can!
|
||||
===
|
@ -1,4 +1,4 @@
|
||||
class Dialogue extends h2d.Object {
|
||||
class DialogueBox extends h2d.Object {
|
||||
var game:Game;
|
||||
var bg:h2d.ScaleGrid;
|
||||
var tf:h2d.Text;
|
||||
@ -12,11 +12,8 @@ class Dialogue extends h2d.Object {
|
||||
var textPos:Int = 0;
|
||||
var chan:hxd.snd.Channel;
|
||||
|
||||
// public function new(width:Int, height:Int, text : String,sfx:hxd.res.Sound) {
|
||||
public function new(width:Int, height:Int, text:String) {
|
||||
super();
|
||||
// if( sfx != null )
|
||||
// chan = sfx.play(true);
|
||||
if (text == null)
|
||||
text = "NULL";
|
||||
game = Game.inst;
|
||||
@ -24,8 +21,6 @@ class Dialogue extends h2d.Object {
|
||||
bg = new h2d.ScaleGrid(Res.ui.toTile(), 5, 5, this);
|
||||
bg.colorKey = 0xFF00FF;
|
||||
tf = new h2d.Text(game.font, this);
|
||||
tf.scaleX = 2;
|
||||
tf.scaleY = 2;
|
||||
tf.y = 5;
|
||||
tf.x = 7;
|
||||
tf.dropShadow = {
|
112
src/DialogueManager.hx
Normal file
112
src/DialogueManager.hx
Normal file
@ -0,0 +1,112 @@
|
||||
import hxyarn.dialogue.Dialogue;
|
||||
import hxyarn.dialogue.VariableStorage.MemoryVariableStore;
|
||||
import hxyarn.dialogue.StringInfo;
|
||||
import hxyarn.dialogue.Line;
|
||||
import hxyarn.dialogue.Command;
|
||||
import hxyarn.dialogue.Option;
|
||||
import hxyarn.dialogue.OptionSet;
|
||||
import hxyarn.compiler.Compiler;
|
||||
import hxyarn.compiler.CompilationJob;
|
||||
|
||||
class DialogueManager {
|
||||
var storage = new MemoryVariableStore();
|
||||
var dialogue:Dialogue;
|
||||
var stringTable:Map<String, StringInfo>;
|
||||
var callback:(DialogueManager, String) -> Void;
|
||||
|
||||
public function new(lineHandlerCallback:(DialogueManager, String) -> Void) {
|
||||
dialogue = new Dialogue(new MemoryVariableStore());
|
||||
|
||||
dialogue.logDebugMessage = this.logDebugMessage;
|
||||
dialogue.logErrorMessage = this.logErrorMessage;
|
||||
dialogue.lineHandler = this.lineHandler;
|
||||
dialogue.optionsHandler = this.optionsHandler;
|
||||
dialogue.commandHandler = this.commandHandler;
|
||||
dialogue.nodeCompleteHandler = this.nodeCompleteHandler;
|
||||
dialogue.nodeStartHandler = this.nodeStartHandler;
|
||||
dialogue.dialogueCompleteHandler = this.dialogueCompleteHandler;
|
||||
|
||||
callback = lineHandlerCallback;
|
||||
}
|
||||
|
||||
public function load(text:Array<String>, fileNames:Array<String>) {
|
||||
var job = CompilationJob.createFromStrings(text, fileNames, dialogue.library);
|
||||
var compiler = Compiler.compile(job);
|
||||
stringTable = compiler.stringTable;
|
||||
|
||||
dialogue.addProgram(compiler.program);
|
||||
}
|
||||
|
||||
public function runNode(nodeName:String) {
|
||||
dialogue.setNode(nodeName);
|
||||
dialogue.resume();
|
||||
}
|
||||
|
||||
public function unload() {
|
||||
dialogue.unloadAll();
|
||||
}
|
||||
|
||||
public function resume() {
|
||||
dialogue.resume();
|
||||
}
|
||||
|
||||
public function logDebugMessage(message:String):Void {
|
||||
}
|
||||
|
||||
public function logErrorMessage(message:String):Void {
|
||||
}
|
||||
|
||||
public function lineHandler(line:Line):HandlerExecutionType {
|
||||
var text = getComposedTextForLine(line);
|
||||
|
||||
callback(this, text);
|
||||
|
||||
return HandlerExecutionType.ContinueExecution;
|
||||
}
|
||||
|
||||
public function optionsHandler(options:OptionSet) {
|
||||
var optionCount = options.options.length;
|
||||
var optionText = new Array<String>();
|
||||
|
||||
for (option in options.options) {
|
||||
var text = getComposedTextForLine(option.line);
|
||||
optionText.push(text);
|
||||
}
|
||||
|
||||
// show options
|
||||
}
|
||||
|
||||
public function getComposedTextForLine(line:Line):String {
|
||||
var substitutedText = Dialogue.expandSubstitutions(stringTable[line.id].text, line.substitutions);
|
||||
|
||||
var markup = dialogue.parseMarkup(substitutedText);
|
||||
|
||||
return markup.text;
|
||||
}
|
||||
|
||||
public function commandHandler(command:Command) {
|
||||
}
|
||||
|
||||
public function nodeCompleteHandler(nodeName:String) {}
|
||||
|
||||
public function nodeStartHandler(nodeName:String) {}
|
||||
|
||||
public function dialogueCompleteHandler() {
|
||||
}
|
||||
|
||||
public function getNodeNames(?includesTag = "") {
|
||||
var nodeNames = [];
|
||||
for (nodeName in dialogue.allNodes) {
|
||||
if (includesTag == "") {
|
||||
nodeNames.push(nodeName);
|
||||
continue;
|
||||
}
|
||||
|
||||
var tags = dialogue.getTagsForNode(nodeName);
|
||||
if (tags.contains(includesTag)) {
|
||||
nodeNames.push(nodeName);
|
||||
}
|
||||
}
|
||||
return nodeNames;
|
||||
}
|
||||
}
|
36
src/Game.hx
36
src/Game.hx
@ -1,4 +1,6 @@
|
||||
import Const;
|
||||
import DialogueBox;
|
||||
import DialogueManager;
|
||||
|
||||
@:publicFields
|
||||
class Game extends hxd.App {
|
||||
@ -6,32 +8,38 @@ class Game extends hxd.App {
|
||||
public var font:h2d.Font;
|
||||
public var world:World;
|
||||
public var curDialog:h2d.Object;
|
||||
public var dialogueManager:DialogueManager;
|
||||
|
||||
override function init() {
|
||||
scene = s2d;
|
||||
s2d.setFixedSize(Const.W, Const.H + 12);
|
||||
s2d.scaleMode = Stretch(Const.W, Const.H + 12);
|
||||
world = new World(Res.map, Res.tiles);
|
||||
s2d.add(world.root, 0);
|
||||
font = Res.minecraftia_regular_6.toFont();
|
||||
|
||||
dialog(["(you slowly wake up)", "...", "where am I?", "(the cold vastness of spaaaaace)"]);
|
||||
font = Res.font.minecraftia_regular_6.toFont();
|
||||
font.resizeTo(24);
|
||||
|
||||
dialogueManager = new DialogueManager(dialogue);
|
||||
|
||||
var yarnText = [
|
||||
hxd.Res.text.encounters.entry.getText(),
|
||||
];
|
||||
var yarnFileNames = [
|
||||
hxd.Res.text.encounters.entry.name,
|
||||
];
|
||||
dialogueManager.load(yarnText, yarnFileNames);
|
||||
dialogueManager.runNode("Intro");
|
||||
}
|
||||
|
||||
public static var inst:Game;
|
||||
|
||||
function dialog(t:Array<String>) {
|
||||
if (t.length == 0) {
|
||||
return;
|
||||
}
|
||||
var d = new Dialogue(Const.W, 100, t[0]);
|
||||
d.y = Const.H - d.height;
|
||||
function dialogue(manager:DialogueManager, t:String) {
|
||||
var d = new DialogueBox(Const.W, 100, t);
|
||||
d.y = 0;
|
||||
d.onClick = function() {
|
||||
d.remove();
|
||||
curDialog = null;
|
||||
var t2 = t.copy();
|
||||
t2.shift();
|
||||
dialog(t2);
|
||||
manager.resume();
|
||||
};
|
||||
|
||||
curDialog = d;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user