[Spout] GenericTextField in a Widget throughs an error???

Discussion in 'Plugin Development' started by Gabriel333, Aug 13, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Gabriel333

    Im trying to make a plugin, where I need a window to popup and some inputfields where I can write some text (parameters).

    I get this error, to me it seems like GenericTextFields are not supported by widgets? But when I read the javadoc it look like it should support GenericTextFields ??? I guess Im doing something wrong?

    Show Spoiler

    15:15:06 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'safe
    tylock' in plugin Safety v0.2.2
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:12
    9)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:3
    20)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:713)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:677)

    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:670)
    at net.minecraft.server.Packet3Chat.a(Packet3Chat.java:33)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:85)
    at net.minecraft.server.NetworkListenThread.a(SourceFile:105)
    at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:451)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:361)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    Caused by: java.lang.UnsupportedOperationException: Unsupported widget type
    at org.getspout.spoutapi.gui.InGameScreen.attachWidget(InGameScreen.java
    :53)
    at org.getspout.spoutapi.gui.InGameScreen.attachWidget(InGameScreen.java
    :14)
    at dk.gabriel333.Safety.utilities.SafetyWindow.SetupSafetyWindow(SafetyW
    indow.java:65)
    at dk.gabriel333.Safety.commands.Safetylock.onCommand(Safetylock.java:70
    )
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35)
    ... 12 more
    >


    Her is my code, can anyone tell me what Im doing wrong? It is the 4th last line which fails :-(

    Show Spoiler

    Code:
    public class SafetyWindow extends GenericPopup {
    
        public SafetyWindow(String title, SpoutPlayer player) {
            super();
            // TODO Auto-generated constructor stub
        }
    
        private static Button saveButton, cancelButton;
        private static GenericTexture iconTexture, background;
        private static String iconurl="";
        private static int marginLeft, marginTop, marginBottom, marginRight, width, height;
    
        private static GenericScreen screen = null;
        private static GenericTextField inputfield, inputfield2;
        private static GenericLabel lbl,inputlabel,inputlabel2;
    
        public static void SetupSafetyWindow(String title, SpoutPlayer sPlayer) {
    
            screen=(GenericScreen) sPlayer.getMainScreen();
            width = screen.getWidth();   //427
            height = screen.getHeight(); //240
    
            background = new GenericTexture("http://dl.dropbox.com/u/36067670/Safety/Textures/messageBox2.png");
            //background.setHeight(200).setWidth(400).setX((width-400)/2).setY((height-200)/2);
            background.setHeight(200).setWidth(400).setX(20).setY(20);
            screen.attachWidget(background);
    
            marginLeft = (width-360)/2;
            marginTop = (background.getY())+10;
            marginBottom = background.getHeight()+background.getX()-10;
            marginRight = background.getX()+background.getWidth();
            sPlayer.sendMessage("H:"+height+" W:"+width+" mL:"+marginLeft+" mT:"+marginTop+
                    " mB:"+marginBottom+" mR:"+marginRight);
    
            //title
            lbl = new GenericLabel(ChatColor.WHITE+title);
            lbl.setX(getMarginLeft()).setY(getMarginTop()+5).setWidth(background.getWidth()-200).setHeight(20);
            screen.attachWidget(lbl);
    
            //field no. 1
            inputlabel = new GenericLabel(ChatColor.WHITE+"Enter pincode:");
            inputlabel.setX(getMarginLeft()).setY(getMarginTop()+30).setWidth(background.getWidth()-200).setHeight(20);
            screen.attachWidget(inputlabel);
    
            inputfield = new GenericTextField();
            inputfield.setX(getMarginLeft()).setY(getMarginTop()+60).setWidth(background.getWidth()-200).setHeight(20);
            inputfield.setMaximumCharacters(6);
            sPlayer.sendMessage("Inputfield:"+inputfield);
            screen.attachWidget(inputfield);  // THIS LINE FAILS???? WHY?????
    
            inputfield.setEnabled(true);
            inputfield.setText("0000");
            inputfield.setDirty(true);
    
     
  2. Offline

    DrBowe

    @SpoutDev

    (This is why having the help thread only in Bukkit+ can be a bit tricky at times :p )

    EDIT:
    Just to clarify, I'm trying to get the spout devs in here to help you out.
     
  3. Offline

    EdTheLoon

    What's at line 65 (it doesn't appear to be in the code snippet you posted)? The reason I'm asking is this

    Line 65 appears to be the part where you call attachWidget from the Spout API and it may be that you are passing through the wrong type.

    Edit: That, or it could be a problem with Spout or maybe there's another reason. Hopefully @SpoutDev sees this soon or anyone else from the SpoutDev team
     
  4. Offline

    EdTheLoon

  5. Offline

    Gabriel333

    No I still have problems with the GUI, and now they have changed the methods from spout 1.0.1 to 1.0.2, so now I need some good examples on how to do...
    • show buttons (attachwidget is depresiated)
    • make input field in a popupscreen
    Im confused about the difference between GenericScreen, GenericPopup and GenericWidget???
     
  6. Offline

    Afforess

    It threw an exception because you can not attach widgets that need the mouse focus (buttons, text fields, etc) to the main HUD. It doesn't make any sense, users could never click or interact with them.

    You need to create a popup screen (with GenericPopup) and attach the popup to the main hud. Then attach the text fields, buttons, etc to the popup instead.

    Next time you need help with spout, tag people, like @Afforess or @SpoutDev ;)
     
  7. Offline

    SpoutDev

    Or post on the actual Spout thread or Spout Bukkit+ thread. ;)

    - Wulfspider
     
  8. Offline

    Gabriel333

    @Afforess or @SpoutDev

    Okay now i got it :) and I have now made all 10 widgets with succes on a GenericPopup !!!

    I have one more problem.

    I want to place some buttons next to a Chestinventory, but each time I open the popup the chestinventory disapears???

    Code:
    GenericButton sortButton =new GenericButton("Sort");
    sortButton.setAuto(false).setX(300).setY(50).setHeight(20).setWidth(50);
    sortButton.setTooltip("Sort your inventory.");
    popup.attachWidget(plugin, sortButton);
    popup.setTransparent(true);
    sPlayer.getMainScreen().attachPopupScreen(popup);
    Cant I place some buttons next to the inventory and interact with the inventory, while I also are able to click on the buttons next to the inventory?
     
  9. Offline

    Afforess

    Yeah, ATM, the Popup overrides any native MC Screen. We are planning on adding custom popups for each of the native MC screens so you can add custom widgets to them as well.
     
Thread Status:
Not open for further replies.

Share This Page