Esempio n. 1
0
        public override void _Ready()
        {
            base._Ready();
            this.parent = GetNode <CharSelectionDataPanel>(parentPath);
            this.parent.buttons.Add(this);

            this.Connect("pressed", this, nameof(this._OnPressed));
        }
        //Shows a character up on the panel on the right hand side
        //Index must be an index found in the itemlist, CharSprites and CharTrees or -1 for non
        private void ShowChar(int index)
        {
            //Remove the data panel if it exists
            if (this.HasNode("pa_char_data"))
            {
                this.RemoveChild(this.nodeDataPanel);
            }

            //if index is -1 then the data panel is supposed to just be removed (so do not add a new one)
            if (index != -1)
            {
                //Set the pointer to the new data panel
                this.nodeDataPanel = this.chars[index];

                //Add the new data panel
                this.AddChild(this.nodeDataPanel);
                this.nodeDataPanel.Reset(this.p1.nodeButton.Pressed);
            }
        }
        public override void _Ready()
        {
            this.p1 = new PlayerData();
            this.p2 = new PlayerData();

            //Get nodes
            this.p1.nodeButton    = GetNode <TextureButton>("pa_player_buttons/bt_p1");
            this.p1.nodeIcon      = GetNode <Sprite>("pa_player_buttons/sp_p1");
            this.p1.nodeConfirmed = GetNode <Sprite>("pa_player_buttons/sp_ready_p1");
            this.p1.nodePresent   = GetNode <Sprite>("pa_player_buttons/sp_present_p1");

            this.p2.nodeButton    = GetNode <TextureButton>("pa_player_buttons/bt_p2");
            this.p2.nodeIcon      = GetNode <Sprite>("pa_player_buttons/sp_p2");
            this.p2.nodeConfirmed = GetNode <Sprite>("pa_player_buttons/sp_ready_p2");
            this.p2.nodePresent   = GetNode <Sprite>("pa_player_buttons/sp_present_p2");

            this.nodeRoleButton = GetNode <TextureButton>("pa_player_buttons/bt_role");

            this.nodePlayButton        = GetNode <TextureButton>("bt_play");
            this.nodeQuitButton        = GetNode <TextureButton>("bt_quit");
            this.nodeSpectators        = GetNode <Label>("la_mp_spectators");
            this.nodeHostingOn         = GetNode <Label>("la_mp_hosting_on");
            this.nodeHighLatencyButton = GetNode <CheckBox>("bt_high_latency");

            //This is removed the moment the scene is opened
            //However I left it in the scene as it works as a good visual guide as to where the everything is in engine
            //And also means that this.nodeDataPanel will not be left null
            this.nodeDataPanel = GetNode <CharSelectionDataPanel>("pa_char_data");

            this.p1.other = this.p2;
            this.p2.other = this.p1;

            this.nodeCharList = GetNode <ItemList>("il_selection");

            //Connect player buttons
            this.p1.nodeButton.Connect("pressed", this, nameof(this._OnPlayerPressed),
                                       new Godot.Collections.Array(new byte[] { 1 }));
            this.p2.nodeButton.Connect("pressed", this, nameof(this._OnPlayerPressed),
                                       new Godot.Collections.Array(new byte[] { 2 }));
            this.nodePlayButton.Connect("pressed", this, nameof(this._OnPlayPressed));
            this.nodeQuitButton.Connect("pressed", Command.lobby, nameof(Command.lobby.Reset));
            this.nodeRoleButton.Connect("pressed", this, nameof(this._OnRolePressed));
            this.nodeHighLatencyButton.Connect("pressed", this, nameof(this._OnHighLatencyPressed));

            this.nodeCharList.Connect("item_selected", this, nameof(this._OnCharSelected));

            //Set mp specific bits to false
            this.nodeSpectators.Visible        = false;
            this.nodeHostingOn.Visible         = false;
            this.nodeRoleButton.Visible        = false;
            this.nodeHighLatencyButton.Visible = false;

            //Map PackedScenes in charScenes into Control nodes in chars
            this.chars = charScenes.Select(character => character.Instance() as CharSelectionDataPanel).ToArray();

            RpcConfig(nameof(this.Confirm), MultiplayerAPI.RPCMode.Remotesync);
            RpcConfig(nameof(this.SetHighLatency), MultiplayerAPI.RPCMode.Remotesync);

            this.ShowChar(-1);
            this.GrabFocus();
        }