extends Control onready var CardList = $PickedCardListScroll/PickedCardList onready var PlayerList = $PlayerList var players = {} var CardUI := preload("res://Scenes/DeckBuilder/UICard.tscn") var PlayerItem := preload("res://Scenes/Draft/PlayerItem.tscn") func _ready(): add_card("pr1") add_card("pr10") add_card("pr20") add_card("pr30") add_card("pr166") add_card("pr171") add_card("pr16") add_card("pr171") add_card("pr1") add_card("pr10") add_card("pr20") add_card("pr30") add_player("Player 1", false) add_player("Bot 1", true) func add_card(cardID: String): var card := CardUI.instance() card.cardID = cardID card.connect("card_selected", self, "_card_selected", [cardID]) card.connect("card_unselected", self, "_card_unselected") card.connect("card_hover", self, "_mouse_on_card", [card]) card.connect("card_clicked", self, "_card_picked", [cardID]) $Cards.add_child(card) func clear_cards(): for card in $Cards.get_children(): card.queue_free() func _card_selected(cardID: String): $CardZoom.cardID = cardID $CardZoom.fadein() func _card_unselected(): $CardZoom.fadeout() func _card_picked(cardID: String): CardList.add_card(cardID) players["Player 1"].set_picked(true) $CardZoom.fadeout() #clear_cards() func add_player(playerName: String, isBot: bool): var item := PlayerItem.instance() item.playerName = playerName item.isBot = isBot players[playerName] = item $PlayerList.add_child(item) item.set_picked(false) const yMargin = 5 const xEdge = 200 const yEdge = 10 func _mouse_on_card(position: Vector2, card: Control): # THIS IS A MESS # Should be cleaned but there are way too many scaling things to keep track of # and it's midnight right now var pos: Vector2 = card.rect_position * $Cards.rect_scale var cardpos: Vector2 = $Cards.rect_position + card.rect_position * $Cards.rect_scale if $CardZoom.rect_size.x > rect_size.x - cardpos.x - xEdge: pos.x -= $CardZoom.rect_size.x * $CardZoom.rect_scale.x else: pos.x += card.rect_size.x * $Cards.rect_scale.x pos.y -= ($CardZoom.rect_size.y * $CardZoom.rect_scale.y)/4 if pos.y < yMargin: pos.y = yMargin elif $CardZoom.rect_size.y > rect_size.y - cardpos.y - yEdge: pos.y = rect_size.y - $CardZoom.rect_size.y - yMargin $CardZoom.rect_position = $Cards.rect_position + pos