First commit 🎉

This commit is contained in:
Tony Bark 2025-07-17 01:49:18 -04:00
commit 43ea213f9b
728 changed files with 37080 additions and 0 deletions

View file

@ -0,0 +1,144 @@
class_name GUIDialogMenu
extends Control
@warning_ignore("return_value_discarded")
@warning_ignore("unused_signal")
signal shown
@export var option_scene: PackedScene
## Max height of the menu in pixels. If visible options make the menu to exceed this value, it will
## enable a vertical scroll bar.
@export var max_height := 49
@export_category("Option buttons")
@export var normal_font_color: Color = Color("706deb")
@export var normal_used_font_color: Color = Color("2e2c9b")
@export var hover_font_color: Color = Color("ffffff")
@export var hover_used_font_color: Color = Color("b2b2b2")
@export var pressed_font_color: Color = Color("a9ff9f")
@export var pressed_used_font_color: Color = Color("56ac4d")
var current_options := []
@onready var panel_container: PanelContainer = $PanelContainer
@onready var dialog_options_container: VBoxContainer = %DialogOptionsContainer
#region Godot ######################################################################################
func _ready() -> void:
for child in dialog_options_container.get_children():
child.queue_free()
panel_container.custom_minimum_size = Vector2.ZERO
# Connect to own signals
gui_input.connect(_clicked)
# Connect to autoloads signals
PopochiuUtils.d.dialog_options_requested.connect(_create_options.bind(true))
PopochiuUtils.d.inline_dialog_requested.connect(_create_inline_options)
PopochiuUtils.d.dialog_finished.connect(remove_options)
hide()
#endregion
#region Private ####################################################################################
func _clicked(event: InputEvent) -> void:
if PopochiuUtils.get_click_or_touch_index(event) == MOUSE_BUTTON_LEFT:
accept_event()
# Creates an Array of PopochiuDialogOption to show dialog tree options created
# during execution, (those that are created after calling D.show_inline_dialog)
func _create_inline_options(opts: Array) -> void:
var tmp_opts := []
for idx in opts.size():
var new_opt: PopochiuDialogOption = PopochiuDialogOption.new()
new_opt.id = str(idx)
new_opt.text = opts[idx]
tmp_opts.append(new_opt)
_create_options(tmp_opts, true)
func _create_options(options := [], autoshow := false) -> void:
remove_options()
if options.is_empty():
if not current_options.is_empty():
show_options()
return
current_options = options.duplicate(true)
for dialog_option: PopochiuDialogOption in options:
var dialog_menu_option := option_scene.instantiate()
dialog_menu_option.normal_color = normal_font_color
dialog_menu_option.normal_used_color = normal_used_font_color
dialog_menu_option.hover_color = hover_font_color
dialog_menu_option.hover_used_color = hover_used_font_color
dialog_menu_option.pressed_color = pressed_font_color
dialog_menu_option.pressed_used_color = pressed_used_font_color
dialog_options_container.add_child(dialog_menu_option)
dialog_menu_option.option = dialog_option
dialog_menu_option.pressed.connect(_on_option_clicked)
if dialog_option.disabled or not dialog_option.visible:
dialog_menu_option.hide()
else:
dialog_menu_option.show()
if autoshow: show_options()
await get_tree().create_timer(0.1).timeout
# Fix: Height and position of the dialog menu was wrong when changing the amount of options to
# show.
var options_height := 0
var visible_options := 0
for opt in dialog_options_container.get_children():
if not opt.visible: continue
options_height += opt.size.y
visible_options += 1
options_height += (
dialog_options_container.get_theme_constant("separation") * (visible_options - 1)
)
panel_container.size.y = min(options_height, max_height)
panel_container.position.y = PopochiuUtils.e.height - panel_container.size.y
func remove_options(_dialog: PopochiuDialog = null) -> void:
if not current_options.is_empty():
current_options.clear()
for btn in dialog_options_container.get_children():
btn.queue_free()
await get_tree().process_frame
size.y = 0
dialog_options_container.size.y = 0
func show_options() -> void:
PopochiuUtils.g.block()
PopochiuUtils.g.dialog_options_shown.emit()
show()
shown.emit()
func _on_option_clicked(opt: PopochiuDialogOption) -> void:
PopochiuUtils.g.unblock()
hide()
PopochiuUtils.d.option_selected.emit(opt)
#endregion

View file

@ -0,0 +1 @@
uid://drauy2w6dsd4l

View file

@ -0,0 +1,39 @@
[gd_scene load_steps=4 format=3 uid="uid://baht1l8l5dupo"]
[ext_resource type="Theme" uid="uid://djl1xk7jgyvpp" path="res://game/gui/resources/gui_theme.tres" id="1_vmaqy"]
[ext_resource type="Script" uid="uid://mevovjy0qsbv" path="res://game/gui/components/dialog_menu/dialog_menu_custom.gd" id="2_d8486"]
[ext_resource type="PackedScene" uid="uid://b8r2dcfb6u1e1" path="res://game/gui/components/dialog_menu/dialog_menu_option/dialog_menu_option.tscn" id="3_30v6t"]
[node name="DialogMenu" 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_vmaqy")
script = ExtResource("2_d8486")
option_scene = ExtResource("3_30v6t")
[node name="PanelContainer" type="PanelContainer" parent="."]
custom_minimum_size = Vector2(0, 53)
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = -53.0
grow_horizontal = 2
grow_vertical = 0
[node name="ScrollContainer" type="ScrollContainer" parent="PanelContainer"]
layout_mode = 2
horizontal_scroll_mode = 0
[node name="DialogOptionsContainer" type="VBoxContainer" parent="PanelContainer/ScrollContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 8
theme_override_constants/separation = 1

View file

@ -0,0 +1 @@
extends "dialog_menu.gd"

View file

@ -0,0 +1 @@
uid://mevovjy0qsbv

View file

@ -0,0 +1,92 @@
class_name GUIDialogMenuOption
extends PanelContainer
signal pressed(node: PopochiuDialogOption)
var option: PopochiuDialogOption : set = set_dialog_option
var text := "" : set = set_text
var used := false : set = set_used
var normal_color := Color.WHITE
var normal_used_color := normal_color
var hover_color := Color.WHITE
var hover_used_color := hover_color
var pressed_color := Color.WHITE
var pressed_used_color := pressed_color
var _state := "normal" : set = set_state
@onready var rich_text_label: RichTextLabel = %RichTextLabel
@onready var handler: Button = %Handler
#region Godot ######################################################################################
func _ready() -> void:
handler.pressed.connect(_on_pressed)
handler.mouse_entered.connect(_on_mouse_entered)
handler.mouse_exited.connect(_on_mouse_exited)
handler.button_down.connect(_on_button_down)
handler.button_up.connect(_on_button_up)
_update_font_color()
#endregion
#region SetGet #####################################################################################
func set_dialog_option(value: PopochiuDialogOption) -> void:
option = value
if PopochiuConfig.should_dialog_options_be_gibberish():
text = PopochiuUtils.d.create_gibberish(option.text)
else:
text = option.text
used = option.used and not option.always_on
func set_text(value: String) -> void:
text = value
rich_text_label.text = value
func set_used(value: bool) -> void:
used = value
_update_font_color()
func set_state(value: String) -> void:
_state = value
_update_font_color()
#endregion
#region Private ####################################################################################
func _on_pressed() -> void:
_state = "pressed"
pressed.emit(option)
func _on_mouse_entered() -> void:
_state = "hover"
func _on_mouse_exited() -> void:
_state = "normal"
func _on_button_down() -> void:
_state = "pressed"
func _on_button_up() -> void:
_state = "hover" if handler.is_hovered() else "normal"
func _update_font_color() -> void:
rich_text_label.add_theme_color_override(
"default_color",
get("%s_color" % (_state + ("_used" if used else "")))
)
#endregion

View file

@ -0,0 +1 @@
uid://mts5xfg7vhp1

View file

@ -0,0 +1,40 @@
[gd_scene load_steps=6 format=3 uid="uid://b8r2dcfb6u1e1"]
[ext_resource type="Theme" uid="uid://djl1xk7jgyvpp" path="res://game/gui/resources/gui_theme.tres" id="1_tdxhg"]
[ext_resource type="Script" uid="uid://blkbqigv64y7w" path="res://game/gui/components/dialog_menu/dialog_menu_option/dialog_menu_option_custom.gd" id="2_rads0"]
[ext_resource type="FontFile" uid="uid://cpr61sg33sxdo" path="res://game/gui/fonts/monkeyisland_1991.ttf" id="3_35cmc"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_un1pr"]
content_margin_left = 2.0
content_margin_right = 2.0
content_margin_bottom = 2.0
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_we03b"]
[node name="DialogMenuOption" type="PanelContainer"]
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 24.0
grow_horizontal = 2
mouse_filter = 2
theme = ExtResource("1_tdxhg")
theme_override_styles/panel = SubResource("StyleBoxEmpty_un1pr")
script = ExtResource("2_rads0")
[node name="RichTextLabel" type="RichTextLabel" parent="."]
unique_name_in_owner = true
layout_mode = 2
bbcode_enabled = true
text = "A [wave]veeeeeeeeeeeeeery[/wave] long line option that should wrap so devs can have long options......"
fit_content = true
scroll_active = false
[node name="Handler" type="Button" parent="."]
unique_name_in_owner = true
layout_mode = 2
theme_override_fonts/font = ExtResource("3_35cmc")
theme_override_font_sizes/font_size = 12
theme_override_styles/focus = SubResource("StyleBoxEmpty_we03b")
flat = true
alignment = 0
text_overrun_behavior = 4

View file

@ -0,0 +1 @@
extends "dialog_menu_option.gd"

View file

@ -0,0 +1 @@
uid://ng1tegikh23s