mlpcardgame/Scenes/Scripts/Draft.gd

80 lines
2.2 KiB
GDScript3
Raw Permalink Normal View History

2019-06-11 23:13:24 +00:00
extends Control
onready var CardList = $PickedCardListScroll/PickedCardList
2019-06-29 13:02:11 +00:00
onready var PlayerList = $PlayerList
var players = {}
2019-06-12 22:36:35 +00:00
var CardUI := preload("res://Scenes/DeckBuilder/UICard.tscn")
2019-06-29 13:02:11 +00:00
var PlayerItem := preload("res://Scenes/Draft/PlayerItem.tscn")
2019-06-12 22:36:35 +00:00
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")
2019-06-29 13:02:11 +00:00
add_player("Player 1", false)
add_player("Bot 1", true)
2019-06-12 22:36:35 +00:00
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])
2019-06-12 22:36:35 +00:00
$Cards.add_child(card)
func clear_cards():
for card in $Cards.get_children():
card.queue_free()
2019-06-12 22:36:35 +00:00
func _card_selected(cardID: String):
$CardZoom.cardID = cardID
$CardZoom.fadein()
func _card_unselected():
$CardZoom.fadeout()
func _card_picked(cardID: String):
CardList.add_card(cardID)
2019-06-29 13:02:11 +00:00
players["Player 1"].set_picked(true)
$CardZoom.fadeout()
2019-06-29 13:25:13 +00:00
clear_cards()
2019-06-29 13:02:11 +00:00
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)
2019-06-12 22:36:35 +00:00
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