Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.rothcraft.gui;
- import java.util.HashMap;
- import net.rothcraft.Money;
- import net.rothcraft.Rothcraft;
- import org.bukkit.inventory.ItemStack;
- import org.getspout.spoutapi.gui.Button;
- import org.getspout.spoutapi.gui.GenericButton;
- import org.getspout.spoutapi.gui.GenericItemWidget;
- import org.getspout.spoutapi.gui.ItemWidget;
- import org.getspout.spoutapi.gui.RenderPriority;
- import org.getspout.spoutapi.gui.Screen;
- /**
- *
- * @author Rothens
- */
- public class ItemButton {
- private ItemStack is;
- private Button btn;
- private int price;
- private Screen scn;
- private ItemWidget itemWidget;
- private static HashMap<Button, ItemButton> instances = new HashMap<Button, ItemButton>();
- private boolean visible;
- private int x, y;
- public ItemButton(ItemStack is, Screen scn) {
- if (is == null) {
- is = new ItemStack(0);
- }
- this.is = is;
- this.scn = scn;
- price = 0;
- initWidget();
- }
- public ItemButton(ItemStack is, Screen scn, int price) {
- if (is == null) {
- is = new ItemStack(0);
- }
- this.is = is;
- this.scn = scn;
- this.price = price;
- initWidget();
- }
- private void initWidget() {
- String p = "ingyenes";
- if (price != 0) {
- p = Rothcraft.getInstance().money.convertMoney(price);
- }
- btn = new GenericButton();
- btn.setHeight(20).setWidth(20);
- btn.setPriority(RenderPriority.High);
- btn.setTooltip(p);
- itemWidget = new GenericItemWidget(is);
- itemWidget.setPriority(RenderPriority.Normal);
- itemWidget.setTooltip(p);
- if (is.getType().isBlock()) {
- itemWidget.setWidth(8).setHeight(8).setDepth(8);
- } else {
- itemWidget.setWidth(8).setHeight(8).setDepth(1);
- }
- instances.put(btn, this);
- }
- public void attachToScreen() {
- scn.attachWidget(Rothcraft.getInstance(), btn).attachWidget(Rothcraft.getInstance(), itemWidget);
- setVisible(true);
- }
- public void setVisible(boolean b) {
- btn.setVisible(b);
- btn.setEnabled(b);
- itemWidget.setVisible(b);
- dirtyWidgets();
- visible = b;
- }
- public void dirtyWidgets() {
- btn.setDirty(true);
- itemWidget.setDirty(true);
- }
- public void remove() {
- scn.removeWidget(itemWidget).removeWidget(btn);
- }
- public Button getButton() {
- return btn;
- }
- public Screen getScreen() {
- return scn;
- }
- public static ItemButton getByButton(Button btn) {
- return instances.get(btn);
- }
- public boolean isVisible() {
- return visible;
- }
- public void setX(int x){
- this.x = x;
- btn.setX(x);
- btn.setVisible(true);
- itemWidget.setX(x+2);
- dirtyWidgets();
- }
- public void setY(int y){
- this.y = y;
- btn.setY(y);
- btn.setVisible(true);
- itemWidget.setY(y+2);
- dirtyWidgets();
- }
- public ItemStack getItemStack(){
- return is;
- }
- }
Add Comment
Please, Sign In to add comment