// Layout public void ToStandardLayout(TSLayout layout) { if (layout != null) { layout.BackgroundImage = LayoutBackgroundImage; } }
public void TestPositionOnScreenWhenAddToLayout() { TSLayout layout = new TSLayout(); layout.Position = new Vector2(1, 2); TSControlConcreteClass c = new TSControlConcreteClass(); layout.ControlManager.Add(c); Assert.AreEqual(c.PositionOnScreenX, 1); Assert.AreEqual(c.PositionOnScreenY, 2); }
public override void Initialize() { // pauseGameLayout _pauseGameLayout = new TSLayout(); _pauseGameLayout.Width = 200; _pauseGameLayout.Height = 150; _pauseGameLayout.ParentControlManager = this.ControlManager; _pauseGameLayout.MarginLeft = TSMarginType.CENTER; _pauseGameLayout.MarginTop = TSMarginType.CENTER; _pauseGameLayout.Visibled = false; _pauseGameLayout.Enabled = false; _btnContinueGame = new TSButton("Tiếp tục"); _btnContinueGame.Width = 150; _btnContinueGame.Height = 50; _btnContinueGame.MarginTop = 10; _btnContinueGame.MarginLeft = TSMarginType.CENTER; _btnContinueGame.MouseClick += btnContinueGame_MouseClick; _pauseGameLayout.Add(_btnContinueGame); _btnSaveAndExitGame = new TSButton("Lưu và thoát game"); _btnSaveAndExitGame.Width = 150; _btnSaveAndExitGame.Height = 50; _btnSaveAndExitGame.MarginTop = 70; _btnSaveAndExitGame.MarginLeft = TSMarginType.CENTER; _btnSaveAndExitGame.MouseClick += btnSaveAndExitGame_MouseClick; _pauseGameLayout.Add(_btnSaveAndExitGame); // gameEntities _gameEntities = new List <TSGameEntity>(); Random random = new Random(); int numEntities = 500;//random.Next(900, 2000); for (int idx = 0; idx < numEntities; idx++) { _gameEntities.Add(new Tree()); } // map _map = new TSMap(Width, Height); // mainWarrior mainWarrior = new SilverWarrior(); mainWarrior.Map = _map; base.Initialize(); }
public void ResetControl() { layout = new TSLayout(); control = new TSControlConcreteClass(); layout.ControlManager.Add(control); layout.Width = 800; layout.Height = 600; layout.Position = new Vector2(0, 0); control.MarginBottom = TSMarginType.NONE; control.MarginLeft = TSMarginType.NONE; control.MarginRight = TSMarginType.NONE; control.MarginTop = TSMarginType.NONE; control.Width = 100; control.Height = 20; control.Position = new Vector2(0, 0); }
public override void Initialize() { lblMessage = new TSLabel(); lblMessage.Width = 300; lblMessage.Height = 60; lblMessage.MarginLeft = 50; lblMessage.MarginTop = 80; lblMessage.TextColor = Color.White; this.Add(lblMessage); menuLayout = new TSLayout(); menuLayout.MarginLeft = TSMarginType.CENTER; //-200; menuLayout.MarginBottom = TSMarginType.CENTER; //= 0; menuLayout.Width = 180; menuLayout.Height = 230; this.Add(menuLayout); btnStartGame = new TSButton("Bắt đầu"); btnStartGame.Width = 180; btnStartGame.Height = 40; btnStartGame.MarginLeft = 0; btnStartGame.MarginTop = 0; btnStartGame.MouseClick += btnStartGame_Click; menuLayout.Add(btnStartGame); btnIntroduction = new TSButton("Giới thiệu"); btnIntroduction.Width = 180; btnIntroduction.Height = 40; btnIntroduction.MarginLeft = 0; btnIntroduction.MarginTop = 45; btnIntroduction.MouseClick += btnIntroduction_Click; menuLayout.Add(btnIntroduction); btnSettings = new TSButton("Cài đặt"); btnSettings.Width = 180; btnSettings.Height = 40; btnSettings.MarginLeft = 0; btnSettings.MarginTop = 90; btnSettings.MouseClick += btnSettings_Click; menuLayout.Add(btnSettings); btnAbout = new TSButton("Về trò chơi"); btnAbout.Width = 180; btnAbout.Height = 40; btnAbout.MarginLeft = 0; btnAbout.MarginTop = 135; btnAbout.MouseClick += btnAbout_Click; menuLayout.Add(btnAbout); btnExitGame = new TSButton("Thoát"); btnExitGame.Width = 180; btnExitGame.Height = 40; btnExitGame.MarginLeft = 0; btnExitGame.MarginTop = 180; btnExitGame.MouseClick += btnExitGame_Click; menuLayout.Add(btnExitGame); }
protected void UpdateMouseEvent(GameTime gameTime) { TSControl mouseHoverControl = null; if (Enabled == false) { return; } mouseHoverControl = FindMouseHoverControl(); if (mouseHoverControl == null) { if (lastMouseHoverControl != null) { lastMouseHoverControl.OnMouseLeave(null); if (lastMouseHoverControl is TSLayout) { TSLayout mouseHoverLayout = ((TSLayout)lastMouseHoverControl); mouseHoverLayout.ControlManager.Enabled = true; mouseHoverLayout.ControlManager.Update(gameTime); mouseHoverLayout.ControlManager.Enabled = false; } lastMouseHoverControl = null; } } // truyền quyền Update cho layout con if ((mouseHoverControl != null) && (mouseHoverControl is TSLayout)) { TSLayout mouseHoverLayout = ((TSLayout)mouseHoverControl); mouseHoverLayout.ControlManager.Enabled = true; mouseHoverLayout.ControlManager.Update(gameTime); mouseHoverLayout.ControlManager.Enabled = false; lastMouseHoverControl = mouseHoverControl; } // Kiểm tra sự kiện di chuyển của chuột if ((mouseHoverControl != null) && (mouseHoverControl != lastMouseHoverControl)) { mouseHoverControl.OnMouseEnter(null); } if ((lastMouseHoverControl != null) && (mouseHoverControl != lastMouseHoverControl)) { lastMouseHoverControl.OnMouseLeave(null); } if ((mouseHoverControl != null) && (lastMouseHoverControl != null) && (lastMouseHoverControl == mouseHoverControl)) { mouseHoverControl.OnMouseMove(null); } lastMouseHoverControl = mouseHoverControl; // Kiểm tra sự kiện nhấn của chuột if (TSInputHandler.MouseState.LeftButton == ButtonState.Released) { if (lastMousePressControl != null) { lastMousePressControl.OnMouseUp(null); lastMousePressControl = null; return; } } if (mouseHoverControl == null) { return; } if (TSInputHandler.LastMouseState.LeftButton == ButtonState.Pressed) { if (mouseHoverControl == lastMousePressControl) { mouseHoverControl.OnMouseDown(null); } else { mouseHoverControl.OnMouseClick(null); lastMousePressControl = mouseHoverControl; if ((focusingControl != null) && (focusingControl == mouseHoverControl)) { return; } if (focusingControl != null) { focusingControl.OnFocusLeave(null); } focusingControl = mouseHoverControl; focusingControl.OnFocusEnter(null); } } }