Thread: Object Oriented Hardcoding Interfaces

Results 1 to 10 of 10
  1. #1 Object Oriented Hardcoding Interfaces 
    Community Veteran

    Dexter Morgan's Avatar
    Join Date
    Nov 2008
    Age
    28
    Posts
    4,419
    Thanks given
    1,184
    Thanks received
    757
    Rep Power
    3098
    This was made for something but is no longer going to be used. Before you rant, it is optimal not to hardcode interfaces but instead cache pack them.

    Constructive criticism only please

    Class InterfaceSystem
    Code:
    package com.runique.graphics.interfaces;
    
    import com.runique.graphics.RSInterface;
    import com.runique.utils.DataUtils;
    
    /**
     * 
     * Handles the InterfaceSystem
     *
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     *
     */
    public class InterfaceSystem extends RSInterface {
    
    	@SuppressWarnings("rawtypes")
    	public static final void load() {
    		try {
    			/**
    			 * The classes
    			 */
    			Class[] classes = DataUtils
    					.getClasses("com.runique.graphics.interfaces.impl");
    			/**
    			 * Loops through classes
    			 */
    			for (Class c : classes) {
    				/**
    				 * Invalid class
    				 */
    				if (c.isAnonymousClass()) // next
    					continue;
    				/**
    				 * The instance
    				 */
    				Object o = c.newInstance();
    				/**
    				 * Not game interface
    				 */
    				if (!(o instanceof GameInterface))
    					continue;
    				/**
    				 * The interface
    				 */
    				GameInterface i = (GameInterface) o;
    				/**
    				 * Creates interface
    				 */
    				createInterface(i);
    			}
    		} catch (Throwable e) {
    			e.printStackTrace();
    		}
    	}
    
    	/**
    	 * Creates the game interface
    	 * 
    	 * @param gameInteface
    	 *            the game interface
    	 */
    	private static void createInterface(GameInterface gameInterface) {
    		/**
    		 * The new interface
    		 */
    		final RSInterface rsInterface = addInterface(gameInterface.getId());
    		/**
    		 * Sets the amount
    		 */
    		setChildren(gameInterface.getComponents().size(), rsInterface);
    		/**
    		 * Adds the components
    		 */
    		for (InterfaceComponent component : gameInterface.getComponents()) {
    			/**
    			 * Invalid component
    			 */
    			if (component == null) {
    				continue;
    			}
    			/**
    			 * Sets the boundary
    			 */
    			setBounds(component.getId().getId(), component.getAxis().getX(),
    					component.getAxis().getY(), gameInterface.getFrame(),
    					rsInterface);
    			/**
    			 * Increases the frame
    			 */
    			gameInterface.setFrame(1);
    		}
    		System.out.println("Interface: " + gameInterface.getId()
    				+ " - Components: " + gameInterface.getComponents().size());
    	}
    }
    Class GameInterface

    Code:
    package com.runique.graphics.interfaces;
    
    import java.util.ArrayList;
    
    import com.runique.graphics.RSInterface;
    
    /**
     * Represents a game interface
     * 
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     * 
     */
    public abstract class GameInterface extends RSInterface {
    	
    	/**
    	 * The interface id
    	 */
    	private int id;
    
    	/**
    	 * The frame
    	 */
    	private int frame;
    
    	/**
    	 * The interface components
    	 */
    	private ArrayList<InterfaceComponent> components;
    
    	/**
    	 * The child id
    	 */
    	private int childId;
    	
    	/**
    	 * The sprite directory
    	 */
    	private String directory;
    
    	/**
    	 * Creates a new game interface
    	 * @param id the id
    	 * @param directory the directory
    	 */
    	public GameInterface(int id, String directory) {
    		this.setId(id);
    		this.setFrame(0);
    		this.setComponents(new ArrayList<InterfaceComponent>());
    		this.setChildId(id);
    		this.setDirectory(directory);
    		compose();
    	}
    
    	/**
    	 * Gets the id
    	 *
    	 * @return the id
    	 */
    	public int getId() {
    		return id;
    	}
    
    	/**
    	 * Sets the id
    	 * 
    	 * @param id
    	 *            the id
    	 */
    	public void setId(int id) {
    		this.id = id;
    	}
    
    	/**
    	 * Gets the frame
    	 *
    	 * @return the frame
    	 */
    	public int getFrame() {
    		return frame;
    	}
    
    	/**
    	 * Sets the frame
    	 * 
    	 * @param frame
    	 *            the frame
    	 */
    	public void setFrame(int frame) {
    		this.frame += frame;
    	}
    
    	/**
    	 * Gets the components
    	 *
    	 * @return the components
    	 */
    	public ArrayList<InterfaceComponent> getComponents() {
    		return components;
    	}
    
    	/**
    	 * Sets the components
    	 * 
    	 * @param components
    	 *            the components
    	 */
    	public void setComponents(ArrayList<InterfaceComponent> components) {
    		this.components = components;
    	}
    
    	/**
    	 * Gets the childId
    	 *
    	 * @return the childId
    	 */
    	public int getChildId() {
    		return childId;
    	}
    
    	/**
    	 * Sets the childId
    	 * 
    	 * @param childId
    	 *            the childId
    	 */
    	public void setChildId(int childId) {
    		this.childId = childId;
    	}
    	
    	/**
    	 * Composes the interface
    	 */
    	public abstract void compose();
    
    	/**
    	 * Gets the directory
    	 *
    	 * @return the directory
    	 */
    	public String getDirectory() {
    		return directory;
    	}
    
    	/**
    	 * Sets the directory
    	 * 
    	 * @param directory the directory
    	 */
    	public void setDirectory(String directory) {
    		this.directory = directory;
    	}
    }
    Class InterfaceAxis
    Code:
    package com.runique.graphics.interfaces;
    
    /**
     * Represents an interface axis
     * 
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     * 
     */
    public class InterfaceAxis {
    
    	/**
    	 * The x axis
    	 */
    	private int x;
    
    	/**
    	 * The y axis
    	 */
    	private int y;
    
    	/**
    	 * Creates a new axis
    	 * 
    	 * @param x
    	 *            the x
    	 * @param y
    	 *            the y
    	 */
    	public InterfaceAxis(int x, int y) {
    		this.setX(x);
    		this.setY(y);
    	}
    
    	/**
    	 * Gets the x
    	 *
    	 * @return the x
    	 */
    	public int getX() {
    		return x;
    	}
    
    	/**
    	 * Sets the x
    	 * 
    	 * @param x
    	 *            the x
    	 */
    	public void setX(int x) {
    		this.x = x;
    	}
    
    	/**
    	 * Gets the y
    	 *
    	 * @return the y
    	 */
    	public int getY() {
    		return y;
    	}
    
    	/**
    	 * Sets the y
    	 * 
    	 * @param y
    	 *            the y
    	 */
    	public void setY(int y) {
    		this.y = y;
    	}
    }
    Class InterfaceComponent
    Code:
    package com.runique.graphics.interfaces;
    
    import com.runique.graphics.RSInterface;
    
    /**
     * Represents an interface component
     * 
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     * 
     */
    public class InterfaceComponent {
    
    	/**
    	 * The interface id
    	 */
    	private InterfaceId id;
    
    	/**
    	 * The interface axis
    	 */
    	private InterfaceAxis axis;
    
    	/**
    	 * The component type
    	 */
    	private RSInterface componentType;
    
    	/**
    	 * Creates a interface component
    	 * 
    	 * @param axis
    	 *            the axis
    	 * @param componentType
    	 *            the component type
    	 */
    	public InterfaceComponent(InterfaceId id, InterfaceAxis axis,
    			RSInterface componentType) {
    		this.setId(id);
    		this.setAxis(axis);
    		this.setComponentType(componentType);
    	}
    
    	/**
    	 * Gets the axis
    	 *
    	 * @return the axis
    	 */
    	public InterfaceAxis getAxis() {
    		return axis;
    	}
    
    	/**
    	 * Sets the axis
    	 * 
    	 * @param axis
    	 *            the axis
    	 */
    	public void setAxis(InterfaceAxis axis) {
    		this.axis = axis;
    	}
    
    	/**
    	 * Gets the componentType
    	 *
    	 * @return the componentType
    	 */
    	public RSInterface getComponentType() {
    		return componentType;
    	}
    
    	/**
    	 * Sets the componentType
    	 * 
    	 * @param componentType
    	 *            the componentType
    	 */
    	public void setComponentType(RSInterface componentType) {
    		this.componentType = componentType;
    	}
    
    	/**
    	 * Gets the id
    	 *
    	 * @return the id
    	 */
    	public InterfaceId getId() {
    		return id;
    	}
    
    	/**
    	 * Sets the id
    	 * 
    	 * @param id
    	 *            the id
    	 */
    	public void setId(InterfaceId id) {
    		this.id = id;
    	}
    }
    Class InterfaceDimension
    Code:
    package com.runique.graphics.interfaces;
    
    /**
     * Represents an interface dimension
     * 
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     * 
     */
    public class InterfaceDimension {
    
    	/**
    	 * The interface width
    	 */
    	private int width;
    
    	/**
    	 * The interface height
    	 */
    	private int height;
    
    	/**
    	 * Represents an interface dimension
    	 * 
    	 * @param width
    	 *            the width
    	 * @param height
    	 *            the height
    	 */
    	public InterfaceDimension(int width, int height) {
    		this.setWidth(width);
    		this.setHeight(height);
    	}
    
    	/**
    	 * Gets the width
    	 *
    	 * @return the width
    	 */
    	public int getWidth() {
    		return width;
    	}
    
    	/**
    	 * Sets the width
    	 * 
    	 * @param width
    	 *            the width
    	 */
    	public void setWidth(int width) {
    		this.width = width;
    	}
    
    	/**
    	 * Gets the height
    	 *
    	 * @return the height
    	 */
    	public int getHeight() {
    		return height;
    	}
    
    	/**
    	 * Sets the height
    	 * 
    	 * @param height
    	 *            the height
    	 */
    	public void setHeight(int height) {
    		this.height = height;
    	}
    }
    Class InterfaceId
    Code:
    package com.runique.graphics.interfaces;
    
    /**
     * Represents an interface id
     * 
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     * 
     */
    public class InterfaceId {
    	
    	/**
    	 * The interface id
    	 */
    	private int id;
    
    	/**
    	 * Creates a new interface id
    	 * 
    	 * @param id
    	 *            the id
    	 */
    	public InterfaceId(int id) {
    		this.setId(id);
    	}
    
    	/**
    	 * Gets the id
    	 *
    	 * @return the id
    	 */
    	public int getId() {
    		return id;
    	}
    
    	/**
    	 * Sets the id
    	 * 
    	 * @param id
    	 *            the id
    	 */
    	public void setId(int id) {
    		this.id = id;
    	}
    }
    Class InterfacePadding
    Code:
    package com.runique.graphics.interfaces;
    
    /**
     * Represents an interface padding
     * 
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     * 
     */
    public class InterfacePadding extends InterfaceAxis {
    
    	/**
    	 * Creates a new padding
    	 * 
    	 * @param x
    	 *            the x
    	 * @param y
    	 *            the y
    	 */
    	public InterfacePadding(int x, int y) {
    		super(x, y);
    	}
    }
    ---

    Class Components
    Code:
    package com.runique.graphics.interfaces.components;
    
    import com.runique.graphics.RSFontSystem;
    import com.runique.graphics.RSInterface;
    import com.runique.graphics.interfaces.GameInterface;
    import com.runique.graphics.interfaces.InterfaceAxis;
    import com.runique.graphics.interfaces.InterfaceComponent;
    import com.runique.graphics.interfaces.InterfaceId;
    import com.runique.graphics.interfaces.components.impl.InterfaceButton;
    import com.runique.graphics.interfaces.components.impl.InterfaceContainer;
    import com.runique.graphics.interfaces.components.impl.InterfaceSprite;
    import com.runique.graphics.interfaces.components.impl.InterfaceText;
    
    /**
     * Handles interface components
     * 
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     * 
     */
    public class Components {
    
    	/**
    	 * Adds an interface sprite component
    	 * 
    	 * @param game
    	 *            the game interface
    	 * @param axis
    	 *            the axis
    	 * @param sprite
    	 *            the sprite
    	 * @return interface component
    	 */
    	public static InterfaceComponent addSprite(GameInterface game,
    			InterfaceAxis axis, InterfaceSprite sprite) {
    		/**
    		 * Increases child
    		 */
    		game.setChildId(game.getChildId() + 1);
    		/**
    		 * The interface id
    		 */
    		InterfaceId newId = new InterfaceId(game.getChildId());
    		/**
    		 * The component
    		 */
    		return new InterfaceComponent(newId, axis, addSprite(game, newId,
    				sprite));
    	}
    
    	/**
    	 * Adds a interface button component
    	 * 
    	 * @param game
    	 *            the game
    	 * @param axis
    	 *            the axis
    	 * @param button
    	 *            the button
    	 * @return new component
    	 */
    	public static InterfaceComponent addButton(GameInterface game,
    			InterfaceAxis axis, InterfaceButton button) {
    		/**
    		 * Increases child
    		 */
    		game.setChildId(game.getChildId() + 1);
    		/**
    		 * The interface id
    		 */
    		InterfaceId newId = new InterfaceId(game.getChildId());
    		/**
    		 * The component
    		 */
    		return new InterfaceComponent(newId, axis, addButton(game, newId,
    				button));
    	}
    
    	/**
    	 * Adds new text
    	 * 
    	 * @param game
    	 *            the game
    	 * @param axis
    	 *            the axis
    	 * @param text
    	 *            the text
    	 * @return
    	 */
    	public static InterfaceComponent addText(GameInterface game,
    			InterfaceAxis axis, InterfaceText text) {
    		/**
    		 * Increases child
    		 */
    		game.setChildId(game.getChildId() + 1);
    		/**
    		 * The interface id
    		 */
    		InterfaceId newId = new InterfaceId(game.getChildId());
    		/**
    		 * The component
    		 */
    		return new InterfaceComponent(newId, axis, addText(newId, text));
    	}
    
    	/**
    	 * Adds an model container
    	 * 
    	 * @param game
    	 *            the game
    	 * @param axis
    	 *            the axis
    	 * @param container
    	 *            the container
    	 * @return interface component
    	 */
    	public static InterfaceComponent addContainer(GameInterface game,
    			InterfaceAxis axis, InterfaceContainer container) {
    		/**
    		 * Increases child
    		 */
    		game.setChildId(game.getChildId() + 1);
    		/**
    		 * The interface id
    		 */
    		InterfaceId newId = new InterfaceId(game.getChildId());
    		/**
    		 * The component
    		 */
    		return new InterfaceComponent(newId, axis, addContainer(newId,
    				container));
    	}
    
    	/**
    	 * Adds a new interface button
    	 * 
    	 * @param game
    	 *            the game
    	 * @param id
    	 *            the id
    	 * @param button
    	 *            the button
    	 * @return new button
    	 */
    	private static RSInterface addButton(GameInterface game, InterfaceId id,
    			InterfaceButton button) {
    		RSInterface tab = RSInterface.interfaceCache[id.getId()] = new RSInterface();
    		tab.id = id.getId();
    		tab.parentId = id.getId();
    		tab.type = 5;
    		tab.actionType = 1;
    		tab.contentType = 0;
    		tab.alpha = (byte) 0;
    		tab.hoverId = -1;
    		if (button.getSprite() != null) {
    			tab.sprite1 = RSInterface.imageLoader(button.getSprite()
    					.getPrimaryId(), game.getDirectory());
    			tab.sprite2 = RSInterface.imageLoader(button.getSprite()
    					.getSecondaryId(), game.getDirectory());
    		}
    		tab.width = button.getDimension().getWidth();
    		tab.height = button.getDimension().getHeight();
    		tab.tooltip = button.getTooltip();
    		return tab;
    	}
    
    	/**
    	 * Adds a new sprite
    	 * 
    	 * @param game
    	 *            the game
    	 * @param id
    	 *            the id
    	 * @param sprite
    	 *            the sprite
    	 * @return new sprite
    	 */
    	private static RSInterface addSprite(GameInterface game, InterfaceId id,
    			InterfaceSprite sprite) {
    		RSInterface tab = RSInterface.interfaceCache[id.getId()] = new RSInterface();
    		tab.id = id.getId();
    		tab.parentId = id.getId();
    		tab.type = sprite.isHighDetail() ? 10 : 5;
    		tab.actionType = 0;
    		tab.contentType = 0;
    		tab.alpha = (byte) 0;
    		tab.hoverId = -1;
    		tab.opacity = sprite.getOpacity();
    		tab.drawsTransparent = sprite.isTransparent();
    		tab.sprite1 = RSInterface.imageLoader(sprite.getPrimaryId(),
    				game.getDirectory());
    		tab.sprite2 = RSInterface.imageLoader(sprite.getSecondaryId(),
    				game.getDirectory());
    		tab.width = 512;
    		tab.height = 334;
    		return tab;
    	}
    
    	/**
    	 * Adds a model container
    	 * 
    	 * @param id
    	 *            the id
    	 * @param container
    	 *            the container
    	 * @return new container
    	 */
    	private static RSInterface addContainer(InterfaceId id,
    			InterfaceContainer container) {
    		final RSInterface tab = RSInterface.interfaceCache[id.getId()] = new RSInterface();
    		tab.parentId = id.getId();
    		tab.id = id.getId();
    		tab.actions = new String[10];
    		tab.spritesX = new int[20];
    		tab.spritesY = new int[20];
    		tab.inventoryAmount = new long[50];
    		tab.inventory = new long[50];
    		tab.children = new int[0];
    		tab.childX = new int[0];
    		tab.childY = new int[0];
    		tab.centerText = true;
    		tab.usableItemInterface = false;
    		tab.isInventoryInterface = false;
    		tab.modelMovement = true;
    		tab.shadeText = false;
    		tab.invSpritePadX = container.getPadding().getX();
    		tab.invSpritePadY = container.getPadding().getY();
    		tab.height = container.getDimension().getHeight();
    		tab.width = container.getDimension().getWidth();
    		tab.type = 2;
    		return tab;
    	}
    
    	/**
    	 * Adds text
    	 * 
    	 * @param id
    	 *            the id
    	 * @param text
    	 *            the text
    	 * @param colour
    	 *            the colour
    	 * @param style
    	 *            the style
    	 * @param font
    	 *            the font
    	 * @param clickable
    	 *            wheth clickable
    	 * @return new text
    	 */
    	private static RSInterface addText(InterfaceId id, InterfaceText text) {
    		RSFontSystem fontStyle = RSInterface.fonts[text.getFont()];
    		RSInterface tab = RSInterface.addInterface(id.getId());
    		tab.parentId = id.getId();
    		tab.id = id.getId();
    		tab.type = 4;
    		tab.actionType = text.isClickable() ? 1 : 0;
    		tab.width = fontStyle.getTextWidth(text.getText().getPrimaryText());
    		tab.height = fontStyle.baseCharacterHeight;
    		tab.contentType = 0;
    		tab.alpha = 0;
    		tab.hoverId = -1;
    		tab.centerText = text.getStyle().isCenter();
    		tab.shadeText = text.getStyle().isShadow();
    		tab.font = fontStyle;
    		tab.enabledText = text.getText().getPrimaryText();
    		tab.disabledText = text.getText().getPrimaryText();
    		tab.disabledColor = text.getColour().getPrimaryColour();
    		tab.enabledColor = text.getColour().getSecondaryColour();
    		tab.tooltip = text.getText().getTooltip();
    		return tab;
    	}
    }
    impl.

    Class InterfaceButton
    Code:
    package com.runique.graphics.interfaces.components.impl;
    
    import com.runique.graphics.interfaces.InterfaceDimension;
    
    /**
     * Represents an interface button
     *
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     *
     */
    public class InterfaceButton {
    
    	/**
    	 * The tooltip
    	 */
    	private String tooltip;
    
    	/**
    	 * The sprite
    	 */
    	private InterfaceSprite sprite;
    
    	/**
    	 * The dimension
    	 */
    	private InterfaceDimension dimension;
    
    	/**
    	 * Creates a new interface button
    	 * 
    	 * @param tooltip
    	 *            the tooltip
    	 * @param sprite
    	 *            the sprite
    	 * @param dimension
    	 *            the dimension
    	 */
    	public InterfaceButton(String tooltip, InterfaceSprite sprite,
    			InterfaceDimension dimension) {
    		this.setTooltip(tooltip);
    		this.setSprite(sprite);
    		this.setDimension(dimension);
    	}
    
    	/**
    	 * Gets the tooltip
    	 *
    	 * @return the tooltip
    	 */
    	public String getTooltip() {
    		return tooltip;
    	}
    
    	/**
    	 * Sets the tooltip
    	 * 
    	 * @param tooltip
    	 *            the tooltip
    	 */
    	public void setTooltip(String tooltip) {
    		this.tooltip = tooltip;
    	}
    
    	/**
    	 * Gets the sprite
    	 *
    	 * @return the sprite
    	 */
    	public InterfaceSprite getSprite() {
    		return sprite;
    	}
    
    	/**
    	 * Sets the sprite
    	 * 
    	 * @param sprite
    	 *            the sprite
    	 */
    	public void setSprite(InterfaceSprite sprite) {
    		this.sprite = sprite;
    	}
    
    	/**
    	 * Gets the dimension
    	 *
    	 * @return the dimension
    	 */
    	public InterfaceDimension getDimension() {
    		return dimension;
    	}
    
    	/**
    	 * Sets the dimension
    	 * 
    	 * @param dimension
    	 *            the dimension
    	 */
    	public void setDimension(InterfaceDimension dimension) {
    		this.dimension = dimension;
    	}
    
    }
    Class InterfaceContainer
    Code:
    package com.runique.graphics.interfaces.components.impl;
    
    import com.runique.graphics.interfaces.InterfaceDimension;
    import com.runique.graphics.interfaces.InterfacePadding;
    
    /**
     * Represents an interface container
     *
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     *
     */
    public class InterfaceContainer {
    
    	/**
    	 * The dimension
    	 */
    	private InterfaceDimension dimension;
    
    	/**
    	 * The padding
    	 */
    	private InterfacePadding padding;
    
    	/**
    	 * Creates a new interface container
    	 * 
    	 * @param dimension
    	 *            the dimension
    	 * @param padding
    	 *            the padding
    	 */
    	public InterfaceContainer(InterfaceDimension dimension,
    			InterfacePadding padding) {
    		this.setDimension(dimension);
    		this.setPadding(padding);
    	}
    
    	/**
    	 * Gets the dimension
    	 *
    	 * @return the dimension
    	 */
    	public InterfaceDimension getDimension() {
    		return dimension;
    	}
    
    	/**
    	 * Sets the dimension
    	 * 
    	 * @param dimension
    	 *            the dimension
    	 */
    	public void setDimension(InterfaceDimension dimension) {
    		this.dimension = dimension;
    	}
    
    	/**
    	 * Gets the padding
    	 *
    	 * @return the padding
    	 */
    	public InterfacePadding getPadding() {
    		return padding;
    	}
    
    	/**
    	 * Sets the padding
    	 * 
    	 * @param padding
    	 *            the padding
    	 */
    	public void setPadding(InterfacePadding padding) {
    		this.padding = padding;
    	}
    }
    Class InterfaceSprite
    Code:
    package com.runique.graphics.interfaces.components.impl;
    
    /**
     * Represents an interface sprite
     * 
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     * 
     */
    public class InterfaceSprite {
    
    	/**
    	 * The normal transparency
    	 */
    	public static final int NORMAL_TRANSPARENCY = 128;
    
    	/**
    	 * No transparency value
    	 */
    	public static final int NO_TRANSPARENCY = 256;
    
    	/**
    	 * The primary sprite id
    	 */
    	private int primaryId;
    
    	/**
    	 * The secondary sprite id
    	 */
    	private int secondaryId;
    
    	/**
    	 * Whether the sprite is transparent
    	 */
    	private boolean transparent;
    
    	/**
    	 * The opacity of the sprite
    	 */
    	private int opacity;
    
    	/**
    	 * Whether a high detail sprite
    	 */
    	private boolean highDetail;
    
    	/**
    	 * Creates a new interface sprite
    	 * 
    	 * @param primaryId
    	 *            the primary id
    	 * @param secondaryId
    	 *            the secondary id
    	 * @param transparent
    	 *            whether transparent
    	 * @param opacity
    	 *            the opacity
    	 * @param highDetail
    	 *            the high detail
    	 */
    	public InterfaceSprite(int primaryId, int secondaryId, boolean transparent,
    			int opacity, boolean highDetail) {
    		this.setPrimaryId(primaryId);
    		this.setSecondaryId(secondaryId);
    		this.setTransparent(transparent);
    		this.setOpacity(opacity);
    		this.setHighDetail(highDetail);
    	}
    
    	/**
    	 * Adds a regular sprite
    	 * 
    	 * @param id
    	 *            the id
    	 * @return regular sprite
    	 */
    	public static InterfaceSprite regular(int id) {
    		return new InterfaceSprite(id, id, false, NO_TRANSPARENCY, false);
    	}
    
    	/**
    	 * Adds a high detail sprite
    	 * 
    	 * @param id
    	 *            the id
    	 * @return high detail sprite
    	 */
    	public static InterfaceSprite highDetail(int id) {
    		return new InterfaceSprite(id, id, false, NO_TRANSPARENCY, true);
    	}
    
    	/**
    	 * Adds a regular transparent sprite with opacity selection
    	 * 
    	 * @param id
    	 *            the id
    	 * @param opacity
    	 *            the opacity
    	 * @return regular sprite
    	 */
    	public static InterfaceSprite transparent(int id,
    			int opacity) {
    		return new InterfaceSprite(id, id, true, opacity, false);
    	}
    
    	/**
    	 * Adds a regular transparent sprite
    	 * 
    	 * @param id
    	 *            the id
    	 * @param opacity
    	 *            the opacity
    	 * @return regular sprite
    	 */
    	public static InterfaceSprite transparent(int id) {
    		return transparent(id, NORMAL_TRANSPARENCY);
    	}
    
    	/**
    	 * Gets the primaryId
    	 *
    	 * @return the primaryId
    	 */
    	public int getPrimaryId() {
    		return primaryId;
    	}
    
    	/**
    	 * Sets the primaryId
    	 * 
    	 * @param primaryId
    	 *            the primaryId
    	 */
    	public void setPrimaryId(int primaryId) {
    		this.primaryId = primaryId;
    	}
    
    	/**
    	 * Gets the secondaryId
    	 *
    	 * @return the secondaryId
    	 */
    	public int getSecondaryId() {
    		return secondaryId;
    	}
    
    	/**
    	 * Sets the secondaryId
    	 * 
    	 * @param secondaryId
    	 *            the secondaryId
    	 */
    	public void setSecondaryId(int secondaryId) {
    		this.secondaryId = secondaryId;
    	}
    
    	/**
    	 * Gets the transparent
    	 *
    	 * @return the transparent
    	 */
    	public boolean isTransparent() {
    		return transparent;
    	}
    
    	/**
    	 * Sets the transparent
    	 * 
    	 * @param transparent
    	 *            the transparent
    	 */
    	public void setTransparent(boolean transparent) {
    		this.transparent = transparent;
    	}
    
    	/**
    	 * Gets the opacity
    	 *
    	 * @return the opacity
    	 */
    	public int getOpacity() {
    		return opacity;
    	}
    
    	/**
    	 * Sets the opacity
    	 * 
    	 * @param opacity
    	 *            the opacity
    	 */
    	public void setOpacity(int opacity) {
    		this.opacity = opacity;
    	}
    
    	/**
    	 * Gets the highDetail
    	 *
    	 * @return the highDetail
    	 */
    	public boolean isHighDetail() {
    		return highDetail;
    	}
    
    	/**
    	 * Sets the highDetail
    	 * 
    	 * @param highDetail
    	 *            the highDetail
    	 */
    	public void setHighDetail(boolean highDetail) {
    		this.highDetail = highDetail;
    	}
    }
    Class InterfaceText
    Code:
    package com.runique.graphics.interfaces.components.impl;
    
    /**
     * Represents an interface text
     * 
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     * 
     */
    public class InterfaceText {
    	
    	/**
    	 * Small text
    	 */
    	public static final int SMALL = 0;
    
    	/**
    	 * Normal text
    	 */
    	public static final int NORMAL = 1;
    	
    	/**
    	 * Bold text
    	 */
    	public static final int BOLD = 2;
    	
    	/**
    	 * Fancy text
    	 */
    	public static final int FANCY = 3;
    
    	/**
    	 * The text
    	 */
    	private Text text;
    
    	/**
    	 * The style
    	 */
    	private TextStyle style;
    
    	/**
    	 * The text colour
    	 */
    	private TextColour colour;
    
    	/**
    	 * The font
    	 */
    	private int font;
    
    	/**
    	 * Whether clickable
    	 */
    	private boolean clickable;
    
    	/**
    	 * Adds non-clickable text
    	 * 
    	 * @param text
    	 *            the text
    	 * @param colour
    	 *            the colour
    	 * @param font
    	 *            the font
    	 * @return clickable text
    	 */
    	public static InterfaceText regular(Text text, TextColour colour, int font) {
    		return new InterfaceText(text, new TextStyle(), colour, font, false);
    	}
    	
    	/**
    	 * Adds clickable text
    	 * 
    	 * @param text
    	 *            the text
    	 * @param colour
    	 *            the colour
    	 * @param font
    	 *            the font
    	 * @return clickable text
    	 */
    	public static InterfaceText clickable(Text text, TextColour colour, int font) {
    		return new InterfaceText(text, new TextStyle(), colour, font, true);
    	}
    
    	/**
    	 * Unset text with select tooltip
    	 * 
    	 * @param colour
    	 *            the colour
    	 * @param font
    	 *            the font
    	 * @return clickable text
    	 */
    	public static InterfaceText select(TextColour colour, int font) {
    		return new InterfaceText(new Text("", "", "Select"), new TextStyle(),
    				colour, font, true);
    	}
    
    	/**
    	 * Creates new interface text
    	 * 
    	 * @param text
    	 *            the text
    	 * @param style
    	 *            the style
    	 * @param colour
    	 *            the colour
    	 */
    	public InterfaceText(Text text, TextStyle style, TextColour colour,
    			int font, boolean clickable) {
    		this.setText(text);
    		this.setStyle(style);
    		this.setColour(colour);
    		this.setFont(font);
    		this.setClickable(clickable);
    	}
    
    	/**
    	 * Non clickable text with shadow
    	 * 
    	 * @param text
    	 *            the text
    	 * @param colour
    	 *            the colour
    	 * @param font
    	 *            the font
    	 */
    	public InterfaceText(Text text, TextColour colour, int font) {
    		this.setText(text);
    		this.setStyle(new TextStyle());
    		this.setColour(colour);
    		this.setFont(font);
    		this.setClickable(false);
    	}
    
    	/**
    	 * Non clickable text with shadow and centered
    	 * 
    	 * @param text
    	 *            the text
    	 * @param font
    	 *            the font
    	 * @param colour
    	 *            the colour
    	 */
    	public InterfaceText(Text text, int font, TextColour colour) {
    		this.setText(text);
    		this.setStyle(new TextStyle(true, true));
    		this.setColour(colour);
    		this.setFont(font);
    		this.setClickable(false);
    	}
    
    	/**
    	 * Clickable text
    	 * 
    	 * @param text
    	 *            the text
    	 * @param font
    	 *            the font
    	 * @param colour
    	 *            the colour
    	 */
    	public InterfaceText(int font, TextColour colour, Text text) {
    		this.setText(text);
    		this.setStyle(new TextStyle());
    		this.setColour(colour);
    		this.setFont(font);
    		this.setClickable(true);
    	}
    
    	/**
    	 * Gets the text
    	 *
    	 * @return the text
    	 */
    	public Text getText() {
    		return text;
    	}
    
    	/**
    	 * Sets the text
    	 * 
    	 * @param text
    	 *            the text
    	 */
    	public void setText(Text text) {
    		this.text = text;
    	}
    
    	/**
    	 * Gets the style
    	 *
    	 * @return the style
    	 */
    	public TextStyle getStyle() {
    		return style;
    	}
    
    	/**
    	 * Sets the style
    	 * 
    	 * @param style
    	 *            the style
    	 */
    	public void setStyle(TextStyle style) {
    		this.style = style;
    	}
    
    	/**
    	 * Gets the colour
    	 *
    	 * @return the colour
    	 */
    	public TextColour getColour() {
    		return colour;
    	}
    
    	/**
    	 * Sets the colour
    	 * 
    	 * @param colour
    	 *            the colour
    	 */
    	public void setColour(TextColour colour) {
    		this.colour = colour;
    	}
    
    	/**
    	 * Gets the font
    	 *
    	 * @return the font
    	 */
    	public int getFont() {
    		return font;
    	}
    
    	/**
    	 * Sets the font
    	 * 
    	 * @param font
    	 *            the font
    	 */
    	public void setFont(int font) {
    		this.font = font;
    	}
    
    	/**
    	 * Gets the clickable
    	 *
    	 * @return the clickable
    	 */
    	public boolean isClickable() {
    		return clickable;
    	}
    
    	/**
    	 * Sets the clickable
    	 * 
    	 * @param clickable
    	 *            the clickable
    	 */
    	public void setClickable(boolean clickable) {
    		this.clickable = clickable;
    	}
    
    	/**
    	 * Represents a text string
    	 */
    	public static class Text {
    
    		/**
    		 * The primary text
    		 */
    		private String primaryText;
    
    		/**
    		 * The secondary text
    		 */
    		private String secondaryText;
    
    		/**
    		 * The tool tip
    		 */
    		private String tooltip;
    
    		/**
    		 * Creates new text
    		 * 
    		 * @param primaryText
    		 *            the primary text
    		 * @param secondaryText
    		 *            the secondary text
    		 * @param tooltip
    		 *            the tooltip
    		 */
    		public Text(String primaryText, String secondaryText, String tooltip) {
    			this.setPrimaryText(primaryText);
    			this.setSecondaryText(secondaryText);
    			this.setTooltip(tooltip);
    		}
    
    		/**
    		 * Creates new text
    		 * 
    		 * @param text
    		 *            the text
    		 */
    		public Text(String text) {
    			this.setPrimaryText(text);
    			this.setSecondaryText(text);
    			this.setTooltip(text);
    		}
    
    		/**
    		 * Gets the primaryText
    		 *
    		 * @return the primaryText
    		 */
    		public String getPrimaryText() {
    			return primaryText;
    		}
    
    		/**
    		 * Sets the primaryText
    		 * 
    		 * @param primaryText
    		 *            the primaryText
    		 */
    		public void setPrimaryText(String primaryText) {
    			this.primaryText = primaryText;
    		}
    
    		/**
    		 * Gets the secondaryText
    		 *
    		 * @return the secondaryText
    		 */
    		public String getSecondaryText() {
    			return secondaryText;
    		}
    
    		/**
    		 * Sets the secondaryText
    		 * 
    		 * @param secondaryText
    		 *            the secondaryText
    		 */
    		public void setSecondaryText(String secondaryText) {
    			this.secondaryText = secondaryText;
    		}
    
    		/**
    		 * Gets the tooltip
    		 *
    		 * @return the tooltip
    		 */
    		public String getTooltip() {
    			return tooltip;
    		}
    
    		/**
    		 * Sets the tooltip
    		 * 
    		 * @param tooltip
    		 *            the tooltip
    		 */
    		public void setTooltip(String tooltip) {
    			this.tooltip = tooltip;
    		}
    	}
    
    	/**
    	 * Represents the text style
    	 */
    	public static class TextStyle {
    
    		/**
    		 * Whether text has shadow
    		 */
    		private boolean shadow;
    
    		/**
    		 * Whether text is centered
    		 */
    		private boolean center;
    
    		/**
    		 * Creates new text style
    		 * 
    		 * @param shadow
    		 *            the shadow
    		 * @param center
    		 *            the center
    		 */
    		public TextStyle(boolean shadow, boolean center) {
    			this.setShadow(shadow);
    			this.setCenter(center);
    		}
    
    		/**
    		 * Creates the default text style
    		 */
    		public TextStyle() {
    			this.setShadow(true);
    			this.setCenter(false);
    		}
    
    		/**
    		 * Gets the shadow
    		 *
    		 * @return the shadow
    		 */
    		public boolean isShadow() {
    			return shadow;
    		}
    
    		/**
    		 * Sets the shadow
    		 * 
    		 * @param shadow
    		 *            the shadow
    		 */
    		public void setShadow(boolean shadow) {
    			this.shadow = shadow;
    		}
    
    		/**
    		 * Gets the center
    		 *
    		 * @return the center
    		 */
    		public boolean isCenter() {
    			return center;
    		}
    
    		/**
    		 * Sets the center
    		 * 
    		 * @param center
    		 *            the center
    		 */
    		public void setCenter(boolean center) {
    			this.center = center;
    		}
    	}
    
    	/**
    	 * Represents the text colour
    	 */
    	public static class TextColour {
    
    		/**
    		 * The primary colour
    		 */
    		private int primaryColour;
    
    		/**
    		 * The secondary colour
    		 */
    		private int secondaryColour;
    
    		/**
    		 * Creates a new text colour
    		 * 
    		 * @param primaryColour
    		 *            the primary colour
    		 * @param secondaryColour
    		 *            the secondary colour
    		 */
    		public TextColour(int primaryColour, int secondaryColour) {
    			this.setPrimaryColour(primaryColour);
    			this.setSecondaryColour(secondaryColour);
    		}
    
    		/**
    		 * Creates a new text colour with both colour types the same
    		 * 
    		 * @param colour
    		 *            the colour
    		 */
    		public TextColour(int colour) {
    			this.setPrimaryColour(colour);
    			this.setSecondaryColour(colour);
    		}
    
    		/**
    		 * Gets the primaryColour
    		 *
    		 * @return the primaryColour
    		 */
    		public int getPrimaryColour() {
    			return primaryColour;
    		}
    
    		/**
    		 * Sets the primaryColour
    		 * 
    		 * @param primaryColour
    		 *            the primaryColour
    		 */
    		public void setPrimaryColour(int primaryColour) {
    			this.primaryColour = primaryColour;
    		}
    
    		/**
    		 * Gets the secondaryColour
    		 *
    		 * @return the secondaryColour
    		 */
    		public int getSecondaryColour() {
    			return secondaryColour;
    		}
    
    		/**
    		 * Sets the secondaryColour
    		 * 
    		 * @param secondaryColour
    		 *            the secondaryColour
    		 */
    		public void setSecondaryColour(int secondaryColour) {
    			this.secondaryColour = secondaryColour;
    		}
    	}
    }






    Here's an example

    Code:
    package com.runique.graphics.interfaces.impl;
    
    import com.runique.graphics.interfaces.GameInterface;
    import com.runique.graphics.interfaces.InterfaceAxis;
    import com.runique.graphics.interfaces.InterfaceDimension;
    import com.runique.graphics.interfaces.components.Components;
    import com.runique.graphics.interfaces.components.impl.InterfaceScrollBar;
    import com.runique.graphics.interfaces.components.impl.InterfaceSprite;
    import com.runique.graphics.interfaces.components.impl.InterfaceText;
    import com.runique.graphics.interfaces.components.impl.InterfaceText.Text;
    import com.runique.graphics.interfaces.components.impl.InterfaceText.TextColour;
    
    /**
     * Handles the Statistics GameInterface
     *
     * @author 2012 <http://www.rune-server.org/members/dexter+morgan/>
     *
     */
    public class StatisticsGameInterface extends GameInterface {
    
    	/**
    	 * New Statistics GameInterface
    	 */
    	public StatisticsGameInterface() {
    		super(47000, "statistics/statistics");
    	}
    
    	@Override
    	public void compose() {
    		/**
    		 * The background sprite
    		 */
    		getComponents().add(
    				Components.addSprite(this, new InterfaceAxis(7, 8),
    						InterfaceSprite.regular(0)));
    		/**
    		 * The text
    		 */
    		getComponents().add(
    				Components.addText(this, new InterfaceAxis(56, 88),
    						InterfaceText.clickable(new Text("Career"),
    								new TextColour(0xffffff), InterfaceText.NORMAL)));
    		getComponents().add(
    				Components.addText(this, new InterfaceAxis(150, 88),
    						InterfaceText.clickable(new Text("Skills"),
    								new TextColour(0xffffff), InterfaceText.NORMAL)));
    		getComponents().add(
    				Components.addText(this, new InterfaceAxis(241, 88),
    						InterfaceText.clickable(new Text("Misc"),
    								new TextColour(0xffffff), InterfaceText.NORMAL)));
    		getComponents().add(
    				Components.addText(this, new InterfaceAxis(313, 88),
    						InterfaceText.clickable(new Text("Minigames"),
    								new TextColour(0xffffff), InterfaceText.NORMAL)));
    		getComponents().add(
    				Components.addText(this, new InterfaceAxis(406, 88),
    						InterfaceText.clickable(new Text("Weapons"),
    								new TextColour(0xffffff), InterfaceText.NORMAL)));
    		getComponents().add(
    				Components.addText(this, new InterfaceAxis(192, 18),
    						InterfaceText.clickable(new Text("Viewing Statistics"),
    								new TextColour(0xffffff), InterfaceText.BOLD)));
    
    	}
    }
    Reply With Quote  
     

  2. #2  
    I'm Back

    Stewie's Avatar
    Join Date
    Jul 2008
    Age
    29
    Posts
    7,987
    Thanks given
    1,877
    Thanks received
    1,491
    Rep Power
    5000
    Its one thing to create a new system to make it simpler and more user friendly. Its another to overly complicate something.

    Also, couldn't you just use http://docs.oracle.com/javase/7/docs...Rectangle.html for your "axis" and "dimensions". Would definitely help not to re-invent the wheel.


    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    Banned

    Join Date
    Mar 2011
    Posts
    982
    Thanks given
    384
    Thanks received
    61
    Rep Power
    0
    You're using over 10 classes (stopped counting) for an interface system, that's overkill.
    I like the idea you have though.
    Reply With Quote  
     

  5. #4  
    Community Veteran

    Dexter Morgan's Avatar
    Join Date
    Nov 2008
    Age
    28
    Posts
    4,419
    Thanks given
    1,184
    Thanks received
    757
    Rep Power
    3098
    Quote Originally Posted by Herpes Derpes View Post
    You're using over 10 classes (stopped counting) for an interface system, that's overkill.
    I like the idea you have though.
    A system consists of many branches. Allow me to define from a biological stand point. Cell > Tissue > Organ > System. I hope you understand what I'm trying to explain.

    Thank you

    Quote Originally Posted by Stewie View Post
    Its one thing to create a new system to make it simpler and more user friendly. Its another to overly complicate something.

    Also, couldn't you just use Rectangle (Java Platform SE 7 ) for your "axis" and "dimensions". Would definitely help not to re-invent the wheel.
    Well to create the system, I agree, it can appear to over complicate things, although, using the system is extremely easy and flexible.

    Thank you for your criticism and suggestions, will definitely use Rectangle.
    Reply With Quote  
     

  6. #5  
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    Good idea, poorly implemented. Too complex.
    Attached image
    Reply With Quote  
     

  7. Thankful users:


  8. #6  
    Community Veteran

    Dexter Morgan's Avatar
    Join Date
    Nov 2008
    Age
    28
    Posts
    4,419
    Thanks given
    1,184
    Thanks received
    757
    Rep Power
    3098
    Quote Originally Posted by Galkon View Post
    Good idea, poorly implemented. Too complex.

    What's so complicated. Some constructive criticism wouldn't hurt. All I understand is that a few classes could be removed and replaced by existing libraries. Please explain further

    Thank you
    Reply With Quote  
     

  9. #7  
    Vitality

    Raw Envy's Avatar
    Join Date
    Dec 2010
    Posts
    3,034
    Thanks given
    869
    Thanks received
    1,186
    Rep Power
    3054
    Nice work as usual Dexter!

    Anyone complaining about this, don't use it simple... He does some very good work which I've seen before
    Reply With Quote  
     

  10. Thankful users:


  11. #8  
    Registered Member

    Join Date
    Dec 2013
    Posts
    530
    Thanks given
    19
    Thanks received
    355
    Rep Power
    1729
    A more in-depth & thought out design is always a plus in my opinion as it makes modifying a specific aspect of the system much easier. Good job, Dexter.
    Reply With Quote  
     

  12. Thankful user:


  13. #9  
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    Quote Originally Posted by Dexter Morgan View Post
    What's so complicated. Some constructive criticism wouldn't hurt. All I understand is that a few classes could be removed and replaced by existing libraries. Please explain further

    Thank you
    Remove the axis and dimension classes and replace them with the native classes, and then all the component classes could extend an abstract component class or something to reduce the number of times copy/pasted code exists in each component class.
    Attached image
    Reply With Quote  
     

  14. Thankful user:


  15. #10  
    Community Veteran

    Dexter Morgan's Avatar
    Join Date
    Nov 2008
    Age
    28
    Posts
    4,419
    Thanks given
    1,184
    Thanks received
    757
    Rep Power
    3098
    Quote Originally Posted by Galkon View Post
    Remove the axis and dimension classes and replace them with the native classes, and then all the component classes could extend an abstract component class or something to reduce the number of times copy/pasted code exists in each component class.
    Thank you for your feedback Galkon
    Quote Originally Posted by Raw Envy View Post
    Nice work as usual Dexter!

    Anyone complaining about this, don't use it simple... He does some very good work which I've seen before
    Thank you Raw Envy

    Quote Originally Posted by Swiffy View Post
    Nice concept!
    Thank you Swiffy

    Quote Originally Posted by mack_ View Post
    A more in-depth & thought out design is always a plus in my opinion as it makes modifying a specific aspect of the system much easier. Good job, Dexter.
    Thank you mack_
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [508] Hardcoding interfaces
    By Ed in forum Show-off
    Replies: 35
    Last Post: 07-23-2009, 08:15 PM
  2. importing hardcoded interfaces..?
    By joey. in forum Requests
    Replies: 4
    Last Post: 05-10-2009, 08:55 PM
  3. Object Oriented Commands
    By meiscooldude in forum Tutorials
    Replies: 24
    Last Post: 03-11-2009, 12:17 AM
  4. Replies: 6
    Last Post: 05-09-2008, 07:07 PM
  5. How to make an Object open an Interface on Devolution.
    By Soul Breaker in forum Tutorials
    Replies: 5
    Last Post: 01-30-2008, 03:46 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •