Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply type hints to example scripts to avoid triggering any GDScript warnings or errors #1975

Merged
merged 13 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ extends DialogicLayoutBase

## The default layout base scene.

@export var canvas_layer := 1
@export var canvas_layer: int = 1

@export_subgroup("Global")
@export var global_bg_color := Color(0, 0, 0, 0.9)
@export var global_font_color := Color("white")
@export_file('*.ttf') var global_font := ""
@export var global_font_size := 18
coppolaemilio marked this conversation as resolved.
Show resolved Hide resolved
@export var global_bg_color: Color = Color(0, 0, 0, 0.9)
@export var global_font_color: Color = Color("white")
@export_file('*.ttf') var global_font: String = ""
@export var global_font_size: int = 18


func _apply_export_overrides() -> void:
# apply layer
self.layer = canvas_layer
set(&'layer', canvas_layer)


Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,73 @@ extends DialogicLayoutLayer

@export_group('Text')
enum Alignment {LEFT, CENTER, RIGHT}
@export var title_alignment := Alignment.LEFT
@export var text_alignment := Alignment.LEFT
@export var extra_alignment := Alignment.RIGHT
@export var title_alignment: Alignment = Alignment.LEFT
@export var text_alignment: Alignment = Alignment.LEFT
@export var extra_alignment: Alignment = Alignment.RIGHT

@export_subgroup("Colors")
enum TextColorModes {GLOBAL, ENTRY, CUSTOM}
@export var title_color_mode := TextColorModes.ENTRY
@export var title_custom_color := Color.WHITE
@export var text_color_mode := TextColorModes.ENTRY
@export var text_custom_color := Color.WHITE
@export var extra_color_mode := TextColorModes.ENTRY
@export var extra_custom_color := Color.WHITE
@export var title_color_mode: TextColorModes = TextColorModes.ENTRY
@export var title_custom_color: Color = Color.WHITE
@export var text_color_mode: TextColorModes = TextColorModes.ENTRY
@export var text_custom_color: Color = Color.WHITE
@export var extra_color_mode: TextColorModes = TextColorModes.ENTRY
@export var extra_custom_color: Color = Color.WHITE


@export_group("Font")
@export var font_use_global := true
@export_file('*.ttf') var font_custom := ""
@export var font_use_global: bool = true
@export_file('*.ttf') var font_custom: String = ""

@export_subgroup('Sizes')
@export var font_title_size := 18
@export var font_text_size := 17
@export var font_extra_size := 15
@export var font_title_size: int = 18
@export var font_text_size: int = 17
@export var font_extra_size: int = 15


@export_group("Box")
@export_subgroup("Color")
enum ModulateModes {BASE_COLOR_ONLY, ENTRY_COLOR_ON_BOX, GLOBAL_BG_COLOR}
@export var box_modulate_mode := ModulateModes.ENTRY_COLOR_ON_BOX
@export var box_base_modulate := Color.WHITE
@export var box_modulate_mode: ModulateModes = ModulateModes.ENTRY_COLOR_ON_BOX
@export var box_base_modulate: Color = Color.WHITE
@export_subgroup("Size")
@export var box_width := 200
@export var box_width: int = 200

func get_pointer() -> Control:
return $Pointer


func get_title() -> Label:
return %Title


func get_text() -> RichTextLabel:
return %Text


func get_extra() -> RichTextLabel:
return %Extra


func get_panel() -> PanelContainer:
return %Panel


func get_panel_point() -> PanelContainer:
return %PanelPoint


func _ready() -> void:
if Engine.is_editor_hint():
return

$Pointer.hide()
DialogicUtil.autoload().Text.animation_textbox_hide.connect($Pointer.hide)
DialogicUtil.autoload().Text.meta_hover_started.connect(_on_dialogic_display_dialog_text_meta_hover_started)
DialogicUtil.autoload().Text.meta_hover_ended.connect(_on_dialogic_display_dialog_text_meta_hover_ended)
DialogicUtil.autoload().Text.meta_clicked.connect(_on_dialogic_display_dialog_text_meta_clicked)
get_pointer().hide()
var text_system: Node = DialogicUtil.autoload().get(&'Text')
var _error: int = 0
_error = text_system.connect(&'animation_textbox_hide', get_pointer().hide)
_error = text_system.connect(&'meta_hover_started', _on_dialogic_display_dialog_text_meta_hover_started)
_error = text_system.connect(&'meta_hover_ended', _on_dialogic_display_dialog_text_meta_hover_ended)
_error = text_system.connect(&'meta_clicked', _on_dialogic_display_dialog_text_meta_clicked)


