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

Units can now change weapons by clicking on different weapons from item drop down menu

parent c8aaf63d
No related branches found
No related tags found
No related merge requests found
......@@ -344,7 +344,7 @@ namespace Model
Returns the button type
* @param buttonType The button to return (Move, Attack, Item, Wait, and attack confirm)
*/
public Button getButtonOfType(ButtonType buttonType)
public Button getButtonType(ButtonType buttonType)
{
switch (buttonType)
{
......
......@@ -5,6 +5,7 @@ using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Model;
using System.Diagnostics;
namespace View
{
......@@ -33,14 +34,8 @@ namespace View
set
{
weapons = value;
if(value== null)
{
hasItem = false;// set item to false if null
}
else
{
hasItem = true;// set item to true if weapon is added
}
hasItem = true;
Debug.WriteLine(hasItem);
}
}
......@@ -58,11 +53,6 @@ namespace View
Active = true;
}
public void addItem(Weapon weapon)
{
}
/**
Returns the pixel coordinate of the button
*/
......
......@@ -365,7 +365,7 @@ namespace Controller
}
#region Attack menu
Button confirmButton = unit.getButtonOfType(ButtonType.AttackConfirm);
Button confirmButton = unit.getButtonType(ButtonType.AttackConfirm);
Vector2 attackInfoLocation2 = new Vector2(519, 0);
if (GameState.attackConfirmOpen)
......@@ -430,6 +430,26 @@ namespace Controller
}
#endregion
#endregion
//Inventory Drop down menu - if item is clicked
if (GameState.inventoryOpen)
{
unit.setButtonCoordinates(unit.PixelCoordinates); //update button positions
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].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);
}
}
}
}
}
#region Character Info Screen player1
......@@ -568,7 +588,10 @@ namespace Controller
{
Unit unit = new Warrior(Content.Load<Texture2D>("warrior"),unitButtons, Content.Load<Texture2D>("warrior_stats"), Content.Load<Texture2D>("warrior_attack"), unitPosition);
Weapon startingWeap = new BronzeSword();
Weapon startingWeap2 = new BronzeBow();
unit.equippedWeapon = startingWeap;
unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap;
unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2;
graph.getNode(unitPosition).unitOnNode = (unit);
return unit;
}
......@@ -577,7 +600,10 @@ namespace Controller
{
Unit unit = new Mage(Content.Load<Texture2D>("mage"),unitButtons, Content.Load<Texture2D>("mage_stats"), Content.Load<Texture2D>("mage_attack"), unitPosition);
Weapon startingWeap = new Fireball();
Weapon startingWeap2 = new BronzeBow();
unit.equippedWeapon = startingWeap;
unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap;
unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2;
graph.getNode(unitPosition).unitOnNode = (unit);
return unit;
}
......@@ -586,7 +612,10 @@ namespace Controller
{
Unit unit = new Archer(Content.Load<Texture2D>("archer"), unitButtons, Content.Load<Texture2D>("archer_stats"), Content.Load<Texture2D>("archer_attack"), unitPosition);
Weapon startingWeap = new BronzeBow();
Weapon startingWeap2 = new BronzeSword();
unit.equippedWeapon = startingWeap;
unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap;
unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2;
graph.getNode(unitPosition).unitOnNode = (unit);
return unit;
}
......@@ -599,7 +628,10 @@ namespace Controller
{
Unit unit = new Warrior(Content.Load<Texture2D>("2warrior"), unitButtons, Content.Load<Texture2D>("2warrior_stats"), Content.Load<Texture2D>("2warrior_attack"), unitPosition);
Weapon startingWeap = new BronzeSword();
Weapon startingWeap2 = new BronzeBow();
unit.equippedWeapon = startingWeap;
unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap;
unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2;
graph.getNode(unitPosition).unitOnNode = (unit);
return unit;
}
......@@ -608,7 +640,10 @@ namespace Controller
{
Unit unit = new Mage(Content.Load<Texture2D>("2mage"), unitButtons, Content.Load<Texture2D>("2mage_stats"), Content.Load<Texture2D>("2mage_attack"), unitPosition);
Weapon startingWeap = new Fireball();
Weapon startingWeap2 = new BronzeBow();
unit.equippedWeapon = startingWeap;
unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap;
unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2;
graph.getNode(unitPosition).unitOnNode = (unit);
return unit;
}
......@@ -617,7 +652,10 @@ namespace Controller
{
Unit unit = new Archer(Content.Load<Texture2D>("2archer"),unitButtons, Content.Load<Texture2D>("2archer_stats"), Content.Load<Texture2D>("2archer_attack"), unitPosition);
Weapon startingWeap = new BronzeBow();
Weapon startingWeap2 = new BronzeBow();
unit.equippedWeapon = startingWeap;
unit.getButtonType(ButtonType.Inventory1).weapon = startingWeap;
unit.getButtonType(ButtonType.Inventory2).weapon = startingWeap2;
graph.getNode(unitPosition).unitOnNode = (unit);
return unit;
}
......
......@@ -344,7 +344,7 @@ namespace Model
Returns the button type
* @param buttonType The button to return (Move, Attack, Item, Wait, and attack confirm)
*/
public Button getButtonOfType(ButtonType buttonType)
public Button getButtonType(ButtonType buttonType)
{
switch (buttonType)
{
......
......@@ -99,7 +99,7 @@ namespace Controller
// if path finder returns a non-null path, then end node is valid
if (path != null)
{
GameState.selectedUnit.getButtonOfType(ButtonType.Move).Active = false; // move button no longer active
GameState.selectedUnit.getButtonType(ButtonType.Move).Active = false; // move button no longer active
updateUnitPosition(graph, mouseClickCoordinates, path);
GameState.beforeMove = false;
turnState = TurnState.Wait;
......@@ -133,7 +133,7 @@ namespace Controller
setSelectedUnit(unit, true);
GameFunction.setMovableNodes(graph, unit);
GameState.dropDownMenuOpen = true;
if (unit.getButtonOfType(ButtonType.Move).Active)
if (unit.getButtonType(ButtonType.Move).Active)
{
GameState.beforeMove = true;
}
......@@ -346,13 +346,13 @@ namespace Controller
}
}
int ButtonX = (int)unit.getButtonOfType(ButtonType.AttackConfirm).getPixelCoordinates().X;
int ButtonY = (int)unit.getButtonOfType(ButtonType.AttackConfirm).getPixelCoordinates().Y;
int ButtonX = (int)unit.getButtonType(ButtonType.AttackConfirm).getPixelCoordinates().X;
int ButtonY = (int)unit.getButtonType(ButtonType.AttackConfirm).getPixelCoordinates().Y;
if (ButtonX+90 <= clickX && clickX < ButtonX + 214 && ButtonY+127 <= clickY && clickY < ButtonY + 172)
{
if (GameState.attackConfirmOpen)
{
return unit.getButtonOfType(ButtonType.AttackConfirm);
return unit.getButtonType(ButtonType.AttackConfirm);
}
}
return null;
......@@ -384,8 +384,8 @@ namespace Controller
break;
case ButtonType.AttackConfirm: // if confirm attack clicked
button.Active = false;
unit.getButtonOfType(ButtonType.Move).Active = false; // move button is no longer active
unit.getButtonOfType(ButtonType.Attack).Active = false; // attack button is no longer active
unit.getButtonType(ButtonType.Move).Active = false; // move button is no longer active
unit.getButtonType(ButtonType.Attack).Active = false; // attack button is no longer active
int attackDirection = 0;
int counterAttackDirection = 0;
//Gets attack anaimation direction
......@@ -460,7 +460,7 @@ namespace Controller
break;
case ButtonType.Items: // if item is clicked
turnState = TurnState.Items;
GameState.dropDownMenuOpen = false;
GameState.inventoryOpen = true;
break;
case ButtonType.Wait: // if wait is clicked
turnState = TurnState.Wait;
......@@ -468,6 +468,22 @@ namespace Controller
setSelectedUnit(null, false);
button.Active = false;
break;
case ButtonType.Inventory1:
GameState.inventoryOpen = false;
unit.equippedWeapon = button.weapon;
break;
case ButtonType.Inventory2:
GameState.inventoryOpen = false;
unit.equippedWeapon = button.weapon;
break;
case ButtonType.Inventory3:
GameState.inventoryOpen = false;
unit.equippedWeapon = button.weapon;
break;
case ButtonType.Inventory4:
GameState.inventoryOpen = false;
unit.equippedWeapon = button.weapon;
break;
default:
break;
......
......@@ -146,7 +146,7 @@ namespace Model
Returns the button type
* @param buttonType The button to return (Move, Attack, Item, Wait, and attack confirm)
*/
Button getButtonOfType(ButtonType buttonType);
Button getButtonType(ButtonType buttonType);
/**
returns the current sprite frame in animation sequence
......
......@@ -345,7 +345,7 @@ namespace Model
Returns the button type
* @param buttonType The button to return (Move, Attack, Item, Wait, and attack confirm)
*/
public Button getButtonOfType(ButtonType buttonType)
public Button getButtonType(ButtonType buttonType)
{
switch (buttonType)
{
......@@ -392,7 +392,7 @@ namespace Model
buttons[4].setPixelCoordinates(330, 120);
for (int i = 5; i < 9; i++)
{
buttons[i].setPixelCoordinates((int)(pixelCoordinates.X + 150), (int)(pixelCoordinates.Y + (i - 1 * 32)));
buttons[i].setPixelCoordinates((int)(pixelCoordinates.X + 160), (int)(pixelCoordinates.Y + (i * 32-96)));
}
}
......
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