package com.lucasdnd.ags.ui; import org.newdawn.slick.Font; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.SlickException; import org.newdawn.slick.state.StateBasedGame; import com.lucasdnd.ags.gameplay.Business; import com.lucasdnd.ags.gameplay.Misc; import com.lucasdnd.ags.system.GameSystem; import com.lucasdnd.ags.system.MainState; import com.lucasdnd.ags.system.ResourceLoader; public class MiscMiniPanel extends MiniPanel { // Shelf private Misc misc; // Buttons private Button moveMiscButton; private Button sellMiscButton; public MiscMiniPanel(float xPos, float yPos, float width, float height, Misc misc) throws SlickException { super(misc.getReferringMarketAsset().getName(), xPos, yPos, width, height); // The Misc! this.misc = misc; // The Buttons! moveMiscButton = new Button(ResourceLoader.getInstance().moveButtonImages, xPos, yPos); sellMiscButton = new Button(ResourceLoader.getInstance().sellButtonImages, xPos, yPos); } /** * Update! */ public void update(GameContainer container, StateBasedGame game, int delta, MainState mainState, Business business, boolean leftMouseClicked, boolean leftMouseDown, int mouseX, int mouseY) throws SlickException { // Only if visible! if(visible) { // Super Class Update super.update(container, game, delta, business, leftMouseClicked, mouseX, mouseY); // Fix Button Positions, check for Mouse Overs moveMiscButton.setxPos(xPos + width - moveMiscButton.getWidth()); moveMiscButton.setyPos(yPos + 1f); moveMiscButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); sellMiscButton.setxPos(xPos + leftMargin); sellMiscButton.setyPos(yPos + topBodyMargin); sellMiscButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); // If this Shelf can move, it can be moved or deleted. Same for its Shelf and Console if(misc.canMove()) { // Move Shelf if(moveMiscButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Set the Moving Asset mainState.setSelectedEntity(misc); mainState.setPlacingAsset(misc); mainState.getPlacingAsset().setBeingMoved(true); // Hide the Panel this.visible = false; // Enter Moving Asset Mode mainState.setCurrentMode(MainState.MOVING_ASSET); // Unblock the Tiles it currently occupies (so we can freely move it into tiles it already blocks) business.getStore().getMap().removeObject(misc); } // Sell Table if(sellMiscButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Remove Characters from this Asset business.getStore().removeCharacterReferences(misc); // Remove the Table from the Map business.getStore().getMap().removeObject(misc); // Return 40% of the money to the Player business.makeBusiness((int)(misc.getReferringMarketAsset().getPrice() * 0.4), Business.DISPOSING, true); // Flag the Table to be removed in the next Update cycle misc.setCanBeDisposed(true); // Enter Mode 0 mainState.setCurrentMode(MainState.SELECTION_MODE); } } } } /** * Render! */ @Override public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException { // Only if visible! if(visible) { // Super Class Render super.render(container, game, g, panelFont, shadowFont); // Misc label shadowFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + 1f, misc.getReferringMarketAsset().getName()); panelFont.drawString(xPos + leftMargin, yPos + topHeaderMargin, misc.getReferringMarketAsset().getName()); // Render Buttons! moveMiscButton.render(container, game, g); sellMiscButton.render(container, game, g); shadowFont.drawString(sellMiscButton.getxPos() + sellMiscButton.getWidth() + leftMargin + 1f, sellMiscButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(misc.getReferringMarketAsset().getPrice() * 0.4), false)); panelFont.drawString(sellMiscButton.getxPos() + sellMiscButton.getWidth() + leftMargin, sellMiscButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(misc.getReferringMarketAsset().getPrice() * 0.4), false)); } } }