Guest User

Untitled

a guest
Jan 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. package net.rothcraft.gui;
  2.  
  3. import java.util.HashMap;
  4. import net.rothcraft.Money;
  5. import net.rothcraft.Rothcraft;
  6. import org.bukkit.inventory.ItemStack;
  7. import org.getspout.spoutapi.gui.Button;
  8. import org.getspout.spoutapi.gui.GenericButton;
  9. import org.getspout.spoutapi.gui.GenericItemWidget;
  10. import org.getspout.spoutapi.gui.ItemWidget;
  11. import org.getspout.spoutapi.gui.RenderPriority;
  12. import org.getspout.spoutapi.gui.Screen;
  13.  
  14. /**
  15.  *
  16.  * @author Rothens
  17.  */
  18. public class ItemButton {
  19.  
  20.     private ItemStack is;
  21.     private Button btn;
  22.     private int price;
  23.     private Screen scn;
  24.     private ItemWidget itemWidget;
  25.     private static HashMap<Button, ItemButton> instances = new HashMap<Button, ItemButton>();
  26.     private boolean visible;
  27.     private int x, y;
  28.  
  29.     public ItemButton(ItemStack is, Screen scn) {
  30.         if (is == null) {
  31.             is = new ItemStack(0);
  32.         }
  33.         this.is = is;
  34.         this.scn = scn;
  35.         price = 0;
  36.         initWidget();
  37.     }
  38.  
  39.     public ItemButton(ItemStack is, Screen scn, int price) {
  40.         if (is == null) {
  41.             is = new ItemStack(0);
  42.         }
  43.         this.is = is;
  44.         this.scn = scn;
  45.         this.price = price;
  46.         initWidget();
  47.     }
  48.  
  49.     private void initWidget() {
  50.         String p = "ingyenes";
  51.         if (price != 0) {
  52.             p = Rothcraft.getInstance().money.convertMoney(price);
  53.         }
  54.         btn = new GenericButton();
  55.         btn.setHeight(20).setWidth(20);
  56.        
  57.         btn.setPriority(RenderPriority.High);
  58.         btn.setTooltip(p);
  59.         itemWidget = new GenericItemWidget(is);
  60.         itemWidget.setPriority(RenderPriority.Normal);
  61.         itemWidget.setTooltip(p);
  62.         if (is.getType().isBlock()) {
  63.             itemWidget.setWidth(8).setHeight(8).setDepth(8);
  64.         } else {
  65.             itemWidget.setWidth(8).setHeight(8).setDepth(1);
  66.         }
  67.         instances.put(btn, this);
  68.     }
  69.  
  70.     public void attachToScreen() {
  71.         scn.attachWidget(Rothcraft.getInstance(), btn).attachWidget(Rothcraft.getInstance(), itemWidget);
  72.         setVisible(true);
  73.     }
  74.  
  75.     public void setVisible(boolean b) {
  76.         btn.setVisible(b);
  77.         btn.setEnabled(b);
  78.         itemWidget.setVisible(b);
  79.         dirtyWidgets();
  80.         visible = b;
  81.     }
  82.  
  83.     public void dirtyWidgets() {
  84.         btn.setDirty(true);
  85.         itemWidget.setDirty(true);
  86.     }
  87.  
  88.     public void remove() {
  89.         scn.removeWidget(itemWidget).removeWidget(btn);
  90.     }
  91.  
  92.     public Button getButton() {
  93.         return btn;
  94.     }
  95.  
  96.     public Screen getScreen() {
  97.         return scn;
  98.     }
  99.  
  100.     public static ItemButton getByButton(Button btn) {
  101.         return instances.get(btn);
  102.     }
  103.  
  104.     public boolean isVisible() {
  105.         return visible;
  106.     }
  107.    
  108.     public void setX(int x){
  109.         this.x = x;
  110.         btn.setX(x);
  111.         btn.setVisible(true);
  112.         itemWidget.setX(x+2);
  113.         dirtyWidgets();
  114.     }
  115.  
  116.     public void setY(int y){
  117.         this.y = y;
  118.         btn.setY(y);
  119.         btn.setVisible(true);
  120.         itemWidget.setY(y+2);
  121.         dirtyWidgets();
  122.     }
  123.    
  124.     public ItemStack getItemStack(){
  125.         return is;
  126.     }
  127. }
Add Comment
Please, Sign In to add comment