Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Top-Cat authored and Top-Cat committed Aug 18, 2011
1 parent 224af7c commit fd288c5
Showing 1 changed file with 57 additions and 20 deletions.
77 changes: 57 additions & 20 deletions src/main/java/org/getspout/spouttest/SpoutTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.getspout.spouttest;

import java.util.HashMap;
import java.util.Random;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
Expand All @@ -13,27 +15,35 @@
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.block.SpoutWeather;
import org.getspout.spoutapi.event.input.InputListener;
import org.getspout.spoutapi.event.input.KeyPressedEvent;
import org.getspout.spoutapi.event.screen.ButtonClickEvent;
import org.getspout.spoutapi.event.screen.ScreenListener;
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
import org.getspout.spoutapi.event.spout.SpoutListener;
import org.getspout.spoutapi.gui.Align;
import org.getspout.spoutapi.gui.Color;
import org.getspout.spoutapi.gui.Container;
import org.getspout.spoutapi.gui.GenericButton;
import org.getspout.spoutapi.gui.GenericContainer;
import org.getspout.spoutapi.gui.GenericGradient;
import org.getspout.spoutapi.gui.GenericLabel;
import org.getspout.spoutapi.gui.GenericPopup;
import org.getspout.spoutapi.gui.GenericSlider;
import org.getspout.spoutapi.gui.GenericTextField;
import org.getspout.spoutapi.gui.GenericTexture;
import org.getspout.spoutapi.gui.RenderPriority;
import org.getspout.spoutapi.gui.WidgetAnchor;
import org.getspout.spoutapi.keyboard.Keyboard;
import org.getspout.spoutapi.player.SpoutPlayer;

public class SpoutTest extends JavaPlugin {

public HashMap<Player, Integer> movement = new HashMap<Player, Integer>();
public HashMap<Player, GenericLabel> labels = new HashMap<Player, GenericLabel>();
public HashMap<Player, GenericTexture> texts = new HashMap<Player, GenericTexture>();
public Plugin plugin = this;

public Container aContainer = new GenericContainer();
@Override
public void onDisable() {
// TODO Auto-generated method stub
Expand All @@ -42,8 +52,9 @@ public void onDisable() {

@Override
public void onEnable() {
getServer().getPluginManager().registerEvent(Type.PLAYER_MOVE, new pL(), Priority.Normal, this);
getServer().getPluginManager().registerEvent(Type.PLAYER_CHAT, new pL(), Priority.Normal, this);
pL pl = new pL();
getServer().getPluginManager().registerEvent(Type.PLAYER_MOVE, pl, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Type.PLAYER_CHAT, pl, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Type.CUSTOM_EVENT, new spL(), Priority.Normal, this);
getServer().getPluginManager().registerEvent(Type.CUSTOM_EVENT, new sL(), Priority.Normal, this);
getServer().getPluginManager().registerEvent(Type.CUSTOM_EVENT, new iL(), Priority.Normal, this);
Expand All @@ -59,11 +70,15 @@ public void onPlayerMove(PlayerMoveEvent event) {
movement.put(event.getPlayer(), movement.get(event.getPlayer()) + 1);
}
if (!labels.containsKey(event.getPlayer())) {
GenericLabel label = (GenericLabel) ((GenericLabel) new GenericLabel().setHexColor(0xFFFFFF).setAlignY(Align.FIRST)).setAlignX(Align.THIRD).setX(240).setY(0);
GenericLabel label = (GenericLabel) ((GenericLabel) new GenericLabel().setHexColor(0xFFFFFF)).setX(240).setY(0);
SpoutManager.getPlayer(event.getPlayer()).getMainScreen().attachWidget(plugin, label);
labels.put(event.getPlayer(), label);
aContainer.addChild(label);
}
labels.get(event.getPlayer()).setText(movement.get(event.getPlayer()).toString());
if (movement.get(event.getPlayer()) % 10 == 0) {
aContainer.setX(movement.get(event.getPlayer())).setDirty(true);
}
labels.get(event.getPlayer()).setText(movement.get(event.getPlayer()).toString()).setDirty(true);
}

@Override
Expand All @@ -79,21 +94,32 @@ public class spL extends SpoutListener {

@Override
public void onSpoutCraftEnable(SpoutCraftEnableEvent event) {
SpoutManager.getBiomeManager().setPlayerBiomeWeather(event.getPlayer(), Biome.DESERT, SpoutWeather.SNOW); // Desert snow ftw!

event.getPlayer().sendMessage("Testing commences!");
popup = new GenericPopup();
popup.attachWidget(plugin, new GenericButton("Test").setX(114).setY(50).setHeight(20).setWidth(200));
popup.attachWidget(plugin, new GenericTextField().setX(114).setY(80).setHeight(20).setWidth(200));
popup.attachWidget(plugin, new GenericSlider().setX(114).setY(140).setHeight(20).setWidth(200));
popup.attachWidget(plugin, ((GenericLabel) new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlignY(Align.FIRST)).setAlignX(Align.FIRST).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, ((GenericLabel) new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlignY(Align.FIRST)).setAlignX(Align.SECOND).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, ((GenericLabel) new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlignY(Align.FIRST)).setAlignX(Align.THIRD).setX(240).setY(0));

popup.attachWidget(plugin, ((GenericLabel) new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlignY(Align.SECOND)).setAlignX(Align.FIRST).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, ((GenericLabel) new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlignY(Align.SECOND)).setAlignX(Align.SECOND).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, ((GenericLabel) new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlignY(Align.SECOND)).setAlignX(Align.THIRD).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, ((GenericLabel) new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlignY(Align.THIRD)).setAlignX(Align.FIRST).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, ((GenericLabel) new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlignY(Align.THIRD)).setAlignX(Align.SECOND).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, ((GenericLabel) new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlignY(Align.THIRD)).setAlignX(Align.THIRD).setX(0).setY(0).setHeight(240).setWidth(427));
Random r = new Random();
for (int i = 0; i < 15; i++) {
int x = -150 + i * 20;
int y = -40;
popup.attachWidget(plugin, new GenericGradient().setTopColor(new Color(r.nextFloat(), r.nextFloat(), r.nextFloat(), 1)).setAnchor(WidgetAnchor.BOTTOM_CENTER).setWidth(20).setHeight(20).setX(x).setY(y).setPriority(RenderPriority.Low));
popup.attachWidget(plugin, new GenericLabel(i+"").setAnchor(WidgetAnchor.BOTTOM_CENTER).setWidth(20).setHeight(20).setX(x + 5).setY(y + 5).setPriority(RenderPriority.Lowest));
}

popup.attachWidget(plugin, new GenericButton("Test").setY(-75).setX(-70).setHeight(20).setWidth(150).setAnchor(WidgetAnchor.CENTER_CENTER));
popup.attachWidget(plugin, new GenericTextField().setMaximumCharacters(50).setX(-50).setY(-50).setHeight(20).setWidth(50).setAnchor(WidgetAnchor.CENTER_CENTER));
popup.attachWidget(plugin, new GenericSlider().setX(-100).setY(20).setHeight(20).setWidth(200).setAnchor(WidgetAnchor.CENTER_CENTER));

popup.attachWidget(plugin, new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlign(WidgetAnchor.TOP_LEFT).setAnchor(WidgetAnchor.TOP_LEFT)).setX(50).setY(50);
popup.attachWidget(plugin, new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlign(WidgetAnchor.TOP_CENTER).setAnchor(WidgetAnchor.TOP_CENTER));
popup.attachWidget(plugin, new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlign(WidgetAnchor.TOP_RIGHT).setAnchor(WidgetAnchor.TOP_RIGHT));
popup.attachWidget(plugin, new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlign(WidgetAnchor.CENTER_LEFT).setAnchor(WidgetAnchor.CENTER_LEFT).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlign(WidgetAnchor.CENTER_CENTER).setAnchor(WidgetAnchor.CENTER_CENTER).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlign(WidgetAnchor.CENTER_RIGHT).setAnchor(WidgetAnchor.CENTER_RIGHT).setX(0).setY(0).setHeight(240).setWidth(427));
popup.attachWidget(plugin, new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlign(WidgetAnchor.BOTTOM_LEFT).setAnchor(WidgetAnchor.BOTTOM_LEFT).setX(0).setY(0));
popup.attachWidget(plugin, new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlign(WidgetAnchor.BOTTOM_CENTER).setAnchor(WidgetAnchor.BOTTOM_CENTER).setX(0).setY(0));
popup.attachWidget(plugin, new GenericLabel("Some\nLonger Text\nis").setHexColor(0xFFFFFF).setAlign(WidgetAnchor.BOTTOM_RIGHT).setAnchor(WidgetAnchor.BOTTOM_RIGHT).setX(0).setY(0));

popup.attachWidget(plugin, new GenericLabel("Bottom right of middle").setHexColor(0xFFFFFF).setX(230).setY(130));

Expand All @@ -115,8 +141,18 @@ public void onKeyPressedEvent(KeyPressedEvent event) {
} else if (event.getKey() == Keyboard.KEY_C) {
((SpoutPlayer) event.getPlayer()).resetTexturePack();
} else if (event.getKey() == Keyboard.KEY_B) {

popup = new GenericPopup();

Random r = new Random();
for (int i = 0; i < 15; i++) {
int x = -150 + i * 20;
int y = -40;
popup.attachWidget(plugin, new GenericGradient().setTopColor(new Color(r.nextFloat(), r.nextFloat(), r.nextFloat(), 1)).setAnchor(WidgetAnchor.BOTTOM_CENTER).setWidth(20).setHeight(20).setX(x).setY(y).setPriority(RenderPriority.Low));
popup.attachWidget(plugin, new GenericLabel(i+"").setAnchor(WidgetAnchor.BOTTOM_CENTER).setWidth(20).setHeight(20).setX(x + 5).setY(y + 5).setPriority(RenderPriority.Lowest));
}

event.getPlayer().getMainScreen().attachPopupScreen(popup);
//popup.setDirty(true);
} else if (event.getKey() == Keyboard.KEY_N) {
event.getPlayer().getMainScreen().closePopup();
}
Expand All @@ -131,7 +167,8 @@ public void onButtonClick(ButtonClickEvent event) {
if (event.getButton() instanceof GenericButton && event.getButton().getText().equals("Test")) {
((SpoutPlayer) event.getPlayer()).getMainScreen().closePopup();
event.getScreen().setDirty(true);
((SpoutPlayer) event.getPlayer()).getMainScreen().attachWidget(plugin, ((GenericLabel) new GenericLabel("I'm on the main screen!").setHexColor(0xFFFFFF).setAlignY(Align.FIRST)).setAlignX(Align.FIRST).setX(0).setY(0).setHeight(240).setWidth(427));
((SpoutPlayer) event.getPlayer()).getMainScreen().attachWidget(plugin, ((GenericLabel) new GenericLabel("I'm on the main screen!").setHexColor(0xFFFFFF)).setX(0).setY(0).setHeight(240).setWidth(427));
((SpoutPlayer) event.getPlayer()).getMainScreen().attachWidget(plugin, (GenericTexture) new GenericTexture("http://i.imgur.com/GFEBP.png").setWidth(64).setHeight(64).setX(100).setY(100));
event.getPlayer().sendMessage("Button test successful!");
}
}
Expand Down

0 comments on commit fd288c5

Please sign in to comment.