2022-09-07 23:07:08 +00:00
|
|
|
package funkin.ui.haxeui;
|
|
|
|
|
|
|
|
import haxe.ui.RuntimeComponentBuilder;
|
|
|
|
import haxe.ui.core.Component;
|
|
|
|
|
|
|
|
class HaxeUISubState extends MusicBeatSubstate
|
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
// The component representing the main UI.
|
|
|
|
public var component:Component;
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var _componentKey:String;
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
public function new(key:String)
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
_componentKey = key;
|
|
|
|
}
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
override function create()
|
|
|
|
{
|
|
|
|
super.create();
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
refreshComponent();
|
|
|
|
}
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* Builds a component from a given XML file.
|
|
|
|
* Call this in your code to load additional components at runtime.
|
|
|
|
*/
|
|
|
|
public function buildComponent(assetPath:String)
|
|
|
|
{
|
|
|
|
trace('Building component $assetPath');
|
|
|
|
return RuntimeComponentBuilder.fromAsset(assetPath);
|
|
|
|
}
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
// Force quit.
|
|
|
|
if (FlxG.keys.justPressed.F4) FlxG.switchState(new MainMenuState());
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
// Refresh the component.
|
|
|
|
if (FlxG.keys.justPressed.F5)
|
|
|
|
{
|
|
|
|
refreshComponent();
|
|
|
|
}
|
|
|
|
}
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
function refreshComponent()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (component != null)
|
|
|
|
{
|
|
|
|
remove(component);
|
|
|
|
component = null;
|
|
|
|
}
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
if (component != null)
|
|
|
|
{
|
|
|
|
trace('Success!');
|
|
|
|
add(component);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace('Failed to build component $_componentKey');
|
|
|
|
}
|
|
|
|
*/
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
if (component == null)
|
|
|
|
{
|
|
|
|
component = buildComponent(_componentKey);
|
|
|
|
add(component);
|
|
|
|
trace(component);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var component2 = buildComponent(_componentKey);
|
|
|
|
component2.x += 100;
|
|
|
|
add(component2);
|
|
|
|
trace(component2);
|
|
|
|
remove(component);
|
|
|
|
}
|
|
|
|
}
|
2022-09-07 23:07:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
override function destroy()
|
|
|
|
{
|
|
|
|
if (component != null) remove(component);
|
|
|
|
component = null;
|
|
|
|
}
|
2022-09-07 23:07:08 +00:00
|
|
|
}
|