reusable Hank story window
This commit is contained in:
5
haxe_libraries/hank.hxml
Normal file
5
haxe_libraries/hank.hxml
Normal file
@@ -0,0 +1,5 @@
|
||||
# @install: lix --silent download "git:https://k7izh9.gitea.cloud/NQN/hank#915f0ea58cc0940f47eb88171a36b7f39e1070e5" into hank/0.0.8/git/915f0ea58cc0940f47eb88171a36b7f39e1070e5
|
||||
# @run: haxelib run-dir hank "${HAXE_LIBCACHE}/hank/0.0.8/git/915f0ea58cc0940f47eb88171a36b7f39e1070e5"
|
||||
-lib hscript
|
||||
-cp ${HAXE_LIBCACHE}/hank/0.0.8/git/915f0ea58cc0940f47eb88171a36b7f39e1070e5/
|
||||
-D hank=0.0.8
|
||||
@@ -22,6 +22,7 @@ import flixel.input.mouse.FlxMouseEvent;
|
||||
import kiss_flixel.KissExtendedSprite;
|
||||
import flixel.addons.plugin.FlxMouseControl;
|
||||
import hx.strings.Strings;
|
||||
import hank.Story;
|
||||
|
||||
using haxe.io.Path;
|
||||
using StringTools;
|
||||
@@ -46,5 +47,7 @@ typedef ConstructorArgs = {
|
||||
?screenReaderAudioFolder:String
|
||||
};
|
||||
|
||||
typedef HankChoiceTagEvent = String->Void;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class SimpleWindow extends FlxSprite {}
|
||||
|
||||
@@ -1064,4 +1064,34 @@
|
||||
(choiceWindow.moveTo mousePos)
|
||||
(choiceWindow.resize
|
||||
(+ (or choiceWindow.selectionMarker?.width 0) (* textSize 2) (or choiceWindow.xText?.width 0) (apply max (for control choiceWindow.controls control.width)))
|
||||
(Std.int choiceWindow.nextControlY)))))
|
||||
(Std.int choiceWindow.nextControlY)))))
|
||||
|
||||
(function hankStoryWindow [:String file :ConstructorArgs args &opt :Map<String,HankChoiceTagEvent> onChoiceTags]
|
||||
(let [story (Story.FromFile file)
|
||||
window (SimpleWindow.create args)]
|
||||
(localFunction :Void showNextFrame []
|
||||
(let [frame (story.nextFrame)]
|
||||
(case frame
|
||||
(Finished
|
||||
(window.makeTextV2 "Done"
|
||||
(object
|
||||
onClick ->_ (window.hide))))
|
||||
((HasText text)
|
||||
(window.makeTextV2 text)
|
||||
(showNextFrame))
|
||||
((HasChoices choices tags)
|
||||
(doFor [idx choice] (enumerate choices)
|
||||
(window.makeTextV2 "[$(+ idx 1)] $choice"
|
||||
(object onClick
|
||||
->_ {
|
||||
// Call events for tags
|
||||
(doFor tag (nth tags idx)
|
||||
(when (onChoiceTags?.exists tag)
|
||||
((dictGet onChoiceTags tag) choice)))
|
||||
(story.choose idx)
|
||||
(window.clearControls)
|
||||
(showNextFrame)
|
||||
}))))
|
||||
(never null))))
|
||||
(showNextFrame)
|
||||
window))
|
||||
Reference in New Issue
Block a user