/// <summary> /// Initializes the screen /// </summary> /// <param id="sm">ScreenManager that handles this screen</param> public virtual void Initialize(ScreenManager sm) { TitleFont = UI.Instance.GetFont(TITLE_FONT_NAME); ControlFont = UI.Instance.GetFont(CONTROL_FONT_NAME); ButtonSkin = new GUISkin(UI.Instance.GetGuiTex(BUTTON_SKIN_NAME), ControlFont, BUTTON_TEXT_COLOR, false, true); LabelSkin = new GUISkin(UI.Instance.GetGuiTex(BUTTON_SKIN_NAME), ControlFont, UI_TEXT_COLOR, false, true); TextBoxSkin = new GUISkin(UI.Instance.GetGuiTex(TEXTBOX_SKIN_NAME), ControlFont, TEXTBOX_TEXT_COLOR, false, false); this.sm = sm; }
/// <summary> /// Initializes the screen, places the user controls /// </summary> /// <param id="sm">ScreenManager that handles this screen</param> public override void Initialize(ScreenManager sm) { cm = new ControlManager(); base.Initialize(sm); int idx = 0; int starty = 90; int startx = 30; int width = 200; int height = 48; cm.AddControl(new Button("multiplayer", new Vector2(startx, starty + height * idx++), new Vector2(width, height), "Start game [M]", ButtonSkin) { onLClickSubscriber = _ => sm.SwitchScreen("creategame") }); cm.AddControl(new Button("exit", new Vector2(startx, starty + height * idx++), new Vector2(width, height), "Exit [E]", ButtonSkin) { onLClickSubscriber = _ => UI.Instance.Exit() }); }
/// <summary> /// Initializes the screen, places the user controls /// </summary> /// <param id="sm">ScreenManager that handles this screen</param> public override void Initialize(ScreenManager sm) { cm = new ControlManager(); base.Initialize(sm); Vector2 clientBounds = UI.Instance.ScreenBounds; int clientWidth = (int)clientBounds.X; int clientHeight = (int)clientBounds.Y; int starty = 108; int startx = 143; int width = 200; int height = 48; int chatWidth = clientWidth - startx * 2; int chatHeight = clientHeight - 40 * 2 - starty - height; int tBoxHeight = 26; cm.AddControl(new Button("mainmenu", new Vector2(startx, starty + chatHeight + tBoxHeight + 4), new Vector2(width, height), "Main menu", ButtonSkin) { onLClickSubscriber = _ => { sm.CloseSubscreen(); sm.SwitchScreen("main"); } }); cm.AddControl(new Button("back", new Vector2(startx + chatWidth - width, starty + chatHeight + tBoxHeight + 4), new Vector2(width, height), "Back to game", ButtonSkin) { onLClickSubscriber = _ => sm.CloseSubscreen() }); cm.AddControl(new MultilineLabel("chatHistory", new Vector2(startx, starty), new Vector2(chatWidth, chatHeight), TextBoxSkin) { StringDataSource = Network.Messages }); cm.AddControl(new TextBox("chatTextBox", new Vector2(startx, starty + chatHeight), new Vector2(chatWidth, tBoxHeight), "", TextBoxSkin) { LoseFocusOnSubmit = false, callbackOnEnterSubscriber = SendMessage }); }
/// <summary> /// Initializes a new instance of the SharpDX.Toolkit.Game class. /// </summary> public GameWindow() { gdm = new GraphicsDeviceManager(this); sm = new ScreenManager(); }
/// <summary> /// Initializes the screen, places the user controls /// </summary> /// <param id="sm">ScreenManager that handles this screen</param> public override void Initialize(ScreenManager sm) { cm = new ControlManager(); base.Initialize(sm); currentClientGameState = GameState.NotConnected; int scrWidth = 1024; int scrheight = 480; int idx = 0; // ***** Menu int heightNormal = 48; int heightSmall = 24; int heightTotal = heightNormal + heightSmall; int mainMenuStartYNormal = 90;// 80; int mainMenuStartYSmall = 90 + heightNormal; int mainMenuStartX = 30;// 50; int buttonWidth = 200; int tBoxHeight = 26; cm.AddControl(new Button("startServer", new Vector2(mainMenuStartX, mainMenuStartYNormal + heightTotal * idx), new Vector2(buttonWidth, heightNormal), "Start server [S]", ButtonSkin) { onLClickSubscriber = StartServer }); cm.AddControl(new Button("stopServer", new Vector2(mainMenuStartX, mainMenuStartYSmall + heightTotal * idx++), new Vector2(buttonWidth, heightSmall), "Stop server", ButtonSkin) { onLClickSubscriber = StopServer, Enabled = false }); cm.AddControl(new TextBox("ipTextbox", new Vector2(mainMenuStartX, mainMenuStartYNormal + heightTotal * idx), new Vector2(buttonWidth, tBoxHeight), "127.0.0.1", TextBoxSkin) { LoseFocusOnSubmit = true, callbackOnEnterSubscriber = UpdateIp, Enabled = true }); cm.AddControl(new Button("joinServer", new Vector2(mainMenuStartX, mainMenuStartYNormal + heightTotal * idx + tBoxHeight), new Vector2(buttonWidth, heightNormal), "Join server [J]", ButtonSkin) { onLClickSubscriber = JoinServer }); cm.AddControl(new Button("disconnect", new Vector2(mainMenuStartX, mainMenuStartYSmall + heightTotal * idx++ + tBoxHeight), new Vector2(buttonWidth, heightSmall), "Disconnect", ButtonSkin) { onLClickSubscriber = Disconnect, Enabled = false }); cm.AddControl(new Button("exit", new Vector2(mainMenuStartX, mainMenuStartYNormal + heightTotal * idx + tBoxHeight), new Vector2(buttonWidth, heightNormal), "Exit", ButtonSkin) { onLClickSubscriber = _ => UI.Instance.Exit() }); // ***** Chat int chatStartX = 270; int chatStartY = 270; int borderSpacing = 20; int chatWidth = scrWidth - borderSpacing - chatStartX; int chatTextboxY = scrheight - tBoxHeight - borderSpacing; int chatHeight = chatTextboxY - chatStartX - 16; int labelHeight = 16; cm.AddControl(new Label("chatLabel", new Vector2(chatStartX, chatStartY), "Messages:", LabelSkin)); cm.AddControl(new MultilineLabel("chatHistory", new Vector2(chatStartX, chatStartY + labelHeight), new Vector2(chatWidth, chatHeight), TextBoxSkin) { StringDataSource = Network.Messages }); cm.AddControl(new TextBox("chatTextBox", new Vector2(chatStartX, chatTextboxY), new Vector2(chatWidth, tBoxHeight), "", TextBoxSkin) { LoseFocusOnSubmit = false, callbackOnEnterSubscriber = SendMessage, Enabled = false }); // ***** User list int userListStartX = chatStartX; int userListStartY = 80; int userListHeight = chatStartY - userListStartY - labelHeight; int userListWidth = 200; cm.AddControl(new Label("userListLabel", new Vector2(userListStartX, userListStartY), "List of users:", LabelSkin)); cm.AddControl(new MultilineLabel("userList", new Vector2(userListStartX, userListStartY + labelHeight), new Vector2(userListWidth, userListHeight), TextBoxSkin)); // ***** Properties int propStartX = userListStartX + userListWidth; int propStartY = userListStartY; int userNameWidth = userListWidth; int adjustButtonWidth = tBoxHeight; int adjustButtonHeight = tBoxHeight; int mapSizeTextboxWidth = userListWidth - 2 * adjustButtonWidth; cm.AddControl(new Label("userName", new Vector2(propStartX, propStartY), "Your nickname:", LabelSkin)); cm.AddControl(new TextBox("userNameTextBox", new Vector2(propStartX, propStartY + labelHeight), new Vector2(userListWidth, tBoxHeight), currentUserName, TextBoxSkin) { LoseFocusOnSubmit = true, callbackOnEnterSubscriber = ChangeNick, onFocusLostSubscriber = ChangeNickFail }); propStartY += labelHeight + tBoxHeight + 2; cm.AddControl(new Label("mapWidthLabel", new Vector2(propStartX, propStartY), "Map width:", LabelSkin)); cm.AddControl(new Button("mapWidthSmallerButton", new Vector2(propStartX, propStartY + labelHeight), new Vector2(adjustButtonWidth, adjustButtonHeight), "-", ButtonSkin) { Enabled = false, onLClickSubscriber = _ => ChangeWidth(-16) }); cm.AddControl(new TextBox("mapWidthTextBox", new Vector2(propStartX + adjustButtonWidth, propStartY + labelHeight), new Vector2(mapSizeTextboxWidth, tBoxHeight), "?", TextBoxSkin) { Enabled = false }); cm.AddControl(new Button("mapWidthLargerButton", new Vector2(propStartX + adjustButtonWidth + mapSizeTextboxWidth, propStartY + labelHeight), new Vector2(adjustButtonWidth, adjustButtonHeight), "+", ButtonSkin) { Enabled = false, onLClickSubscriber = _ => ChangeWidth(16) }); propStartY += labelHeight + tBoxHeight + 2; cm.AddControl(new Label("mapHeightLabel", new Vector2(propStartX, propStartY), "Map height:", LabelSkin)); cm.AddControl(new Button("mapHeightSmallerButton", new Vector2(propStartX, propStartY + labelHeight), new Vector2(adjustButtonWidth, adjustButtonHeight), "-", ButtonSkin) { Enabled = false, onLClickSubscriber = _ => ChangeHeight(-16) }); cm.AddControl(new TextBox("mapHeightTextBox", new Vector2(propStartX + adjustButtonWidth, propStartY + labelHeight), new Vector2(mapSizeTextboxWidth, tBoxHeight), "?", TextBoxSkin) { Enabled = false }); cm.AddControl(new Button("mapHeightLargerButton", new Vector2(propStartX + adjustButtonWidth + mapSizeTextboxWidth, propStartY + labelHeight), new Vector2(adjustButtonWidth, adjustButtonHeight), "+", ButtonSkin) { Enabled = false, onLClickSubscriber = _ => ChangeHeight(16) }); propStartY += labelHeight + tBoxHeight + 2; cm.AddControl(new Label("unitCapLabel", new Vector2(propStartX, propStartY), "Unit cap:", LabelSkin)); cm.AddControl(new Button("unitCapSmallerButton", new Vector2(propStartX, propStartY + labelHeight), new Vector2(adjustButtonWidth, adjustButtonHeight), "-", ButtonSkin) { Enabled = false, onLClickSubscriber = _ => ChangeUnitCap(-10) }); cm.AddControl(new TextBox("unitCapTextBox", new Vector2(propStartX + adjustButtonWidth, propStartY + labelHeight), new Vector2(mapSizeTextboxWidth, tBoxHeight), "?", TextBoxSkin) { Enabled = false }); cm.AddControl(new Button("unitCapLargerButton", new Vector2(propStartX + adjustButtonWidth + mapSizeTextboxWidth, propStartY + labelHeight), new Vector2(adjustButtonWidth, adjustButtonHeight), "+", ButtonSkin) { Enabled = false, onLClickSubscriber = _ => ChangeUnitCap(10) }); // ***** game control int controlStartX = scrWidth - borderSpacing - buttonWidth; int controlStartY = chatStartY - heightSmall; cm.AddControl(new Button("startGame", new Vector2(controlStartX, controlStartY), new Vector2(buttonWidth, heightSmall), "Start game [G]", ButtonSkin) { Enabled = false, onLClickSubscriber = StartGame }); }
/// <summary> /// Initializes the screen /// </summary> /// <param id="sm">ScreenManager that handles this screen</param> public override void Initialize(ScreenManager sm) { base.Initialize(sm); messageQueue = new Queue<string[]>(); }