It is currently Fri Dec 15, 2017 12:25 am

All times are UTC + 9:30 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Gui Menu separation
PostPosted: Sat Jan 03, 2009 10:30 am 
Offline
Main Coder

Joined: Fri Apr 04, 2008 10:50 pm
Posts: 169
The MainMenu.java class is too big, it not only controls every menu but also input for all these menus.
+ it takes a while to load the whole file when doing a diff on google code.

I think it would be better to separate each menu in it's own JPanel class like:
MainMenu
CoSelectMenu
MapSelectMenu
etc...

they can have their own key/mouse input by passing a reference to the JFrame.

the menuSession class can then handle requests to move to another 'state' ie
Code:
if (newGame) {
logger.info("Moving into the New Game Menu");
menuSession.setState("NEW_GAME");
}


menuSession would then
remove all listeners
remove all panels
from the JFrame
and
add the newGameMenu JPanel

With any new framework in mind having a separate class would make it easier to integrate gui components.
It would be best to handle this menu/menu in a separate package? branch? as the impact is very big...
I already separated the main menu in another package, not yet committed. Do I have a green light?


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Sat Jan 03, 2009 9:52 pm 
Offline
User avatar

Joined: Tue Oct 28, 2008 8:51 am
Posts: 121
When you say the impact is very big everything still works as it did yes?
If so then cool improvements are to be encouraged. I have only been refactoring the bits which concern the bug which I am working on. I didn't want to start cleaning up the main menu class because it was such a big job. If you've made it easier to work with then that is surely good!


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Sat Jan 03, 2009 10:01 pm 
Offline
Main Coder

Joined: Fri Apr 04, 2008 10:50 pm
Posts: 169
yes, I meant by big impact that I will have to spawn a class of 4 extra
and that It won't happen overnight. I'll create a new package menus and start from there.
First I'll copy each menu into a new class and test it with it's own main, later they can be connected to each other.


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Sat Jan 03, 2009 11:48 pm 
Offline
User avatar

Joined: Tue Oct 28, 2008 8:51 am
Posts: 121
Maybe I have mistakenly read your last post but do not start them over anew. If you are not refactoring them into individual elements don't separate them. Work with what we have got down. If you start a new you are just introducing new problems rather than refining the code.If you have already finished achieving the exact functionality of the existing menus then by all means go ahead and commit. Otherwise refactor them down slowly until you achieve a more desirable design.


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Sun Jan 04, 2009 8:30 am 
Offline
Main Coder

Joined: Fri Apr 04, 2008 10:50 pm
Posts: 169
No worries, I just copy the paint functions, and then look up the input handling for that menu and copy that over as well.
then I test with old/new next to each other.

start refactoring paints functions, make constants for Color, Font
refactoring input so it is generic, remove action functions and replace with menuSession.setState("NEW_STATE")

Nice job on the range checks in MainMenu.java that must of been a time consumer!
I'll commit the first 2 menus so you can see, it's in the menus package, menu was taken :D
I'm not going to debug #24 anymore instead the smaller gui s will eventually replace it.


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Sun Jan 04, 2009 10:46 pm 
Offline
User avatar

Joined: Tue Oct 28, 2008 8:51 am
Posts: 121
I haven't actually checked that it works but it does look a lot smaller! Just stick them in menu rather than menus and menu!


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Sat Jan 10, 2009 10:54 am 
Offline
Main Coder

Joined: Fri Apr 04, 2008 10:50 pm
Posts: 169
All menus have been ported to their own classes. MainMenu will be removed.
todo:
coselect needs better logic
snailGame has been removed from map selecting menu it should probably be somewhere else, I don't know where thought.
This is optional right?
Full code:
Code:
         // New Snail Mode Game
         if (Options.snailGame) {
            sess.setIsCOselectScreen(false);
            sess.setIsSnailInfoScreen(true);
            sess.setCurrentlyHighlightedItem(0);
            sess.setCurrentlyHighlightedItem2(0);

            String comment = JOptionPane.showInputDialog("Type in a comment for your game");

            // get army that the player wants to join
            int joinnum = -1;
            while (joinnum < 1 || joinnum > sess.getNumOfArmiesOnMap()) {
               String t = JOptionPane.showInputDialog("What side do you want to join? Pick from 1-" + sess.getNumOfArmiesOnMap());
               if (t == null) {
                  Options.snailGame = false;
                  sess.setIsMapSelectScreen(false);
                  sess.setIsTitleScreen(true);
                  return;
               }
               joinnum = Integer.parseInt(t);
            }

            // register new game
            String command = "newgame";
            String extra = Options.gamename + "\n" + Options.masterpass + "\n" + sess.getNumOfArmiesOnMap() + "\n" + Options.version + "\n" + comment + "\n" + mapName + "\n"
                  + Options.username;
            String reply = null;

            try {
               reply = networkingManager.sendCommandToMain(command, extra);
            } catch (MalformedURLException e1) {
               logger.info("Bad URL " + Options.getServerName());
               JOptionPane.showMessageDialog(this, "Bad URL: " + Options.getServerName());
            } catch (IOException e2) {
               logger.error("Connection Problem during command " + command + " with information:\n" + extra);
               JOptionPane.showMessageDialog(this, "Connection Problem during command " + command + " with the following information:\n" + extra);
            }

            while (!reply.equals("game created")) {
               logger.info(reply);
               if (reply.equals("no")) {
                  logger.info("Game name taken");
                  JOptionPane.showMessageDialog(this, "Game name taken");
                  Options.gamename = JOptionPane.showInputDialog("Type in a new name for your game");
                  if (Options.gamename == null) {
                     return;
                  }

                  command = "newgame";
                  extra = Options.gamename + "\n" + Options.masterpass + "\n" + sess.getNumOfArmiesOnMap() + "\n" + Options.version + "\n" + comment + "\n" + mapName + "\n"
                        + Options.username;
                  try {
                     reply = networkingManager.sendCommandToMain(command, extra);
                  } catch (MalformedURLException e1) {
                     logger.info("Bad URL " + Options.getServerName());
                     JOptionPane.showMessageDialog(this, "Bad URL: " + Options.getServerName());
                  } catch (IOException e2) {
                     logger.error("Connection Problem during command " + command + " with information:\n" + extra);
                     JOptionPane.showMessageDialog(this, "Connection Problem during command " + command + " with the following information:\n" + extra);
                  }

               } else {
                  Options.snailGame = false;
                  sess.setIsMapSelectScreen(false);
                  sess.setIsTitleScreen(true);
                  return;
               }
            }

            // upload map
            String script = "umap.pl";
            extra = Options.gamename;
            String file = sess.getFilename();

            try {
               String temp = networkingManager.sendFile(script, extra, file);
               logger.info(temp);
            } catch (MalformedURLException e1) {
               logger.info("Bad URL " + Options.getServerName());
               JOptionPane.showMessageDialog(this, "Bad URL: " + Options.getServerName());
            } catch (IOException e2) {
               logger.error("Connection Problem during command " + command + " with information:\n" + extra);
               JOptionPane.showMessageDialog(this, "Connection Problem during command " + command + " with the following information:\n" + extra);
            }

            // Join Game
            extra = Options.gamename + "\n" + Options.masterpass + "\n" + Options.username + "\n" + Options.password + "\n" + joinnum + "\n" + Options.version;
            command = "join";

            try {
               reply = networkingManager.sendCommandToMain(command, extra);
            } catch (MalformedURLException e1) {
               logger.info("Bad URL " + Options.getServerName());
               JOptionPane.showMessageDialog(this, "Bad URL: " + Options.getServerName());
            } catch (IOException e2) {
               logger.error("Connection Problem during command " + command + " with information:\n" + extra);
               JOptionPane.showMessageDialog(this, "Connection Problem during command " + command + " with the following information:\n" + extra);
            }

            logger.info(reply);
            refreshInfo();
            return;
         }


is Snail Mode the mode in which you play online? or 2 players compete against each other?


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Tue Jan 13, 2009 2:36 am 
Offline
User avatar

Joined: Thu Jun 22, 2006 3:25 am
Posts: 3233
It was terminology invented to explain how the games work.

Snail Mode: Essentially a play by post mode, this is how CW currently works. The completed turn is mailed to your opponent/the server and they then retrieve it and play their turn and send it to the next person.

Lightning Mode: This was intended to be included during development, but basically it was a mimic of the Link-Play modes of the AW games where you can see the actions updated in realtime.

_________________
Deoxy wrote:
Xen watches us all go about our daily lives with his finger floating above the "Destroy everything" button.

Mooglegunner wrote:
Seriously, if there's an American in College who isn't on when you are, they're not working hard enough, or Liberal Arts Majors.


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Tue Jan 13, 2009 9:15 pm 
Offline
Main Coder

Joined: Fri Apr 04, 2008 10:50 pm
Posts: 169
Thanks for the explanation Xenesis
I haven't been able to play a snail game yet, Maybe i'm doing something wrong?
I created a game and chom_chom joined all went well, we could chat but when I hit play we never get into the game.
instead I get an error msg:
#see http://code.google.com/p/customwars/issues/detail?id=32

Could you login and see if you can play?
gameName:blaat
playerName:stef
playerPass:p

I need a working server game so I can test the separated network menus.
another quick question what is a masterPassword for? is it like admin login that can change the game on the server?


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Tue Jan 13, 2009 10:37 pm 
Offline
User avatar

Joined: Thu Jun 22, 2006 3:25 am
Posts: 3233
Uh, which version of CW is that game? I guess I can give it a shot though.

Master password is a password that you set so that only people who know the p/w can join the game - eg, for private games.

_________________
Deoxy wrote:
Xen watches us all go about our daily lives with his finger floating above the "Destroy everything" button.

Mooglegunner wrote:
Seriously, if there's an American in College who isn't on when you are, they're not working hard enough, or Liberal Arts Majors.


Top
 Profile  
 
 Post subject: Re: Gui Menu separation
PostPosted: Sat Jan 24, 2009 12:45 am 
Offline
Main Coder

Joined: Fri Apr 04, 2008 10:50 pm
Posts: 169
Xenesis wrote:
Uh, which version of CW is that game? I guess I can give it a shot though..

latest from svn.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 9:30 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Blue Moon by Trent © 2007
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group