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

CardUI Signal don't emit when put into custom dropzone #6

Open
Arcadia822 opened this issue Jun 3, 2024 · 11 comments
Open

CardUI Signal don't emit when put into custom dropzone #6

Arcadia822 opened this issue Jun 3, 2024 · 11 comments

Comments

@Arcadia822
Copy link

I'm trying to make some custom Dropzone. Problem is any card dropped into custom dropzones lose ability to trigger _on_mouse_enter or _on_gui_input.

  • CardUI in pile works properly and lose it's hook / signal after call card_ui_dropped.
  • CardUI created manually with _create_card_ui and put into custom dropzone cannot trigger too. (Put into internal piles is OK)

What I figured out:

  • It's not about z-index
  • It's not about _card_can_be_interacted_with function. The hook doesn't triggered at all.
  • Neither connect signals from CardUI nor CardPileUI work.

PS: I'm new to Godot and feel like this is a noob question. Please help. Thanks.

@mathrick
Copy link

mathrick commented Jun 5, 2024

Your question is pretty hard to follow, could you share the code for your custom dropzone? My guess is you need to add a super() call to your code, something like:

class_name MyDropzone extends CardDropzone

func card_ui_dropped(card_ui: CardUI):
    super(card_ui)
    # your code goes here
    do_something()
    do_something_else()

@mathrick
Copy link

mathrick commented Jun 5, 2024

Also note that you might not want to call super() if you don't want to do exactly what it does, and in this case you might need to reimplement bits and pieces of its functionality. I'm working on a series of PRs to modularise a lot of the add-on, so it will be easier to hook in your own code.

In case you're not familiar with super(), have a look at the Godot docs.

@Arcadia822
Copy link
Author

My custom CardDropzone

extends CardDropzone

@onready var game = get_parent()

func _ready():
    pass # Replace with function body.

func card_ui_dropped(card_ui: CardUI):
    super(card_ui)
    # card_pile_ui.set_card_dropzone(card_ui, self)
    game.play_card(card_ui.card_data)

Thanks for the reply. I checked card_ui_dropped and found I didn't call it but insteadly manually called set_card_dropzone.

Though replace it with super(card_ui) didn't change the problem.

Also I checked the code inside set_card_dropzone. It looks nothing to do with the signal card_hovered, card_clicked since they are connected inside card_pile_ui._create_card_ui

I take some screenshots and my codes.

image

Custom Card Class
class_name Card extends CardUI

@export var gold: int
@export var power: int
@export var cost: int
@export var description: String
@export var mode: String = ''
@export var highlighted: bool = false

@onready var name_label = $Frontface/Name
@onready var desc_label = $Frontface/Description

func set_store():
    print_debug('set store')
    set_mode('store')

func set_mode(_mode: String):
    mode = _mode

func highlight():
    if (highlighted):
        return
    position.y += size[1] * 0.1
    scale = Vector2(1.1, 1.1)
    highlighted = true

func unhighlight():
    if (not highlighted):
        return
    scale = Vector2(1, 1)
    position.y -= size[1] * 0.1
    highlighted = false

func _ready():
    super()
    card_data.connect("card_data_updated", _update_display)
    _update_display()

func _card_can_be_interacted_with():
    print_debug('test mode: ', mode)
    if mode == 'store':
        return true
    return super()

func _update_display():
    name_label.text = card_data.nice_name
    desc_label.text = card_data.description

@Arcadia822
Copy link
Author

image
image

@mathrick
Copy link

mathrick commented Jun 6, 2024

@Arcadia822: ah, I see. Just to confirm, since you say "custom dropzone", does it work with stock CardDropzone, without any of your modifications? Cards in dropzones generally don't respond to input at the moment, and my first instinct was to look at can_be_interacted_with(), but you've already done and answered most of what I was going to ask, so good job there :)

@mathrick
Copy link

mathrick commented Jun 6, 2024

Actually, I looked at your tree again, and I'm 90% sure I know what the issue is. Try dragging your CardPileUI so that it's below any dropzones in the tree (and just above UI in your case). The order of nodes is lower-on-top, ie. amongst siblings, the one that comes later will be the one on top. It's predictable, but can trip you up if you don't know it.

@Arcadia822
Copy link
Author

Actually, I looked at your tree again, and I'm 90% sure I know what the issue is. Try dragging your CardPileUI so that it's below any dropzones in the tree (and just above UI in your case). The order of nodes is lower-on-top, ie. amongst siblings, the one that comes later will be the one on top. It's predictable, but can trip you up if you don't know it.

Instant fix. I even don't notice node order matters 😂 . Maybe I should read the docs again. Thanks a lot again.

@Arcadia822
Copy link
Author

I checked the Node / Signal section of godot docs and didn't find an explain.
This looks quite different from web / application development. Intuitively I thought script order should only affect execution order of setup hooks like _ready() and frame loop process like _process(). I don't understand why node order affect signal hooks.

@mathrick
Copy link

mathrick commented Jun 7, 2024

It doesn't! Signals are received just fine regardless of where the node sits in the tree, it's just that for display and input purposes, the nodes are drawn from the top of the tree down, meaning the ones further down will be drawn in front of the ones up the tree. And the ones that are in front are also the ones that receive input from the engine (unless you change their z-index).

Here are the docs describing some of that, and the little pictorial description of how input processing is ordered:

input_event_scene_flow

@Arcadia822
Copy link
Author

It doesn't! Signals are received just fine regardless of where the node sits in the tree, it's just that for display and input purposes, the nodes are drawn from the top of the tree down, meaning the ones further down will be drawn in front of the ones up the tree. And the ones that are in front are also the ones that receive input from the engine (unless you change their z-index).

Here are the docs describing some of that, and the little pictorial description of how input processing is ordered:

input_event_scene_flow

That's pretty clear, Thanks. Now i'm trying to add some features to this project. Hope I could make some pr soon.
Do I need to close this issue or leave it open?

@mathrick
Copy link

mathrick commented Jun 11, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants