diff --git a/addons/popochiu/editor/helpers/popochiu_gui_templates_helper.gd b/addons/popochiu/editor/helpers/popochiu_gui_templates_helper.gd index 711eb001..8b892e2e 100644 --- a/addons/popochiu/editor/helpers/popochiu_gui_templates_helper.gd +++ b/addons/popochiu/editor/helpers/popochiu_gui_templates_helper.gd @@ -9,9 +9,8 @@ static var _progress_idx := 0 static var _template_theme_path := "" #region Public ##################################################################################### -## Create a copy of the selected template, including its components. -## Also, generate the necessary scripts to define custom logic for the graphical -## interface and its commands. +## Creates a copy of the selected template, including its components. Also, generate the necessary +## scripts to define custom logic for the graphical interface and its commands. static func copy_gui_template(template_name: String) -> void: if template_name == PopochiuResources.get_data_value("ui", "template", ""): PopochiuUtils.print_normal("No changes in GUI tempalte.") @@ -141,10 +140,10 @@ static func _create_progress_window() -> void: EditorInterface.get_base_control().add_child(_progress_window) var label := Label.new() - label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER - label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER - label.size_flags_horizontal = Control.SIZE_EXPAND_FILL + label.uppercase = true + label.custom_minimum_size.x = 512.0 label.add_theme_color_override("font_color", Color.WHITE) + PopochiuUtils.override_font(label, 'font', label.get_theme_font("source", "EditorFonts")) _animate_progress_text(label) diff --git a/addons/popochiu/engine/interfaces/i_inventory.gd b/addons/popochiu/engine/interfaces/i_inventory.gd index 6744505a..1ffc59fd 100644 --- a/addons/popochiu/engine/interfaces/i_inventory.gd +++ b/addons/popochiu/engine/interfaces/i_inventory.gd @@ -110,10 +110,4 @@ func set_active(value: PopochiuInventoryItem) -> void: active.unselected.emit() active = value - - if is_instance_valid(active): - Cursor.set_secondary_cursor_texture(active.texture) - else: - Cursor.remove_secondary_cursor_texture() - item_selected.emit(active) diff --git a/addons/popochiu/engine/objects/character/popochiu_character.gd b/addons/popochiu/engine/objects/character/popochiu_character.gd index 0b1c874a..ac56f4f1 100644 --- a/addons/popochiu/engine/objects/character/popochiu_character.gd +++ b/addons/popochiu/engine/objects/character/popochiu_character.gd @@ -701,7 +701,7 @@ func face_direction(destination: Vector2): func get_avatar_for_emotion(emo := "") -> Texture: var texture: Texture = null - while not texture: + while not texture and not avatars.is_empty(): for dic in avatars: if dic.emotion == "": texture = dic.avatar diff --git a/addons/popochiu/engine/objects/clickable/popochiu_clickable.gd b/addons/popochiu/engine/objects/clickable/popochiu_clickable.gd index 861a515b..5c92cb48 100644 --- a/addons/popochiu/engine/objects/clickable/popochiu_clickable.gd +++ b/addons/popochiu/engine/objects/clickable/popochiu_clickable.gd @@ -105,7 +105,7 @@ func _unhandled_input(event: InputEvent): match mouse_event.button_index: MOUSE_BUTTON_LEFT: if I.active: - _on_item_used(I.active) + on_item_used(I.active) else: handle_command(mouse_event.button_index) @@ -257,7 +257,7 @@ func on_middle_click() -> void: ## Called when an [param item] is used on this object. func on_item_used(item: PopochiuInventoryItem) -> void: - await G.show_system_text("Can't USE %s here" % item.description) + _on_item_used(item) ## Triggers the proper GUI command for the clicked mouse button identified with [param button_idx], diff --git a/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/9_verb_commands.gd b/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/9_verb_commands.gd index f74bc188..6f475891 100644 --- a/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/9_verb_commands.gd +++ b/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/9_verb_commands.gd @@ -54,6 +54,10 @@ func fallback() -> void: ## By default makes the character walk to the clicked [code]PopochiuClickable[/code]. func walk_to() -> void: # E.get_node("/root/C").walk_to_clicked() + if I.active: + I.active = null + return + C.player.walk_to_clicked() await C.player.move_ended @@ -67,25 +71,25 @@ func walk_to() -> void: ## Called when [code]E.current_command == Commands.OPEN[/code] and [code]E.command_fallback()[/code] ## is triggered. func open() -> void: - C.player.say("Can't open that") + await C.player.say("Can't open that") ## Called when [code]E.current_command == Commands.PICK_UP[/code] and ## [code]E.command_fallback()[/code] is triggered. func pick_up() -> void: - C.player.say("Not picking that up") + await C.player.say("Not picking that up") ## Called when [code]E.current_command == Commands.PUSH[/code] and [code]E.command_fallback()[/code] ## is triggered. func push() -> void: - C.player.say("I don't want to push that") + await C.player.say("I don't want to push that") ## Called when [code]E.current_command == Commands.CLOSE[/code] and ## [code]E.command_fallback()[/code] is triggered. func close() -> void: - C.player.say("Can't close that") + await C.player.say("Can't close that") ## Called when [code]E.current_command == Commands.LOOK_AT[/code] and @@ -94,35 +98,55 @@ func look_at() -> void: if E.clicked: await C.player.face_clicked() - if I.clicked: - I.clicked.set_active(true) - return - await C.player.say("I have nothing to say about that") ## Called when [code]E.current_command == Commands.PULL[/code] and [code]E.command_fallback()[/code] ## is triggered. func pull() -> void: - C.player.say("I don't want to pull that") + await C.player.say("I don't want to pull that") ## Called when [code]E.current_command == Commands.GIVE[/code] and [code]E.command_fallback()[/code] ## is triggered. func give() -> void: - C.player.say("What?") + await C.player.say("What?") ## Called when [code]E.current_command == Commands.TALK_TO[/code] and ## [code]E.command_fallback()[/code] is triggered. func talk_to() -> void: - C.player.say("Emmmm...") + await C.player.say("Emmmm...") ## Called when [code]E.current_command == Commands.USE[/code] and [code]E.command_fallback()[/code] ## is triggered. func use() -> void: - C.player.say("What?") + if I.active and E.clicked: + use_item_on(I.active, E.clicked) + elif I.active and I.clicked and I.active != I.clicked: + use_item_on(I.active, I.clicked) + elif I.clicked: + match I.clicked.last_click_button: + MOUSE_BUTTON_LEFT: + I.clicked.set_active(true) + MOUSE_BUTTON_RIGHT: + # TODO: I'm not sure this is the right way to do this. Maybe GUIs should capture + # click inputs on clickables and inventory items. ---------------------------- + E.current_command = ( + I.clicked.suggested_command if I.clicked.get("suggested_command") + else Commands.LOOK_AT + ) + + I.clicked.handle_command(MOUSE_BUTTON_LEFT) + # ---------------------------------------------------------------------------------- + else: + await C.player.say("What?") + + +func use_item_on(_item: PopochiuInventoryItem, _target: Node) -> void: + I.active = null + await C.player.say("I don't want to do that") #endregion diff --git a/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/9_verb_gui.gd b/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/9_verb_gui.gd index 638f8a59..9b69f31d 100644 --- a/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/9_verb_gui.gd +++ b/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/9_verb_gui.gd @@ -7,6 +7,9 @@ extends PopochiuGraphicInterface ## bottom right corner of the screen, and the settings popup can be opened using the button in the ## top right corner of the sceen. +# Used to go back to the WALK_TO command when hovering an inventory item without a verb selected +var _return_to_walk_to := false + ## Used to access the [b]9VerbSettingsPopup[/b] node. @onready var settings_popup: PopochiuPopup = $"Popups/9VerbSettingsPopup" ## Used to access the [b]9VerbQuitPopup[/b] node. @@ -114,7 +117,11 @@ func _on_mouse_exited_clickable(clickable: PopochiuClickable) -> void: $"9VerbPanel".highlight_command(clickable.suggested_command, false) Cursor.show_cursor("normal") - if I.active: return + if I.active: + _show_use_in(I.active) + + return + G.show_hover_text() @@ -123,16 +130,15 @@ func _on_mouse_exited_clickable(clickable: PopochiuClickable) -> void: ## [code]"active"[/code] cursor. func _on_mouse_entered_inventory_item(inventory_item: PopochiuInventoryItem) -> void: if E.current_command == NineVerbCommands.Commands.WALK_TO: - E.current_command = NineVerbCommands.Commands.LOOK_AT + _return_to_walk_to = true + E.current_command = NineVerbCommands.Commands.USE $"9VerbPanel".highlight_command(NineVerbCommands.Commands.LOOK_AT) - Cursor.show_cursor("active") + Cursor.show_cursor("normal") if I.active: - if ( - E.current_command == NineVerbCommands.Commands.USE - and I.active != inventory_item - ): + if E.current_command == NineVerbCommands.Commands.USE and I.active != inventory_item: + # Show a hover text in the form: Use xxx in yyy G.show_hover_text( "%s %s in %s" % [ E.get_current_command_name(), @@ -147,8 +153,9 @@ func _on_mouse_entered_inventory_item(inventory_item: PopochiuInventoryItem) -> ## Called when the mouse exits [param inventory_item]. Clears the text in the [HoverText] component and ## shows the [code]"normal"[/code] cursor. func _on_mouse_exited_inventory_item(inventory_item: PopochiuInventoryItem) -> void: - if E.current_command == NineVerbCommands.Commands.LOOK_AT: + if not I.active and _return_to_walk_to: E.current_command = NineVerbCommands.Commands.WALK_TO + _return_to_walk_to = false $"9VerbPanel".highlight_command(NineVerbCommands.Commands.LOOK_AT, false) Cursor.show_cursor("normal") @@ -181,6 +188,16 @@ func _on_dialog_finished(_dialog: PopochiuDialog) -> void: Cursor.show_cursor("normal") +## Called when [param item] is selected in the inventory (i.e. by clicking it). For this GUI, this +## will only occur when the current command is [constant NineVerbCommands.USE]. +func _on_inventory_item_selected(item: PopochiuInventoryItem) -> void: + if not item: + E.current_command = NineVerbCommands.Commands.WALK_TO + G.show_hover_text() + else: + _show_use_in(item) + + #endregion #region Private #################################################################################### @@ -208,4 +225,8 @@ func _on_quit_pressed() -> void: quit_popup.open() +func _show_use_in(item: PopochiuInventoryItem) -> void: + G.show_hover_text("%s %s in" % [E.get_current_command_name(), item.description]) + + #endregion diff --git a/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/components/9_verb_hover_text/9_verb_hover_text.gd b/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/components/9_verb_hover_text/9_verb_hover_text.gd index ae1589f2..e574a04a 100644 --- a/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/components/9_verb_hover_text/9_verb_hover_text.gd +++ b/addons/popochiu/engine/objects/graphic_interface/templates/9_verb/components/9_verb_hover_text/9_verb_hover_text.gd @@ -45,15 +45,15 @@ func _show_text(txt := "") -> void: size = Vector2.ZERO if txt.is_empty(): - if E.current_command == NineVerbCommands.Commands.WALK_TO\ - and is_instance_valid(E.get_hovered()): - text = '[center]%s %s[/center]' % [ - E.get_current_command_name(), E.get_hovered().description - ] + if ( + E.current_command == NineVerbCommands.Commands.WALK_TO + and is_instance_valid(E.get_hovered()) + ): + super("%s %s" % [E.get_current_command_name(), E.get_hovered().description]) elif E.current_command != NineVerbCommands.Commands.WALK_TO: - text = '[center]%s[/center]' % E.get_current_command_name() + super(E.get_current_command_name()) elif not txt.is_empty() and not I.active: - text = '[center]%s %s[/center]' % [E.get_current_command_name(), txt] + super("%s %s" % [E.get_current_command_name(), txt]) elif I.active: super(txt) diff --git a/addons/popochiu/engine/objects/graphic_interface/templates/sierra/sierra_commands.gd b/addons/popochiu/engine/objects/graphic_interface/templates/sierra/sierra_commands.gd index 5b04b073..362216f7 100644 --- a/addons/popochiu/engine/objects/graphic_interface/templates/sierra/sierra_commands.gd +++ b/addons/popochiu/engine/objects/graphic_interface/templates/sierra/sierra_commands.gd @@ -55,8 +55,14 @@ func look() -> void: ## Called when [code]E.current_command == Commands.INTERACT[/code] and ## [code]E.command_fallback()[/code] is triggered. func interact() -> void: - if is_instance_valid(I.clicked): + if (I.active and I.clicked) and I.active != I.clicked: + G.show_system_text("%s can't use %s with %s" % [ + C.player.description, I.active.description, I.clicked.description + ]) + I.clicked = null + elif I.clicked: I.clicked.set_active() + I.clicked = null else: G.show_system_text("%s doesn't want to do anything with that object" % C.player.description) diff --git a/addons/popochiu/engine/objects/graphic_interface/templates/sierra/sierra_gui.gd b/addons/popochiu/engine/objects/graphic_interface/templates/sierra/sierra_gui.gd index 297a24aa..1bd3abfb 100644 --- a/addons/popochiu/engine/objects/graphic_interface/templates/sierra/sierra_gui.gd +++ b/addons/popochiu/engine/objects/graphic_interface/templates/sierra/sierra_gui.gd @@ -103,8 +103,10 @@ func _on_dialog_finished(_dialog: PopochiuDialog) -> void: ## default cursor. func _on_inventory_item_selected(item: PopochiuInventoryItem) -> void: if is_instance_valid(item): + Cursor.set_secondary_cursor_texture(item.texture) Cursor.hide_main_cursor() else: + Cursor.remove_secondary_cursor_texture() Cursor.show_cursor() diff --git a/addons/popochiu/engine/objects/graphic_interface/templates/simple_click/simple_click_commands.gd b/addons/popochiu/engine/objects/graphic_interface/templates/simple_click/simple_click_commands.gd index 02d25a75..79c6ad82 100644 --- a/addons/popochiu/engine/objects/graphic_interface/templates/simple_click/simple_click_commands.gd +++ b/addons/popochiu/engine/objects/graphic_interface/templates/simple_click/simple_click_commands.gd @@ -24,7 +24,10 @@ func fallback() -> void: ## Called when players click (LMB) a [PopochiuClickable]. func click_clickable() -> void: - await G.show_system_text("Can't INTERACT with it") + if I.active: + G.show_system_text("Can't USE %s with %s" % [I.active.description, E.clicked.description]) + else: + await G.show_system_text("Can't INTERACT with it") ## Called when players right click (RMB) a [PopochiuClickable]. @@ -34,7 +37,10 @@ func right_click_clickable() -> void: ## Called when players click (LMB) a [PopochiuInvenoryItem]. func click_inventory_item() -> void: - I.clicked.set_active() + if I.active and I.active != I.clicked: + G.show_system_text("Can't USE %s with %s" % [I.active.description, I.clicked.description]) + else: + I.clicked.set_active() ## Called when players right click (RMB) a [PopochiuInvenoryItem]. diff --git a/addons/popochiu/engine/objects/graphic_interface/templates/simple_click/simple_click_gui.gd b/addons/popochiu/engine/objects/graphic_interface/templates/simple_click/simple_click_gui.gd index ca359aa3..df8e92ce 100644 --- a/addons/popochiu/engine/objects/graphic_interface/templates/simple_click/simple_click_gui.gd +++ b/addons/popochiu/engine/objects/graphic_interface/templates/simple_click/simple_click_gui.gd @@ -83,7 +83,7 @@ func _on_mouse_entered_inventory_item(inventory_item: PopochiuInventoryItem) -> if not I.active: G.show_hover_text(inventory_item.description) - else: + elif I.active != inventory_item: G.show_hover_text( 'Use %s with %s' % [I.active.description, inventory_item.description] ) @@ -129,8 +129,10 @@ func _on_dialog_finished(dialog: PopochiuDialog) -> void: ## default cursor. func _on_inventory_item_selected(item: PopochiuInventoryItem) -> void: if is_instance_valid(item): + Cursor.set_secondary_cursor_texture(item.texture) Cursor.hide_main_cursor() else: + Cursor.remove_secondary_cursor_texture() Cursor.show_cursor() diff --git a/addons/popochiu/engine/objects/inventory_item/popochiu_inventory_item.gd b/addons/popochiu/engine/objects/inventory_item/popochiu_inventory_item.gd index f5120e0e..144a9747 100644 --- a/addons/popochiu/engine/objects/inventory_item/popochiu_inventory_item.gd +++ b/addons/popochiu/engine/objects/inventory_item/popochiu_inventory_item.gd @@ -271,9 +271,10 @@ func on_middle_click() -> void: ## Called when the item is clicked and there is another [param item] currently selected. func on_item_used(item: PopochiuInventoryItem) -> void: - await G.show_system_text( - 'Nothing happens when using %s in this item' % item.description - ) + _on_item_used(item) + #await G.show_system_text( + #'Nothing happens when using %s in this item' % item.description + #) ## Triggers the proper GUI command for the clicked mouse button identified with [param button_idx], @@ -346,7 +347,7 @@ func _on_gui_input(event: InputEvent) -> void: match mouse_event.button_index: MOUSE_BUTTON_LEFT: if I.active: - _on_item_used(I.active) + on_item_used(I.active) else: handle_command(mouse_event.button_index) MOUSE_BUTTON_RIGHT, MOUSE_BUTTON_MIDDLE: