-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #373: Create bar and settings popup for the SimpleClickGUI.
These components will replace the old InventoryBar and SettingsBar as part of the update for the SimpleClickGUI as proposed be Papernoise.
- Loading branch information
Showing
6 changed files
with
326 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+299 Bytes
...imple_click/components/simple_click_bar/images/simple_click_settings_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
216 changes: 216 additions & 0 deletions
216
...engine/objects/gui/templates/simple_click/components/simple_click_bar/simple_click_bar.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
extends Control | ||
|
||
@export var always_visible := false | ||
@export var hide_when_gui_is_blocked := false | ||
## Defines the height in pixels of the zone where moving the mouse in the top of the screen will | ||
## make the bar to show. Note: This value will be affected by the Experimental Scale GUI checkbox | ||
## in Project Settings > Popochiu > GUI. | ||
@export var input_zone_height := 4 | ||
|
||
var is_disabled := false | ||
var tween: Tween = null | ||
|
||
var _is_hidden := true | ||
var _is_mouse_hover := false | ||
|
||
@onready var panel_container: PanelContainer = %PanelContainer | ||
@onready var box: HBoxContainer = %Box | ||
@onready var settings_btn: TextureButton = %SettingsBtn | ||
@onready var hidden_y := panel_container.position.y - panel_container.size.y | ||
|
||
|
||
#region Godot ###################################################################################### | ||
func _ready(): | ||
if not always_visible: | ||
panel_container.position.y = hidden_y | ||
|
||
# Connect to children signals | ||
settings_btn.pressed.connect(_on_settings_pressed) | ||
|
||
# Connect to singletons signals | ||
PopochiuUtils.i.item_added.connect(_add_item) | ||
PopochiuUtils.i.item_removed.connect(_remove_item) | ||
PopochiuUtils.i.item_replaced.connect(_replace_item) | ||
PopochiuUtils.i.inventory_show_requested.connect(_show_and_hide) | ||
PopochiuUtils.i.inventory_hide_requested.connect(_close) | ||
PopochiuUtils.g.blocked.connect(_on_gui_blocked) | ||
PopochiuUtils.g.unblocked.connect(_on_gui_unblocked) | ||
|
||
# Check if there are already items in the inventory (set manually in the scene) | ||
for ii in box.get_children(): | ||
if ii is PopochiuInventoryItem: | ||
ii.in_inventory = true | ||
#ii.selected.connect(_change_cursor) | ||
|
||
set_process_input(not always_visible) | ||
|
||
|
||
func _input(event: InputEvent) -> void: | ||
if not event is InputEventMouseMotion: return | ||
|
||
var rect := panel_container.get_rect() | ||
rect.size += Vector2(0.0, input_zone_height) | ||
if PopochiuUtils.e.settings.scale_gui: | ||
rect = Rect2( | ||
panel_container.get_rect().position * PopochiuUtils.e.scale, | ||
panel_container.get_rect().size * PopochiuUtils.e.scale | ||
) | ||
|
||
if rect.has_point(get_global_mouse_position()): | ||
_is_mouse_hover = true | ||
|
||
if PopochiuUtils.i.active: | ||
PopochiuUtils.cursor.hide_main_cursor() | ||
PopochiuUtils.cursor.show_secondary_cursor() | ||
else: | ||
PopochiuUtils.cursor.show_cursor("gui") | ||
elif _is_mouse_hover: | ||
_is_mouse_hover = false | ||
|
||
if PopochiuUtils.d.current_dialog: | ||
PopochiuUtils.cursor.show_cursor("gui") | ||
elif PopochiuUtils.g.gui.is_showing_dialog_line: | ||
PopochiuUtils.cursor.show_cursor("wait") | ||
else: | ||
PopochiuUtils.cursor.show_cursor("normal") | ||
|
||
if PopochiuUtils.i.active: | ||
PopochiuUtils.cursor.hide_main_cursor() | ||
PopochiuUtils.cursor.show_secondary_cursor() | ||
|
||
if _is_hidden and rect.has_point(get_global_mouse_position()): | ||
_open() | ||
elif not _is_hidden and not rect.has_point(get_global_mouse_position()): | ||
_close() | ||
|
||
|
||
#endregion | ||
|
||
#region Private #################################################################################### | ||
func _on_settings_pressed() -> void: | ||
PopochiuUtils.g.popup_requested.emit("SimpleClickSettings") | ||
#PopochiuUtils.g.gui.settings_requested.emit() | ||
|
||
|
||
func _open() -> void: | ||
if always_visible: return | ||
if not is_disabled and panel_container.position.y != hidden_y: return | ||
|
||
if is_instance_valid(tween) and tween.is_running(): | ||
tween.kill() | ||
|
||
tween = create_tween().set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT) | ||
tween.tween_property( | ||
panel_container, "position:y", 0.0, 0.5 | ||
).from(hidden_y if not is_disabled else panel_container.position.y) | ||
|
||
_is_hidden = false | ||
|
||
|
||
func _close() -> void: | ||
if always_visible: return | ||
await get_tree().process_frame | ||
|
||
if is_instance_valid(tween) and tween.is_running(): | ||
tween.kill() | ||
|
||
tween = create_tween() | ||
tween.tween_property( | ||
panel_container, "position:y", | ||
hidden_y if not is_disabled else hidden_y - 3.5, | ||
0.2 | ||
).from(0.0).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN) | ||
|
||
_is_hidden = true | ||
|
||
|
||
func _on_tween_finished() -> void: | ||
_is_hidden = panel_container.position.y == hidden_y | ||
|
||
|
||
func _add_item(item: PopochiuInventoryItem, animate := true) -> void: | ||
box.add_child(item) | ||
|
||
item.custom_minimum_size.x = box.size.y | ||
item.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN | ||
item.size_flags_vertical = Control.SIZE_FILL | ||
|
||
item.selected.connect(_change_cursor) | ||
|
||
if not always_visible and animate: | ||
# Show the inventory for a while and hide after a couple of seconds so players can see the | ||
# item being added to the inventory | ||
set_process_input(false) | ||
|
||
_open() | ||
await get_tree().create_timer(2.0).timeout | ||
|
||
# The mouse not being on the inventory can close the inventory prior to the 2 seconds | ||
# expiring. This check fixes this. Bug 350. | ||
if not _is_hidden: | ||
_close() | ||
await get_tree().create_timer(0.5).timeout | ||
|
||
set_process_input(true) | ||
else: | ||
await get_tree().process_frame | ||
|
||
PopochiuUtils.i.item_add_done.emit(item) | ||
|
||
|
||
func _remove_item(item: PopochiuInventoryItem, animate := true) -> void: | ||
item.selected.disconnect(_change_cursor) | ||
box.remove_child(item) | ||
|
||
if not always_visible: | ||
PopochiuUtils.cursor.show_cursor() | ||
PopochiuUtils.g.show_hover_text() | ||
|
||
if animate: | ||
_close() | ||
await get_tree().create_timer(1.0).timeout | ||
|
||
await get_tree().process_frame | ||
|
||
PopochiuUtils.i.item_remove_done.emit(item) | ||
|
||
|
||
func _change_cursor(item: PopochiuInventoryItem) -> void: | ||
PopochiuUtils.i.set_active_item(item) | ||
|
||
|
||
func _replace_item(item: PopochiuInventoryItem, new_item: PopochiuInventoryItem) -> void: | ||
item.replace_by(new_item) | ||
await get_tree().process_frame | ||
|
||
PopochiuUtils.i.item_replace_done.emit() | ||
|
||
|
||
func _show_and_hide(time := 1.0) -> void: | ||
set_process_input(false) | ||
_open() | ||
await tween.finished | ||
await PopochiuUtils.e.wait(time) | ||
|
||
_close() | ||
await tween.finished | ||
|
||
set_process_input(true) | ||
PopochiuUtils.i.inventory_shown.emit() | ||
|
||
|
||
func _on_gui_blocked() -> void: | ||
set_process_input(false) | ||
|
||
if hide_when_gui_is_blocked: | ||
hide() | ||
|
||
|
||
func _on_gui_unblocked() -> void: | ||
set_process_input(true) | ||
|
||
if hide_when_gui_is_blocked: | ||
show() | ||
|
||
|
||
#endregion |
57 changes: 57 additions & 0 deletions
57
...gine/objects/gui/templates/simple_click/components/simple_click_bar/simple_click_bar.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[gd_scene load_steps=8 format=3 uid="uid://dqlw4tn2oe6d7"] | ||
|
||
[ext_resource type="Script" path="res://addons/popochiu/engine/objects/gui/templates/simple_click/components/simple_click_bar/simple_click_bar.gd" id="1_0tdpv"] | ||
[ext_resource type="Theme" uid="uid://dpequqav4rjaf" path="res://addons/popochiu/engine/objects/gui/resources/base_gui_theme.tres" id="1_tnnrn"] | ||
[ext_resource type="Texture2D" uid="uid://md62x2moalng" path="res://addons/popochiu/engine/objects/gui/templates/simple_click/components/simple_click_bar/images/simple_click_settings_button.png" id="2_nw3cn"] | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_lxom0"] | ||
atlas = ExtResource("2_nw3cn") | ||
region = Rect2(0, 0, 24, 24) | ||
|
||
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_fxk42"] | ||
load_path = "res://.godot/imported/simple_click_settings_button.png-84386e981dc3f2aef33ed100f3aa30eb.ctex" | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_l51nv"] | ||
atlas = SubResource("CompressedTexture2D_fxk42") | ||
region = Rect2(0, 24, 24, 24) | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_3kcf8"] | ||
atlas = SubResource("CompressedTexture2D_fxk42") | ||
region = Rect2(0, 24, 24, 24) | ||
|
||
[node name="SimpleClickBar" type="Control" groups=["popochiu_gui_component"]] | ||
layout_mode = 3 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
mouse_filter = 2 | ||
theme = ExtResource("1_tnnrn") | ||
script = ExtResource("1_0tdpv") | ||
|
||
[node name="PanelContainer" type="PanelContainer" parent="."] | ||
unique_name_in_owner = true | ||
self_modulate = Color(1, 1, 1, 0.74902) | ||
texture_filter = 1 | ||
layout_mode = 1 | ||
anchors_preset = 10 | ||
anchor_right = 1.0 | ||
offset_bottom = 24.0 | ||
grow_horizontal = 2 | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer"] | ||
layout_mode = 2 | ||
|
||
[node name="Box" type="HBoxContainer" parent="PanelContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
size_flags_horizontal = 3 | ||
mouse_filter = 2 | ||
|
||
[node name="SettingsBtn" type="TextureButton" parent="PanelContainer/HBoxContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
texture_normal = SubResource("AtlasTexture_lxom0") | ||
texture_pressed = SubResource("AtlasTexture_l51nv") | ||
texture_hover = SubResource("AtlasTexture_3kcf8") |
5 changes: 5 additions & 0 deletions
5
...plates/simple_click/components/simple_click_settings_popup/simple_click_settings_popup.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extends PopochiuPopup | ||
|
||
|
||
#region Godot ###################################################################################### | ||
#endregion |
46 changes: 46 additions & 0 deletions
46
...ates/simple_click/components/simple_click_settings_popup/simple_click_settings_popup.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://bmpxoiebdf67g"] | ||
|
||
[ext_resource type="PackedScene" uid="uid://c51xplyeuk787" path="res://addons/popochiu/engine/objects/gui/components/popups/popochiu_popup.tscn" id="1_l0ff4"] | ||
[ext_resource type="Script" path="res://addons/popochiu/engine/objects/gui/templates/simple_click/components/simple_click_settings_popup/simple_click_settings_popup.gd" id="2_y4ddu"] | ||
|
||
[node name="SimpleClickSettingsPopup" instance=ExtResource("1_l0ff4")] | ||
script = ExtResource("2_y4ddu") | ||
script_name = &"SimpleClickSettings" | ||
|
||
[node name="HeaderContainer" parent="Overlay/PanelContainer/VBoxContainer" index="0"] | ||
visible = false | ||
|
||
[node name="BodyContainer" type="HBoxContainer" parent="Overlay/PanelContainer/VBoxContainer" index="1"] | ||
layout_mode = 2 | ||
|
||
[node name="VBoxContainer" type="VBoxContainer" parent="Overlay/PanelContainer/VBoxContainer/BodyContainer" index="0"] | ||
layout_mode = 2 | ||
|
||
[node name="Save" type="Button" parent="Overlay/PanelContainer/VBoxContainer/BodyContainer/VBoxContainer" index="0"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "Save" | ||
|
||
[node name="Load" type="Button" parent="Overlay/PanelContainer/VBoxContainer/BodyContainer/VBoxContainer" index="1"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "Load" | ||
|
||
[node name="History" type="Button" parent="Overlay/PanelContainer/VBoxContainer/BodyContainer/VBoxContainer" index="2"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "History" | ||
|
||
[node name="Quit" type="Button" parent="Overlay/PanelContainer/VBoxContainer/BodyContainer/VBoxContainer" index="3"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "Quit game" | ||
|
||
[node name="VSeparator" type="VSeparator" parent="Overlay/PanelContainer/VBoxContainer/BodyContainer" index="1"] | ||
layout_mode = 2 | ||
|
||
[node name="VBoxContainer2" type="VBoxContainer" parent="Overlay/PanelContainer/VBoxContainer/BodyContainer" index="2"] | ||
layout_mode = 2 | ||
|
||
[node name="FooterContainer" parent="Overlay/PanelContainer/VBoxContainer" index="2"] | ||
visible = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters