/// <summary> /// Places the dragged ship onto the grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GridAIDragDrop(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Copy; ShipButton shipButton = (ShipButton)e.Data.GetData(DataFormats.Serializable); Ship selectedShip = SelectShip(shipButton.ShipSize); Point relativePoint = gridAI.PointToClient(new Point(e.X, e.Y)); int shipSize = selectedShip.Length; Coordinates coordinates = gridAI.GetCoordinatesFromMouse(relativePoint.X, relativePoint.Y); ShipOrientation direction = shiftKey_Down(e.KeyState) ? ShipOrientation.Horizontal : ShipOrientation.Vertical; int modX = direction == ShipOrientation.Horizontal ? 1 : 0; int modY = direction == ShipOrientation.Vertical ? 1 : 0; int count = 0; for (int x = coordinates.X; x <= coordinates.X + ((shipSize - 1) * modX); x++) { for (int y = coordinates.Y; y <= coordinates.Y + ((shipSize - 1) * modY); y++) { Coordinates coords = new Coordinates(x, y); gridAI.SetCellShip(coords, shipButton.ShipPiece, count++, direction); } } selectedShip.Place(coordinates, direction); shipButton.Visible = false; gridAI.CurrentHover = null; gridAI.Invalidate(); AttemptPlayMatch(); }
private void GridAIDrag(object sender, DragEventArgs e) { ShipButton shipButton = (ShipButton)e.Data.GetData(DataFormats.Serializable); int shipSize = shipButton.ShipSize; Point relativePoint = gridAI.PointToClient(new Point(e.X, e.Y)); Coordinates coordinates = gridAI.GetCoordinatesFromMouse(relativePoint.X, relativePoint.Y); ShipOrientation orientation = shiftKey_Down(e.KeyState) ? ShipOrientation.Horizontal : ShipOrientation.Vertical; int modX = orientation == ShipOrientation.Horizontal ? 1 : 0; int modY = orientation == ShipOrientation.Vertical ? 1 : 0; if (gridAI.CurrentHover == null) { gridAI.CurrentHover = new FieldHover(); gridAI.CurrentHover.HoverSize = shipSize; gridAI.CurrentHover.ShipPiece = shipButton.ShipPiece; } gridAI.CurrentHover.MouseX = relativePoint.X; gridAI.CurrentHover.MouseY = relativePoint.Y; gridAI.CurrentHover.Orientation = orientation; gridAI.CurrentHover.Coordinates = coordinates; if (ShipCanFit(coordinates, shipSize, modX, modY)) { e.Effect = DragDropEffects.Copy; gridAI.CurrentHover.HoverSize = shipSize; } else { e.Effect = DragDropEffects.None; gridAI.CurrentHover.HoverSize = 0; } gridAI.Invalidate(); }
public void OnBackButton() { gameObject.SetActive(true); bool showMessage = false; if (currentShip != null) { currentShip.CompressedGrid = shipManager.Compress(); foreach (var slot in currentShip.CompressedGrid) { if (slot != null && slot.Module == null) { showMessage = true; break; } } currentShip = null; } if (showMessage) { messageWindow.SetActive(true); } }
/// <summary> /// @Author Steven /// </summary> /// <param name="game"></param> /// <param name="title"></param> public LobbyMenu(Game1 game, String title) { this.game = game; game.mainScreen.Desktop.Children.Clear(); //Clear the gui lobbyTitle = title; /* White background for UI */ WhiteBackground = new Rectangle((int)game.mainScreen.Width / 2 - UIConstants.LOBBY_WHITE_BG.X, (int)game.mainScreen.Height / 2 - UIConstants.LOBBY_WHITE_BG.Y, UIConstants.LOBBY_WHITE_BG.Width, UIConstants.LOBBY_WHITE_BG.Height); /* Scrolling background */ /* Menu's Banner */ TexBanner = Game1.Assets.suMultiLobby; Banner = new Rectangle((int)game.mainScreen.Width / 2 - UIConstants.SU_BANNER.X, (int)game.mainScreen.Height / 2 - UIConstants.SU_BANNER.Y, UIConstants.SU_BANNER.Width, UIConstants.SU_BANNER.Height); /* For constructing the list of players with LabelControls */ playerLabelList = new List <LabelControl>(); playerLabelList.Add(player1Label = GuiHelper.CreateLabel("Empty", 0, 0, UIConstants.LOBBY_PLAYER_LABEL.Width, UIConstants.LOBBY_PLAYER_LABEL.Height)); playerLabelList.Add(player2Label = GuiHelper.CreateLabel("Empty", 0, 0, UIConstants.LOBBY_PLAYER_LABEL.Width, UIConstants.LOBBY_PLAYER_LABEL.Height)); playerLabelList.Add(player3Label = GuiHelper.CreateLabel("Empty", 0, 0, UIConstants.LOBBY_PLAYER_LABEL.Width, UIConstants.LOBBY_PLAYER_LABEL.Height)); playerLabelList.Add(player4Label = GuiHelper.CreateLabel("Empty", 0, 0, UIConstants.LOBBY_PLAYER_LABEL.Width, UIConstants.LOBBY_PLAYER_LABEL.Height)); playerLabelList.Add(player5Label = GuiHelper.CreateLabel("Empty", 0, 0, UIConstants.LOBBY_PLAYER_LABEL.Width, UIConstants.LOBBY_PLAYER_LABEL.Height)); playerLabelList.Add(player6Label = GuiHelper.CreateLabel("Empty", 0, 0, UIConstants.LOBBY_PLAYER_LABEL.Width, UIConstants.LOBBY_PLAYER_LABEL.Height)); /* List of names used to correlate to the labels */ playerNameList = new List <string>(); playerNameList.Add("Player 1"); playerNameList.Add("Player 2"); playerNameList.Add("Player 3"); playerNameList.Add("Player 4"); playerNameList.Add("Player 5"); playerNameList.Add("Player 6"); /* List of Ships */ shipSelectionList = new List <ShipButton>(); shipSelectionList.Add(new ShipButton(new UFO(game))); shipSelectionList.Add(new ShipButton(new Scout(game))); shipSelectionList.Add(new ShipButton(new Zoid(game))); /* List of choices for ships */ shipChoiceList = new List <ChoiceControl>(); shipChoiceList.Add(shipChoice_1 = GuiHelper.CreateChoice("", 0, 0, UIConstants.LOBBY_CHOICE_RADIO.Width, UIConstants.LOBBY_CHOICE_RADIO.Height)); shipChoiceList.Add(shipChoice_2 = GuiHelper.CreateChoice("", 0, 0, UIConstants.LOBBY_CHOICE_RADIO.Width, UIConstants.LOBBY_CHOICE_RADIO.Height)); shipChoiceList.Add(shipChoice_3 = GuiHelper.CreateChoice("", 0, 0, UIConstants.LOBBY_CHOICE_RADIO.Width, UIConstants.LOBBY_CHOICE_RADIO.Height)); /* Sets the default selected ship */ lastButton = shipSelectionList[0]; shipSelectionList[0].selected = true; shipChoiceList[0].Selected = true; setGridDisplay(game.getScreenWidth() - UIConstants.LOBBY_SHIP_GRID.X, game.getScreenHeight() - UIConstants.LOBBY_SHIP_GRID.Y); CreateMenuControls(game.mainScreen); Background = Game1.Assets.guiRectangle; new Thread(updatePlayerList).Start(); }
void Start() { foreach (var ship in ships) { ShipButton button = Instantiate(shipButtonPrefab, transform).GetComponent <ShipButton>(); button.SetUpButton(ship, OnShipOpen); } backButton.onClick.AddListener(OnBackButton); }
/// <summary> /// Sets the ship icon clicked on to be selected /// @Author Steven /// </summary> /// <param name="index"></param> private void selectShipIcon(int index) { foreach (ShipButton btn in shipSelectionList) { if (btn.selected == true) { lastButton = btn; } btn.selected = false; } shipSelectionList[index].selected = true; }
public void OnShipOpen(ShipButton shipButton) { shipManager.CreateShip(shipButton.Ship); if (shipButton.CompressedGrid != null) { shipManager.Decompress(shipButton.CompressedGrid); } currentShip = shipButton; categoriesManager.Reset(); gameObject.SetActive(false); }
// call this to activate the selected button public void ActivateButton() { // get the activated button (execute might change this so grab it now) var activatedButton = m_buttonList[m_selectedButtonIndex]; // execute the current button and check if it returned true if (activatedButton.Execute()) { // update the current button m_currentButton = activatedButton; // do the first update m_currentButton.Update(); } }
/// <summary> /// Update the screen /// </summary> /// Created by Matthew Baldock /// Edited by Steven Chen public void update() { MouseState mouseState = Mouse.GetState(); confirmButton.update(mouseState); for (int i = 0; i < shipSelectionArray.Length; i++) { shipSelectionArray[i].update(mouseState); } /* Allows for feedback of selecting a ship and sets the selected ship */ for (int i = 0; i < SHIPCOUNT; i++) { for (int j = 0; j < SHIPCOUNT; j++) { /* Due to how BaseButton works, at most 2 ships will be selected * which results in this logic to compensate for that fact */ if (shipSelectionArray[i].selected && shipSelectionArray[j].selected && i != j) { if (lastButton == shipSelectionArray[j]) { selectedShip = shipSelectionArray[i].getShip(); shipSelectionArray[j].selected = false; lastButton = shipSelectionArray[i]; } else { selectedShip = shipSelectionArray[j].getShip(); shipSelectionArray[i].selected = false; lastButton = shipSelectionArray[j]; } displaySelectedShip(selectedShip); } if (shipSelectionArray[i].hover()) { displayHoverShip(shipSelectionArray[i].getShip()); } } } if (confirmButton.isClicked == true) { game.EnterLoginMenu(); confirmButton.isClicked = false; } }
// Use this for initialization void Start() { int id = 0; GameController gc = FindObjectOfType <GameController>(); foreach (GameController.ShipList sl in gc.shipList) { GameObject g = Instantiate(prefab, contentviewer); ShipButton sb = g.GetComponent <ShipButton>(); sb.Init(sl.picture, sl.title, sl.cost); sb.id = id; id++; } }
/// <summary> /// Constructor for Ship Selection Screen /// </summary> /// Created by Matthew Baldock /// <param name="game"></param> public ShipSelectionScreen(Game1 game) { guiRectangle = Game1.Assets.guiRectangle; this.game = game; totalWidth = game.getScreenWidth(); totalHeight = game.getScreenHeight(); shipSelectWidth = totalWidth; shipSelectHeight = (int)(totalHeight * 0.70); shipDescWidth = (int)(totalWidth * 0.375); shipDescHeight = (int)(totalHeight * 0.3); shipSelectionArray = new ShipButton[SHIPCOUNT]; /* Actual ships used; commented out to test other functions */ shipSelectionArray[0] = new ShipButton(new UFO(game)); shipSelectionArray[1] = new ShipButton(new Scout(game)); shipSelectionArray[2] = new ShipButton(new Zoid(game)); shipSelectionArray[3] = new ShipButton(new Bug(game)); shipSelectionArray[4] = new ShipButton(new Lobstar(game)); shipSelectionArray[5] = new ShipButton(new Galactuship(game)); /* For Testing X amount of ships; Remove */ //for (int i = 0; i < SHIPCOUNT; i++) //{ // shipSelectionArray[i] = new ShipButton(Game1.Assets.ufo); //} confirmButton = new BaseButton(Game1.Assets.confirm) { height = 100, width = 200 }; setGridDisplay(shipSelectWidth, shipSelectHeight); shipDescDisplay(totalHeight - shipDescHeight, shipDescWidth, shipDescHeight); confirmButton.setPosition(new Vector2((int)(totalWidth * 0.75), (int)(shipSelectHeight + 100))); /* Sets the default selected ship */ selectedShip = shipSelectionArray[0].getShip(); displaySelectedShip(selectedShip); hoverShipTexture = selectedShip.texture; shipSelectionArray[0].selected = true; lastButton = shipSelectionArray[0]; }
/// <summary> /// @Author Steven /// </summary> /// <param name="gameTime"></param> public void Update(GameTime gameTime) { game.scroll.update(); MouseState mouseState = Mouse.GetState(); foreach (ShipButton btn in shipSelectionList) { btn.update(mouseState); } /* Allows for feedback of selecting a ship and sets the selected ship */ for (int i = 0; i < SHIPCOUNT; i++) { for (int j = 0; j < SHIPCOUNT; j++) { /* Due to how BaseButton works, at most 2 ships will be selected * which results in this logic to compensate for that fact */ if (shipSelectionList[i].selected && shipSelectionList[j].selected && i != j) { if (lastButton == shipSelectionList[j]) { //selectedShip = shipSelectionList[i].getShip(); selectship(i); shipSelectionList[j].selected = false; lastButton = shipSelectionList[i]; } else { selectship(j); //selectedShip = shipSelectionList[j].getShip(); shipSelectionList[i].selected = false; lastButton = shipSelectionList[j]; } //displaySelectedShip(selectedShip); } if (shipSelectionList[i].hover()) { //displayHoverShip(shipSelectionList[i].getShip()); } } } }
public void OnActivate() { // Store window window = Root.Singleton.Window; rctScreen = Util.ScreenRect(window.Size.X, window.Size.Y, 1.7778f); finishnow = false; window.KeyPressed += window_KeyPressed; // Create UI pnObscure = new Panel(); pnObscure.Colour = new Color(0, 0, 0, 192); Util.LayoutControl(pnObscure, 0, 0, 1280, 720, rctScreen); pnObscure.Parent = Root.Singleton.Canvas; pnObscure.Init(); pnWindow = new ImagePanel(); pnWindow.Image = Root.Singleton.Material("img/customizeUI/ship_list_main.png"); Util.LayoutControl(pnWindow, (1280 / 2) - (647 / 2), (720 / 2) - (465 / 2), 647, 465, rctScreen); pnWindow.Parent = Root.Singleton.Canvas; pnWindow.Init(); int shipX = 0; int shipY = 0; foreach (var gen in Root.Singleton.mgrState.Get <Library>().GetPlayerShipGenerators()) { var btnShip = new ShipButton(gen); Util.LayoutControl(btnShip, 24 + 205 * shipX, 52 + 135 * shipY, 191, 121, rctScreen); btnShip.Parent = pnWindow; btnShip.Init(); shipX++; if (shipX >= 3) { shipX = 0; shipY++; } } // Modal screen Root.Singleton.Canvas.ModalFocus = pnWindow; }
public void OnActivate() { // Store window window = Root.Singleton.Window; rctScreen = Util.ScreenRect(window.Size.X, window.Size.Y, 1.7778f); finishnow = false; window.KeyPressed += window_KeyPressed; // Create UI pnObscure = new Panel(); pnObscure.Colour = new Color(0, 0, 0, 192); Util.LayoutControl(pnObscure, 0, 0, 1280, 720, rctScreen); pnObscure.Parent = Root.Singleton.Canvas; pnObscure.Init(); pnWindow = new ImagePanel(); pnWindow.Image = Root.Singleton.Material("img/customizeUI/ship_list_main.png"); Util.LayoutControl(pnWindow, (1280 / 2) - (647 / 2), (720 / 2) - (465 / 2), 647, 465, rctScreen); pnWindow.Parent = Root.Singleton.Canvas; pnWindow.Init(); int shipX = 0; int shipY = 0; foreach (var gen in Root.Singleton.mgrState.Get<Library>().GetPlayerShipGenerators()) { var btnShip = new ShipButton(gen); Util.LayoutControl(btnShip, 24 + 205 * shipX, 52 + 135 * shipY, 191, 121, rctScreen); btnShip.Parent = pnWindow; btnShip.Init(); shipX++; if (shipX >= 3) { shipX = 0; shipY++; } } // Modal screen Root.Singleton.Canvas.ModalFocus = pnWindow; }
// call this to stop calling update on the current button public void ClearCurrentButton() { m_currentButton = null; }