## Method that shows the bubble and fills in the info
Expand All @@ -58,96 +83,100 @@ func _on_dialogic_display_dialog_text_meta_hover_started(meta:String) -> void:
if not info:
return

$Pointer.show()
%Title.text = info.get('title', '')
%Text.text = info.get('text', '')
%Text.text = ['', '[center]', '[right]'][text_alignment] + %Text.text
%Extra.text = info.get('extra', '')
%Extra.text = ['', '[center]', '[right]'][extra_alignment] + %Extra.text
$Pointer.global_position = $Pointer.get_global_mouse_position()
get_pointer().show()
get_title().text = info.get(&'title', '')
get_text().text = info.get(&'text', '')
get_text().text = ['', '[center]', '[right]'][text_alignment] + get_text().text
get_extra().text = info.get(&'extra', '')
get_extra().text = ['', '[center]', '[right]'][extra_alignment] + get_extra().text
get_pointer().global_position = get_pointer().get_global_mouse_position()

if title_color_mode == TextColorModes.ENTRY:
%Title.add_theme_color_override("font_color", info.get('color', title_custom_color))
get_title().add_theme_color_override(&"font_color", info.get(&'color', title_custom_color) as Color)
if text_color_mode == TextColorModes.ENTRY:
%Text.add_theme_color_override("default_color", info.get('color', text_custom_color))
get_text().add_theme_color_override(&"default_color", info.get(&'color', text_custom_color) as Color)
if extra_color_mode == TextColorModes.ENTRY:
%Extra.add_theme_color_override("default_color", info.get('color', extra_custom_color))
get_extra().add_theme_color_override(&"default_color", info.get(&'color', extra_custom_color) as Color)

match box_modulate_mode:
ModulateModes.ENTRY_COLOR_ON_BOX:
%Panel.self_modulate = info.get('color', Color.WHITE)
%PanelPoint.self_modulate = info.get('color', Color.WHITE)
get_panel().self_modulate = info.get(&'color', Color.WHITE)
get_panel_point().self_modulate = info.get(&'color', Color.WHITE)

DialogicUtil.autoload().Input.action_was_consumed = true


## Method that keeps the bubble at mouse position when visible
func _process(delta) -> void:
func _process(_delta : float) -> void:
if Engine.is_editor_hint():
return

if $Pointer.visible:
$Pointer.global_position = $Pointer.get_global_mouse_position()
var pointer: Control = get_pointer()
if pointer.visible:
pointer.global_position = pointer.get_global_mouse_position()


## Method that hides the bubble
func _on_dialogic_display_dialog_text_meta_hover_ended(meta:String) -> void:
$Pointer.hide()
func _on_dialogic_display_dialog_text_meta_hover_ended(_meta:String) -> void:
get_pointer().hide()
DialogicUtil.autoload().Input.action_was_consumed = false


func _on_dialogic_display_dialog_text_meta_clicked(meta:String) -> void:
func _on_dialogic_display_dialog_text_meta_clicked(_meta:String) -> void:
DialogicUtil.autoload().Input.action_was_consumed = true


func _apply_export_overrides() -> void:
# Apply fonts
var font: FontFile
if font_use_global and ResourceLoader.exists(get_global_setting('font', '')):
font = load(get_global_setting('font', ''))
if font_use_global and ResourceLoader.exists(get_global_setting(&'font', '') as String):
font = load(get_global_setting(&'font', '') as String)
elif ResourceLoader.exists(font_custom):
font = load(font_custom)

var title: Label = get_title()
if font:
%Title.add_theme_font_override("font", font)
%Title.horizontal_alignment = title_alignment
title.add_theme_font_override(&"font", font)
title.horizontal_alignment = title_alignment as HorizontalAlignment

# Apply font & sizes
%Title.add_theme_font_size_override("font_size", font_title_size)
for i in [[%Text, font_text_size], [%Extra, font_extra_size]]:
title.add_theme_font_size_override(&"font_size", font_title_size)
var labels: Array[RichTextLabel] = [get_text(), get_extra()]
var sizes: PackedInt32Array = [font_text_size, font_extra_size]
for i : int in len(labels):
if font:
i[0].add_theme_font_override('normal_font', font)
labels[i].add_theme_font_override(&'normal_font', font)

i[0].add_theme_font_size_override("normal_font_size", i[1])
i[0].add_theme_font_size_override("bold_font_size", i[1])
i[0].add_theme_font_size_override("italics_font_size", i[1])
i[0].add_theme_font_size_override("bold_italics_font_size", i[1])
i[0].add_theme_font_size_override("mono_font_size", i[1])
labels[i].add_theme_font_size_override(&"normal_font_size", sizes[i])
labels[i].add_theme_font_size_override(&"bold_font_size", sizes[i])
labels[i].add_theme_font_size_override(&"italics_font_size", sizes[i])
labels[i].add_theme_font_size_override(&"bold_italics_font_size", sizes[i])
labels[i].add_theme_font_size_override(&"mono_font_size", sizes[i])


# Apply text colors
var texts := [
[%Title, 'font_color', title_color_mode, title_custom_color],
[%Text, 'default_color', text_color_mode, text_custom_color],
[%Extra, 'default_color', extra_color_mode, extra_custom_color],
]
for i in texts:
match i[2]:
var controls: Array[Control] = [get_title(), get_text(), get_extra()]
var global_settings: Array[StringName] = [&'font_color', &'default_color', &'default_color']
var color_modes: Array[TextColorModes] = [title_color_mode, text_color_mode, extra_color_mode]
var custom_colors: PackedColorArray = [title_custom_color, text_custom_color, extra_custom_color]
for i : int in len(controls):
match color_modes[i]:
TextColorModes.GLOBAL:
i[0].add_theme_color_override(i[1], get_global_setting('font_color', i[3]))
controls[i].add_theme_color_override(global_settings[i], get_global_setting(&'font_color', custom_colors[i]) as Color)
TextColorModes.CUSTOM:
i[0].add_theme_color_override(i[1], i[3])
controls[i].add_theme_color_override(global_settings[i], custom_colors[i])

# Apply box size
%Panel.size.x = box_width
%Panel.position.x = -box_width/2.0
var panel: PanelContainer = get_panel()
panel.size.x = box_width
panel.position.x = -box_width/2.0

# Apply box coloring
match box_modulate_mode:
ModulateModes.BASE_COLOR_ONLY:
%Panel.self_modulate = box_base_modulate
%PanelPoint.self_modulate = box_base_modulate
panel.self_modulate = box_base_modulate
get_panel_point().self_modulate = box_base_modulate
ModulateModes.GLOBAL_BG_COLOR:
%Panel.self_modulate = get_global_setting('bg_color', box_base_modulate)
%PanelPoint.self_modulate = get_global_setting('bg_color', box_base_modulate)
panel.self_modulate = get_global_setting(&'bg_color', box_base_modulate)
get_panel_point().self_modulate = get_global_setting(&'bg_color', box_base_modulate)

Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
extends Container

func get_text_box() -> RichTextLabel:
return %TextBox

func load_info(text:String, character:String = "", character_color:=Color(), icon:Texture= null) -> void:
%TextBox.text = text

func get_name_label() -> Label:
return %NameLabel


func get_icon() -> TextureRect:
return %Icon


func load_info(text:String, character:String = "", character_color: Color =Color(), icon:Texture= null) -> void:
get_text_box().text = text
var name_label : Label = get_name_label()
if character:
%NameLabel.text = character
%NameLabel.add_theme_color_override('font_color', character_color)
%NameLabel.show()
name_label.text = character
name_label.add_theme_color_override('font_color', character_color)
name_label.show()
else:
%NameLabel.hide()
name_label.hide()

var icon_node : TextureRect = get_icon()
if icon == null:
%Icon.hide()
icon_node.hide()
else:
%Icon.show()
%Icon.texture = icon
icon_node.show()
icon_node.texture = icon
Loading
Loading