123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- extends Control
- @onready var hand = get_parent().get_parent().get_node("Hand")
- var hand_index = 0
- var hand_selected = false
- var item_count = 0
- func add_item(item):
- item_count = item_count + 1
- var instance = item.duplicate()
- var style = StyleBoxFlat.new()
-
- # set style
- style.bg_color = Color("#313131")
- instance.add_theme_stylebox_override('panel', style)
-
- # mobile button code
- if GameManager.is_running_on_mobile():
- var b = TouchScreenButton.new()
- b.position = Vector2(0, 0)
- b.texture_normal = preload("res://Textures/Controls/mobile_hotbar_fix.png")
- b.texture_pressed = preload("res://Textures/Controls/mobile_hotbar_fix.png")
- b.shape = RectangleShape2D.new()
- b.shape.size = Vector2(40, 40)
- b.set_script(load("res://Scripts/Misc/mobile_hotbar_button.gd"))
- b.shape_visible = true
-
- instance.add_child(b)
-
- self.add_child(instance)
- instance.visible = true
- func remove_id(id):
- for item in get_children():
- if item.has_meta("id") and item.get_meta("id") == id:
- item.queue_free()
-
- if hand.get_child(0) and hand.get_child(0).has_meta("id") and hand.get_child(0).get_meta("id") == id:
- item_count = item_count - 1
- hand.get_child(0).queue_free()
-
- return
- func remove_index(index):
- get_child(index).queue_free()
- item_count = item_count - 1
- func remove_item(item):
- item.queue_free()
- item_count = item_count - 1
- func select_item(index):
- if get_child_count() >= index and get_child(index):
- if hand_selected and hand_index == index:
- for child in hand.get_children():
- child.queue_free()
-
- for item_panel in get_children():
- unhighlight_panel(item_panel)
-
- hand_selected = false
- return
-
- hand_index = index # set the selected index to the current one
- var item = get_child(index) # get the index
-
- # unhighlight everything
- for item_panel in get_children():
- unhighlight_panel(item_panel)
-
- # highlight the current item
- highlight_panel(item)
-
- var mesh = item.get_child(0).get_child(0).get_child(0) # get the mesh
-
- # Clear everything in the hand
- for child in hand.get_children():
- child.queue_free()
-
- mesh = mesh.duplicate() # duplicate the mesh
-
- if item.has_meta("id"):
- mesh.set_meta("id", item.get_meta("id"))
-
- if item.has_meta("scale"):
- mesh.scale = item.get_meta("scale")
-
- if item.has_meta("rotation"):
- mesh.rotation_degrees = item.get_meta("rotation")
- else:
- mesh.rotation_degrees = Vector3.ZERO
-
- hand.add_child(mesh)
- hand_selected = true
- else:
- hand_selected = false
-
- for item_panel in get_children():
- unhighlight_panel(item_panel)
-
- for child in hand.get_children():
- child.queue_free()
- return
- func highlight_panel(panel):
- var style = panel.get_theme_stylebox('panel')
- style.bg_color = Color("#525252")
- func unhighlight_panel(panel):
- var style = panel.get_theme_stylebox('panel')
- style.bg_color = Color("#313131")
- func _input(event):
- if event.is_action_pressed("slot1"):
- select_item(0)
- elif event.is_action_pressed("slot2"):
- select_item(1)
- elif event.is_action_pressed("slot3"):
- select_item(2)
- elif event.is_action_pressed("slot4"):
- select_item(3)
- elif event.is_action_pressed("slot5"):
- select_item(4)
|