Skip to content
Snippets Groups Projects
Commit 808126c3 authored by Trandinh Thien's avatar Trandinh Thien
Browse files

moved logic decisions outside of DrawUI

parent 7ce36fbf
No related branches found
No related tags found
No related merge requests found
......@@ -348,16 +348,28 @@ namespace Controller
if (!GameState.isAnimating)
{
drawUI.drawHighlightNodes(spriteBatch, graph, moveableNode, attackableNode);
drawUI.drawDropDownMenu(spriteBatch);
drawUI.drawInventoryMenu(spriteBatch, font);
if (GameState.dropDownMenuOpen) // if dropDowMenu should be opened, draw dropDownMenu
{
drawUI.drawDropDownMenu(spriteBatch);
}
if (GameState.inventoryOpen)
{
drawUI.drawInventoryMenu(spriteBatch, font);
}
}
}
#endregion
// redraws unit at game over to be darker
drawUI.drawUnitsAtGameOver(spriteBatch, player1, player2);
if (GameState.gameOver)
{
drawUI.drawUnitsAtGameOver(spriteBatch, player1, player2);
}
// draws end turn button
drawUI.drawEndTurnButton(spriteBatch, endTurnButton);
if (GameState.endTurnButton)
{
drawUI.drawEndTurnButton(spriteBatch, endTurnButton);
}
break;
}
spriteBatch.End(); // end spriteBatch
......@@ -371,8 +383,12 @@ namespace Controller
if (GameState.playableUnitSelected)
{
//draw attack confirm menu
drawUI.drawAttackConfirm(spriteBatch, font, largeFont, largestFont, player1, graph);
if (GameState.attackConfirmOpen && !GameState.isAnimating)
{
drawUI.drawAttackConfirm(spriteBatch, font, largeFont, largestFont, player1, graph);
}
//draw char info screen menu
drawUI.drawInfoScreen(spriteBatch, player1, font, largeFont);
Unit unit = GameState.selectedUnit;
......@@ -525,9 +541,15 @@ namespace Controller
}
}
//draw game over menu
drawUI.drawGameOverMenu(spriteBatch, gameOver, backGround, largestFont);
if (GameState.gameOver)
{
drawUI.drawGameOverMenu(spriteBatch, gameOver, backGround, largestFont);
}
//draw turn transition
drawUI.drawTurnTransition(spriteBatch, player1Transition, player2Transition, player1);
if (GameState.transitionTurn)
{
drawUI.drawTurnTransition(spriteBatch, player1Transition, player2Transition, player1);
}
spriteBatch.End();
#endregion
......
......@@ -42,79 +42,71 @@ namespace View
{
Unit unit = GameState.selectedUnit;
if (GameState.beforeMove && !GameState.attackSelect) // if unit has yet to move, display the overall move and attack range of unit
{
// Highlight movable nodes in blue
foreach (Node move in GameState.moveableNodes)
{
spriteBatch.Draw(moveableNode, move.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f);
}
{
// Highlight movable nodes in blue
foreach (Node move in GameState.moveableNodes)
{
spriteBatch.Draw(moveableNode, move.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f);
}
// Highlight attackable nodes in red
LinkedList<Node> attackableNodes = GameFunction.getAttackableNodes(graph, unit);
// Highlight attackable nodes in red
LinkedList<Node> attackableNodes = GameFunction.getAttackableNodes(graph, unit);
foreach (Node attack in attackableNodes)
{
if ((!GameState.moveableNodes.Contains(attack)) && (attack.unitOnNode != unit) && (!attack.isObstacle))
{
spriteBatch.Draw(attackableNode, attack.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f);
}
}
foreach (Node attack in attackableNodes)
{
if ((!GameState.moveableNodes.Contains(attack)) && (attack.unitOnNode != unit) && (!attack.isObstacle))
{
spriteBatch.Draw(attackableNode, attack.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f);
}
}
}
else // else if unit has already moved, only display the attack range
{
LinkedList<Node> attackableNodes = GameFunction.getAttackRangeAfterMoving(graph, unit);
foreach (Node attack in attackableNodes)
{
spriteBatch.Draw(attackableNode, attack.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f);
}
}
}
else // else if unit has already moved, only display the attack range
{
LinkedList<Node> attackableNodes = GameFunction.getAttackRangeAfterMoving(graph, unit);
foreach (Node attack in attackableNodes)
{
spriteBatch.Draw(attackableNode, attack.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f);
}
}
}
public static void drawDropDownMenu(SpriteBatch spriteBatch)
{
Unit unit = GameState.selectedUnit;
unit.setButtonCoordinates(unit.PixelCoordinates);
Button[] unitButtons = unit.getButtons();
for (int i = 0; i < 4; i++)
unit.setButtonCoordinates(unit.PixelCoordinates);
Button[] unitButtons = unit.getButtons();
for (int i = 0; i < 4; i++)
{
if (unitButtons[i].Active)
{
if (unitButtons[i].Active)
{
spriteBatch.Draw(unitButtons[i].getImage(), unitButtons[i].getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f);
}
spriteBatch.Draw(unitButtons[i].getImage(), unitButtons[i].getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f);
}
}
}
public static void drawInventoryMenu(SpriteBatch spriteBatch, SpriteFont font)
{
Unit unit = GameState.selectedUnit;
if (GameState.inventoryOpen)
{
unit.setButtonCoordinates(unit.PixelCoordinates); //update button positions
unit.setButtonCoordinates(unit.PixelCoordinates); //update button positions
Button[] unitButtons = unit.getButtons(); //for each inventory button
for (int i = 5; i < 9; i++)
Button[] unitButtons = unit.getButtons(); //for each inventory button
for (int i = 5; i < 9; i++)
{
if (unitButtons[i].Active) //if inventory menu buttons are active
{
if (unitButtons[i].Active) //if inventory menu buttons are active
if (unitButtons[i].hasItem) //if current menu button actually has an item stored in it
{
if (unitButtons[i].hasItem) //if current menu button actually has an item stored in it
{
spriteBatch.DrawString(font, unitButtons[i].weapon.name.ToString(), unitButtons[i].getPixelCoordinates() + (new Vector2(15, 5)), Color.Black, 0,
Vector2.Zero, 1f, SpriteEffects.None, 0f); //draws item stored in unitButtons[i]
spriteBatch.Draw(unitButtons[i].getImage(), unitButtons[i].getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.1f);
}
spriteBatch.DrawString(font, unitButtons[i].weapon.name.ToString(), unitButtons[i].getPixelCoordinates() + (new Vector2(15, 5)), Color.Black, 0,
Vector2.Zero, 1f, SpriteEffects.None, 0f); //draws item stored in unitButtons[i]
spriteBatch.Draw(unitButtons[i].getImage(), unitButtons[i].getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.1f);
}
}
}
}
public static void drawUnitsAtGameOver(SpriteBatch spriteBatch, Player player1, Player player2)
{
if (GameState.gameOver)
{
// draws faded units
#region Player 1 Units
......@@ -142,15 +134,14 @@ namespace View
}
}
#endregion
}
}
public static void drawEndTurnButton(SpriteBatch spriteBatch, Texture2D endTurnButton)
{
if (GameState.endTurnButton)
{
spriteBatch.Draw(endTurnButton, GameState.endTurnButtonLocation, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0);
}
}
private static bool findAttackType(Unit unit1)
......@@ -167,8 +158,7 @@ namespace View
public static void drawAttackConfirm(SpriteBatch spriteBatch, SpriteFont font, SpriteFont largeFont, SpriteFont largestFont, Player player1, Graph graph)
{
if (GameState.attackConfirmOpen && !GameState.isAnimating)
{
Unit unit = GameState.selectedUnit;
Unit attackedUnit = GameState.unitToAttack;
Button confirmButton = unit.getButtonType(ButtonType.AttackConfirm);
......@@ -233,7 +223,7 @@ namespace View
}
}
spriteBatch.Draw(confirmButton.getImage(), confirmButton.getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f);
}
}
public static void drawInfoScreen(SpriteBatch spriteBatch, Player player1, SpriteFont font, SpriteFont largeFont)
......@@ -293,20 +283,18 @@ namespace View
public static void drawGameOverMenu(SpriteBatch spriteBatch, Texture2D gameOver, Texture2D backGround, SpriteFont largestFont)
{
if (GameState.gameOver)
{
Vector2 gameOverLocation = new Vector2(-370, -300);
spriteBatch.DrawString(largestFont, "Game Over", new Vector2(350, 200), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f); //draws Game Over Text
spriteBatch.Draw(gameOver, Vector2.Zero, null, Color.White, 0, gameOverLocation, 1f, SpriteEffects.None, 0f);
spriteBatch.Draw(backGround, Vector2.Zero, null, Color.Black * 0.5f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f);
}
}
public static void drawTurnTransition(SpriteBatch spriteBatch, Texture2D player1Transition, Texture2D player2Transition, Player player1)
{
if (GameState.transitionTurn)
{
if (GameState.currentPlayer == player1)
{
spriteBatch.Draw(player1Transition, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw turn transition
......@@ -316,6 +304,6 @@ namespace View
spriteBatch.Draw(player2Transition, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw turn transition
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment