package com.lucasdnd.ags.gameplay; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.Input; import org.newdawn.slick.SlickException; import org.newdawn.slick.state.StateBasedGame; import com.lucasdnd.ags.gameplay.market.MarketTable; import com.lucasdnd.ags.map.OffsetUtil; import com.lucasdnd.ags.system.GameSystem; import com.lucasdnd.ags.system.MainState; import com.lucasdnd.ags.ui.MiniPanel; import com.lucasdnd.ags.ui.TableMiniPanel; import com.lucasdnd.ags.ui.components.Clickable; public class Table extends Asset implements Clickable { private Console console; // The Console this Table has private Tv tv; // The tv this console is connected to private Chair chair1, chair2; // The Chairs public Table(int id, MarketTable marketTable) throws SlickException { // Super class Constructor super(id, marketTable); // Defines the size of the Consoles this.xSize = marketTable.getxSize(); this.ySize = marketTable.getySize(); // Create the Chairs chair1 = new Chair(); chair2 = new Chair(); // Create the MiniPanel with basic info float miniPanelHeight = MiniPanel.topBodyMargin + MiniPanel.lineSize*9; miniPanel = new TableMiniPanel(0f, 0f, 380f, miniPanelHeight, this); } /** * Adds a new Character as a player in this Table * @param character */ public void addCharacter(Customer character) { // Adds the User this.getUsers().add(character); // Adds it to the Chair if(chair1.getCharacter() == null) { chair1.setCharacter(character); } else if(chair2.getCharacter() == null) { chair2.setCharacter(character); } } /** * Removes a Character that was a player in this Table * @param character */ public void removeCharacter(Character character) { // Removes the User this.getUsers().remove(character); // Removes the Character from the Chair if(chair1.getCharacter() != null && chair1.getCharacter().equals(character)) { chair1.setCharacter(null); } else if(chair2.getCharacter() != null && chair2.getCharacter().equals(character)) { chair2.setCharacter(null); } } /** * Update */ public void update(GameContainer container, StateBasedGame game, int delta, Input input, boolean leftMouseClicked, boolean leftMouseDown, int mouseX, int mouseY, boolean isShiftDown, Business business, MainState mainState) throws SlickException { // Asset update (movement control) super.update(container, game, delta, input, leftMouseClicked, leftMouseDown, mouseX, mouseY, business, mainState); // Fix offset precision xSpriteOffset = OffsetUtil.getPreciseOffset(xSpriteOffset); ySpriteOffset = OffsetUtil.getPreciseOffset(ySpriteOffset); xOffset = OffsetUtil.getPreciseOffset(xOffset); yOffset = OffsetUtil.getPreciseOffset(yOffset); // Update Mini Panel ((TableMiniPanel)miniPanel).update(container, game, delta, mainState, business, leftMouseClicked, leftMouseDown, mouseX, mouseY, isShiftDown); // Update Tv and Console Positions if(tv != null) { // Pass basic position stuff tv.setBeingMoved(this.isBeingMoved); tv.setFacingDirection(this.facingDirection); // Update positions and shit if(facingDirection == Entity.DOWN_RIGHT) { tv.setxSpriteOffset(this.xSpriteOffset + 18f); tv.setySpriteOffset(this.ySpriteOffset - 8f); } else if(facingDirection == Entity.DOWN_LEFT) { tv.setxSpriteOffset(this.xSpriteOffset + 18f); tv.setySpriteOffset(this.ySpriteOffset - 4f); } else if(facingDirection == Entity.UP_LEFT) { tv.setxSpriteOffset(this.xSpriteOffset + 18f); tv.setySpriteOffset(this.ySpriteOffset - 8f); } else { //if(facingDirection == ENTITY.UP_RIGHT) { tv.setxSpriteOffset(this.xSpriteOffset + 12f); tv.setySpriteOffset(this.ySpriteOffset - 8f); } // Basic position stuff tv.setXPos(this.xPos); tv.setYPos(this.yPos); tv.setxOffset(this.xOffset); tv.setyOffset(this.yOffset); } if(console != null) { // Pass the Being Moved property to the Console console.setBeingMoved(this.isBeingMoved); console.setFacingDirection(this.facingDirection); // Update positions and shit if(facingDirection == Entity.DOWN_RIGHT) { console.setxSpriteOffset(this.xSpriteOffset + 4f); console.setySpriteOffset(this.ySpriteOffset + 4f); } else if(facingDirection == Entity.DOWN_LEFT) { console.setxSpriteOffset(this.xSpriteOffset + 9f); console.setySpriteOffset(this.ySpriteOffset - 2f); } else if(facingDirection == Entity.UP_LEFT) { console.setxSpriteOffset(this.xSpriteOffset + 4f); console.setySpriteOffset(this.ySpriteOffset + 4f); } else { //if(facingDirection == ENTITY.UP_RIGHT) { console.setxSpriteOffset(this.xSpriteOffset + 21f); console.setySpriteOffset(this.ySpriteOffset + 4f); } // Basic position stuff console.setXPos(this.xPos); console.setYPos(this.yPos); console.setxOffset(this.xOffset); console.setyOffset(this.yOffset); } // Set Chair Tiles (z position) if(facingDirection == Entity.DOWN_RIGHT) { chair1.setxTile(xTile + 2); chair1.setyTile(yTile); chair2.setxTile(xTile + 2); chair2.setyTile(yTile + 1); } else if (facingDirection == Entity.DOWN_LEFT) { chair1.setxTile(xTile); chair1.setyTile(yTile + 2); chair2.setxTile(xTile - 1); chair2.setyTile(yTile + 2); } else if (facingDirection == Entity.UP_LEFT) { chair1.setxTile(xTile - 2); chair1.setyTile(yTile); chair2.setxTile(xTile - 2); chair2.setyTile(yTile - 1); } else { //facingDirection == Entity.UP_RIGHT) { chair1.setxTile(xTile); chair1.setyTile(yTile - 2); chair2.setxTile(xTile + 1); chair2.setyTile(yTile - 2); } // Calculates the x and y positions of the Chairs if(facingDirection == Entity.DOWN_RIGHT) { if(isBeingMoved) { // x and y chair1.setX(xSpriteOffset + 42f + (float)container.getInput().getMouseX() / GameSystem.globalScale); chair1.setY(ySpriteOffset + 24f + (float)container.getInput().getMouseY() / GameSystem.globalScale); chair2.setX(xSpriteOffset + 57f + (float)container.getInput().getMouseX() / GameSystem.globalScale); chair2.setY(ySpriteOffset + 16f + (float)container.getInput().getMouseY() / GameSystem.globalScale); } else { // x and y chair1.setX(xSpriteOffset + xPos + xOffset + 42f); chair1.setY(ySpriteOffset + yPos + yOffset + 24f); chair2.setX(xSpriteOffset + xPos + xOffset + 58f); chair2.setY(ySpriteOffset + yPos + yOffset + 16f); } } else if(facingDirection == Entity.DOWN_LEFT) { if(isBeingMoved) { // x and y chair1.setX(xSpriteOffset - 8f + (float)container.getInput().getMouseX() / GameSystem.globalScale); chair1.setY(ySpriteOffset + 25f + (float)container.getInput().getMouseY() / GameSystem.globalScale); chair2.setX(xSpriteOffset - 24f + (float)container.getInput().getMouseX() / GameSystem.globalScale); chair2.setY(ySpriteOffset + 17f + (float)container.getInput().getMouseY() / GameSystem.globalScale); } else { // x and y chair1.setX(xSpriteOffset + xPos + xOffset - 8f); chair1.setY(ySpriteOffset + yPos + yOffset + 25f); chair2.setX(xSpriteOffset + xPos + xOffset - 24f); chair2.setY(ySpriteOffset + yPos + yOffset + 17f); } } else if(facingDirection == Entity.UP_LEFT) { if(isBeingMoved) { // x and y chair1.setX(xSpriteOffset - 8f + (float)container.getInput().getMouseX() / GameSystem.globalScale); chair1.setY(ySpriteOffset - 18f + (float)container.getInput().getMouseY() / GameSystem.globalScale); chair2.setX(xSpriteOffset - 24f + (float)container.getInput().getMouseX() / GameSystem.globalScale); chair2.setY(ySpriteOffset - 9f + (float)container.getInput().getMouseY() / GameSystem.globalScale); } else { // x and y chair1.setX(xSpriteOffset + xPos + xOffset - 8f); chair1.setY(ySpriteOffset + yPos + yOffset - 17f); chair2.setX(xSpriteOffset + xPos + xOffset - 24f); chair2.setY(ySpriteOffset + yPos + yOffset - 9f); } } else {//(facingDirection == Entity.UP_RIGHT) if(isBeingMoved) { // x and y chair1.setX(xSpriteOffset + 40f + (float)container.getInput().getMouseX() / GameSystem.globalScale); chair1.setY(ySpriteOffset - 18f + (float)container.getInput().getMouseY() / GameSystem.globalScale); chair2.setX(xSpriteOffset + 56f + (float)container.getInput().getMouseX() / GameSystem.globalScale); chair2.setY(ySpriteOffset - 10f + (float)container.getInput().getMouseY() / GameSystem.globalScale); } else { // x and y chair1.setX(xSpriteOffset + xPos + xOffset + 40f); chair1.setY(ySpriteOffset + yPos + yOffset - 18f); chair2.setX(xSpriteOffset + xPos + xOffset + 56f); chair2.setY(ySpriteOffset + yPos + yOffset - 10f); } } } @Override public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException { // Mini Panel rendering happens in the Main State to avoid scale problems // Chairs are rendered in the Main State for proper Z ordering // Basic rendering super.render(container, game, g); // Render Tv and Console if(facingDirection == Entity.DOWN_RIGHT) { if(tv != null) tv.render(container, game, g); if(console != null) console.render(container, game, g); } else if(facingDirection == Entity.DOWN_LEFT) { if(console != null) console.render(container, game, g); if(tv != null) tv.render(container, game, g); } else if(facingDirection == Entity.UP_LEFT) { if(tv != null) tv.render(container, game, g); if(console != null) console.render(container, game, g); } else { // UP_RIGHT if(tv != null) tv.render(container, game, g); if(console != null) console.render(container, game, g); } } public Tv getTv() { return tv; } public void setTv(Tv tv) { this.tv = tv; } public Console getConsole() { return console; } public void setConsole(Console console) { this.console = console; } public MiniPanel getMiniPanel() { return miniPanel; } public void setMiniPanel(MiniPanel miniPanel) { this.miniPanel = miniPanel; } public Chair getChair1() { return chair1; } public void setChair1(Chair chair1) { this.chair1 = chair1; } public Chair getChair2() { return chair2; } public void setChair2(Chair chair2) { this.chair2 = chair2; } }