diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/control.gd | 2 | ||||
-rw-r--r-- | scripts/gui_picker.gd | 44 | ||||
-rw-r--r-- | scripts/gui_turret.gd | 64 | ||||
-rw-r--r-- | scripts/gui_turret_detail.gd | 3 | ||||
-rw-r--r-- | scripts/load_turrets.gd | 11 |
5 files changed, 34 insertions, 90 deletions
diff --git a/scripts/control.gd b/scripts/control.gd index 2e31667..b88874f 100644 --- a/scripts/control.gd +++ b/scripts/control.gd @@ -58,9 +58,9 @@ func build_option (st, sttype): var tname = turret_holder.get_node(editing_turret).info.name for t in load_turrets.get_upg_turrets(tname): opts += [ { "type": "turret upg", "name": t.name } ] - opts += [ { "type": "text", "name": "sell" } ] opts += [ { "type": "text", "name": "priority" } ] opts += [ { "type": "text", "name": "modules" } ] + opts += [ { "type": "text", "name": "sell" } ] opts += [ { "type": "text", "name": "back" } ] gui.bottom_bar.picker.build(opts) diff --git a/scripts/gui_picker.gd b/scripts/gui_picker.gd index 7a20842..616b3e8 100644 --- a/scripts/gui_picker.gd +++ b/scripts/gui_picker.gd @@ -2,17 +2,23 @@ extends Panel var _hbox : HBoxContainer var _gui_button : Resource = load("res://scenes/gui/gui_button.tscn") -var _gui_turret_button : Resource = load("res://scenes/gui/gui_turret.tscn") var _options = [] var gui : Control +var load_turrets : Node +var resources : Node var hovering = "" func _fetch (): if gui == null: gui = get_parent().gui if _hbox == null: _hbox = $Hbox + + var root = get_tree().root.get_node("world") + resources = root.get_node("player").get_node("resources") + load_turrets = root.get_node("saveload").get_node("load_turrets") + if !load_turrets.loaded: yield(load_turrets, "done_loading") func build (options : Array = []): _fetch() @@ -26,28 +32,25 @@ func build (options : Array = []): _options = options for opt in _options: - var button = null + var button = _gui_button.instance() + button.option = opt.name + if opt.type == "turret buy": - button = _gui_turret_button.instance() - _hbox.add_child(button) - button.init(opt.name) + var tinfo = load_turrets.info[opt.name] + button.get_node("name").text = tinfo.name + button.get_node("cash").text = resources.dict_to_str(tinfo.cost) + button.get_node("texture").texture = load_turrets.thumbnails[tinfo.thumbnail_name] if opt.type == "turret upg": - button = _gui_turret_button.instance() - _hbox.add_child(button) - button.init(opt.name) + var tinfo = load_turrets.info[opt.name] + button.get_node("name").text = tinfo.name + button.get_node("cash").text = resources.dict_to_str(tinfo.cost) + button.get_node("texture").texture = load_turrets.thumbnails[tinfo.thumbnail_name] if opt.type == "text": - button = _gui_button.instance() - _hbox.add_child(button) - button.get_node("hbox").get_node("name_label").text = opt.name + button.get_node("name").text = opt.name if opt.type == "color": - button = _gui_button.instance() - _hbox.add_child(button) - button.get_node("hbox").get_node("name_label").text = "" + button.get_node("name").text = "" button.get_node("color").color = opt.color - - if button != null: - button.option = opt.name - else: print("no option for " + str(opt)) + _hbox.add_child(button) for child in _hbox.get_children(): child.connect("mouse_entered", self, "_on_gui_turret_mouse_entered", [child.option]) @@ -56,11 +59,6 @@ func build (options : Array = []): func refresh (): _fetch() - if gui.control.state == Globals.PlayerState.PICK: - for child in _hbox.get_children(): child.picked = false - if gui.control.selected == name: - for child in _hbox.get_children(): - child.picked = child.name == gui.control.selected func _on_gui_turret_mouse_entered(option : String): hovering = option; diff --git a/scripts/gui_turret.gd b/scripts/gui_turret.gd deleted file mode 100644 index 55e3f5a..0000000 --- a/scripts/gui_turret.gd +++ /dev/null @@ -1,64 +0,0 @@ -extends TextureButton - -var option : String - -var info : Dictionary - -var _color_rect : ColorRect -var _name_label : Label -var _cash_label : Label - -var _viewport : Viewport -var _spinner : Node -var _mesh : Node - -var _resources : Node - -var picked : bool -var enabled : bool = false - -var _rotate_timer : float - -func init (turret_name : String): - var root = get_tree().root.get_node("world") - var saveload = root.get_node("saveload") - var load_turrets = saveload.get_node("load_turrets") - if !load_turrets.loaded: yield(load_turrets, "done_loading") - info = load_turrets.info[turret_name] - - _color_rect = $ColorRect - _name_label = $hbox/name_label - _cash_label = $cash_label - _viewport = $viewport - _spinner = $viewport/spinner - - _resources = root.get_node("player").get_node("resources") - - _name_label.text = turret_name - _cash_label.text = _resources.dict_to_str(info.cost) - - var model = load_turrets.models[info.model_name] - _mesh = model.instance() - _spinner.add_child(_mesh) - - texture_normal = _viewport.get_texture() - -func _process(delta): - if !has_node("viewport"): return - if _spinner == null: _spinner = $viewport/spinner - if _spinner != null: - if _resources == null: - var root = get_tree().root.get_node("world") - _resources = root.get_node("player").get_node("resources") - - var afforded = _resources.greater_than(info.cost) - if afforded: _color_rect.color = Color(0,0,0,0) - else: _color_rect.color = Color(0,0,0,0.5) - - if afforded and (is_hovered() or picked): - _spinner.transform.basis = _spinner.transform.rotated(Vector3.UP, delta).basis - _rotate_timer = 0 - else: - _rotate_timer = min(1, _rotate_timer + delta * 5) - var idle_rot = Transform.rotated(Vector3.UP, PI-PI/4).basis - _spinner.transform.basis = _spinner.transform.basis.slerp(idle_rot, _rotate_timer) diff --git a/scripts/gui_turret_detail.gd b/scripts/gui_turret_detail.gd index f895a6e..74e382e 100644 --- a/scripts/gui_turret_detail.gd +++ b/scripts/gui_turret_detail.gd @@ -5,6 +5,7 @@ var hbox_global var _turret_holder : Node var _turret_values : Resource = load("res://scenes/gui/gui_turret_values.tscn") var load_turrets : Node +var resources : Node var gui : Control @@ -18,6 +19,8 @@ func _fetch (): hbox_labels = $"hbox_global/hbox_labels" hbox_global = $"hbox_global" + resources = root.get_node("player").get_node("resources") + load_turrets = root.get_node("saveload").get_node("load_turrets") if !load_turrets.loaded: yield(load_turrets, "done_loading") diff --git a/scripts/load_turrets.gd b/scripts/load_turrets.gd index 194525c..93e7841 100644 --- a/scripts/load_turrets.gd +++ b/scripts/load_turrets.gd @@ -4,7 +4,7 @@ var saveload : Node var info : Dictionary var models : Dictionary -var thumbs : Dictionary +var thumbnails : Dictionary var loaded : bool = false signal done_loading @@ -13,6 +13,7 @@ func _ready(): get_saveload() load_models() load_info() + load_thumbnails() emit_signal("done_loading") loaded = true @@ -21,7 +22,6 @@ func get_saveload(): func get_upg_turrets(turret_name): var results = [] - return results # otherwise everything breaks for turr in info[turret_name].get("upgrades", []): results += [info[turr]] return results @@ -51,3 +51,10 @@ func load_models(): var files = saveload.parse_dir("res://assets/models/turrets", ".glb") for turr in files: models[turr] = load("res://assets/models/turrets/" + turr) + +func load_thumbnails(): + thumbnails.clear() + var files = saveload.parse_dir("res://assets/textures/thumbnails/turrets", ".png") + for turr in files: + print(turr) + thumbnails[turr] = load("res://assets/textures/thumbnails/turrets/" + turr) |