Problem creating a chat Panel

Hello. It been a few day now since I start working on my chat panel but so far it realy don’t work out so well. The server part is complete but the window itself is pretty broken. I did try to google it to find information but still, all i can see is broken code and incomplet information everywhere. Plus for some reason all toneGod code available in the tutorial section is kinda outadated, even if you can see a realy good chat panel in the youtube demo. I did ask on youtube if the code was available anywhere but i don’t get any anwser there, one month after i ask.

I also did try to use the ScrollPanel of the ToneGod section but it work well only in one direction, from top to bot, while a chat should be from bot to top, and it start to bug real hard if you try anything.

So where should I go check? And why is there so many missing link and bad information in the tonegod section? I would like to help fill those hole but realy i don’t know how, or what i can do, but still, the offer is on the table.

I haven’t worked on a chat panel yet so can’t help you there. Maybe try find the post here where the person made the chat control and ask a question there with a “@nickname” so that person gets a mail.

I can provide some code for most of her controls if needed otherwise. Just ask if there’s a control you’re having problems with and I’ll see if I have code for it.

A rule I follow is to fill controls before adding them to their parent. Not sure if it is still needed but I know it works fine when I do it that way. For example, if I want to modify the content of a scroll, I detach it from it’s window and then detach the window from the screen, then fill/modify the scroll as needed then reattach it to the window and then reattach the window to the screen.

I loved using that lib. Support was great too… guess she’s having a lil break and hopefully will be back. Been refactoring my code + idling for months so haven’t used it for a while.
There are lots of example of code all over the place too.

I guess additional documentation would be helpful. No idea if everybody is granted the rights to add to the doc pages. But I’m sure someone would find a solution if needed.

Well if you could simply tell me whit what class should i work whit, i think i could do the job. Right now my problem is that the ScrollArea let the text get out of bound ( it continue to show up even if it get out of the box area) and the ScrollPanel only consider the scroling part if something is under im, not over im, meaning that if i try to put my text from bot to top it will ignore everything that get over the area.

I simply don’t know the method, the class and can’t find any good information on what and how. If I knew where to search i could take care of everything but as i said, i can’t find any good code exemple out there :confused:

I tried a simple chat and seems to work fine here.

[java]
import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapFont;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f;
import tonegod.gui.controls.buttons.ButtonAdapter;
import tonegod.gui.controls.scrolling.ScrollAreaAdapter;
import tonegod.gui.controls.text.Label;
import tonegod.gui.controls.windows.Window;
import tonegod.gui.core.Screen;

/**
*

  • @author jo
    */
    public class TestBasicChatControl extends SimpleApplication {
    private int lineNbr = -1;
    private final float LINE_HEIGHT = 25;

    private Screen screen;
    private Window window;
    private ScrollAreaAdapter area;

    public static void main(String[] args) {
    new TestBasicChatControl();
    }

    public TestBasicChatControl() {
    this.start();
    }

    @Override
    public void simpleInitApp() {
    getFlyByCamera().setEnabled(false);
    getInputManager().setCursorVisible(true);

     screen = new Screen(this);
     getGuiNode().addControl(screen);
     
     window = new Window(screen, "topWindow", new Vector2f(10, 10), new Vector2f(400, 400));
     
     area = new ScrollAreaAdapter(screen,
             "aScrollArea", new Vector2f(10, 30), new Vector2f(380, 210));
     
     window.addChild(area);
     screen.addElement(window);
     
     addLineButton();
    

    }

    private void addLineButton(){
    ButtonAdapter addLine = new ButtonAdapter(screen, “addLineButton”,
    new Vector2f(20, 250), new Vector2f(60, 30)){

         @Override
         public void onMouseLeftReleased(MouseButtonEvent evt) {
             addLineToChat("Line of text ");
         }
                 
     };
     addLine.setToolTipText("Press to add a line to chat");
     addLine.setTextAlign(BitmapFont.Align.Center);
     addLine.setText("Add");
     addLine.setIgnoreMouse(false);
     window.addChild(addLine);
    

    }

    private void addLineToChat(String text){
    float nextLineY = getNextLineY();
    Label label = new Label(screen, “line_” + lineNbr, new Vector2f(10, nextLineY), new Vector2f(340, 25));
    label.setText(text + lineNbr);
    area.addScrollableChild(label);
    area.scrollToBottom();
    }

    private float getNextLineY(){
    lineNbr++;
    return lineNbr * LINE_HEIGHT;
    }

}
[/java]

Wasn’t sure if still needed to go detach modify reattach, but seems at least the scrollArea doesn’t need that anymore.
The lib used to have problems with scrollable containers inserted into scrollable containers, but there was talk about it being taken care of, dunno if it totally was, and maybe that is giving you problems?

In case you didn’t find those links:
http://hub.jmonkeyengine.org/forum/topic/scroll-area-text-is-going-out-of-the-area/
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:contributions:tonegodgui
http://hub.jmonkeyengine.org/forum/topic/tonegodgui-documentation/

This code is working great, but not for what i need… I want the text to get from bot to top. I think you can underthand my problem whit that little piece of code :

[java]
import tonegod.gui.controls.scrolling.ScrollPanel;
import tonegod.gui.controls.text.Label;
import tonegod.gui.core.Screen;

import com.jme3.app.SimpleApplication ;
import com.jme3.math.Vector2f;

public class Main extends SimpleApplication
{

 public static void main(String[] args) {
	    Main app = new Main();
	    app.start();
	  }


@Override
public void simpleInitApp()
{
	
	
	
	flyCam.setEnabled(false);
	Screen screen = new Screen(this);
	guiNode.addControl(screen);
	
	
	float dockBHeight = 30;
	float width = screen.getWidth();
	float height = screen.getHeight();
	 
	final ScrollPanel dockP = new ScrollPanel(screen, "duckPanel", new Vector2f(width*0.8f, height*0.10f), new Vector2f(width*0.20f, height*0.85f));
	dockP.setIsMovable(false);
	dockP.setIsResizable(false);
	dockP.setUseVerticalWrap(false);
	dockP.setScrollSize(20f);
	dockP.getVerticalScrollBar().setDimensions(10, dockP.getHeight());
	
	int  test = -1 ;
	 test = 30 ; 
	 //test = -30 ; 
	// test = 1 ;
	
	 Vector2f size = new Vector2f(dockP.getWidth()-dockP.getVerticalScrollBar().getWidth(),dockBHeight) ; 
	


            //for (int i = test; i < 0; i++) {   // negatif test
	for (int i = test; i > 0; i--) {  // positif test 
	    Label tempB = new Label(screen, size);
	    tempB.setText(" Test  " + String.valueOf(i));
	
	   tempB.setPosition(0, dockP.getHeight() - (dockBHeight*i));
	   dockP.addScrollableContent(tempB);
	}
	
	

	screen.addElement(dockP);
	
	

	
}

}
[/java]

try the different combinaison of test and i think this showcase what i have been saying all the time. It won’t work from bot to top, but will from top to bot

or you could also take your getNextLine method and change the ++ per a – and see

[java]
private float getNextLineY(){
lineNbr–;
return lineNbr * LINE_HEIGHT;
}
[/java]

The code is never show and the scrooler never allows you to go up and look for it…

Well, chats usually are top to bottom, but if you need the other way round, this works:

[java]
private void addLineToChatTop(String text){
float nextLineY = getNextLineY();
Label label = new Label(screen, “line_” + lineNbr, new Vector2f(10, nextLineY), new Vector2f(340, 25));
label.setText(text + lineNbr);
area.addScrollableChild(label);

    for(int i = 0; i < lineNbr; i++){
        Label element = (Label)screen.getElementById("line_" + i);
        element.setPosition(10, i * LINE_HEIGHT);
    }
    label.setPosition(10, lineNbr * LINE_HEIGHT);
    
    area.scrollToTop();
}

[/java]

Some additional explanation: http://hub.jmonkeyengine.org/forum/topic/moving-elements-inside-parents-wrong/