Exemple #1
0
        public override void Initialize()
        {
            ClientRectangle = new Rectangle(0, 0, WindowManager.RenderResolutionX - 64,
                                            WindowManager.RenderResolutionY - 64);

            Name = "CnCNetLobby";
            BackgroundTexture = AssetLoader.LoadTexture("cncnetlobbybg.png");
            localGameID       = ClientConfiguration.Instance.LocalGame;
            localGame         = gameCollection.GameList.Find(g => g.InternalName.ToUpper() == localGameID.ToUpper());

            btnNewGame                 = new XNAClientButton(WindowManager);
            btnNewGame.Name            = "btnNewGame";
            btnNewGame.ClientRectangle = new Rectangle(12, ClientRectangle.Height - 29, 133, 23);
            btnNewGame.Text            = "Create Game";
            btnNewGame.AllowClick      = false;
            btnNewGame.LeftClick      += BtnNewGame_LeftClick;

            btnJoinGame                 = new XNAClientButton(WindowManager);
            btnJoinGame.Name            = "btnJoinGame";
            btnJoinGame.ClientRectangle = new Rectangle(btnNewGame.ClientRectangle.Right + 12,
                                                        btnNewGame.ClientRectangle.Y, 133, 23);
            btnJoinGame.Text       = "Join Game";
            btnJoinGame.AllowClick = false;
            btnJoinGame.LeftClick += BtnJoinGame_LeftClick;

            btnLogout                 = new XNAClientButton(WindowManager);
            btnLogout.Name            = "btnLogout";
            btnLogout.ClientRectangle = new Rectangle(ClientRectangle.Width - 145, btnNewGame.ClientRectangle.Y,
                                                      133, 23);
            btnLogout.Text       = "Log Out";
            btnLogout.LeftClick += BtnLogout_LeftClick;

            lbGameList                 = new GameListBox(WindowManager, localGameID);
            lbGameList.Name            = "lbGameList";
            lbGameList.ClientRectangle = new Rectangle(btnNewGame.ClientRectangle.X,
                                                       41, btnJoinGame.ClientRectangle.Right - btnNewGame.ClientRectangle.X,
                                                       btnNewGame.ClientRectangle.Top - 47);
            lbGameList.DrawMode            = PanelBackgroundImageDrawMode.STRETCHED;
            lbGameList.BackgroundTexture   = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1);
            lbGameList.DoubleLeftClick    += LbGameList_DoubleLeftClick;
            lbGameList.AllowMultiLineItems = false;

            lbPlayerList                 = new XNAListBox(WindowManager);
            lbPlayerList.Name            = "lbPlayerList";
            lbPlayerList.ClientRectangle = new Rectangle(ClientRectangle.Width - 202,
                                                         20, 190,
                                                         btnLogout.ClientRectangle.Top - 26);
            lbPlayerList.DrawMode          = PanelBackgroundImageDrawMode.STRETCHED;
            lbPlayerList.BackgroundTexture = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1);
            lbPlayerList.LineHeight        = 16;
            lbPlayerList.DoubleLeftClick  += LbPlayerList_DoubleLeftClick;
            lbPlayerList.RightClick       += LbPlayerList_RightClick;

            playerContextMenu                 = new PlayerContextMenu(WindowManager);
            playerContextMenu.Name            = "playerContextMenu";
            playerContextMenu.ClientRectangle = new Rectangle(0, 0, 150, 2);
            playerContextMenu.Enabled         = false;
            playerContextMenu.Visible         = false;
            playerContextMenu.AddItem("Private Message");
            playerContextMenu.AddItem("Add Friend");
            playerContextMenu.OptionSelected += PlayerContextMenu_OptionSelected;

            lbChatMessages                 = new ChatListBox(WindowManager);
            lbChatMessages.Name            = "lbChatMessages";
            lbChatMessages.ClientRectangle = new Rectangle(lbGameList.ClientRectangle.Right + 12, lbGameList.ClientRectangle.Y,
                                                           lbPlayerList.ClientRectangle.Left - lbGameList.ClientRectangle.Right - 24, lbPlayerList.ClientRectangle.Height);
            lbChatMessages.DrawMode          = PanelBackgroundImageDrawMode.STRETCHED;
            lbChatMessages.BackgroundTexture = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1);
            lbChatMessages.LineHeight        = 16;

            tbChatInput                 = new XNATextBox(WindowManager);
            tbChatInput.Name            = "tbChatInput";
            tbChatInput.ClientRectangle = new Rectangle(lbChatMessages.ClientRectangle.X,
                                                        btnNewGame.ClientRectangle.Y, lbChatMessages.ClientRectangle.Width,
                                                        btnNewGame.ClientRectangle.Height);
            tbChatInput.Enabled           = false;
            tbChatInput.MaximumTextLength = 200;
            tbChatInput.EnterPressed     += TbChatInput_EnterPressed;

            lblColor                 = new XNALabel(WindowManager);
            lblColor.Name            = "lblColor";
            lblColor.ClientRectangle = new Rectangle(lbChatMessages.ClientRectangle.X, 14, 0, 0);
            lblColor.FontIndex       = 1;
            lblColor.Text            = "YOUR COLOR:";

            ddColor                 = new XNAClientDropDown(WindowManager);
            ddColor.Name            = "ddColor";
            ddColor.ClientRectangle = new Rectangle(lblColor.ClientRectangle.X + 95, 12,
                                                    150, 21);

            chatColors = connectionManager.GetIRCColors();

            foreach (IRCColor color in connectionManager.GetIRCColors())
            {
                if (!color.Selectable)
                {
                    continue;
                }

                XNADropDownItem ddItem = new XNADropDownItem();
                ddItem.Text      = color.Name;
                ddItem.TextColor = color.XnaColor;
                ddItem.Tag       = color;

                ddColor.AddItem(ddItem);
            }

            int selectedColor = UserINISettings.Instance.ChatColor;

            ddColor.SelectedIndex = selectedColor >= ddColor.Items.Count || selectedColor < 0
                ? ClientConfiguration.Instance.DefaultPersonalChatColorIndex:
                                    selectedColor;
            SetChatColor();
            ddColor.SelectedIndexChanged += DdColor_SelectedIndexChanged;

            ddCurrentChannel                 = new XNAClientDropDown(WindowManager);
            ddCurrentChannel.Name            = "ddCurrentChannel";
            ddCurrentChannel.ClientRectangle = new Rectangle(
                lbChatMessages.ClientRectangle.Right - 200,
                ddColor.ClientRectangle.Y, 200, 21);
            ddCurrentChannel.SelectedIndexChanged += DdCurrentChannel_SelectedIndexChanged;
            ddCurrentChannel.AllowDropDown         = false;

            lblCurrentChannel                 = new XNALabel(WindowManager);
            lblCurrentChannel.Name            = "lblCurrentChannel";
            lblCurrentChannel.ClientRectangle = new Rectangle(
                ddCurrentChannel.ClientRectangle.X - 150,
                ddCurrentChannel.ClientRectangle.Y + 2, 0, 0);
            lblCurrentChannel.FontIndex = 1;
            lblCurrentChannel.Text      = "CURRENT CHANNEL:";

            InitializeGameList();

            AddChild(btnNewGame);
            AddChild(btnJoinGame);
            AddChild(btnLogout);

            AddChild(lbPlayerList);
            AddChild(lbChatMessages);
            AddChild(lbGameList);
            AddChild(tbChatInput);
            AddChild(lblColor);
            AddChild(ddColor);
            AddChild(lblCurrentChannel);
            AddChild(ddCurrentChannel);
            AddChild(playerContextMenu);

            base.Initialize();

            WindowManager.CenterControlOnScreen(this);

            PostUIInit();
        }
        public override void Initialize()
        {
            Name              = "PrivateMessagingWindow";
            ClientRectangle   = new Rectangle(0, 0, 600, 600);
            BackgroundTexture = AssetLoader.LoadTextureUncached("privatemessagebg.png");

            unknownGameIcon = AssetLoader.TextureFromImage(ClientCore.Properties.Resources.unknownicon);
            adminGameIcon   = AssetLoader.TextureFromImage(ClientCore.Properties.Resources.cncneticon);

            personalMessageColor  = AssetLoader.GetColorFromString(ClientConfiguration.Instance.SentPMColor);
            otherUserMessageColor = AssetLoader.GetColorFromString(ClientConfiguration.Instance.ReceivedPMColor);

            lblPrivateMessaging           = new XNALabel(WindowManager);
            lblPrivateMessaging.Name      = "lblPrivateMessaging";
            lblPrivateMessaging.FontIndex = 1;
            lblPrivateMessaging.Text      = "PRIVATE MESSAGING";

            AddChild(lblPrivateMessaging);
            lblPrivateMessaging.CenterOnParent();
            lblPrivateMessaging.ClientRectangle = new Rectangle(
                lblPrivateMessaging.ClientRectangle.X, 12,
                lblPrivateMessaging.ClientRectangle.Width,
                lblPrivateMessaging.ClientRectangle.Height);

            tabControl                 = new XNAClientTabControl(WindowManager);
            tabControl.Name            = "tabControl";
            tabControl.ClientRectangle = new Rectangle(60, 50, 0, 0);
            tabControl.SoundOnClick    = AssetLoader.LoadSound("button.wav");
            tabControl.FontIndex       = 1;
            tabControl.AddTab("Messages", 160);
            tabControl.AddTab("Friend List", 160);
            tabControl.AddTab("All Players", 160);
            tabControl.SelectedIndexChanged += TabControl_SelectedIndexChanged;

            lblPlayers                 = new XNALabel(WindowManager);
            lblPlayers.Name            = "lblPlayers";
            lblPlayers.ClientRectangle = new Rectangle(12, tabControl.ClientRectangle.Bottom + 24, 0, 0);
            lblPlayers.FontIndex       = 1;
            lblPlayers.Text            = "PLAYERS:";

            lbUserList                 = new XNAListBox(WindowManager);
            lbUserList.Name            = "lbUserList";
            lbUserList.ClientRectangle = new Rectangle(lblPlayers.ClientRectangle.X,
                                                       lblPlayers.ClientRectangle.Bottom + 6,
                                                       150, ClientRectangle.Height - lblPlayers.ClientRectangle.Bottom - 18);
            lbUserList.RightClick           += LbUserList_RightClick;
            lbUserList.SelectedIndexChanged += LbUserList_SelectedIndexChanged;
            lbUserList.BackgroundTexture     = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1);
            lbUserList.DrawMode              = PanelBackgroundImageDrawMode.STRETCHED;

            lblMessages                 = new XNALabel(WindowManager);
            lblMessages.Name            = "lblMessages";
            lblMessages.ClientRectangle = new Rectangle(lbUserList.ClientRectangle.Right + 12,
                                                        lblPlayers.ClientRectangle.Y, 0, 0);
            lblMessages.FontIndex = 1;
            lblMessages.Text      = "MESSAGES:";

            lbMessages                 = new ChatListBox(WindowManager);
            lbMessages.Name            = "lbMessages";
            lbMessages.ClientRectangle = new Rectangle(lblMessages.ClientRectangle.X,
                                                       lbUserList.ClientRectangle.Y,
                                                       ClientRectangle.Width - lblMessages.ClientRectangle.X - 12,
                                                       lbUserList.ClientRectangle.Height - 25);
            lbMessages.BackgroundTexture = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1);
            lbMessages.DrawMode          = PanelBackgroundImageDrawMode.STRETCHED;

            tbMessageInput                 = new XNATextBox(WindowManager);
            tbMessageInput.Name            = "tbMessageInput";
            tbMessageInput.ClientRectangle = new Rectangle(lbMessages.ClientRectangle.X,
                                                           lbMessages.ClientRectangle.Bottom + 6, lbMessages.ClientRectangle.Width, 19);
            tbMessageInput.EnterPressed     += TbMessageInput_EnterPressed;
            tbMessageInput.MaximumTextLength = 200;
            tbMessageInput.Enabled           = false;

            playerContextMenu                 = new PlayerContextMenu(WindowManager);
            playerContextMenu.Name            = "playerContextMenu";
            playerContextMenu.ClientRectangle = new Rectangle(0, 0, 150, 2);
            playerContextMenu.Enabled         = false;
            playerContextMenu.Visible         = false;
            playerContextMenu.AddItem("Add Friend");
            playerContextMenu.OptionSelected += PlayerContextMenu_OptionSelected;

            notificationBox         = new PrivateMessageNotificationBox(WindowManager);
            notificationBox.Enabled = false;
            notificationBox.Visible = false;

            AddChild(tabControl);
            AddChild(lblPlayers);
            AddChild(lbUserList);
            AddChild(lblMessages);
            AddChild(lbMessages);
            AddChild(tbMessageInput);
            AddChild(playerContextMenu);
            WindowManager.AddAndInitializeControl(notificationBox);

            base.Initialize();

            CenterOnParent();

            try
            {
                friendList = File.ReadAllLines(ProgramConstants.GamePath + FRIEND_LIST_PATH).ToList();
            }
            catch
            {
                Logger.Log("Loading friend list failed!");
                friendList = new List <string>();
            }

            tabControl.SelectedTab = 0;

            connectionManager.PrivateMessageReceived += ConnectionManager_PrivateMessageReceived;

            sndMessageSound = new EnhancedSoundEffect("message.wav");

            sndPrivateMessageSound = new EnhancedSoundEffect("pm.wav");

            sndMessageSound.Enabled = UserINISettings.Instance.MessageSound;

            GameProcessLogic.GameProcessExited += SharedUILogic_GameProcessExited;
        }
        public override void Initialize()
        {
            Name              = nameof(PrivateMessagingWindow);
            ClientRectangle   = new Rectangle(0, 0, 600, 600);
            BackgroundTexture = AssetLoader.LoadTextureUncached("privatemessagebg.png");

            unknownGameIcon = AssetLoader.TextureFromImage(ClientCore.Properties.Resources.unknownicon);
            adminGameIcon   = AssetLoader.TextureFromImage(ClientCore.Properties.Resources.cncneticon);

            personalMessageColor  = AssetLoader.GetColorFromString(ClientConfiguration.Instance.SentPMColor);
            otherUserMessageColor = AssetLoader.GetColorFromString(ClientConfiguration.Instance.ReceivedPMColor);

            lblPrivateMessaging           = new XNALabel(WindowManager);
            lblPrivateMessaging.Name      = nameof(lblPrivateMessaging);
            lblPrivateMessaging.FontIndex = 1;
            lblPrivateMessaging.Text      = "PRIVATE MESSAGING";

            AddChild(lblPrivateMessaging);
            lblPrivateMessaging.CenterOnParent();
            lblPrivateMessaging.ClientRectangle = new Rectangle(
                lblPrivateMessaging.X, 12,
                lblPrivateMessaging.Width,
                lblPrivateMessaging.Height);

            tabControl                 = new XNAClientTabControl(WindowManager);
            tabControl.Name            = nameof(tabControl);
            tabControl.ClientRectangle = new Rectangle(60, 50, 0, 0);
            tabControl.ClickSound      = new EnhancedSoundEffect("button.wav");
            tabControl.FontIndex       = 1;
            tabControl.AddTab("Messages", UIDesignConstants.BUTTON_WIDTH_160);
            tabControl.AddTab("Friend List", UIDesignConstants.BUTTON_WIDTH_160);
            tabControl.AddTab("All Players", UIDesignConstants.BUTTON_WIDTH_160);
            tabControl.SelectedIndexChanged += TabControl_SelectedIndexChanged;

            lblPlayers                 = new XNALabel(WindowManager);
            lblPlayers.Name            = nameof(lblPlayers);
            lblPlayers.ClientRectangle = new Rectangle(12, tabControl.Bottom + 24, 0, 0);
            lblPlayers.FontIndex       = 1;
            lblPlayers.Text            = "PLAYERS:";

            lbUserList                 = new XNAListBox(WindowManager);
            lbUserList.Name            = nameof(lbUserList);
            lbUserList.ClientRectangle = new Rectangle(lblPlayers.X,
                                                       lblPlayers.Bottom + 6,
                                                       150, Height - lblPlayers.Bottom - 18);
            lbUserList.RightClick             += LbUserList_RightClick;
            lbUserList.SelectedIndexChanged   += LbUserList_SelectedIndexChanged;
            lbUserList.BackgroundTexture       = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1);
            lbUserList.PanelBackgroundDrawMode = PanelBackgroundImageDrawMode.STRETCHED;

            lblMessages                 = new XNALabel(WindowManager);
            lblMessages.Name            = nameof(lblMessages);
            lblMessages.ClientRectangle = new Rectangle(lbUserList.Right + 12,
                                                        lblPlayers.Y, 0, 0);
            lblMessages.FontIndex = 1;
            lblMessages.Text      = "MESSAGES:";

            lbMessages                 = new ChatListBox(WindowManager);
            lbMessages.Name            = nameof(lbMessages);
            lbMessages.ClientRectangle = new Rectangle(lblMessages.X,
                                                       lbUserList.Y,
                                                       Width - lblMessages.X - 12,
                                                       lbUserList.Height - 25);
            lbMessages.BackgroundTexture       = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 1, 1);
            lbMessages.PanelBackgroundDrawMode = PanelBackgroundImageDrawMode.STRETCHED;

            tbMessageInput                 = new XNATextBox(WindowManager);
            tbMessageInput.Name            = nameof(tbMessageInput);
            tbMessageInput.ClientRectangle = new Rectangle(lbMessages.X,
                                                           lbMessages.Bottom + 6, lbMessages.Width, 19);
            tbMessageInput.EnterPressed     += TbMessageInput_EnterPressed;
            tbMessageInput.MaximumTextLength = 200;
            tbMessageInput.Enabled           = false;

            playerContextMenu            = new PlayerContextMenu(WindowManager, connectionManager, cncnetUserData, this);
            playerContextMenu.JoinEvent += PlayerContextMenu_JoinUser;

            notificationBox            = new PrivateMessageNotificationBox(WindowManager);
            notificationBox.Enabled    = false;
            notificationBox.Visible    = false;
            notificationBox.LeftClick += NotificationBox_LeftClick;

            AddChild(tabControl);
            AddChild(lblPlayers);
            AddChild(lbUserList);
            AddChild(lblMessages);
            AddChild(lbMessages);
            AddChild(tbMessageInput);
            AddChild(playerContextMenu);
            WindowManager.AddAndInitializeControl(notificationBox);

            base.Initialize();

            CenterOnParent();

            tabControl.SelectedTab = 0;

            privateMessageHandler.PrivateMessageReceived += PrivateMessageHandler_PrivateMessageReceived;
            connectionManager.UserAdded            += ConnectionManager_UserAdded;
            connectionManager.UserRemoved          += ConnectionManager_UserRemoved;
            connectionManager.UserGameIndexUpdated += ConnectionManager_UserGameIndexUpdated;

            sndMessageSound = new EnhancedSoundEffect("message.wav", 0.0, 0.0, ClientConfiguration.Instance.SoundMessageCooldown);

            sndPrivateMessageSound = new EnhancedSoundEffect("pm.wav", 0.0, 0.0, ClientConfiguration.Instance.SoundPrivateMessageCooldown);

            sndMessageSound.Enabled = UserINISettings.Instance.MessageSound;

            GameProcessLogic.GameProcessExited += SharedUILogic_GameProcessExited;
        }