mlpcardgame/Scenes/Scripts/Lobby.gd

111 lines
3 KiB
GDScript

extends Control
signal loaded()
onready var roomList := $RoomScroll/RoomList
onready var gametypeDropdown := $CreateRoomDialog/DialogElements/RoomRow1/GameType/Dropdown
onready var gametypeMenu: PopupMenu = gametypeDropdown.get_popup()
onready var draftOptions := $CreateRoomDialog/DialogElements/DraftRows
onready var drafttypeDropdown := $CreateRoomDialog/DialogElements/DraftRows/DraftRow1/DraftType/Dropdown
onready var drafttypeMenu: PopupMenu = drafttypeDropdown.get_popup()
onready var draftRowBlock := $CreateRoomDialog/DialogElements/DraftRows/DraftRowBlock
onready var draftblockDropdown := $CreateRoomDialog/DialogElements/DraftRows/DraftRowBlock/DraftBlock/Dropdown
onready var draftblockMenu: PopupMenu = draftblockDropdown.get_popup()
onready var draftRowCube := $CreateRoomDialog/DialogElements/DraftRows/DraftCubeURL
var RoomItem := preload("res://Scenes/Lobby/RoomEntry.tscn")
var playerName := ""
const GAMETYPE_DRAFT = 0
const DRAFTTYPE_BLOCK = 0
const DRAFTTYPE_CUBE = 1
const DRAFTTYPE_I8P = 2
const DRAFTBLOCK_PR = 0
const DRAFTBLOCK_EO = 1
const DRAFTBLOCK_DE = 2
func _ready():
# Load bgm
BGM.set_volume(BGM.LOW)
BGM.load_music("lobby")
emit_signal("loaded")
Server.get_rooms(self, "_room_list")
add_room("test", "Unnamed room")
$ChooseNameDialog.popup_centered()
# Add options to room creation dialog
gametypeMenu.add_item("Draft", GAMETYPE_DRAFT)
drafttypeMenu.add_item("Booster draft (block)", DRAFTTYPE_BLOCK)
drafttypeMenu.add_item("Cube draft (classic)", DRAFTTYPE_CUBE)
drafttypeMenu.add_item("Cube draft (I8Pages' style)", DRAFTTYPE_I8P)
draftblockMenu.add_item("Premiere block", DRAFTBLOCK_PR)
draftblockMenu.add_item("Odyssey block", DRAFTBLOCK_EO)
draftblockMenu.add_item("Defenders block", DRAFTBLOCK_DE)
func add_room(id: String, name: String):
var item := RoomItem.instance()
item.roomName = name
item.connect("clicked", self, "_room_clicked", [id])
roomList.add_child(item)
func _room_list(result, obj):
if result != OK:
# Handle error
breakpoint
print(obj)
func _room_clicked(id: String):
print(id)
func _create_room():
$CreateRoomDialog.popup_centered()
gametypeDropdown.select(GAMETYPE_DRAFT)
func _name_changed(new_text):
var name := $ChooseNameDialog/Name
$ChooseNameDialog/Confirm.visible = name.text.length() > 0
func _name_chosen(new_text):
var name := $ChooseNameDialog/Name
playerName = name.text
$ChooseNameDialog.visible = false
func _toggle_spectators(button_pressed):
$CreateRoomDialog/DialogElements/RoomRow2/MaxSpec/Spinner.editable = button_pressed
func _game_type_selected(ID):
# Hide all options
draftOptions.visible = false
# Enable options for chosen game type
match ID:
GAMETYPE_DRAFT:
draftOptions.visible = true
func _draft_type_selected(ID):
# Hide all options
draftRowCube.visible = false
draftRowBlock.visible = false
print(ID)
# Enable options for chosen game type
match ID:
DRAFTTYPE_BLOCK:
draftRowBlock.visible = true
DRAFTTYPE_CUBE:
draftRowCube.visible = true
DRAFTTYPE_I8P:
draftRowCube.visible = true