This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Scenes/UI/Items/ItemBox.gd

65 lines
1.5 KiB
GDScript3
Raw Normal View History

2020-07-28 07:54:04 +00:00
extends TextureRect
class_name UIItemBox
signal selected(hand)
signal used_in_hand()
enum CurrentHand {
None,
Left,
Right
}
2020-09-15 23:23:45 +00:00
var hovering := false
export var selected := false setget set_selected
export(CurrentHand) var current_hand := CurrentHand.None setget set_hand
2020-07-28 07:54:04 +00:00
2020-09-15 23:23:45 +00:00
const LEFT_Y_OFFSET := 0
const RIGHT_Y_OFFSET := 10
2020-07-28 07:54:04 +00:00
2020-09-15 23:23:45 +00:00
onready var hand_icon := $HandIcon
2020-07-28 07:54:04 +00:00
func _ready():
hand_icon.texture = hand_icon.texture.duplicate()
set_hand(current_hand)
func _mouse_hover(inside: bool) -> void:
hovering = inside
if hovering:
self_modulate.a = 1
else:
self_modulate.a = 0.86
func set_selected(val: bool) -> void:
selected = val
$SelectedOverlay.visible = selected
func set_hand(hand):
current_hand = hand
if hand_icon != null:
match hand:
CurrentHand.None:
hand_icon.visible = false
CurrentHand.Left:
hand_icon.visible = true
(hand_icon.texture as AtlasTexture).region.position.y = LEFT_Y_OFFSET
CurrentHand.Right:
hand_icon.visible = true
(hand_icon.texture as AtlasTexture).region.position.y = RIGHT_Y_OFFSET
func _gui_input(event):
if event is InputEventMouseButton:
2020-09-15 23:23:45 +00:00
var mouse_event := event as InputEventMouseButton
2020-07-28 07:54:04 +00:00
if mouse_event.pressed:
if mouse_event.button_index == BUTTON_LEFT:
if current_hand != CurrentHand.Left:
emit_signal("selected", CurrentHand.Left)
else:
emit_signal("used_in_hand")
elif mouse_event.button_index == BUTTON_RIGHT:
if current_hand != CurrentHand.Right:
emit_signal("selected", CurrentHand.Right)
else:
emit_signal("used_in_hand")