summaryrefslogtreecommitdiff
path: root/src/ui/stats_display/scripts
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-06-04 23:00:58 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-06-04 23:00:58 -0600
commit36abc689d783774ce4f2d7b5a1bb621d8684be45 (patch)
treea3dbed6069fbd8d9a588c7510ce581af3e847af0 /src/ui/stats_display/scripts
parent9a2bcf02c2623c8f3e8f5e74e70b3c0333790484 (diff)
added more ui for after gameplay, generalized basic food
Diffstat (limited to 'src/ui/stats_display/scripts')
-rw-r--r--src/ui/stats_display/scripts/progression_label.gd48
-rw-r--r--src/ui/stats_display/scripts/stats_display.gd80
2 files changed, 128 insertions, 0 deletions
diff --git a/src/ui/stats_display/scripts/progression_label.gd b/src/ui/stats_display/scripts/progression_label.gd
new file mode 100644
index 0000000..d4a0da0
--- /dev/null
+++ b/src/ui/stats_display/scripts/progression_label.gd
@@ -0,0 +1,48 @@
+class_name ProgressionLabel
+extends MarginContainer
+
+enum Type {
+ BODY_SEGMENT,
+ EMPTY
+}
+
+export(int) var TYPE: int = Type.EMPTY
+export(String) var PREFIX: String
+export(float) var BEFORE_VALUE: float
+export(float) var AFTER_VALUE: float = -1.0
+
+onready var label_prefix: Label = $HBox/Prefix
+onready var label_stats: Label = $HBox/Stats
+onready var texture_rect: TextureRect = $HBox/Center/VBox/TextureRect
+
+
+var textures: Dictionary = {
+ Type.BODY_SEGMENT: preload("res://ui/hud/progress_bars/sprites/grow_progress_icon.png"),
+ Type.EMPTY: preload("res://ui/stats_display/sprites/sep_8x8.png")
+}
+
+var _fmt: String = "%s->%s"
+var _fmt_partial: String = "%s"
+var _fmt_prefix: String = " %s "
+
+
+func _ready() -> void:
+ set_properties(TYPE, PREFIX, BEFORE_VALUE, AFTER_VALUE)
+
+
+func set_properties(icon: int, prefix: String, before: float, after: float=-1.0) -> void:
+ texture_rect.texture = textures[icon]
+ if after == -1.0:
+ label_stats.text =_fmt_partial % before
+ else:
+ label_stats.text =_fmt % [before, after]
+ if after > before:
+ label_stats.add_color_override("font_color", Color.green)
+ elif after < before:
+ label_stats.add_color_override("font_color", Color.red)
+ if not prefix.empty():
+ label_prefix.text = _fmt_prefix % prefix
+ else:
+ label_prefix.text = " "
+ label_prefix.update()
+ label_stats.update()
diff --git a/src/ui/stats_display/scripts/stats_display.gd b/src/ui/stats_display/scripts/stats_display.gd
new file mode 100644
index 0000000..f1f77ef
--- /dev/null
+++ b/src/ui/stats_display/scripts/stats_display.gd
@@ -0,0 +1,80 @@
+extends MarginContainer
+
+export(PackedScene) var PROGRESSION_LABEL: PackedScene
+
+onready var label_parent: VBoxContainer = $Center/HBox/ProgressionPanel/VBox/VBox
+
+
+func _ready():
+ Event.connect("display_stats", self, "_on_display_stats")
+ visible = false
+
+
+func _on_display_stats(old_stats: Stats, new_stats: Stats, mut_stats: Array) -> void:
+ visible = true
+ var old_stats_dict: Dictionary = old_stats.get_stats()
+ var new_stats_dict: Dictionary = new_stats.get_stats()
+ var mut_stats_dict: Array = []
+ for i in mut_stats:
+ mut_stats_dict.append(i)
+ print(i)
+
+ var type: int
+ var prefix: String
+ var should_print: bool
+
+ for stat_name in old_stats_dict:
+ should_print = _should_print(stat_name, new_stats_dict)
+ if should_print:
+ type = _get_type(stat_name)
+ prefix = _get_prefix(stat_name)
+ var _temp_label: ProgressionLabel = PROGRESSION_LABEL.instance()
+ label_parent.add_child(_temp_label)
+ _temp_label.set_properties(type, prefix, old_stats_dict[stat_name], new_stats_dict[stat_name])
+
+
+func _get_type(stat_name: String) -> int:
+ var type: int
+ match stat_name:
+ "segments":
+ type = ProgressionLabel.Type.BODY_SEGMENT
+ _:
+ type = ProgressionLabel.Type.EMPTY
+ return type
+
+
+func _get_prefix(stat_name: String) -> String:
+ var prefix: String
+ match stat_name:
+ "points":
+ prefix = "points"
+ _:
+ prefix = ""
+ return prefix
+
+
+func _should_print(stat_name: String, stats: Dictionary) -> bool:
+ var to_print: Array = [
+ "points",
+ "segments",
+ ]
+ var to_print_check: Array = [
+ "dash_percentage",
+ "slow_percentage",
+ "jump_lenght"
+ ]
+ var checks: Dictionary = {
+ to_print_check[0]: stats["trait_dash"],
+ to_print_check[1]: stats["trait_slow"],
+ to_print_check[2]: stats["trait_jump"]
+ }
+
+ if to_print.has(stat_name):
+ return true
+ elif to_print_check.has(stat_name):
+ if checks[stat_name]:
+ return true
+ else:
+ return false
+ else:
+ return false