- package com.precipicegames.Market.ui;
- import org.bukkit.Material;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.getspout.spoutapi.gui.Color;
- import org.getspout.spoutapi.event.screen.ButtonClickEvent;
- import org.getspout.spoutapi.event.screen.TextFieldChangeEvent;
- import org.getspout.spoutapi.gui.ContainerType;
- import org.getspout.spoutapi.gui.GenericButton;
- import org.getspout.spoutapi.gui.GenericContainer;
- import org.getspout.spoutapi.gui.GenericItemWidget;
- import org.getspout.spoutapi.gui.GenericLabel;
- import org.getspout.spoutapi.gui.GenericPopup;
- import org.getspout.spoutapi.gui.GenericRectange;
- import org.getspout.spoutapi.gui.GenericTextField;
- import org.getspout.spoutapi.gui.RenderPriority;
- import org.getspout.spoutapi.gui.Widget;
- import org.getspout.spoutapi.gui.WidgetAnchor;
- import com.precipicegames.Market.Asset;
- import com.precipicegames.Market.ItemAsset;
- import com.precipicegames.Market.Market;
- import com.precipicegames.Market.Trade;
- public class MainUI extends GenericPopup {
- private JavaPlugin jplugin;
- private class assetButton extends GenericButton
- {
- public assetButton(String string) {
- super(string);
- }
- public void onButtonClick(ButtonClickEvent event)
- {
- event.getPlayer().sendMessage("Hello!");
- }
- }
- private class marketButton extends GenericButton
- {
- public marketButton(String string) {
- super(string);
- }
- public void onButtonClick(ButtonClickEvent event)
- {
- super.onButtonClick(event);
- for(Widget w : mscBody.getChildren())
- mscBody.removeChild(w);
- if(mWindow == null)
- mWindow = new marketWindow();
- mscBody.addChild(mWindow).setDirty(true);
- }
- }
- private class tradeButton extends GenericButton
- {
- public tradeButton(String string) {
- super(string);
- }
- public void onButtonClick(ButtonClickEvent event)
- {
- super.onButtonClick(event);
- event.getPlayer().sendMessage("Hello!");
- }
- }
- private class searchField extends GenericTextField implements Runnable
- {
- private long lastUpdate;
- public void onTextFieldChange(TextFieldChangeEvent event)
- {
- lastUpdate = System.currentTimeMillis();
- jplugin.getServer().getScheduler().scheduleSyncDelayedTask(jplugin, this, 21);
- }
- @Override
- public void run() {
- if(System.currentTimeMillis() - lastUpdate > 1000)
- {
- this.showSearchWidget();
- }
- // TODO Auto-generated method stub
- }
- public void showSearchWidget()
- {
- for(Widget w : mscBody.getChildren())
- {
- if(w == sWindow)
- return;
- }
- for(Widget w : mscBody.getChildren())
- mscBody.removeChild(w);
- mscBody.setDirty(true);
- if(sWindow == null)
- sWindow = new searchWindow();
- mscBody.addChild(sWindow).setDirty(true);
- }
- }
- public class searchWindow extends GenericContainer
- {
- public searchWindow()
- {
- super();
- this.setLayout(ContainerType.VERTICAL);
- this.setMargin(1);
- Market m = new Market("The cool Place",null);
- //Market m2 = new Market("Spawn City");
- Asset sell = new ItemAsset(new ItemStack(Material.BROWN_MUSHROOM,20));
- Asset buy = new ItemAsset(new ItemStack(Material.CHAINMAIL_LEGGINGS,60));
- Trade t = new Trade("System Test", sell, buy);
- m.addTrade(t);
- //m2.addTrade(t);
- addChild(new SearchResultWidget(t));
- addChild(new SearchResultWidget(t));
- //mscBody.addChild(new SearchResultWidget(Material.DIAMOND_SWORD,"Diamond Sword",1,"Evil Faction Lab"));
- //mscBody.addChild(new SearchResultWidget(Material.DIAMOND_BLOCK,"Diamond Block",20,"Dotblank's Minning co."));
- addChild(new GenericContainer());
- }
- }
- private class marketWindow extends GenericContainer
- {
- public marketWindow()
- {
- super();
- this.setLayout(ContainerType.VERTICAL);
- this.setMargin(1);
- //mscBody.addChild(new SearchResultWidget(Material.DIAMOND_SWORD,"Diamond Sword",1,"Evil Faction Lab"));
- //mscBody.addChild(new SearchResultWidget(Material.DIAMOND_BLOCK,"Diamond Block",20,"Dotblank's Minning co."));
- addChild(new GenericLabel("Hello this is the market"));
- addChild(new GenericContainer());
- }
- }
- private GenericContainer mscBody = null;
- private assetButton assetB;
- private tradeButton tradeB;
- private marketButton marketB;
- private searchWindow sWindow = null;
- private marketWindow mWindow = null;
- private searchField sField = null;
- public MainUI(JavaPlugin p)
- {
- super();
- jplugin = p;
- //popup.setBgVisible(enable)
- //popup.setHeight(200);
- //popup.setWidth(300);
- //popup.setAnchor(WidgetAnchor.CENTER_CENTER);
- //popup.shiftXPos(-popup.getWidth()/2);
- //popup.shiftYPos(-popup.getHeight()/2);
- GenericRectange bground = new GenericRectange();
- GenericRectange fground = new GenericRectange();
- GenericContainer msc = new GenericContainer();
- GenericContainer horz = new GenericContainer();
- horz.setLayout(ContainerType.HORIZONTAL);
- GenericContainer mscWindow = new GenericContainer();
- GenericContainer mscHeader = new GenericContainer();
- mscBody = new GenericContainer();
- GenericContainer mscblank = new GenericContainer();
- GenericContainer mscTextContain = new GenericContainer();
- mscWindow.setLayout(ContainerType.VERTICAL);
- mscWindow.setMargin(1);
- mscHeader.setMaxHeight(20);
- mscHeader.setLayout(ContainerType.HORIZONTAL);
- //mscHeader.setAlign(WidgetAnchor.CENTER_LEFT);
- mscHeader.setWidth(300);
- //mscHeader.setMargin(1);
- marketB = new marketButton("Market:");
- mscHeader.addChild(marketB);
- mscHeader.addChild(mscblank.setMaxWidth(5));
- mscTextContain.setMargin(2);
- sField = new searchField();
- mscTextContain.addChild(sField);
- mscHeader.addChild(mscTextContain.setMaxHeight(17).setMinWidth(100));
- //mscHeader.addChild(new GenericTextField().setMaxHeight(15).setMinWidth(100));
- mscHeader.addChild(new GenericContainer().setMaxWidth(24));
- mscHeader.addChild(new GenericButton("Trades"));
- assetB = new assetButton("Assets");
- mscHeader.addChild(assetB);
- mscWindow.addChild(mscHeader);
- //bground.setTopColor(new Color(0,0,0));
- //bground.setBottomColor(new Color(255,255,255));
- bground.setHeight(200);
- bground.setWidth(300);
- bground.setColor(new Color(127,127,127));
- //fground.setHeight(198);
- //fground.setWidth(298);
- fground.setColor(new Color(0,0,0));
- fground.setPriority(RenderPriority.High);
- GenericContainer mscFground = new GenericContainer();
- mscFground.setMargin(1);
- mscFground.setWidth(200);
- mscFground.setHeight(300);
- mscFground.addChild(fground);
- //bground.setFixed(true);
- bground.setPriority(RenderPriority.Highest);
- sWindow = new searchWindow();
- mscBody.addChild(sWindow);
- mscWindow.addChild(mscBody);
- msc.setHeight(200);
- msc.setWidth(300);
- msc.shiftXPos(-150);
- msc.shiftYPos(-100);
- GenericContainer textcontainer = new GenericContainer();
- msc.setLayout(ContainerType.OVERLAY);
- msc.setAlign(WidgetAnchor.CENTER_CENTER);
- msc.setAnchor(WidgetAnchor.CENTER_CENTER);
- horz.addChild(textcontainer);
- GenericItemWidget itm = new GenericItemWidget(new ItemStack(Material.BOOK));
- itm.setDepth(20);
- itm.setHeight(20);
- itm.setWidth(20);
- itm.setAnchor(WidgetAnchor.SCALE);
- itm.setTooltip("The Book of Secrets");
- //itm.setMaxHeight(20);
- //itm.setMaxWidth(20);
- //horz.addChild(itm);
- msc.insertChild(0,mscWindow);
- msc.insertChild(1,bground);
- msc.insertChild(2, mscFground);
- this.attachWidget(p, msc);
- //popup.attachWidget(this,msc);
- //popup.attachWidget(this,bground);
- //popup.setTransparent(true);
- //sp.getMainScreen().getContainer()
- }
- }