NewClientForZMUohMy.html
05sep09 CmdrZin
15oct09

This is a log of what I went through to develop a client for Zombies, Mutants, and Undead oh My (ZMUohMy).
The project that it is based on is in Subversion at:
    https://darkmud-redux.dev.java.net/svn/darkmud-redux/trunk/NetBeans/WebStartClient/ZMUohMyNB/ZMUohMyClient

The first thing to do is to specify what additional features the Client would need to support ZMUohMy.
Start by taking a screen shot of the current DarkMud-Redux client and print it out to use as a reference.

Client Design Requirements

The GUI has three main areas: a text area, a text line, and a status line. These are also major components needed by ZMUohMy.
Since the game add player statistics (stats), skills, assingments (quests), and a more extensive inventory, the decision was to add a side panel with scrolling list (combo boxes) to manage this information. Using scrolling list allow the user to get more information about a selected item.
So, the modification will consist of widening the frame and adding a panel to the right of the text area.
A status line (Name, class, level, etc.) will be at the top with info boxes below for each of the player imformation sections. If this looks too sparce, an list of online players, with scroll bars, could be added at the bottom.

Time to go to the source code to find out how the current Client GUI is generated. MudClient.java generates the GUI in its constructor.

MudClient Constructor

Since MudClient extends JFrame, the first thig it does is call its parent and pass in the title text for the Frame.
MudClient.java
    Change the title text from "DarkMUD Client" to "Zombies, Mutants, and Undead oh My! Client".

The next thing it does is call initComponents() to build the GUI parts.
This method calls createArea() to setup the maim text area with scroll bars. This area is set to 550w x 400h. The area is then passed to a JScrollPane object scroll to managed as a scrollable text area.
The method then sets up two Box objects. Boxes are containers like JPanel, but default to BoxLayout for flow control. These will be used to manage the positioning of user text input field and status line near the bottom of the GUI.
Next, createLable() is called to build up various commonly used text lables.
Then, createTextBoxes() is called to build a used input text field txtInput and set up an ActionListener for it.
Then, createBoxes() is used to add components to the two Box objects previously instantiated.
Finally, it generates a new JPanel and adds the scroll, box1, and box2 components to it and sets up a border.

Adding New Stuff

Now that the construction process is known, new components can be add following the basic design of the original GUI.
The new components will all be grouped in the new right side panel and aligned vertically. A JPanel with FlowLayout will be used to allow control of the size of each component. Padding can be used to better align things. All of the new stuff will be in a new class called ClientInfo.java that will basically be a stand alone panel that the server can write to and the user can querry.
The JPanel that this class manages will be placed to the right of the scroll/textPane.
Pass the DefaultListModels objects to the ClientInfo object rightBox so that it can update the lists.

ClientInfo class

This class returns a JPanel like object for the MudClient GUI to dsplay. The MudClient passes any INFO message types to this class for processing. INFO is a new message type that is added to the Flags enum list. This also has to match up with the server's list of message types.

First, a new Box is made to hold both the scroll object and the new panel called boxRight.
A new method is added call createUserInfoBoxes to build up all of the new components. There is a multipart JLabel for the name, class, and level info and four JLabels and their associated JScrollPane/JTextPanels; one for each of the info areas.
Four new EventHandlers will also be needed and the message handler will need to be adjusted to support new info messages from the server.

ClientInfor.parse()

This method is used to parse the message from the Server that has lists or other list relative information.
At this stage, only a list message parser is needed and the test string will be used as a sample message.
From MyFirstManagedObject.html, the test string is
    "@Health,100|Strength,23#Lock Pick,2"
and uses an @ character to act as a start token, a | to seperate pairs, and a # character to seperate the lists. Since the contents are all String, Integer pairs (comma delimited), parsing the message should be no problem. The message is a String object, so time to learn how to manipulate Strings and Tokens.
An excellent reference book is Joel Fan's "Black Art of Java Game Programming". When you need basic stuff, this is the book to have due to its well done Index and useful code examples even if it was made in 1996. The StringTokenizer class (which is what is needed) isn't even mentioned in the Sun's "Core Java" books and it was a long hunt to find even a referece to split. StringTokenizer has been replace by String.split() method (per a note in the API) as of 1.4, so it will be used.

The code design will be:
1. Remove the leading @ character from the message.
2. Copy everything before the # into a temp String.
3. Send the temp to the list parser.
4. Repeat for each of the four lists or until no more tokens.
(see code in ClientInfo.java for details)

Debug
Almost works..only Stats show up..parser doesn't see the second list..had to add delimiter to end of last list pair
Also had to add this.validate() after updateing the lists to get all of them to show up.
New test string set up in MudUser.java
  command.addOutput("@00");
  command.addOutput("Health,100|Strength,23#");
  command.addOutput("Lock Pick,2|Perception,3#");
  command.addOutput("9mm Pistol,1|First Aid Kits,1#");
  command.addOutput("None,0#");
makes
  "@Health,100|Strength,23#Lock Pick,2|Perception,3#9mm Pistol,1|First Aid Kits,1#None,0#"
Info shows up in lists, but every time "info" is sent, the same items are added to the lists again..need to stop duplicatons.
Simple to do a .removeAll before adding anything to the list since these are complete list updates anyway.

Additional
Added a message type of two digits after the @ character. This will be used to further parse infomation messages when a
list element is selected.
In MudMain.java.loggedIn(), added a send "info" message after login welcome.

Now that the message format is setup and message passing is inplace a new document will look at supporting the list message content. (see InfoListsContentControl.html)

15oct09 Update
Moving Specialty down under name. Adding a label for experience. Adding a setName method.
Adding a message type 01 for sending Experience to Client. Level is based on experience.
Adding type 02 message to change Profession/Specialty

MudClient.java

Change createBoxes
    JLabel test01 replace with a global JLabel nameLabel
    Add global JLabel specLabel and set to "Agent" + level = 1
    Add global JLabel experienceLabel and set to 0

Add setNameLabel( )
Add updateExperience( )
Add setProfession( )

Change loggedIn()
    Add call to setNameLabel()

ClientInfo.java

Change parse()
    Add "01" test and call MudClient.updateExperience() if found.
    Add "02" test and call MudClient.setProfession() if found.

Use "info" and MudUser.processInfoCommand() to test "01" and "02" messages. This was left over from earlier changes.

All looks ok..back to the server.