From d6bfa962ad4865c06c3362a3bc0fe2bb175a9764 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:52:29 +0100 Subject: [PATCH] funkintext --- buildnumber.txt | 2 +- source/funkin/game/PlayState.hx | 21 +++++----- source/funkin/menus/MainMenuState.hx | 4 +- source/funkin/options/OptionsScreen.hx | 42 ++++++++++++++++--- .../options/categories/BehaviourOptions.hx | 15 +++++-- .../options/categories/GameplayOptions.hx | 15 +++++-- .../options/categories/SaveDataOptions.hx | 7 +++- source/funkin/options/type/Checkbox.hx | 4 +- source/funkin/options/type/OptionType.hx | 6 +++ source/funkin/options/type/TextOption.hx | 4 +- source/funkin/shaders/CustomShader.hx | 15 ++++--- source/funkin/system/CoolUtil.hx | 2 +- source/funkin/ui/FunkinText.hx | 14 +++++++ 13 files changed, 111 insertions(+), 40 deletions(-) create mode 100644 source/funkin/ui/FunkinText.hx diff --git a/buildnumber.txt b/buildnumber.txt index 8ea0a3e6..14e963ae 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -971 \ No newline at end of file +975 \ No newline at end of file diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index d1a16881..c635d205 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -1,5 +1,6 @@ package funkin.game; +import funkin.ui.FunkinText; import flixel.group.FlxSpriteGroup; import funkin.options.Options; import funkin.scripting.Script; @@ -126,9 +127,9 @@ class PlayState extends MusicBeatState public var songScore:Int = 0; public var misses:Int = 0; - public var scoreTxt:FlxText; - public var missesTxt:FlxText; - public var accuracyTxt:FlxText; + public var scoreTxt:FunkinText; + public var missesTxt:FunkinText; + public var accuracyTxt:FunkinText; public static var campaignScore:Int = 0; @@ -298,17 +299,12 @@ class PlayState extends MusicBeatState add(icon); } - scoreTxt = new FlxText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Score:0", 20); - missesTxt = new FlxText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Misses:0", 20); - accuracyTxt = new FlxText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Accuracy:-%", 20); + scoreTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Score:0", 20); + missesTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Misses:0", 20); + accuracyTxt = new FunkinText(healthBarBG.x + 50, healthBarBG.y + 30, Std.int(healthBarBG.width - 100), "Accuracy:-%", 20); for(text in [scoreTxt, missesTxt, accuracyTxt]) { - text.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE); - text.borderStyle = OUTLINE; - text.borderSize = 1; - text.borderColor = 0xFF000000; text.scrollFactor.set(); - add(text); } scoreTxt.alignment = RIGHT; missesTxt.alignment = CENTER; @@ -433,6 +429,9 @@ class PlayState extends MusicBeatState private function generateSong(dataPath:String, ?songData:SwagSong):Void { if (songData == null) songData = SONG; + + Conductor.reset(); + Conductor.changeBPM(songData.bpm); curSong = songData.song; diff --git a/source/funkin/menus/MainMenuState.hx b/source/funkin/menus/MainMenuState.hx index 901eb256..f6b11213 100644 --- a/source/funkin/menus/MainMenuState.hx +++ b/source/funkin/menus/MainMenuState.hx @@ -1,5 +1,6 @@ package funkin.menus; +import funkin.ui.FunkinText; import funkin.options.Options; #if desktop import funkin.system.Discord.DiscordClient; @@ -94,9 +95,8 @@ class MainMenuState extends MusicBeatState FlxG.camera.follow(camFollow, null, 0.06); - var versionShit:FlxText = new FlxText(5, FlxG.height - 2, 0, 'Codename Engine v${Application.current.meta.get('version')}\nPre-Alpha: Build ${funkin.macros.BuildCounterMacro.getBuildNumber()}\n', 12); + var versionShit:FunkinText = new FunkinText(5, FlxG.height - 2, 0, 'Codename Engine v${Application.current.meta.get('version')}\nPre-Alpha: Build ${funkin.macros.BuildCounterMacro.getBuildNumber()}\n'); versionShit.scrollFactor.set(); - versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); versionShit.y -= versionShit.height; add(versionShit); diff --git a/source/funkin/options/OptionsScreen.hx b/source/funkin/options/OptionsScreen.hx index 9aca35e5..aabd3eba 100644 --- a/source/funkin/options/OptionsScreen.hx +++ b/source/funkin/options/OptionsScreen.hx @@ -1,5 +1,7 @@ package funkin.options; +import funkin.ui.FunkinText; +import flixel.text.FlxText; import flixel.math.FlxMath; import flixel.math.FlxPoint; import flixel.util.FlxColor; @@ -18,10 +20,19 @@ class OptionsScreen extends MusicBeatState { // public var bgColor:FlxColor = 0xFFFDE871; public var bg:FlxSprite; + + public var descBG:FlxSprite; + public var descText:FunkinText; + public var curSelected:Int = -1; public var options:Array = []; + private var transparentFormat:FlxTextFormat; + private var descLetters:Float = 0; + + public var descSpeed:Float = 35; + public function new() { super(); instance = this; @@ -39,10 +50,16 @@ class OptionsScreen extends MusicBeatState { bg.antialiasing = true; add(bg); + descText = new FunkinText(10, 10, FlxG.width - 20); + descText.alignment = CENTER; + add(descText); + for(k=>option in options) { option.setPosition(k * 20, 10 + (k * optionHeight)); add(option); } + + transparentFormat = new FlxTextFormat(FlxColor.TRANSPARENT); changeSelection(1); } @@ -55,6 +72,7 @@ class OptionsScreen extends MusicBeatState { } if (controls.BACK) { Options.applySettings(); + Options.save(); exit(); } FlxG.camera.scroll.x = lerp(FlxG.camera.scroll.x, scrollDest.x, 0.25); @@ -65,6 +83,11 @@ class OptionsScreen extends MusicBeatState { option.x = -50 + (Math.abs(angle) * 150); } + var offset:Int; + if (Std.int(descLetters) != (offset = Std.int(Math.min(descText.text.length, descLetters += elapsed * descSpeed)))) { + descText.clearFormats(); + descText.addFormat(transparentFormat, offset, descText.text.length); + } } public function exit() { @@ -76,12 +99,21 @@ class OptionsScreen extends MusicBeatState { public function changeSelection(change:Int) { if (change == 0 && curSelected != -1) return; - curSelected = FlxMath.wrap(curSelected + change, 0, options.length - 1); - for(e in options) - e.selected = false; - options[curSelected].selected = true; CoolUtil.playMenuSFX(0); - scrollDest.set(-50, -(FlxG.height / 2) + ((curSelected + 0.5) * optionHeight)); + if (curSelected != (curSelected = FlxMath.wrap(curSelected + change, 0, options.length - 1))) { + for(e in options) + e.selected = false; + options[curSelected].selected = true; + scrollDest.set(-50, -(FlxG.height / 2) + ((curSelected + 0.5) * optionHeight)); + updateDesc(); + } + } + + public function updateDesc() { + descLetters = 0; + descText.text = options[curSelected].desc; + descSpeed = descText.text.length; + descText.addFormat(transparentFormat, 0, descText.text.length); } public override function destroy() { diff --git a/source/funkin/options/categories/BehaviourOptions.hx b/source/funkin/options/categories/BehaviourOptions.hx index 86966853..48dd90e1 100644 --- a/source/funkin/options/categories/BehaviourOptions.hx +++ b/source/funkin/options/categories/BehaviourOptions.hx @@ -3,9 +3,18 @@ package funkin.options.categories; class BehaviourOptions extends OptionsScreen { public override function create() { options = [ - new Checkbox("Naughtyness", "naughtyness"), - new Checkbox("Flashing Menu", "flashingMenu"), - new Checkbox("Camera Zoom on Beat", "camZoomOnBeat"), + new Checkbox( + "Naughtyness", + "If unchecked, will censor Week 7 cutscenes.", + "naughtyness"), + new Checkbox( + "Flashing Menu", + "If unchecked, will disable menu flashing when you select an option in the Main Menu, and other flashs will be slower.", + "flashingMenu"), + new Checkbox( + "Camera Zoom on Beat", + "If unchecked, will disable camera zooming every 4 beats.", + "camZoomOnBeat"), ]; super.create(); } diff --git a/source/funkin/options/categories/GameplayOptions.hx b/source/funkin/options/categories/GameplayOptions.hx index 761c5250..92db806f 100644 --- a/source/funkin/options/categories/GameplayOptions.hx +++ b/source/funkin/options/categories/GameplayOptions.hx @@ -3,9 +3,18 @@ package funkin.options.categories; class GameplayOptions extends OptionsScreen { public override function create() { options = [ - new Checkbox("Downscroll", "downscroll"), - new Checkbox("Auto Pause", "autoPause"), - new Checkbox("Antialiasing", "antialiasing"), + new Checkbox( + "Downscroll", + "If checked, notes will go from up to down instead of down to up, like if they were falling.", + "downscroll"), + new Checkbox( + "Auto Pause", + "If checked, switching windows will pause the game.", + "autoPause"), + new Checkbox( + "Antialiasing", + "If unchecked, will disable antialiasing on every sprite. Can boost performances at the cost of sharper, more pixely sprites.", + "antialiasing"), ]; super.create(); } diff --git a/source/funkin/options/categories/SaveDataOptions.hx b/source/funkin/options/categories/SaveDataOptions.hx index 80659019..bbd24b32 100644 --- a/source/funkin/options/categories/SaveDataOptions.hx +++ b/source/funkin/options/categories/SaveDataOptions.hx @@ -3,8 +3,11 @@ package funkin.options.categories; class SaveDataOptions extends OptionsScreen { public override function create() { options = [ - new TextOption("Reset Save Data", function() { - + new TextOption( + "Reset Save Data", + "Select this option to reset save data. This will remove all of your highscores.", + function() { + // TODO!! }) ]; super.create(); diff --git a/source/funkin/options/type/Checkbox.hx b/source/funkin/options/type/Checkbox.hx index b35819b7..bcce8f5a 100644 --- a/source/funkin/options/type/Checkbox.hx +++ b/source/funkin/options/type/Checkbox.hx @@ -21,8 +21,8 @@ class Checkbox extends TextOption { ]; private var baseCheckboxOffset:FlxPoint = FlxPoint.get(); - public function new(text:String, optionName:String) { - super(text, null); + public function new(text:String, desc:String, optionName:String) { + super(text, desc, null); checkbox = new FlxSprite(10, -40); checkbox.frames = Paths.getSparrowAtlas('menus/options/checkboxThingie'); diff --git a/source/funkin/options/type/OptionType.hx b/source/funkin/options/type/OptionType.hx index dcdaea59..078e21cd 100644 --- a/source/funkin/options/type/OptionType.hx +++ b/source/funkin/options/type/OptionType.hx @@ -7,6 +7,12 @@ import funkin.options.OptionsScreen; class OptionType extends FlxSpriteGroup { public var controls(get, null):Controls; public var selected:Bool = false; + public var desc:String; + + public function new(desc:String) { + super(); + this.desc = desc; + } private function get_controls() {return PlayerSettings.player1.controls;} diff --git a/source/funkin/options/type/TextOption.hx b/source/funkin/options/type/TextOption.hx index d868813a..c745f93c 100644 --- a/source/funkin/options/type/TextOption.hx +++ b/source/funkin/options/type/TextOption.hx @@ -11,8 +11,8 @@ class TextOption extends OptionType { private function get_text() {return __text.text;} private function set_text(v:String) {return __text.text = v;} - public function new(text:String, selectCallback:Void->Void) { - super(); + public function new(text:String, desc:String, selectCallback:Void->Void) { + super(desc); this.selectCallback = selectCallback; add(__text = new Alphabet(100, 20, text, true)); } diff --git a/source/funkin/shaders/CustomShader.hx b/source/funkin/shaders/CustomShader.hx index 514ad281..4da56e88 100644 --- a/source/funkin/shaders/CustomShader.hx +++ b/source/funkin/shaders/CustomShader.hx @@ -42,17 +42,16 @@ class CustomShader extends FunkinShader implements IHScriptCustomBehaviour { } if (!Reflect.hasField(data, v)) return null; var field = Reflect.field(data, v); - if (field is ShaderInput) { + var cl = Std.string(Type.getClass(field)); + + // cant do "field is ShaderInput" for some reason + if (cl.startsWith("openfl.display.ShaderInput")) { var si = cast(field, ShaderInput); return si.input; } else if (field is ShaderParameter) { var sp = cast(field, ShaderParameter); - switch(sp.type) { - case BOOL, FLOAT, INT: - return sp.value[0]; - default: - return sp.value; - } + @:privateAccess + return (sp.__length > 1) ? sp.value : sp.value[0]; } return field; } @@ -80,7 +79,7 @@ class CustomShader extends FunkinShader implements IHScriptCustomBehaviour { field.input = cast val; } else if (cl.startsWith("openfl.display.ShaderParameter")) { @:privateAccess - if (field.__arrayLength <= 1) { + if (field.__length <= 1) { // that means we wait for a single number, instead of an array @:privateAccess if (field.__isInt && !(val is Int)) { diff --git a/source/funkin/system/CoolUtil.hx b/source/funkin/system/CoolUtil.hx index 3ed817fe..f0f3650e 100644 --- a/source/funkin/system/CoolUtil.hx +++ b/source/funkin/system/CoolUtil.hx @@ -104,7 +104,7 @@ class CoolUtil return null; } - public static function playMenuSong(fadeIn:Bool) { + public static function playMenuSong(fadeIn:Bool = false) { if (FlxG.sound.music == null || !FlxG.sound.music.playing) { Conductor.reset(); diff --git a/source/funkin/ui/FunkinText.hx b/source/funkin/ui/FunkinText.hx new file mode 100644 index 00000000..25660bc7 --- /dev/null +++ b/source/funkin/ui/FunkinText.hx @@ -0,0 +1,14 @@ +package funkin.ui; + +import flixel.util.FlxColor; +import flixel.text.FlxText; + +class FunkinText extends FlxText { + public function new(X:Float = 0, Y:Float = 0, FieldWidth:Float = 0, ?Text:String, Size:Int = 16, EmbeddedFont:Bool = true) { + super(X, Y, FieldWidth, Text, Size, EmbeddedFont); + setFormat(Paths.font("vcr.ttf"), Size, FlxColor.WHITE); + borderStyle = OUTLINE; + borderSize = 1; + borderColor = 0xFF000000; + } +} \ No newline at end of file