Basic dialogue box support

This commit is contained in:
3wc 2024-02-12 18:03:26 -03:00
parent f39ece171e
commit ea32d0356d
5 changed files with 315 additions and 0 deletions

View File

@ -0,0 +1,195 @@
<?xml version="1.0" encoding="utf-8"?>
<Font size="6" family="Minecraftia" height="11" style="Regular">
<Char width="2" offset="0 14" rect="1 13 0 0" code=" "/>
<Char width="2" offset="0 2" rect="2 1 1 7" code="!"/>
<Char width="4" offset="0 2" rect="4 1 3 2" code="&quot;"/>
<Char width="6" offset="0 2" rect="8 1 5 7" code="#"/>
<Char width="6" offset="0 2" rect="14 1 5 7" code="$"/>
<Char width="6" offset="0 2" rect="20 1 5 7" code="%"/>
<Char width="6" offset="0 2" rect="26 1 5 7" code="&amp;"/>
<Char width="2" offset="0 2" rect="32 1 1 2" code="'"/>
<Char width="5" offset="0 2" rect="34 1 4 7" code="("/>
<Char width="5" offset="0 2" rect="39 1 4 7" code=")"/>
<Char width="5" offset="0 2" rect="44 1 4 3" code="*"/>
<Char width="6" offset="0 4" rect="49 3 5 5" code="+"/>
<Char width="2" offset="0 7" rect="55 6 1 3" code=","/>
<Char width="6" offset="0 6" rect="57 5 5 1" code="-"/>
<Char width="2" offset="0 7" rect="63 6 1 2" code="."/>
<Char width="6" offset="0 2" rect="65 1 5 7" code="/"/>
<Char width="6" offset="0 2" rect="71 1 5 7" code="0"/>
<Char width="6" offset="0 2" rect="77 1 5 7" code="1"/>
<Char width="6" offset="0 2" rect="83 1 5 7" code="2"/>
<Char width="6" offset="0 2" rect="89 1 5 7" code="3"/>
<Char width="6" offset="0 2" rect="95 1 5 7" code="4"/>
<Char width="6" offset="0 2" rect="101 1 5 7" code="5"/>
<Char width="6" offset="0 2" rect="1 14 5 7" code="6"/>
<Char width="6" offset="0 2" rect="7 14 5 7" code="7"/>
<Char width="6" offset="0 2" rect="13 14 5 7" code="8"/>
<Char width="6" offset="0 2" rect="19 14 5 7" code="9"/>
<Char width="2" offset="0 3" rect="25 15 1 6" code=":"/>
<Char width="2" offset="0 3" rect="27 15 1 7" code=";"/>
<Char width="5" offset="0 2" rect="29 14 4 7" code="&lt;"/>
<Char width="6" offset="0 4" rect="34 16 5 4" code="="/>
<Char width="5" offset="0 2" rect="40 14 4 7" code=">"/>
<Char width="6" offset="0 2" rect="45 14 5 7" code="?"/>
<Char width="7" offset="0 2" rect="51 14 6 7" code="@"/>
<Char width="6" offset="0 2" rect="58 14 5 7" code="A"/>
<Char width="6" offset="0 2" rect="64 14 5 7" code="B"/>
<Char width="6" offset="0 2" rect="70 14 5 7" code="C"/>
<Char width="6" offset="0 2" rect="76 14 5 7" code="D"/>
<Char width="6" offset="0 2" rect="82 14 5 7" code="E"/>
<Char width="6" offset="0 2" rect="88 14 5 7" code="F"/>
<Char width="6" offset="0 2" rect="94 14 5 7" code="G"/>
<Char width="6" offset="0 2" rect="100 14 5 7" code="H"/>
<Char width="4" offset="0 2" rect="1 23 3 7" code="I"/>
<Char width="6" offset="0 2" rect="5 23 5 7" code="J"/>
<Char width="6" offset="0 2" rect="11 23 5 7" code="K"/>
<Char width="6" offset="0 2" rect="17 23 5 7" code="L"/>
<Char width="6" offset="0 2" rect="23 23 5 7" code="M"/>
<Char width="6" offset="0 2" rect="29 23 5 7" code="N"/>
<Char width="6" offset="0 2" rect="35 23 5 7" code="O"/>
<Char width="6" offset="0 2" rect="41 23 5 7" code="P"/>
<Char width="6" offset="0 2" rect="47 23 5 7" code="Q"/>
<Char width="6" offset="0 2" rect="53 23 5 7" code="R"/>
<Char width="6" offset="0 2" rect="59 23 5 7" code="S"/>
<Char width="6" offset="0 2" rect="65 23 5 7" code="T"/>
<Char width="6" offset="0 2" rect="71 23 5 7" code="U"/>
<Char width="6" offset="0 2" rect="77 23 5 7" code="V"/>
<Char width="6" offset="0 2" rect="83 23 5 7" code="W"/>
<Char width="6" offset="0 2" rect="89 23 5 7" code="X"/>
<Char width="6" offset="0 2" rect="95 23 5 7" code="Y"/>
<Char width="6" offset="0 2" rect="101 23 5 7" code="Z"/>
<Char width="4" offset="0 2" rect="1 32 3 7" code="["/>
<Char width="6" offset="0 2" rect="5 32 5 7" code="\"/>
<Char width="4" offset="0 2" rect="11 32 3 7" code="]"/>
<Char width="6" offset="0 2" rect="15 32 5 3" code="^"/>
<Char width="6" offset="0 9" rect="21 39 5 1" code="_"/>
<Char width="3" offset="0 1" rect="27 31 2 2" code="`"/>
<Char width="6" offset="0 4" rect="30 34 5 5" code="a"/>
<Char width="6" offset="0 2" rect="36 32 5 7" code="b"/>
<Char width="6" offset="0 4" rect="42 34 5 5" code="c"/>
<Char width="6" offset="0 2" rect="48 32 5 7" code="d"/>
<Char width="6" offset="0 4" rect="54 34 5 5" code="e"/>
<Char width="5" offset="0 2" rect="60 32 4 7" code="f"/>
<Char width="6" offset="0 4" rect="65 34 5 6" code="g"/>
<Char width="6" offset="0 2" rect="71 32 5 7" code="h"/>
<Char width="2" offset="0 2" rect="77 32 1 7" code="i"/>
<Char width="6" offset="0 2" rect="79 32 5 8" code="j"/>
<Char width="5" offset="0 2" rect="85 32 4 7" code="k"/>
<Char width="3" offset="0 2" rect="90 32 2 7" code="l"/>
<Char width="6" offset="0 4" rect="93 34 5 5" code="m"/>
<Char width="6" offset="0 4" rect="99 34 5 5" code="n"/>
<Char width="6" offset="0 4" rect="1 43 5 5" code="o"/>
<Char width="6" offset="0 4" rect="7 43 5 6" code="p"/>
<Char width="6" offset="0 4" rect="13 43 5 6" code="q"/>
<Char width="6" offset="0 4" rect="19 43 5 5" code="r"/>
<Char width="6" offset="0 4" rect="25 43 5 5" code="s"/>
<Char width="4" offset="0 2" rect="31 41 3 7" code="t"/>
<Char width="6" offset="0 4" rect="35 43 5 5" code="u"/>
<Char width="6" offset="0 4" rect="41 43 5 5" code="v"/>
<Char width="6" offset="0 4" rect="47 43 5 5" code="w"/>
<Char width="6" offset="0 4" rect="53 43 5 5" code="x"/>
<Char width="6" offset="0 4" rect="59 43 5 6" code="y"/>
<Char width="6" offset="0 4" rect="65 43 5 5" code="z"/>
<Char width="5" offset="0 2" rect="71 41 4 7" code="{"/>
<Char width="2" offset="0 2" rect="76 41 1 8" code="|"/>
<Char width="5" offset="0 2" rect="78 41 4 7" code="}"/>
<Char width="7" offset="0 2" rect="83 41 6 2" code="~"/>
<Char width="2" offset="0 2" rect="90 41 1 7" code="¡"/>
<Char width="5" offset="0 4" rect="92 43 4 5" code="¢"/>
<Char width="6" offset="0 2" rect="97 41 5 7" code="£"/>
<Char width="6" offset="0 3" rect="103 42 5 5" code="¤"/>
<Char width="6" offset="0 2" rect="1 51 5 7" code="¥"/>
<Char width="2" offset="0 2" rect="7 51 1 7" code="¦"/>
<Char width="6" offset="0 2" rect="9 51 5 7" code="§"/>
<Char width="5" offset="1 2" rect="15 51 3 1" code="¨"/>
<Char width="8" offset="0 2" rect="19 51 7 7" code="©"/>
<Char width="4" offset="0 2" rect="27 51 3 6" code="ª"/>
<Char width="5" offset="0 5" rect="31 54 4 4" code="«"/>
<Char width="5" offset="0 4" rect="36 53 4 3" code="¬"/>
<Char width="8" offset="0 2" rect="41 51 7 7" code="®"/>
<Char width="6" offset="0 2" rect="49 51 5 1" code="¯"/>
<Char width="4" offset="0 2" rect="55 51 3 3" code="°"/>
<Char width="6" offset="0 2" rect="59 51 5 7" code="±"/>
<Char width="4" offset="0 2" rect="65 51 3 4" code="²"/>
<Char width="4" offset="0 2" rect="69 51 3 4" code="³"/>
<Char width="3" offset="0 1" rect="73 50 2 2" code="´"/>
<Char width="6" offset="0 4" rect="76 53 5 6" code="µ"/>
<Char width="6" offset="0 2" rect="82 51 5 7" code="¶"/>
<Char width="2" offset="0 6" rect="88 55 1 1" code="·"/>
<Char width="4" offset="1 9" rect="90 58 2 2" code="¸"/>
<Char width="4" offset="0 2" rect="93 51 3 4" code="¹"/>
<Char width="4" offset="0 2" rect="97 51 3 6" code="º"/>
<Char width="5" offset="0 5" rect="101 54 4 4" code="»"/>
<Char width="9" offset="0 2" rect="1 63 8 7" code="¼"/>
<Char width="9" offset="0 2" rect="10 63 8 7" code="½"/>
<Char width="9" offset="0 2" rect="19 63 8 7" code="¾"/>
<Char width="6" offset="0 2" rect="28 63 5 7" code="¿"/>
<Char width="6" offset="0 0" rect="34 61 5 9" code="À"/>
<Char width="6" offset="0 0" rect="40 61 5 9" code="Á"/>
<Char width="6" offset="0 0" rect="46 61 5 9" code="Â"/>
<Char width="6" offset="0 0" rect="52 61 5 9" code="Ã"/>
<Char width="6" offset="0 0" rect="58 61 5 9" code="Ä"/>
<Char width="6" offset="0 0" rect="64 61 5 9" code="Å"/>
<Char width="10" offset="0 2" rect="70 63 9 7" code="Æ"/>
<Char width="6" offset="0 2" rect="80 63 5 9" code="Ç"/>
<Char width="6" offset="0 0" rect="86 61 5 9" code="È"/>
<Char width="6" offset="0 0" rect="92 61 5 9" code="É"/>
<Char width="6" offset="0 0" rect="98 61 5 9" code="Ê"/>
<Char width="6" offset="0 0" rect="1 73 5 9" code="Ë"/>
<Char width="4" offset="0 0" rect="7 73 3 9" code="Ì"/>
<Char width="4" offset="0 0" rect="11 73 3 9" code="Í"/>
<Char width="4" offset="0 0" rect="15 73 3 9" code="Î"/>
<Char width="4" offset="0 0" rect="19 73 3 9" code="Ï"/>
<Char width="7" offset="0 2" rect="23 75 6 7" code="Ð"/>
<Char width="6" offset="0 0" rect="30 73 5 9" code="Ñ"/>
<Char width="6" offset="0 0" rect="36 73 5 9" code="Ò"/>
<Char width="6" offset="0 0" rect="42 73 5 9" code="Ó"/>
<Char width="6" offset="0 0" rect="48 73 5 9" code="Ô"/>
<Char width="6" offset="0 0" rect="54 73 5 9" code="Õ"/>
<Char width="6" offset="0 0" rect="60 73 5 9" code="Ö"/>
<Char width="5" offset="0 5" rect="66 78 4 4" code="×"/>
<Char width="6" offset="0 2" rect="71 75 5 7" code="Ø"/>
<Char width="6" offset="0 0" rect="77 73 5 9" code="Ù"/>
<Char width="6" offset="0 0" rect="83 73 5 9" code="Ú"/>
<Char width="6" offset="0 0" rect="89 73 5 9" code="Û"/>
<Char width="6" offset="0 0" rect="95 73 5 9" code="Ü"/>
<Char width="6" offset="0 0" rect="101 73 5 9" code="Ý"/>
<Char width="6" offset="0 2" rect="1 85 5 7" code="Þ"/>
<Char width="6" offset="0 2" rect="7 85 5 7" code="ß"/>
<Char width="6" offset="0 1" rect="13 84 5 8" code="à"/>
<Char width="6" offset="0 1" rect="19 84 5 8" code="á"/>
<Char width="6" offset="0 1" rect="25 84 5 8" code="â"/>
<Char width="6" offset="0 1" rect="31 84 5 8" code="ã"/>
<Char width="6" offset="0 2" rect="37 85 5 7" code="ä"/>
<Char width="6" offset="0 0" rect="43 83 5 9" code="å"/>
<Char width="10" offset="0 4" rect="49 87 9 5" code="æ"/>
<Char width="6" offset="0 4" rect="59 87 5 7" code="ç"/>
<Char width="6" offset="0 1" rect="65 84 5 8" code="è"/>
<Char width="6" offset="0 1" rect="71 84 5 8" code="é"/>
<Char width="6" offset="0 1" rect="77 84 5 8" code="ê"/>
<Char width="6" offset="0 2" rect="83 85 5 7" code="ë"/>
<Char width="2" offset="-1 1" rect="89 84 2 8" code="ì"/>
<Char width="3" offset="0 1" rect="92 84 2 8" code="í"/>
<Char width="3" offset="-1 1" rect="95 84 3 8" code="î"/>
<Char width="3" offset="-1 2" rect="99 85 3 7" code="ï"/>
<Char width="6" offset="0 2" rect="103 85 5 7" code="ð"/>
<Char width="6" offset="0 1" rect="1 95 5 8" code="ñ"/>
<Char width="6" offset="0 1" rect="7 95 5 8" code="ò"/>
<Char width="6" offset="0 1" rect="13 95 5 8" code="ó"/>
<Char width="6" offset="0 1" rect="19 95 5 8" code="ô"/>
<Char width="6" offset="0 1" rect="25 95 5 8" code="õ"/>
<Char width="6" offset="0 2" rect="31 96 5 7" code="ö"/>
<Char width="6" offset="0 4" rect="37 98 5 5" code="÷"/>
<Char width="6" offset="0 4" rect="43 98 5 5" code="ø"/>
<Char width="6" offset="0 1" rect="49 95 5 8" code="ù"/>
<Char width="6" offset="0 1" rect="55 95 5 8" code="ú"/>
<Char width="6" offset="0 1" rect="61 95 5 8" code="û"/>
<Char width="6" offset="0 2" rect="67 96 5 7" code="ü"/>
<Char width="6" offset="0 1" rect="73 95 5 9" code="ý"/>
<Char width="6" offset="0 2" rect="79 96 5 8" code="þ"/>
<Char width="6" offset="0 4" rect="85 98 5 6" code="ÿ"/>
<Char width="10" offset="0 2" rect="91 96 9 7" code="Œ"/>
<Char width="10" offset="0 4" rect="1 107 9 5" code="œ"/>
<Char width="6" offset="0 2" rect="11 105 5 7" code="€"/>
</Font>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
res/ui.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

94
src/Dialogue.hx Normal file
View File

@ -0,0 +1,94 @@
class Dialogue 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,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;
game.scene.add(this, 1);
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 = { 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;
}
}

View File

@ -5,13 +5,39 @@ class Game extends hxd.App {
public var scene : h2d.Scene; public var scene : h2d.Scene;
public var font : h2d.Font; public var font : h2d.Font;
public var world : World; public var world : World;
public var curDialog : h2d.Object;
override function init() { override function init() {
scene = s2d; scene = s2d;
s2d.setFixedSize(Const.W, Const.H + 12); s2d.setFixedSize(Const.W, Const.H + 12);
world = new World(Res.map, Res.tiles); world = new World(Res.map, Res.tiles);
s2d.add(world.root, 0); s2d.add(world.root, 0);
font = Res.minecraftia_regular_6.toFont();
dialog([
"(you slowly wake up)",
"...",
"where am I?",
"(the cold vastness of spaaaaace)"
]);
} }
public static var inst : Game; 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;
d.onClick = function() {
d.remove();
curDialog = null;
var t2 = t.copy();
t2.shift();
dialog(t2);
};
curDialog = d;
}
} }