guladam / deck_builder_tutorial

A roguelike deckbuilder tutorial project made in Godot 4.
MIT License
207 stars 30 forks source link

Updating UI for CardUI costs not working correctly #28

Closed dsemiao closed 1 month ago

dsemiao commented 1 month ago

For context, my CardUI scene has a label with the cost of the card and the font color should change to red if the player doesn't have enough energy to play the card and should be white if player can play the card. In order to achieve this I added a method to the hand.gd script called update_playable_cards

func update_playable_cards(char_stats: CharacterStats) -> void:
    for card: CardUI in get_children():
        card.playable = char_stats.can_play_card(card.card)

This method is called, by the PlayerHandler, at the start of every turn, after the hand is drawn, and on the method that handles the card_played signal. At the start of the turn, this seems to work fine, but if I play a card and then have no mana to play some of the remaining cards, those cards cost UI isn't updated. However, if I don't have enough mana to play any of the remaining cards, then it updates. It basically only seems to work if I can't play any of my remaining cards. This is only a visual bug though, because even if it shows I can play the card, if I don't have enough mana, the game doesn't let me play it. Also, I only did everything until season 1, haven't started season 2 yet. If you need any more info please let me know. Any help would be really appreciated

UncannyCritter commented 1 month ago

@dsemiao I have the same issue, any updates on fixes? Specifically my issue is when the cost goes red for one card, it goes red for all and vice versa. I think they all share the same char_stats maybe? Oddly, the icon updates correctly to transparent and back.

guladam commented 1 month ago

Hey people, I'll look into it today and get back to you asap!

guladam commented 1 month ago

I looked into this, with the season 1 ending code: https://github.com/guladam/deck_builder_tutorial/tree/season-1-code

And I didn't encounter this issue at all: mana_costs

I think this might be a problem on your end. The relevant code is in the CardUI class. Check the _set_char_stats() and _on_char_stats_changed() methods, these are responsible for updating the UI when the mana changes, it's not done in the PlayerHandler class.

Hope that helps. I will close this for now and let me know if I can do anything to help.

UncannyCritter commented 1 month ago

Thanks for taking the time Adam! I actually just changed the card's modulate to make the whole thing transparent when it's disabled. Still not sure what the actual issue was, but I'm not code savvy enough to pinpoint it exactly.