Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members

charcreator.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #ifdef WIN32
00005 #include <windows.h>
00006 #else
00007 #include <unistd.h>
00008 #endif
00009 #include <math.h>
00010 #include <GL/glut.h>
00011 #include <plib/pu.h>
00012  
00013 #include "common_gui_funcs.h"
00014 #include "common_vars_gui.h"
00015 
00016 class charCreator {
00017   public:
00018     charCreator();
00019     ~charCreator();
00020     bool _inputvals_ok();
00021     puDialogBox* foo;
00022   private:
00023     void _display_screen();
00024     puButtonBox* nation_chooser;
00025     puButtonBox* gender_switch;
00026     puInput*     player_nick;
00027     puText*      description;    
00028 };
00029 
00030 charCreator* playerGen  = NULL;
00031 
00032 void kill_dialog(puObject* e) {
00033   playerGen->foo->hide();
00034   delete playerGen->foo;
00035   playerGen->foo = NULL;
00036 }
00037 
00038 void start_game_cb(puObject* o) {
00039   if (playerGen != NULL && playerGen->_inputvals_ok()) {
00040     printf("going playing\n");
00041      }
00042   else {
00043     playerGen->foo = new puDialogBox(10, 40);
00044    
00045       puFrame* dframe = new puFrame(0, display_height/2, display_width - 10, display_height/2 + 70);
00046       dframe->setLegend("invalid nickname or name already used...");
00047       puOneShot* killer = new puOneShot(display_width-100, display_height/2+20, "OK");  
00048       killer->makeReturnDefault(true);
00049       killer->setCallback(kill_dialog);
00050        playerGen->foo->close();
00051       playerGen->foo->reveal();
00052   }
00053 }
00054 
00055 void remove_char_creator (puObject* o) {
00056   total_menu->hide();
00057   if (playerGen != NULL);
00058   delete playerGen;
00059   total_menu = NULL;
00060   playerGen = NULL;
00061   _make_main_menu(NULL);
00062 }
00063 
00064 void make_char_creator (puObject* o) {
00065   remove_char_creator(NULL);
00066   playerGen = new charCreator();
00067 }
00068 
00069 bool charCreator::_inputvals_ok() {
00070   char s[80];
00071   if (player_nick == NULL)
00072     return false;
00073   player_nick->getValue((char*)&s);
00074   if (strlen((const char*)&s) > 0)
00075     return true;
00076   return false;
00077 }
00078 
00079 charCreator::charCreator() {
00080   _display_screen();
00081 }
00082 
00083 charCreator::~charCreator() {
00084   _clear_total_menu();
00085 }
00086 
00087 void charCreator::_display_screen() {
00088   _clear_total_menu();
00089   total_menu = new puGroup(0,0);
00090   puFrame* top_frame = new puFrame(10, display_height-10,
00091       display_width - 10, display_height - 30);
00092   top_frame->setLegend("character creation");
00093   top_frame->setColour(PUCOL_FOREGROUND, 0.2, 0.5, 0.9, 1.0);
00094 
00095   puFrame* t1 = new puFrame(30, 50,
00096       display_width - 30 , display_height - 50);
00097   puGroup* p1 = new puGroup(30, display_height - 220);
00098   static char* nations_strings[] = {"english", "dutch", "french", "spanish", NULL};
00099   nation_chooser = new puButtonBox(10, 0, 140, 130, nations_strings, 1);
00100   nation_chooser->setLabel("choose your nationality");
00101   nation_chooser->setLabelPlace(PUPLACE_TOP_LEFT);
00102   p1->close();
00103   p1->setChildColourScheme(PUCLASS_BUTTONBOX, 0.3, 0.6, 0.7, 0.8);
00104   p1->setChildStyle(PUCLASS_BUTTONBOX, PUSTYLE_NONE,0);
00105   
00106   puGroup* p2 = new puGroup(30, display_height - 320); 
00107   static char* gender_str[] = {"male", "female", NULL};
00108   gender_switch = new puButtonBox(10, 0, 110, 70, gender_str, 1);
00109   gender_switch->setLabel("choose your gender");
00110   gender_switch->setLabelPlace(PUPLACE_TOP_LEFT);
00111   p2->close();
00112   p2->setChildColourScheme(PUCLASS_BUTTONBOX, 0.3, 0.6, 0.7, 0.8);
00113   p2->setChildStyle(PUCLASS_BUTTONBOX, PUSTYLE_NONE, 0);
00114 
00115   puGroup* p3 = new puGroup(30, display_height - 420);
00116   player_nick = new puInput(10, 0, 220, 30);
00117   player_nick->setLabel("enter a nickname (no spaces, nothing funny;-)");
00118   player_nick->setLabelPlace(PUPLACE_TOP_LEFT);  
00119   player_nick->setValidData("0123456789abcdefghijklmnopqrstuvwxzy_-ABCDEFGHIJKLMNOPQRSTUVWXZY");
00120   p3->close();
00121   p3->setChildColourScheme(PUCLASS_BUTTONBOX|PUCLASS_INPUT, 0.3, 0.6, 0.7, 0.8);
00122   p3->setChildStyle(PUCLASS_BUTTONBOX|PUCLASS_INPUT, PUSTYLE_NONE, 0);
00123 
00124   puButton* cancel_button = new puButton(10, 10, "main menu");
00125   cancel_button->setCallback(remove_char_creator);
00126 
00127   puButton* go_button = new puButton(200, 10, "go adventuring");
00128   go_button->setCallback(start_game_cb);
00129   total_menu->close();
00130   total_menu->setChildColourScheme(PUCLASS_BUTTON, 0.3, 0.6, 0.7, 0.8);
00131 }
00132 

Generated on Sat Jul 12 04:29:20 2003 for glPirates by doxygen 1.3.2