Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  lwjgl,slick, slick-util. Chat box/dialogue box  (Read 976 times)
0 Members and 1 Guest are viewing this topic.
Offline vastrolorde

Junior Devvie





« Posted 2014-03-16 10:49:10 »

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.
Offline trollwarrior1
« Reply #1 - Posted 2014-03-16 11:07:57 »



9 patch.
Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #2 - Posted 2014-03-16 12:18:08 »

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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline vastrolorde

Junior Devvie





« Reply #3 - Posted 2014-03-16 13:49:04 »

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.
Online BurntPizza

« JGO Bitwise Duke »


Medals: 291
Exp: 5 years



« Reply #4 - Posted 2014-03-17 21:22:04 »

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

Quote from: Google
Nine Patch
Nine Patch is an image format that adds extra information into a normal image file to define which part of it should be scaled when the image is used in a size larger than its original size. The technique in using this format is also implemented in the core of the Android OS.

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.
Offline vastrolorde

Junior Devvie





« Reply #5 - Posted 2014-03-29 10:31:17 »

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.
Offline trollwarrior1
« Reply #6 - Posted 2014-03-29 10:34:32 »

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
   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;

   }
Offline vastrolorde

Junior Devvie





« Reply #7 - Posted 2014-03-30 10:10:58 »

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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
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
1  
2  
3  
4  
5  
6  
7  
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?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!