networkMenu.cpp

00001 /*
00002   ネットワーク対戦メニュー
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "networkMenu.h"
00008 #include "networkMenuUnicode.h"
00009 #include "nettyping.h"
00010 #include "firstMenuUnicode.h"
00011 #include "serverActivate.h"
00012 #include "connectScr.h"
00013 
00014 
00015 NetworkMenu::NetworkMenu(void)
00016   : title(NULL), user_name(NULL),
00017     connect_normal(NULL), run_normal(NULL),
00018     replay_normal(NULL), back_normal(NULL),
00019     connect_focused(NULL), run_focused(NULL),
00020     replay_focused(NULL), back_focused(NULL) {
00021 }
00022 
00023 
00024 NetworkMenu::~NetworkMenu(void) {
00025   deleteObject();
00026 }
00027 
00028 
00029 void NetworkMenu::deleteObject(void) {
00030   delete connect_normal;
00031   delete run_normal;
00032   delete replay_normal;
00033   delete back_normal;
00034   delete connect_focused;
00035   delete run_focused;
00036   delete replay_focused;
00037   delete back_focused;
00038 
00039   delete user_name;
00040   delete title;
00041 }
00042 
00043 
00044 void NetworkMenu::recreate(void) {
00045   win->lock();
00046   win->clear(ForeDepth);
00047   deleteObject();
00048   Initialize(0, NULL);
00049   win->unlock();
00050 }
00051 
00052 
00053 int NetworkMenu::Initialize(int argc, char *argv[]) {
00054   win->clear(ForeDepth);
00055 
00056   // タイトル文字
00057   title = new DrawSurface(ttf->createText(FirstMenu_title, TitleSize,
00058                                          Fore, Back), true);
00059   win->add((new LabelComponent(title))
00060            ->setPosition(Grid(win->w/2, 120), Middle | Center), ForeDepth);
00061 
00062   // メニュー
00063   connect_normal =
00064     new DrawSurface(ttf->createText(NetworkMenu_connect, NormalSize,
00065                                     Normal, Back), true);
00066   run_normal = new DrawSurface(ttf->createText(NetworkMenu_run, NormalSize,
00067                                                Normal, Back), true);
00068   replay_normal =
00069     new DrawSurface(ttf->createText(NetworkMenu_replay, NormalSize,
00070                                     Normal, Back), true);
00071   back_normal = new DrawSurface(ttf->createText(NetworkMenu_back, NormalSize,
00072                                                 Normal, Back), true);
00073   connect_focused =
00074     new DrawSurface(ttf->createText(NetworkMenu_connect, NormalSize,
00075                                     Focused, Back), true);
00076   run_focused = new DrawSurface(ttf->createText(NetworkMenu_run, NormalSize,
00077                                                 Focused, Back), true);
00078   replay_focused =
00079     new DrawSurface(ttf->createText(NetworkMenu_replay, NormalSize,
00080                                     Focused, Back), true);
00081   back_focused = new DrawSurface(ttf->createText(NetworkMenu_back, NormalSize,
00082                                                  Focused, Back), true);
00083 
00084   connect_btn = new ButtonComponent(connect_normal);
00085   run_btn = new ButtonComponent(run_normal);
00086   replay_btn = new ButtonComponent(replay_normal);
00087   back_btn = new ButtonComponent(back_normal);
00088   connect_btn->setFocusedSurface(connect_focused);
00089   run_btn->setFocusedSurface(run_focused);
00090   replay_btn->setFocusedSurface(replay_focused);
00091   back_btn->setFocusedSurface(back_focused);
00092 
00093   menu = new MenuComponent();
00094   menu->add(connect_btn);
00095   menu->add(run_btn);
00096   menu->add(replay_btn);
00097   menu->add(back_btn);
00098   menu->setOffset(Rect(0, NormalSize + 8));
00099 
00100   menu->addIcon(new LabelComponent(icon));
00101   menu->setIconOffset(Rect(-icon->w -4, -(icon->h - NormalSize)/2));
00102   menu->activate(true);
00103   menu->setPosition(Grid(win->w/2 +16, win->h/2 -32), Center | Top);
00104   win->add(menu, ForeDepth);
00105 
00106   // 選択ユーザ名
00107   if (property->user) {
00108     user_name =
00109       new DrawSurface(ttf->createText(property->user->name.c_str(), SmallSize,
00110                                       Black, Back), true);
00111     win->add((new LabelComponent(user_name))
00112              ->setPosition(Grid(win->w -16, 16), Right | Top), ForeDepth);
00113   }
00114 
00115   return 0;
00116 }
00117 
00118 
00119 int NetworkMenu::MainLoop(void) {
00120 
00121   bool quit = false;
00122   do {
00123     win->lock();
00124     if (menu->isDecided()) {
00125       int index = menu->getNowIndex();
00126       win->unlock();
00127       if (index == 0) {
00128         // 接続
00129         ConnectScr connect;
00130         connect.run(0, NULL);
00131         recreate();
00132 
00133       } else if (index == 1) {
00134         // サーバ起動
00135         ServerActivate server;
00136         server.run(0, NULL);
00137         recreate();
00138 
00139       } else if (index == 2) {
00140         // 対戦リプレイ
00141         // !!!
00142         recreate();
00143 
00144       } else if (index == 3) {
00145         // 戻る
00146         quit = true;
00147       }
00148       win->lock();
00149     }
00150 
00151     UserInput::userInput_t ui = UserInput::getInputed();
00152     quit |= ui.quit | ui.isPressedCode(SDLK_ESCAPE);
00153     win->unlock();
00154 
00155     SDL_Delay(10);
00156   } while (!quit);
00157 
00158   return 0;
00159 }
00160 

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