add mini texture on icon button and pick random weather
This commit is contained in:
@@ -11,19 +11,17 @@ class_name IconButton
|
||||
if is_inside_tree() and has_node("%Texture"):
|
||||
$%Texture.texture = image
|
||||
|
||||
@onready var mini_texture: TextureRect = $%MiniTexture
|
||||
|
||||
func _ready():
|
||||
if image != null and has_node("%Texture"):
|
||||
$%Texture.texture = image
|
||||
|
||||
|
||||
|
||||
func _on_mouse_entered() -> void:
|
||||
if TweenFX.is_playing(self, TweenFX.Animations.BREATHE):
|
||||
return
|
||||
TweenFX.breathe(self, 1)
|
||||
|
||||
|
||||
func _on_mouse_exited() -> void:
|
||||
TweenFX.stop(self, TweenFX.Animations.BREATHE)
|
||||
scale = Vector2(1, 1)
|
||||
|
||||
@@ -58,6 +58,23 @@ grow_vertical = 2
|
||||
texture = ExtResource("1_upldh")
|
||||
expand_mode = 1
|
||||
|
||||
[node name="MiniTexture" type="TextureRect" parent="." unique_id=65158044]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(32, 32)
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -32.0
|
||||
offset_top = -32.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
texture = ExtResource("1_upldh")
|
||||
expand_mode = 1
|
||||
|
||||
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
|
||||
[connection signal="pressed" from="." to="." method="_on_pressed"]
|
||||
|
||||
@@ -2,8 +2,8 @@ extends HBoxContainer
|
||||
|
||||
signal on_option_changed(data: String)
|
||||
|
||||
@onready var current_icon_button: IconButton
|
||||
@onready var icon_buttons_options: Array[IconButton]
|
||||
@onready var category_icon_button: IconButton
|
||||
@onready var options_icon_buttons: Array[IconButton]
|
||||
@onready var show_container_tween: ContainerTween = $%ShowContainerTween
|
||||
@onready var hide_container_tween: ContainerTween = $%HideContainerTween
|
||||
|
||||
@@ -16,24 +16,23 @@ func _ready() -> void:
|
||||
continue
|
||||
var icon_button: IconButton = get_child(i)
|
||||
if i == 0:
|
||||
current_icon_button = icon_button
|
||||
icon_button.pressed.connect(on_current_icon_button_pressed)
|
||||
category_icon_button = icon_button
|
||||
icon_button.pressed.connect(on_category_icon_button_pressed)
|
||||
icon_button.mini_texture.visible = true
|
||||
else:
|
||||
icon_buttons_options.append(icon_button)
|
||||
icon_button.pressed.connect(_on_icon_pressed_changed.bind(icon_button))
|
||||
|
||||
options_icon_buttons.append(icon_button)
|
||||
icon_button.pressed.connect(on_icon_pressed_changed.bind(icon_button))
|
||||
icon_button.mini_texture.visible = false
|
||||
|
||||
func _on_icon_pressed_changed(in_icon_button: IconButton):
|
||||
for icon_button in icon_buttons_options:
|
||||
func on_icon_pressed_changed(in_icon_button: IconButton):
|
||||
for icon_button in options_icon_buttons:
|
||||
if icon_button == in_icon_button:
|
||||
current_icon_button.image = in_icon_button.image
|
||||
current_icon_button.data = in_icon_button.data
|
||||
category_icon_button.mini_texture.texture = in_icon_button.image
|
||||
category_icon_button.data = in_icon_button.data
|
||||
on_option_changed.emit(icon_button.data)
|
||||
break
|
||||
hide_options()
|
||||
|
||||
|
||||
func on_current_icon_button_pressed() -> void:
|
||||
func on_category_icon_button_pressed() -> void:
|
||||
if show_container_tween.is_running or hide_container_tween.is_running:
|
||||
return
|
||||
|
||||
@@ -42,17 +41,11 @@ func on_current_icon_button_pressed() -> void:
|
||||
else:
|
||||
show_options()
|
||||
|
||||
|
||||
func show_options() -> void:
|
||||
#for icon_button in icon_buttons_options:
|
||||
#icon_button.show()
|
||||
show_container_tween.start_tween()
|
||||
is_menu_open = true
|
||||
|
||||
|
||||
func hide_options() -> void:
|
||||
#for icon_button in icon_buttons_options:
|
||||
#icon_button.hide()
|
||||
hide_container_tween.start_tween()
|
||||
await hide_container_tween.finished
|
||||
is_menu_open = false
|
||||
|
||||
@@ -10,6 +10,7 @@ enum Weather {RAIN, SNOW}
|
||||
@onready var resume_button: Button = $GameMenuPanel/GameMenu/Pages/Page3/OptionMenu/VBoxContainer/ResumeButton
|
||||
@onready var show_container_tween: ContainerTween = $%ShowContainerTween
|
||||
@onready var hide_container_tween: ContainerTween = $%HideContainerTween
|
||||
@onready var weather_row: HBoxContainer = $%WeatherRow
|
||||
|
||||
func _ready() -> void:
|
||||
menu_icon_button.pressed.connect(_on_menu_icon_button_pressed)
|
||||
@@ -62,6 +63,16 @@ func _on_weather_row_on_option_changed(data: String) -> void:
|
||||
"Wind":
|
||||
UIEvents.toggle_wind.emit(true)
|
||||
"Random":
|
||||
pass
|
||||
pick_random_weather()
|
||||
_:
|
||||
pass
|
||||
|
||||
func pick_random_weather() -> void:
|
||||
var valid_buttons = []
|
||||
for child in weather_row.options_icon_buttons:
|
||||
if child.data.to_lower() != "random":
|
||||
valid_buttons.append(child)
|
||||
|
||||
if valid_buttons.size() > 0:
|
||||
var random_button = valid_buttons.pick_random()
|
||||
weather_row.on_icon_pressed_changed(random_button)
|
||||
|
||||
@@ -51,6 +51,7 @@ tween_types = Array[String](["impact_land", "fade_in"])
|
||||
tween_types = Array[String](["impact_land", "fade_out"])
|
||||
|
||||
[node name="WeatherRow" parent="VBoxContainer" unique_id=1803637359 instance=ExtResource("2_4cc8f")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="IconButton2" parent="VBoxContainer/WeatherRow" index="1" unique_id=638856991]
|
||||
|
||||
Reference in New Issue
Block a user