Skip to content

Commit cf980f1

Browse files
committed
HUD class reconfiguration
1 parent 63828df commit cf980f1

13 files changed

Lines changed: 154 additions & 96 deletions

File tree

engine/assets

engine/source/imaginative/backend/system/Settings.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class MainSettings {
5454
/**
5555
* The hud you wish to pick for the default.
5656
*/
57-
public var HUDSelection:imaginative.objects.gameplay.hud.HUDType = Imaginative;
57+
public var HUDSelection:imaginative.objects.gameplay.hud.HUDType = IsImaginativeHUD;
5858

5959
/**
6060
* If true antialiasing can be applied to things.

engine/source/imaginative/objects/gameplay/hud/HUDTemplate.hx renamed to engine/source/imaginative/objects/gameplay/hud/GameplayHUD.hx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package imaginative.objects.gameplay.hud;
22

3+
import imaginative.objects.gameplay.hud.engines.CodenameHUD;
34
import imaginative.objects.ui.Bar;
45

5-
class HUDTemplate extends BeatGroup {
6+
class GameplayHUD extends BeatGroup {
67
/**
78
* The HUD type.
89
*/
910
public var type(get, never):HUDType;
1011
function get_type():HUDType
11-
return Template;
12+
return IsBaseHUD;
1213

1314
// for an easier time layering
1415
/**
@@ -134,7 +135,7 @@ class HUDTemplate extends BeatGroup {
134135
}
135136

136137
function loadScript():Void
137-
if (type != Template || type != Custom)
138+
if (type != IsBaseHUD || type != IsCustomHUD)
138139
/* if (Paths.folderExists('lead:content/huds/$type'))
139140
for (ext in Script.exts)
140141
for (file in Paths.readFolder(folder, ext))
@@ -181,13 +182,9 @@ class HUDTemplate extends BeatGroup {
181182
}
182183

183184
override public function new() {
184-
if (HUDType.instance == null)
185-
HUDType.instance = this;
186-
else {
187-
_log('A HUD already exists, killing new one.');
188-
destroy();
189-
}
185+
HUDType.instance = this;
190186
super();
187+
if (HUDType.instance != this) return;
191188

192189
add(scripts = new ScriptGroup(this));
193190
loadScript();
Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,83 @@
11
package imaginative.objects.gameplay.hud;
22

3-
@SuppressWarnings('checkstyle:FieldDocComment')
3+
import imaginative.objects.gameplay.hud.engines.*;
4+
45
enum abstract HUDType(String) from String to String {
56
/**
67
* The current HUD instance.
78
*/
8-
public static var instance:HUDTemplate;
9+
public static var instance(default, set):GameplayHUD;
10+
@SuppressWarnings('checkstyle:FieldDocComment')
11+
static function set_instance(value:GameplayHUD):GameplayHUD {
12+
if (instance == null || value == null)
13+
instance = value;
14+
else {
15+
_log('[HUDType] A HUD already exists, killing new one.', WarningMessage);
16+
value.destroy();
17+
}
18+
return instance;
19+
}
20+
21+
// Base
22+
/**
23+
* States this is base class.
24+
* This HUD type has nothing special going for it.
25+
*/
26+
var IsBaseHUD = 'base';
27+
/**
28+
* States this is a custom HUD.
29+
* Any HUD with this type
30+
*/
31+
var IsCustomHUD = 'custom';
32+
// Engines
33+
/**
34+
* States this is the base funkin VSlice HUD.
35+
*/
36+
var IsVSliceHUD = 'vslice';
37+
/**
38+
* States this is the Kade Engine HUD.
39+
*/
40+
var IsKadeHUD = 'kade';
41+
/**
42+
* States this is the Psych Engine HUD.
43+
*/
44+
var IsPsychHUD = 'psych';
45+
/**
46+
* States this is the Codename Engine HUD.
47+
*/
48+
var IsCodenameHUD = 'codename';
49+
/**
50+
* States this is the Imaginative Engine HUD.
51+
*/
52+
var IsImaginativeHUD = 'imaginative';
953

10-
var Template;
11-
var VSlice;
12-
var Kade;
13-
var Psych;
14-
var Codename;
15-
var Imaginative;
16-
var Custom;
54+
/**
55+
* Returns the hud class based on the key name.
56+
* @param desiredHUD The desired hud.
57+
* @return GameplayHUD
58+
*/
59+
public static function getHUD(desiredHUD:String):GameplayHUD {
60+
return switch (desiredHUD) {
61+
case 'default': // based on your settings
62+
switch (Settings.setup.HUDSelection) {
63+
case IsVSliceHUD: new VSliceHUD();
64+
case IsKadeHUD: new KadeHUD();
65+
case IsPsychHUD: new PsychHUD();
66+
case IsCodenameHUD: new CodenameHUD();
67+
case IsImaginativeHUD: new ImaginativeHUD();
68+
default: new GameplayHUD();
69+
}
70+
// allows people to use a specific hud type if they want to without messing with user settings
71+
case IsVSliceHUD: return new VSliceHUD();
72+
case IsKadeHUD: return new KadeHUD();
73+
case IsPsychHUD: return new PsychHUD();
74+
case IsCodenameHUD: return new CodenameHUD();
75+
case IsImaginativeHUD: return new ImaginativeHUD();
76+
default:
77+
// allows for custom class huds, idk how else to do it at this moment
78+
var customHUD:GameplayHUD = GlobalScript.call('onHudGet', [desiredHUD]);
79+
customHUD ??= new ModdedHUD(desiredHUD);
80+
customHUD;
81+
}
82+
}
1783
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package imaginative.objects.gameplay.hud;
2+
3+
import imaginative.objects.ui.Bar;
4+
5+
class ModdedHUD extends GameplayHUD {
6+
override function get_type():HUDType
7+
return IsCustomHUD;
8+
9+
/**
10+
* The name of the scripted HUD instance.
11+
*/
12+
public var name(default, null):String;
13+
override function loadScript():Void
14+
for (script in Script.createMulti('lead:content/huds/$name'))
15+
scripts.add(script);
16+
17+
override function initHealthBar():Bar
18+
return call(true, 'onHealthBarInit', [Settings.setupP1.downscroll]) ?? super.initHealthBar(); // so it doesn't create a object that doesn't get used
19+
20+
override function initStatsText():FlxText
21+
return call(true, 'onStatsTextInit', [Settings.setupP1.downscroll]) ?? super.initStatsText();
22+
override function initStatsP2Text():FlxText
23+
return call(true, 'onStatsTextInitP2', [Settings.setupP1.downscroll]) ?? super.initStatsP2Text();
24+
25+
override function createElements():Void {
26+
call(true, 'onCreateElements');
27+
if (elements.length == 0) { // if blank, add for them
28+
elements.add(healthBar = initHealthBar());
29+
elements.add(statsP2Text = initStatsP2Text());
30+
elements.add(statsText = initStatsText());
31+
}
32+
updateStatsText();
33+
updateStatsP2Text();
34+
}
35+
36+
override public function new(name:String) {
37+
this.name = name;
38+
super();
39+
}
40+
41+
override public function updateStatsText():Void
42+
call('onUpdateStats', [Settings.setupP1, Scoring.statsP1]);
43+
override public function updateStatsP2Text():Void
44+
call('onUpdateStatsP2', [Settings.setupP2, Scoring.statsP2]);
45+
}
Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,6 @@
11
package imaginative.objects.gameplay.hud;
22

3-
import imaginative.objects.ui.Bar;
4-
5-
class ScriptedHUD extends HUDTemplate {
6-
override function get_type():HUDType
7-
return Custom;
8-
9-
/**
10-
* The name of the scripted HUD instance.
11-
*/
12-
public var name(default, null):String;
13-
override function loadScript():Void
14-
for (script in Script.createMulti('lead:content/huds/$name'))
15-
scripts.add(script);
16-
17-
override function initHealthBar():Bar
18-
return call(true, 'onHealthBarInit', [Settings.setupP1.downscroll]) ?? super.initHealthBar(); // so it doesn't create a object that doesn't get used
19-
20-
override function initStatsText():FlxText
21-
return call(true, 'onStatsTextInit', [Settings.setupP1.downscroll]) ?? super.initStatsText();
22-
override function initStatsP2Text():FlxText
23-
return call(true, 'onStatsTextInitP2', [Settings.setupP1.downscroll]) ?? super.initStatsP2Text();
24-
25-
override function createElements():Void {
26-
call(true, 'onCreateElements');
27-
if (elements.length == 0) { // if blank, add for them
28-
elements.add(healthBar = initHealthBar());
29-
elements.add(statsP2Text = initStatsP2Text());
30-
elements.add(statsText = initStatsText());
31-
}
32-
updateStatsText();
33-
updateStatsP2Text();
34-
}
35-
36-
override public function new(name:String) {
37-
this.name = name;
38-
super();
39-
}
40-
41-
override public function updateStatsText():Void
42-
call('onUpdateStats', [Settings.setupP1, Scoring.statsP1]);
43-
override public function updateStatsP2Text():Void
44-
call('onUpdateStatsP2', [Settings.setupP2, Scoring.statsP2]);
45-
}
3+
#if CAN_HAXE_SCRIPT
4+
@:ignoreFields([call, event, loadScript])
5+
class ScriptedHUD extends ModdedHUD implements rulescript.scriptedClass.RuleScriptedClass {}
6+
#end

engine/source/imaginative/objects/gameplay/hud/CodenameHUD.hx renamed to engine/source/imaginative/objects/gameplay/hud/engines/CodenameHUD.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package imaginative.objects.gameplay.hud;
1+
package imaginative.objects.gameplay.hud.engines;
22

33
import imaginative.objects.ui.Bar;
44

5-
class CodenameHUD extends HUDTemplate {
5+
class CodenameHUD extends GameplayHUD {
66
override function get_type():HUDType
7-
return Codename;
7+
return IsCodenameHUD;
88

99
/**
1010
* The text that shows you the amount of misses.

engine/source/imaginative/objects/gameplay/hud/ImaginativeHUD.hx renamed to engine/source/imaginative/objects/gameplay/hud/engines/ImaginativeHUD.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package imaginative.objects.gameplay.hud;
1+
package imaginative.objects.gameplay.hud.engines;
22

33
import imaginative.objects.ui.Bar;
44

5-
class ImaginativeHUD extends HUDTemplate {
5+
class ImaginativeHUD extends GameplayHUD {
66
override function get_type():HUDType
7-
return Imaginative;
7+
return IsImaginativeHUD;
88

99
/**
1010
* The text that shows you the amount of misses or plus combo breaks.

engine/source/imaginative/objects/gameplay/hud/KadeHUD.hx renamed to engine/source/imaginative/objects/gameplay/hud/engines/KadeHUD.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package imaginative.objects.gameplay.hud;
1+
package imaginative.objects.gameplay.hud.engines;
22

33
import imaginative.objects.ui.Bar;
44

55
// TODO: Optimize this shit.
6-
class KadeHUD extends HUDTemplate {
6+
class KadeHUD extends GameplayHUD {
77
override function get_type():HUDType
8-
return Kade;
8+
return IsKadeHUD;
99

1010
override public function getFieldYLevel(downscroll:Bool = false, field:ArrowField):Float {
1111
var yLevel:Float = (downscroll ? FlxG.height - 165 : 50) + (ArrowField.arrowSize / 2);

engine/source/imaginative/objects/gameplay/hud/PsychHUD.hx renamed to engine/source/imaginative/objects/gameplay/hud/engines/PsychHUD.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package imaginative.objects.gameplay.hud;
1+
package imaginative.objects.gameplay.hud.engines;
22

33
import imaginative.objects.ui.Bar;
44

5-
class PsychHUD extends HUDTemplate {
5+
class PsychHUD extends GameplayHUD {
66
override function get_type():HUDType
7-
return Psych;
7+
return IsPsychHUD;
88

99
override public function getFieldYLevel(downscroll:Bool = false, field:ArrowField):Float {
1010
var yLevel:Float = (downscroll ? (getDefaultCamera().height - 150) : 50) + (ArrowField.arrowSize / 2);

0 commit comments

Comments
 (0)