Added ui to the engine and buttons and implemented them in the game fixed also a mouse position problem
This commit is contained in:
parent
515281351c
commit
728a68cc48
35 changed files with 436 additions and 23 deletions
|
|
@ -10,6 +10,7 @@ import ei.engine.math.Vector4f;
|
|||
import ei.engine.scene.Box;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.texture.Texture;
|
||||
import ei.game.hud.InGameHud;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.Map;
|
||||
|
||||
|
|
@ -22,6 +23,7 @@ public class InGameMouseInput extends MouseInput{
|
|||
private Vector2f leftKlickPos;
|
||||
private Box markingBox;
|
||||
|
||||
private InGameHud hud;
|
||||
private Map map;
|
||||
|
||||
public InGameMouseInput(Map map) {
|
||||
|
|
@ -40,6 +42,7 @@ public class InGameMouseInput extends MouseInput{
|
|||
|
||||
@Override
|
||||
public void mouseUpdate(int x, int y, int w) {
|
||||
if(hud != null)hud.getBuildHud().getUi().mousePos(x, y);
|
||||
removeDead();
|
||||
|
||||
// mov cam to the left
|
||||
|
|
@ -55,15 +58,21 @@ public class InGameMouseInput extends MouseInput{
|
|||
LWJGLGameWindow.getCamera().getLocation().add(0,-CAMERA_MOVE_SPEED,0);
|
||||
}
|
||||
// mov cam down
|
||||
if(y > LWJGLGameWindow.getHeight()-CAMERA_MOVE_BORDER){
|
||||
if(y > LWJGLGameWindow.getHeight()-10){
|
||||
LWJGLGameWindow.getCamera().getLocation().add(0,CAMERA_MOVE_SPEED,0);
|
||||
}
|
||||
|
||||
Vector2i pos = Map.getPosByPixel(
|
||||
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y);
|
||||
LWJGLGameWindow.getCamera().getLocation().getX()+x+Map.POS_SIZE/2,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y+Map.POS_SIZE/2);
|
||||
|
||||
if(map.posExist(pos.getX(), pos.getY())){
|
||||
//checks if the mous is on the buildbar
|
||||
if(x >= (LWJGLGameWindow.getWidth()/2)-hud.getBuildBar().getSize().getX()/2 &&
|
||||
x <= (LWJGLGameWindow.getWidth()/2)+hud.getBuildBar().getSize().getX()/2 &&
|
||||
y >= LWJGLGameWindow.getHeight()-hud.getBuildBar().getSize().getY() &&
|
||||
y <= LWJGLGameWindow.getHeight()){}
|
||||
// checks wich position the mouse is on top of
|
||||
else if(map.posExist(pos.getX(), pos.getY())){
|
||||
// The marking box is sized and positioned
|
||||
if(leftKlickPos != null){
|
||||
float markingSizeX = 0;
|
||||
|
|
@ -83,7 +92,7 @@ public class InGameMouseInput extends MouseInput{
|
|||
markingSizeY = -Math.abs(leftKlickPos.getY()-(LWJGLGameWindow.getCamera().getLocation().getY()+y));
|
||||
}
|
||||
|
||||
markingBox.setSize(new Vector2f(markingSizeX+getSprite().getSize().getX()/2,markingSizeY+getSprite().getSize().getY()/2));
|
||||
markingBox.setSize(new Vector2f(markingSizeX,markingSizeY));
|
||||
markingBox.setLocation(new Vector2f(
|
||||
leftKlickPos.getX()-markingBox.getSize().getX()/2,
|
||||
leftKlickPos.getY()-markingBox.getSize().getY()/2));
|
||||
|
|
@ -109,11 +118,17 @@ public class InGameMouseInput extends MouseInput{
|
|||
@Override
|
||||
public void mouseDown(int event,int x, int y) {
|
||||
Vector2i pos = Map.getPosByPixel(
|
||||
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y);
|
||||
LWJGLGameWindow.getCamera().getLocation().getX()+x+Map.POS_SIZE/2,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y+Map.POS_SIZE/2);
|
||||
removeDead();
|
||||
//map.printAllUnits();
|
||||
if(map.posExist(pos.getX(), pos.getY())){
|
||||
//checks if the mous is on the buildbar
|
||||
if(x >= (LWJGLGameWindow.getWidth()/2)-hud.getBuildBar().getSize().getX()/2 &&
|
||||
x <= (LWJGLGameWindow.getWidth()/2)+hud.getBuildBar().getSize().getX()/2 &&
|
||||
y >= LWJGLGameWindow.getHeight()-hud.getBuildBar().getSize().getY() &&
|
||||
y <= LWJGLGameWindow.getHeight()){}
|
||||
// checks wich position the mouse presed
|
||||
else if(map.posExist(pos.getX(), pos.getY())){
|
||||
//selecting unit.
|
||||
if(event==LEFT_MOUSE_BUTTON){
|
||||
if(leftKlickPos == null){
|
||||
|
|
@ -159,13 +174,14 @@ public class InGameMouseInput extends MouseInput{
|
|||
@Override
|
||||
public void mouseUp(int event,int x, int y) {
|
||||
Vector2i pos = Map.getPosByPixel(
|
||||
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y);
|
||||
LWJGLGameWindow.getCamera().getLocation().getX()+x+Map.POS_SIZE/2,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y+Map.POS_SIZE/2);
|
||||
if(hud != null)hud.getBuildHud().getUi().mouseDown(x, y, event);
|
||||
removeDead();
|
||||
if(map.posExist(pos.getX(), pos.getY())){
|
||||
if(leftKlickPos != null){
|
||||
deselectAllUnits();
|
||||
selectUnits(Map.getPosByPixel(leftKlickPos.getX(), leftKlickPos.getY()),pos);
|
||||
selectUnits(Map.getPosByPixel((leftKlickPos.getX()+Map.POS_SIZE/2), (leftKlickPos.getY())+Map.POS_SIZE/2),pos);
|
||||
leftKlickPos = null;
|
||||
getNode().remove(markingBox);
|
||||
}
|
||||
|
|
@ -207,5 +223,9 @@ public class InGameMouseInput extends MouseInput{
|
|||
}
|
||||
selected.clear();
|
||||
}
|
||||
|
||||
public void setHud(InGameHud u){
|
||||
hud = u;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue