Console no work correctly.

2012-01-10
2012-08-28
  • you can help me, little doubt: my console does not switch the color of the
    text, even I started to color specified in the parameter?

    it displays the color code out instead of color, background no change too

     
  • anyone help me?

     
  • I found another problem in the console, when we add the controller via XML it,
    simply rude to the console working (lets not add any text on it).

    See the code below, I created 3Tabs, each tab has a console inside each
    console controller calls the

    <?xml version="1.0" encoding="UTF-8"?>
    <nifty xmlns="[url]http://nifty-gui.sourceforge.net/nifty-1.3.xsd[/url]" xmlns:xsi="[url]http://www.w3.org/2001/XMLSchema-instance[/url]" xsi:schemaLocation="[url]http://nifty-gui.sourceforge.net/nifty-1.3.xsd[/url] [url]http://nifty-gui.sourceforge.net/nifty-1.3.xsd[/url]">
      <!-- +++++++++++++++++++++++++++++++++++++++ -->
      <!-- load default styles and controls -->
      <!-- +++++++++++++++++++++++++++++++++++++++ -->
      <!-- <useStyles filename="console/custom-console-style.xml" />  -->
      <useStyles filename="nifty-default-styles.xml" />
      <useControls filename="nifty-default-controls.xml" />
    
      <controlDefinition name="nifty-tabs" controller="game.gui.tab.TabsControlDialogController"/>
    
      <!-- +++++++++++++++++++++++++++++++++++++++ -->
      <!-- start screen -->
      <!-- +++++++++++++++++++++++++++++++++++++++ -->
      <screen id="start" controller="game.gui.screencontroller.InGameStartScreenController" defaultFocusElement="consoleDefault">
        <layer id="background" childLayout="overlay" backgroundImage="resources/images/guiParallax2.png" visibleToMouse="false" />
        <layer id="atributesHero" visibleToMouse="true" childLayout="absolute">
                <text id="textNameCharacter"  childLayout="absolute" x="580px" y="145px" width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
                <text id="textHPCharacter"    childLayout="absolute" x="580px" y="188px" width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
                <text id="textManaCharacter"  childLayout="absolute" x="580px" y="220px" width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
                <text id="textLevelCharacter" childLayout="absolute" x="690px" y="48px"  width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
                <text id="textExpCharacter"   childLayout="absolute" x="680px" y="87px"  width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
                <text id="textStrCharacter"   childLayout="absolute" x="630px" y="275px" width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
                <text id="textDexCharacter"   childLayout="absolute" x="630px" y="298px" width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
                <text id="textIntCharacter"   childLayout="absolute" x="720px" y="275px" width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
                <text id="textConCharacter"   childLayout="absolute" x="720px" y="298px" width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
                <text id="textStaCharacter"   childLayout="absolute" x="630px" y="325px" width="200px" color="#00FF99" style="nifty-label" text="-" textVAlign="top" textHAlign="left" visible="true"/>
    
                <image id="imgFaceCharacter"  childLayout="absolute" x="580px" y="42px" width="96px" height="96px" visible="true"/>
    
                <control id="btnExit" name="button" label="Sair" x="680px" y="557px" width="100px" height="25px" visible="true">
                  <interact onClick="exitGame()" />
                    <effect>
                        <onHover name="changeMouseCursor" id="hand"/>
                    </effect>              
                </control>
                <control id="btnConsole" name="button" label="Console" x="680px" y="457px" width="100px" height="25px" visible="true">
                    <effect>
                        <onHover name="changeMouseCursor" id="hand"/>
                        <onHover name="playSound" sound="credits"/>
                    </effect>              
                </control>
                <control id="tabsMsg" name="nifty-tabs" buttonWidth="100px" buttonHeight="25px" x="14px" y="436px" width="540px" height="155px" visible="true" visibleToMouse="true">
                    <control id="tabDefault" name="nifty-tab" caption="Padrão" childLayout="absolute" visible="true" visibleToMouse="true">
                        <control id="consoleDefault" name="nifty-console" lines="7" x="0px" y="0px" width="513px" height="112px" align="center" valign="center" visible="true" text="z" visibleToMouse="true" controller="game.gui.console.ConsoleController"/>
                        <interact onClick="onClickTabDefault()" />
                    </control>
                    <control id="tabGameChat" name="nifty-tab" caption="GameChat" childLayout="absolute" visible="true" visibleToMouse="true">
                        <control id="consoleGameChat" name="nifty-console" lines="7" x="0px" y="0px" width="513px" height="112px" align="center" valign="center" visible="true" backgroundImage="resources/parallaxes/Dragon_Wallpaper_by_malvs777.jpg" text="y" visibleToMouse="true" controller="game.gui.console.ConsoleController"/>
                        <interact onClick="onClickTabGameChat()" />
                    </control>
                    <control id="tabHelp" name="nifty-tab" caption="Ajuda" childLayout="absolute" visible="true" visibleToMouse="true">
                        <control id="consoleHelp" name="nifty-console" lines="7" x="0px" y="0px" width="513px" height="112px" align="center" valign="center" visible="true" backgroundImage="resources/parallaxes/Dragon_Wallpaper_by_malvs777.jpg" text="x" visibleToMouse="true" controller="game.gui.console.ConsoleController"/>
                        <interact onClick="onClickTabHelp()" />
                    </control>
                </control>
        </layer>
    
      </screen>
    </nifty>
    

    ConsoleController

    package game.gui.console;
    
    import java.util.Properties;
    
    import de.lessvoid.nifty.Nifty;
    import de.lessvoid.nifty.NiftyEventSubscriber;
    import de.lessvoid.nifty.controls.Console;
    import de.lessvoid.nifty.controls.ConsoleExecuteCommandEvent;
    import de.lessvoid.nifty.controls.Controller;
    import de.lessvoid.nifty.elements.Element;
    import de.lessvoid.nifty.input.NiftyInputEvent;
    import de.lessvoid.nifty.screen.Screen;
    import de.lessvoid.xml.xpp3.Attributes;
    
    public class ConsoleController implements Controller {
    
        private Screen screen;
        private Element element;
    
        @Override
        public void bind(Nifty nifty, Screen screen, Element element, Properties properties,
                Attributes attributes) {
            this.screen = screen;
            this.element=element;
            System.out.println("bind() called for element: " + element);
        }
    
        @Override
        public void init(Properties parameter, Attributes controlDefinitionAttributes) {
            System.out.println("init() called for element: " + element);
        }
    
        @Override
        public boolean inputEvent(NiftyInputEvent arg0) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void onFocus(boolean getFocus) {
            System.out.println("onFocus() called for element: " + element + ", with: " +
                    getFocus);
    
        }
    
        @Override
        public void onStartScreen() {
            System.out.println("onStartScreen() called for element: " + element);
    
        }
    
          @NiftyEventSubscriber(id="consoleGameChat")
          public void onConsoleCommand(final String id, final ConsoleExecuteCommandEvent command) {
            Console console = screen.findNiftyControl("consoleGameChat", Console.class);
            console.output("Voce digitou: " + command.getCommandLine() + " [" + command.getArgumentCount() + " parametro(s)]", de.lessvoid.nifty.tools.Color.BLACK);
            if ("exit".equals(command.getCommand())) {
              System.gc();
              System.exit(0);
            }
          }
    }
    

    In the method "initGameAndGUI" I call the code below and he always returns my System.out.println ("in the console exists");

            Console console = getNifty().getCurrentScreen().findNiftyControl("consoleHelp",Console.class);
            ConsoleCommand helpCommand = new HelpCommand(getNifty());
            if (console!=null){
                System.out.println("Console exist!");
            ConsoleCommands consoleCommands = new ConsoleCommands(getNifty(), console);
            consoleCommands.registerCommand("/m", helpCommand);
            consoleCommands.registerCommand("/h", helpCommand);
            consoleCommands.enableCommandCompletion(true);
            final Color HELP_COLOR = new Color("#aaaf");
            console.changeColors(HELP_COLOR, HELP_COLOR);
            } else {
                System.out.println("in the console exists!");
            }
    

    I may be oxml fills in the wrong way, but everything works out it ta, normal,
    until I realized that given time the console has been problematic, the
    interesting thing is that if I do the same thing via Java code, it works
    perfectly. What appears is: When you load the XML it lets you do some actions.

     
  • Another problem, when I use the code below, the controller spotting him, but
    he will not let me add text to the console and press Enter after typing.

    if I have three consoles, one in each tab, depending on where he put the code
    in the same effect fazo 3 Consoles or only 1 or 2, very weird.

    <control id="consoleHelp" name="nifty-console" lines="7" x="0px" y="0px" width="513px" height="112px" align="center" valign="center" visible="true" backgroundImage="resources/parallaxes/Dragon_Wallpaper_by_malvs777.jpg" text="x" visibleToMouse="true" controller="game.gui.console.ConsoleController"/>