firstMenu.cpp

00001 /*
00002   メニュー画面
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "firstMenu.h"
00008 #include "firstMenuUnicode.h"
00009 #include "nettyping.h"
00010 #include "practiceMenu.h"
00011 #include "networkMenu.h"
00012 #include "optionMenu.h"
00013 #include "userCreateScr.h"
00014 
00015 
00016 FirstMenu::FirstMenu(void)
00017   : version(NULL), title(NULL),
00018     practice_normal(NULL), network_normal(NULL),
00019     option_normal(NULL), create_normal(NULL), quit_normal(NULL),
00020     practice_focused(NULL), network_focused(NULL),
00021     option_focused(NULL), create_focused(NULL), quit_focused(NULL),
00022     practice_btn(NULL), network_btn(NULL), option_btn(NULL),
00023     create_btn(NULL), quit_btn(NULL), menu(NULL), users_cmb(NULL) {
00024 }
00025 
00026 
00027 FirstMenu::~FirstMenu(void) {
00028   deleteObject();
00029 }
00030 
00031 
00032 void FirstMenu::deleteObject(void) {
00033   delete practice_normal;
00034   delete network_normal;
00035   delete option_normal;
00036   delete create_normal;
00037   delete quit_normal;
00038   delete practice_focused;
00039   delete network_focused;
00040   delete option_focused;
00041   delete create_focused;
00042   delete quit_focused;
00043 
00044   delete version;
00045   delete title;
00046 }
00047 
00048 
00049 void FirstMenu::recreate(void) {
00050   win->lock();
00051   win->clear(ForeDepth);
00052   deleteObject();
00053   Initialize(0, NULL);
00054   win->unlock();
00055 }
00056 
00057 
00058 int FirstMenu::Initialize(int argc, char *argv[]) {
00059   win->clear(ForeDepth);
00060 
00061   // バージョン
00062   version = new DrawSurface(ttf->createText("version: " Version, 20,
00063                                             Fore, Back), true);
00064   win->add((new LabelComponent(version))
00065            ->setPosition(Grid(8, win->h -8), Bottom), ForeDepth);
00066 
00067   // タイトル文字
00068   title = new DrawSurface(ttf->createText(FirstMenu_title, TitleSize,
00069                                           Fore, Back), true);
00070   win->add((new LabelComponent(title))
00071            ->setPosition(Grid(win->w/2, 120), Middle | Center), ForeDepth);
00072 
00073   // メニュー
00074   practice_normal =
00075     new DrawSurface(ttf->createText(FirstMenu_practice, NormalSize,
00076                                     Normal, Back), true);
00077   network_normal =
00078     new DrawSurface(ttf->createText(FirstMenu_network, NormalSize,
00079                                     Normal, Back), true);
00080   option_normal = new DrawSurface(ttf->createText(FirstMenu_option, NormalSize,
00081                                                   Normal, Back), true);
00082   create_normal = new DrawSurface(ttf->createText(FirstMenu_create, NormalSize,
00083                                                   Normal, Back), true);
00084   quit_normal = new DrawSurface(ttf->createText(FirstMenu_quit, NormalSize,
00085                                                 Normal, Back), true);
00086 
00087   practice_focused =
00088     new DrawSurface(ttf->createText(FirstMenu_practice, NormalSize,
00089                                    Focused, Back), true);
00090   network_focused =
00091     new DrawSurface(ttf->createText(FirstMenu_network, NormalSize,
00092                                     Focused, Back), true);
00093   option_focused =
00094     new DrawSurface(ttf->createText(FirstMenu_option, NormalSize,
00095                                     Focused, Back), true);
00096   create_focused =
00097     new DrawSurface(ttf->createText(FirstMenu_create, NormalSize,
00098                                     Focused, Back), true);
00099   quit_focused = new DrawSurface(ttf->createText(FirstMenu_quit, NormalSize,
00100                                                  Focused, Back), true);
00101 
00102   practice_btn = new ButtonComponent(practice_normal);
00103   network_btn = new ButtonComponent(network_normal);
00104   option_btn = new ButtonComponent(option_normal);
00105   create_btn = new ButtonComponent(create_normal);
00106   quit_btn = new ButtonComponent(quit_normal);
00107   practice_btn->setFocusedSurface(practice_focused);
00108   network_btn->setFocusedSurface(network_focused);
00109   option_btn->setFocusedSurface(option_focused);
00110   create_btn->setFocusedSurface(create_focused);
00111   quit_btn->setFocusedSurface(quit_focused);
00112 
00113   menu = new MenuComponent();
00114   menu->add(practice_btn);
00115   menu->add(network_btn);
00116   menu->add(option_btn);
00117   menu->add(create_btn);
00118   menu->add(quit_btn);
00119   menu->setOffset(Rect(0, NormalSize + 8));
00120 
00121   menu->addIcon(new LabelComponent(icon));
00122   menu->setIconOffset(Rect(-icon->w -4, -(icon->h - NormalSize)/2));
00123   menu->activate(true);
00124   menu->setPosition(Grid(win->w/2 +16, win->h/2 -32), Center | Top);
00125   win->add(menu, ForeDepth);
00126 
00127   // ユーザ選択欄
00128   users_cmb = new ComboBoxComponent(*ttf);
00129   users_cmb->setColor(Black, Pink, White, Blue);
00130   for (std::vector<Property::userInfo_t>::iterator
00131          it = property->users.begin(); it != property->users.end(); ++it) {
00132     users_cmb->add(it->name.c_str());
00133   }
00134   users_cmb->setFontSize(SmallSize);
00135   users_cmb->activate(true);
00136   users_cmb->setNowIndex(property->sys.user_index);
00137   users_cmb->setPosition(Grid(win->w -16, 16), Right | Top);
00138   win->add(users_cmb, ForeDepth);
00139 
00140   return 0;
00141 }
00142 
00143 
00144 void FirstMenu::setFocus(bool menu_focused) {
00145   if (menu_focused) {
00146     users_cmb->endFocus();
00147     menu->beginFocus();
00148 
00149   } else {
00150     menu->endFocus();
00151     users_cmb->beginFocus();
00152   }
00153 }
00154 
00155 
00156 int FirstMenu::MainLoop(void) {
00157 
00158   bool menu_focused = true;
00159   bool quit = false;
00160   property->setUserIndex(users_cmb->getNowIndex());
00161   do {
00162     win->lock();
00163 
00164     // メニュー処理
00165     if (menu->isDecided()) {
00166       int index = menu->getNowIndex();
00167       win->unlock();
00168       if (index == 0) {
00169         // タイピング練習
00170         PracticeMenu practice;
00171         practice.run(0, NULL);
00172         recreate();
00173 
00174       } else if (index == 1) {
00175         // ネットワーク対戦
00176         NetworkMenu network;
00177         network.run(0, NULL);
00178         recreate();
00179 
00180       } else if (index == 2) {
00181         // オプション
00182         OptionMenu option;
00183         option.run(0, NULL);
00184         recreate();
00185 
00186       } else if (index == 3) {
00187         // ユーザ作成
00188         UserCreateScr userCreate;
00189         userCreate.run(0, NULL);
00190         recreate();
00191 
00192       } else if (index == 4) {
00193         // ゲームの終了
00194         quit = true;
00195       }
00196       win->lock();
00197     }
00198     UserInput::userInput_t ui = UserInput::getInputed();
00199 
00200     // フォーカス管理
00201     if (ui.isPressedCode(SDLK_TAB)) {
00202       menu_focused = !menu_focused;
00203       setFocus(menu_focused);
00204     }
00205 
00206     if (users_cmb->isDecided()) {
00207       property->setUserIndex(users_cmb->getNowIndex());
00208       menu_focused = true;
00209       setFocus(menu_focused);
00210     }
00211 
00212     if (ui.isPressedCode(SDLK_ESCAPE)) {
00213       if (menu_focused) {
00214         quit = true;
00215       } else {
00216         menu_focused = true;
00217         setFocus(menu_focused);
00218       }
00219     }
00220     quit |= ui.quit;
00221     win->unlock();
00222 
00223     SDL_Delay(10);
00224   } while (!quit);
00225 
00226   return 0;
00227 }
00228 

Generated on Mon Apr 13 22:52:03 2009 by  doxygen 1.5.7.1