Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 1st, 2012  |  syntax: None  |  size: 7.31 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.precipicegames.Market.ui;
  2.  
  3. import org.bukkit.Material;
  4. import org.bukkit.inventory.ItemStack;
  5. import org.bukkit.plugin.java.JavaPlugin;
  6. import org.getspout.spoutapi.gui.Color;
  7. import org.getspout.spoutapi.event.screen.ButtonClickEvent;
  8. import org.getspout.spoutapi.event.screen.TextFieldChangeEvent;
  9. import org.getspout.spoutapi.gui.ContainerType;
  10. import org.getspout.spoutapi.gui.GenericButton;
  11. import org.getspout.spoutapi.gui.GenericContainer;
  12. import org.getspout.spoutapi.gui.GenericItemWidget;
  13. import org.getspout.spoutapi.gui.GenericLabel;
  14. import org.getspout.spoutapi.gui.GenericPopup;
  15. import org.getspout.spoutapi.gui.GenericRectange;
  16. import org.getspout.spoutapi.gui.GenericTextField;
  17. import org.getspout.spoutapi.gui.RenderPriority;
  18. import org.getspout.spoutapi.gui.Widget;
  19. import org.getspout.spoutapi.gui.WidgetAnchor;
  20.  
  21. import com.precipicegames.Market.Asset;
  22. import com.precipicegames.Market.ItemAsset;
  23. import com.precipicegames.Market.Market;
  24. import com.precipicegames.Market.Trade;
  25. public class MainUI extends GenericPopup {
  26.         private JavaPlugin jplugin;
  27.         private class assetButton extends GenericButton
  28.         {
  29.                 public assetButton(String string) {
  30.                         super(string);
  31.                 }
  32.  
  33.                 public void onButtonClick(ButtonClickEvent event)
  34.                 {
  35.                         event.getPlayer().sendMessage("Hello!");
  36.                 }
  37.         }
  38.         private class marketButton extends GenericButton
  39.         {
  40.                 public marketButton(String string) {
  41.                         super(string);
  42.                 }
  43.  
  44.                 public void onButtonClick(ButtonClickEvent event)
  45.                 {
  46.                         super.onButtonClick(event);
  47.                         for(Widget w : mscBody.getChildren())
  48.                                 mscBody.removeChild(w);
  49.                         if(mWindow == null)
  50.                                 mWindow = new marketWindow();
  51.                         mscBody.addChild(mWindow).setDirty(true);
  52.                 }
  53.         }
  54.         private class tradeButton extends GenericButton
  55.         {
  56.                 public tradeButton(String string) {
  57.                         super(string);
  58.                 }
  59.  
  60.                 public void onButtonClick(ButtonClickEvent event)
  61.                 {
  62.                         super.onButtonClick(event);
  63.                         event.getPlayer().sendMessage("Hello!");
  64.                 }
  65.         }
  66.         private class searchField extends GenericTextField implements Runnable
  67.         {
  68.                 private long lastUpdate;
  69.                 public void onTextFieldChange(TextFieldChangeEvent event)
  70.                 {
  71.                         lastUpdate = System.currentTimeMillis();
  72.                         jplugin.getServer().getScheduler().scheduleSyncDelayedTask(jplugin, this, 21);
  73.                 }
  74.                 @Override
  75.                 public void run() {
  76.                         if(System.currentTimeMillis() - lastUpdate > 1000)
  77.                         {
  78.                                 this.showSearchWidget();
  79.                         }
  80.                         // TODO Auto-generated method stub
  81.                 }
  82.                 public void showSearchWidget()
  83.                 {
  84.                         for(Widget w : mscBody.getChildren())
  85.                         {
  86.                                 if(w == sWindow)
  87.                                         return;
  88.                         }
  89.                         for(Widget w : mscBody.getChildren())
  90.                                 mscBody.removeChild(w);
  91.                         mscBody.setDirty(true);
  92.                         if(sWindow == null)
  93.                                 sWindow = new searchWindow();
  94.                         mscBody.addChild(sWindow).setDirty(true);
  95.                 }
  96.         }
  97.         public class searchWindow extends GenericContainer
  98.         {
  99.                 public searchWindow()
  100.                 {
  101.                         super();
  102.                         this.setLayout(ContainerType.VERTICAL);
  103.                         this.setMargin(1);
  104.                         Market m = new Market("The cool Place",null);
  105.                         //Market m2 = new Market("Spawn City");
  106.                         Asset sell = new ItemAsset(new ItemStack(Material.BROWN_MUSHROOM,20));
  107.                         Asset buy = new ItemAsset(new ItemStack(Material.CHAINMAIL_LEGGINGS,60));
  108.                         Trade t = new Trade("System Test", sell, buy);
  109.                         m.addTrade(t);
  110.                         //m2.addTrade(t);
  111.                        
  112.                         addChild(new SearchResultWidget(t));
  113.                         addChild(new SearchResultWidget(t));
  114.                         //mscBody.addChild(new SearchResultWidget(Material.DIAMOND_SWORD,"Diamond Sword",1,"Evil Faction Lab"));
  115.                         //mscBody.addChild(new SearchResultWidget(Material.DIAMOND_BLOCK,"Diamond Block",20,"Dotblank's Minning co."));
  116.                         addChild(new GenericContainer());
  117.                 }
  118.         }
  119.         private class marketWindow extends GenericContainer
  120.         {
  121.                 public marketWindow()
  122.                 {
  123.                         super();
  124.                         this.setLayout(ContainerType.VERTICAL);
  125.                         this.setMargin(1);
  126.                         //mscBody.addChild(new SearchResultWidget(Material.DIAMOND_SWORD,"Diamond Sword",1,"Evil Faction Lab"));
  127.                         //mscBody.addChild(new SearchResultWidget(Material.DIAMOND_BLOCK,"Diamond Block",20,"Dotblank's Minning co."));
  128.                         addChild(new GenericLabel("Hello this is the market"));
  129.                         addChild(new GenericContainer());
  130.                 }
  131.         }
  132.         private GenericContainer mscBody = null;
  133.         private assetButton assetB;
  134.         private tradeButton tradeB;
  135.         private marketButton marketB;
  136.         private searchWindow sWindow = null;
  137.         private marketWindow mWindow = null;
  138.         private searchField sField = null;
  139.        
  140.         public MainUI(JavaPlugin p)
  141.         {
  142.                 super();
  143.                 jplugin = p;
  144.                 //popup.setBgVisible(enable)
  145.                 //popup.setHeight(200);
  146.                 //popup.setWidth(300);
  147.                 //popup.setAnchor(WidgetAnchor.CENTER_CENTER);
  148.                 //popup.shiftXPos(-popup.getWidth()/2);
  149.                 //popup.shiftYPos(-popup.getHeight()/2);
  150.                 GenericRectange bground = new GenericRectange();
  151.                 GenericRectange fground = new GenericRectange();
  152.                 GenericContainer msc = new GenericContainer();
  153.                 GenericContainer horz = new GenericContainer();
  154.                 horz.setLayout(ContainerType.HORIZONTAL);
  155.                
  156.                 GenericContainer mscWindow = new GenericContainer();
  157.                 GenericContainer mscHeader = new GenericContainer();
  158.                 mscBody = new GenericContainer();
  159.                 GenericContainer mscblank = new GenericContainer();
  160.                 GenericContainer mscTextContain = new GenericContainer();
  161.                 mscWindow.setLayout(ContainerType.VERTICAL);
  162.                 mscWindow.setMargin(1);
  163.                 mscHeader.setMaxHeight(20);
  164.                 mscHeader.setLayout(ContainerType.HORIZONTAL);
  165.                 //mscHeader.setAlign(WidgetAnchor.CENTER_LEFT);
  166.                 mscHeader.setWidth(300);
  167.                 //mscHeader.setMargin(1);
  168.                 marketB = new marketButton("Market:");
  169.                 mscHeader.addChild(marketB);
  170.                 mscHeader.addChild(mscblank.setMaxWidth(5));
  171.                 mscTextContain.setMargin(2);
  172.                 sField = new searchField();
  173.                 mscTextContain.addChild(sField);
  174.                 mscHeader.addChild(mscTextContain.setMaxHeight(17).setMinWidth(100));
  175.                 //mscHeader.addChild(new GenericTextField().setMaxHeight(15).setMinWidth(100));
  176.                 mscHeader.addChild(new GenericContainer().setMaxWidth(24));
  177.                 mscHeader.addChild(new GenericButton("Trades"));
  178.                 assetB = new assetButton("Assets");
  179.                 mscHeader.addChild(assetB);
  180.                
  181.                 mscWindow.addChild(mscHeader);
  182.                
  183.                
  184.                 //bground.setTopColor(new Color(0,0,0));
  185.                 //bground.setBottomColor(new Color(255,255,255));
  186.                 bground.setHeight(200);
  187.                 bground.setWidth(300);
  188.                 bground.setColor(new Color(127,127,127));
  189.                 //fground.setHeight(198);
  190.                 //fground.setWidth(298);
  191.                 fground.setColor(new Color(0,0,0));
  192.                 fground.setPriority(RenderPriority.High);
  193.                 GenericContainer mscFground = new GenericContainer();
  194.                 mscFground.setMargin(1);
  195.                 mscFground.setWidth(200);
  196.                 mscFground.setHeight(300);
  197.                 mscFground.addChild(fground);
  198.                 //bground.setFixed(true);
  199.                 bground.setPriority(RenderPriority.Highest);
  200.                 sWindow = new searchWindow();
  201.                 mscBody.addChild(sWindow);
  202.                 mscWindow.addChild(mscBody);
  203.                
  204.                 msc.setHeight(200);
  205.                 msc.setWidth(300);
  206.                 msc.shiftXPos(-150);
  207.                 msc.shiftYPos(-100);
  208.                
  209.                
  210.                 GenericContainer textcontainer = new GenericContainer();
  211.                 msc.setLayout(ContainerType.OVERLAY);
  212.                 msc.setAlign(WidgetAnchor.CENTER_CENTER);
  213.                 msc.setAnchor(WidgetAnchor.CENTER_CENTER);
  214.  
  215.                 horz.addChild(textcontainer);
  216.                 GenericItemWidget itm = new GenericItemWidget(new ItemStack(Material.BOOK));
  217.                 itm.setDepth(20);
  218.                 itm.setHeight(20);
  219.                 itm.setWidth(20);
  220.                 itm.setAnchor(WidgetAnchor.SCALE);
  221.                
  222.                 itm.setTooltip("The Book of Secrets");
  223.                 //itm.setMaxHeight(20);
  224.                 //itm.setMaxWidth(20);
  225.                 //horz.addChild(itm);
  226.                 msc.insertChild(0,mscWindow);
  227.                 msc.insertChild(1,bground);
  228.                 msc.insertChild(2, mscFground);
  229.                 this.attachWidget(p, msc);
  230.                 //popup.attachWidget(this,msc);
  231.                 //popup.attachWidget(this,bground);
  232.                 //popup.setTransparent(true);
  233.                 //sp.getMainScreen().getContainer()
  234.         }
  235.  
  236. }