Example #1
0
        public override void Add(ScreenManager screenManager)
        {
            base.Add(screenManager);
            Window.Focused = true;
            Bar            = new StatusBar(Manager)
            {
                Top = Window.Height - 24, Width = Window.Width
            };
            Bar.Init();
            Window.Add(Bar);
            StatsLabel = new Label(Manager)
            {
                Top = 4, Left = 8, Width = Window.Width - 16, Text = ""
            };
            StatsLabel.Init();
            Bar.Add(StatsLabel);

            LeaveButton = new Button(Manager)
            {
                Right = Bar.ClientWidth - 4, Top = 4, Height = 16, Text = "Lobby"
            };
            LeaveButton.Init();
            LeaveButton.Click += new TomShane.Neoforce.Controls.EventHandler(delegate(object o, TomShane.Neoforce.Controls.EventArgs e)
            {
                ScreenManager.SwitchScreen(new LobbyScreen());
            });
            Bar.Add(LeaveButton);

            Sidebar = new StatusBar(Manager);
            Sidebar.Init();
            Sidebar.SetSize(SidebarWidth, (int)((Window.Height - Bar.Height)));
            Sidebar.SetPosition(Window.Width - Sidebar.Width, 0);
            Window.Add(Sidebar);

            PlayerList = new ListBox(Manager);
            PlayerList.Init();
            PlayerList.SetSize(SidebarWidth, (int)((Window.Height - Bar.Height - 4) * .25f));
            PlayerList.SetPosition(1, 2);
            Sidebar.Add(PlayerList);

            ChatBox = new Console(Manager);
            Manager.Add(ChatBox);
            ChatBox.Init();
            ChatBox.SetSize(PlayerList.Width, (int)((Window.Height - Bar.Height - 4) * .75f));
            ChatBox.SetPosition(Sidebar.Left + 1, PlayerList.Bottom + 1);
            ChatBox.ChannelsVisible = false;
            ChatBox.MessageSent    += new ConsoleMessageEventHandler(SentChat);
            ChatBox.Channels.Add(new ConsoleChannel(0, "Global", Color.White));
            // Select default channel
            ChatBox.SelectedChannel = 0;
            // Do we want to add timestamp or channel name at the start of every message?
            ChatBox.MessageFormat        = ConsoleMessageFormats.None;
            ChatBox.TextBox.TextChanged += TextBox_TextChanged;

            //Hide them until we recieve the Init packet
            ChatBox.Visible = PlayerList.Visible = Sidebar.Visible = false;
        }
Example #2
0
        /// <summary>
        /// Setup the game UI.
        /// </summary>
        public override void Add(ScreenManager screenManager)
        {
            base.Add(screenManager);

            // Status bar.
            sbStats = new StatusBar(Manager);
            sbStats.Init();
            sbStats.Bottom = Manager.ScreenHeight;
            sbStats.Left   = 0;
            sbStats.Width  = Manager.ScreenWidth;

            lblStats = new Label(Manager)
            {
                Top = 4, Left = 8, Width = Manager.ScreenWidth - 16
            };
            lblStats.Init();

            sbStats.Add(lblStats);
            Window.Add(sbStats);

            // Inventory.
            pnlInventory      = new InventoryControl(this, Manager);
            pnlInventory.Left = Manager.TargetWidth / 2 - (pnlInventory.Width / 2);
            pnlInventory.Init();
            Window.Add(pnlInventory);

            // Chat.
            txtChat = new TextBox(Manager);
            txtChat.Init();
            txtChat.Left = 8;
            txtChat.DrawFormattedText = false;
            txtChat.Bottom            = sbStats.Top - 8;
            txtChat.Width             = (int)(Manager.TargetWidth * .4f) - 16; // Remove 16 to align due to invisible scrollbar
            txtChat.Visible           = false;
            txtChat.Passive           = true;
            Window.Add(txtChat);

            lstChats = new ControlList <ChatDataControl>(Manager)
            {
                Left   = txtChat.Left,
                Width  = txtChat.Width + 16,
                Height = (int)(Manager.TargetHeight * .25f)
            };
            lstChats.Init();
            lstChats.Color          = Color.Transparent;
            lstChats.HideSelection  = true;
            lstChats.Passive        = true;
            lstChats.HideScrollbars = true;
            lstChats.Top            = txtChat.Top - lstChats.Height;
            Window.Add(lstChats);

            // Tablist.
            lstPlayers = new ControlList <PlayerListDataControl>(Manager)
            {
                Width = 256,
                Top   = 256
            };
            lstPlayers.Init();
            lstPlayers.HideSelection  = true;
            lstPlayers.Left           = Manager.TargetWidth / 2 - (lstPlayers.Width / 2);
            lstPlayers.Passive        = true;
            lstPlayers.HideScrollbars = true;
            lstPlayers.Visible        = false;
            Window.Add(lstPlayers);

            foreach (var player in Level.Players)
            {
                lstPlayers.Items.Add(new PlayerListDataControl(player, Manager, lstPlayers));
            }


            // Listen for later player joins.
            Client.Events.Network.Game.PlayerJoinReceived.AddHandler(
                args => { lstPlayers.Items.Add(new PlayerListDataControl(args.Player, Manager, lstPlayers)); });

            // Listen for ping updates for players.
            Client.Events.Network.Game.PingUpdateReceived.AddHandler(args =>
            {
                foreach (var ping in args.Pings)
                {
                    var control =
                        (PlayerListDataControl)
                        lstPlayers.Items.FirstOrDefault(i => ((PlayerListDataControl)i).User.UUID == ping.Key);
                    control?.ChangePing(ping.Value);
                }
            });


            // Hackish way to get chats to start at the bottom.
            for (var i = 0; i < (Manager.TargetHeight * 0.25f) / 18; i++)
            {
                lstChats.Items.Add(new ChatDataControl("", Manager, lstChats, this));
            }

            Client.Events.Network.Game.ChatReceived.AddHandler(args => { AddChat(args.Message, Manager, lstChats); });

            // Level event handlers.
            Client.Events.Game.Level.BlockPlaced.AddHandler(args =>
            {
                // Directly access the tile array, as we don't want to send two BlockPlaced events, as the tile indexer will
                // automatically call the event and send a network message.
                if (args.Level != null)
                {
                    args.Level.Tiles.Tiles[args.X, args.Y, args.Z] = new Tile(args.Type);
                }
            });
        }