Skip to content

Commit

Permalink
Fixes for #159 and #160
Browse files Browse the repository at this point in the history
Improve behavior of all GUI templates for items use.
[upd] Use Mono font for Label in GUI copy progress popup.
[fix] Validate existance of avatars to fix Portrait component.
[fix] Now item use fallback is handled by the commands script of each
GUI template.
  • Loading branch information
mapedorr committed Feb 24, 2024
1 parent 263e782 commit a8a4c82
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 50 deletions.
11 changes: 5 additions & 6 deletions addons/popochiu/editor/helpers/popochiu_gui_templates_helper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 0 additions & 6 deletions addons/popochiu/engine/interfaces/i_inventory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()


Expand All @@ -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(),
Expand All @@ -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")
Expand Down Expand Up @@ -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 ####################################################################################
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -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].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Expand Down Expand Up @@ -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()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a8a4c82

Please sign in to comment.