lwjgl,slick, slick-util. Chat box/dialogue box

How to make a chat box/ dialogue box where you can display messages, and objectives and stuff like that? Anyone knows how to make it or could anyone point me to a page that teaches the basics of this kind of stuff.

9 patch.

Any sentence that starts with “How to” is not a real sentence. If you want answers maybe you should put time into actually writing your question.

In many MMO-s there is that mission log or objective log. You know that thing that shows your current objectives and stuff on screen, Built into HUD. Something like the image trollwarrior1 posted. but the code behind it. I could just draw a rectangle and just cover it with drawStrings. But that will not be very dynamic if the text varies in length. Is there a better way to do it or i need to mess with drawStrings and somekind of controller that sees how long the text is and according to that gives the amount of drawstring calls?

Im not very good at describing what it is that i want.

Although it was brief and a bit subtle, trollwarrior said: “9 patch”

If you google “lwjgl ninepatch” or “slick2d ninepatch” or some variant of those queries, you will have an answer.

Also libGDX has a nice implementation, and tooling for generating them via a GUI.

Hmm… it seems lwjgl doesent have ninepatch support built in and i couldnt find any libaries for it. I think i can do whidout it. Ill just have a fixed texture of the backround. But i need to format the text somehow. So that it wouldnt go out of the bounds.

I made this utility class that cuts up the string you give it into pieces of maximum length at spaces. Just try and see what it does, you will understand. Returned strings won’t be longer than maximum specified length.


	public static String[] cutSpace(String str, int size) {

		// str += " ";

		char[] chars = str.toCharArray();
		char[] output = new char[8192]; // any length here.. You probably need to adjust this depending on input string length

		int ilast = 0;
		int max = size;
		int offset = 0;

		for (int i = 0; i < chars.length; i++) {
			char ch = chars[i];

			if (ch == ' ') {
				int length = i - ilast;

				if (i + offset > max) {
					offset += (max - (ilast + offset));
					max += size;
				}

				for (int ii = 0; ii < length; ii++) {
					output[ilast + ii + offset] = chars[ilast + ii];
				}

				ilast = i;
			}
		}

		String[] strs = new String[max / (size)];
		for (int i = 0; i < strs.length; i++) {
			char[] arr = new char[size];

			int off = 0;// offset
			for (int ii = 0; ii < arr.length; ii++) {
				if (output[ii + i * size] == ' ' && ii == 0) off += 1;
				char ch = output[ii + i * size + off];
				if ((int) ch == 0) ch = ' ';
				arr[ii] = ch;
			}

			strs[i] = new String(arr);
		}

		return strs;

	}

I read through and understood what the code does. And i saw that there is a part that could be done differently. The value of max could have been calculated with simple maths instead of a loop.

for (int i = 0; i < chars.length; i++) {
         char ch = chars[i];

         if (ch == ' ') {
            int length = i - ilast;

            if (i + offset > max) {
               offset += (max - (ilast + offset));
               max += size;
            }

            for (int ii = 0; ii < length; ii++) {
               output[ilast + ii + offset] = chars[ilast + ii];
            }

            ilast = i;
         }
      }

I would change this part into

if(chars.lenght%size != 0)
{
max = chars.lenght // size + 1;
}
else{
max = chars.length // size;
}

Wouldnt this be more efficient? Or is there a reason why you decided to use the loop?