package com.lucasdnd.ags.ui; import org.newdawn.slick.Color; import org.newdawn.slick.Font; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.Image; import org.newdawn.slick.SlickException; import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.util.FontUtils; /** * A List Section is a cell inside the List. It has a text to display and positions on the screen. * @author tulio * */ public class ListColumn extends UIComponent { protected int id; // The id of this column protected String text; // The text protected int textAlignment; // Text alignment. Refer to Alignment statics protected int dataType; // The content of this column: text, number or date? public static final int TEXT = 0; public static final int NUMBER = 1; public static final int DATE = 2; protected Image bulletsImage; // Game Quality protected int imageTopPadding; // Top Padding for the Image protected int imageLeftPadding; // Left Padding for the Image protected Button button; // Button protected boolean isAvailable; private Color lightGrayColor = new Color(0.998f, 0.998f, 0.998f); /** * Header Constructor. The reason for that is that we pass * the x, y, width and height only once. After that, the columns will check these values from the headers, * no need to pass every time. * @param text * @param xPos * @param yPos * @param width * @param height */ protected ListColumn(int id, String text, int textAlignment, float xPos, float yPos, float width, float height) { // Basic Attributes this.id = id; this.text = text; this.textAlignment = textAlignment; this.xPos = xPos; this.yPos = yPos; this.width = width; this.height = height; } /** * Body Constructor. This one is used for the columns of the List Row, because the x, y, width and height are already * known at that point -- the List Headers can be accessed when creating the columns. * @param id * @param text */ protected ListColumn(int id, String text, int textAlignment) { // Basic Attributes this.id = id; this.text = text; this.textAlignment = textAlignment; } /** * Image Body Constructor. This one for when we need to show an Image in the Column * @param id * @param bullets * @param imageLeftPadding * @param imageTopPadding */ protected ListColumn(int id, Image bullets, String text, int imageLeftPadding, int imageTopPadding) { // Basic Attributes this.id = id; this.bulletsImage = bullets; this.imageLeftPadding = imageLeftPadding; this.imageTopPadding = imageTopPadding; this.text = text; } /** * Button Body Constructor. THis one for when we need a Button * @param id * @param button */ protected ListColumn(int id, Button button, int buttonLeftPadding, int buttonTopPadding) { // Basic Attributes this.id = id; this.button = button; this.imageLeftPadding = buttonLeftPadding; this.imageTopPadding = buttonTopPadding; text = ""; } /** * Draws the Column text with an specific alignment * @param container * @param game * @param g * @param alignment * @throws SlickException */ public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException { if(button != null) { // Renders the Button amazingly button.render(container, game, g); } else if(bulletsImage != null) { // Renders the Image amazingly g.drawImage(bulletsImage, (int)this.xPos + imageLeftPadding, (int)this.yPos + imageTopPadding); } else { // Renders the Text amazingly if(isAvailable) { FontUtils.drawString(shadowFont, this.text, this.textAlignment, (int)this.xPos + 1, (int)this.yPos + 1 + 4, (int)this.width, lightGrayColor); FontUtils.drawString(panelFont, this.text, this.textAlignment, (int)this.xPos, (int)this.yPos + 4, (int)this.width, Color.black); } else { FontUtils.drawString(shadowFont, this.text, this.textAlignment, (int)this.xPos + 1, (int)this.yPos + 1 + 4, (int)this.width, lightGrayColor); FontUtils.drawString(disabledFont, this.text, this.textAlignment, (int)this.xPos, (int)this.yPos + 4, (int)this.width, Color.gray); } } } public boolean isAvailable() { return isAvailable; } public void setAvailable(boolean isAvailable) { this.isAvailable = isAvailable; } public String getText() { return text; } public void setText(String text) { this.text = text; } public int getId() { return id; } public void setId(int id) { this.id = id; } public int getImageTopPadding() { return imageTopPadding; } public void setImageTopPadding(int imageTopPadding) { this.imageTopPadding = imageTopPadding; } public int getImageLeftPadding() { return imageLeftPadding; } public void setImageLeftPadding(int imageLeftPadding) { this.imageLeftPadding = imageLeftPadding; } public int getDataType() { return dataType; } public void setDataType(int dataType) { this.dataType = dataType; } public Image getBulletsImage() { return bulletsImage; } public void setBulletsImage(Image bulletsImage) { this.bulletsImage = bulletsImage; } public int getTextAlignment() { return textAlignment; } public void setTextAlignment(int textAlignment) { this.textAlignment = textAlignment; } }