optionMenu.cpp

00001 /*
00002   オプション設定
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "optionMenu.h"
00008 #include "firstMenuUnicode.h"
00009 #include "optionMenuUnicode.h"
00010 
00011 
00012 OptionMenu::OptionMenu(void)
00013   : title(NULL), user_name(NULL), normal_icon(NULL), rank_text(NULL),
00014     options(NULL), rank_web(NULL) {
00015 }
00016 
00017 
00018 OptionMenu::~OptionMenu(void) {
00019   deleteObject();
00020 }
00021 
00022 
00023 void OptionMenu::deleteObject(void) {
00024   delete user_name;
00025   delete title;
00026   delete normal_icon;
00027   delete rank_text;
00028 }
00029 
00030 
00031 void OptionMenu::recreate(void) {
00032   win->lock();
00033   win->clear(ForeDepth);
00034   deleteObject();
00035   Initialize(0, NULL);
00036   win->unlock();
00037 }
00038 
00039 
00040 int OptionMenu::Initialize(int argc, char *argv[]) {
00041   win->clear(ForeDepth);
00042 
00043   // タイトル文字
00044   title = new DrawSurface(ttf->createText(OptionMenu_title, NormalSize,
00045                                           Fore, Back), true);
00046   win->add((new LabelComponent(title))
00047            ->setPosition(Grid(win->w/2, 60), Middle | Center), ForeDepth);
00048 
00049   // 選択ユーザ名
00050   if (property->user) {
00051     user_name =
00052       new DrawSurface(ttf->createText(property->user->name.c_str(), SmallSize,
00053                                       Black, Back), true);
00054     win->add((new LabelComponent(user_name))
00055              ->setPosition(Grid(win->w -16, 16), Right | Top), ForeDepth);
00056   }
00057 
00058   // オプション項目
00059   options = new OptionComponent(*ttf, SmallSize, new LabelComponent(icon));
00060   options->setBaseOffset(Grid(0, NormalSize/2));
00061   OptionComponent::optionLine* row;
00062 
00063   Grid base_offset(TitleSize, 0);
00064   row = new OptionComponent::optionLine(base_offset);
00065 
00066   // 変換方法
00067   row = new OptionComponent::optionLine(base_offset);
00068   row->setTitle(OptionMenu_Convert);
00069   row->addItem(OptionMenu_Roman);
00070   row->addItem(OptionMenu_Kana);
00071   options->lines.push_back(row);
00072 
00073   // 自動改ページ
00074   row = new OptionComponent::optionLine(base_offset);
00075   row->setTitle(OptionMenu_AutoNext);
00076   row->addItem(OptionMenu_Do);
00077   row->addItem(OptionMenu_Not);
00078   options->lines.push_back(row);
00079 
00080   // 覚えよう表示
00081   row = new OptionComponent::optionLine(base_offset);
00082   row->setTitle(OptionMenu_Beginner);
00083   row->addItem(OptionMenu_Use);
00084   row->addItem(OptionMenu_NoUse);
00085   options->lines.push_back(row);
00086 
00087   // スコアのランキング登録
00088   row = new OptionComponent::optionLine(base_offset);
00089   row->setTitle(OptionMenu_Ranking);
00090   row->addItem(OptionMenu_Do);
00091   row->addItem(OptionMenu_Not);
00092   options->lines.push_back(row);
00093 
00094   // 戻る
00095   row = new OptionComponent::optionLine(base_offset);
00096   row->addItem(OptionMenu_Back);
00097   options->lines.push_back(row);
00098 
00099   options->setColor(Fore, Back);
00100   options->activate();
00101   options->setPosition(Grid(win->w/2, win->h/2 -32), Center | Middle);
00102 
00103   // property 情報の反映
00104   options->setSelectedIndex(0, (property->user->roman_convert ? 0 : 1));
00105   options->setSelectedIndex(1, (property->user->auto_next ? 0 : 1));
00106   options->setSelectedIndex(2, (property->user->learn_mode ? 0 : 1));
00107   options->setSelectedIndex(3, (property->user->send_ranking ? 0 : 1));
00108   // !!! 登録先アドレスの反映
00109   win->add(options, ForeDepth);
00110 
00111   // ランキング登録先
00112   int font_size = (SmallSize + TinySize) >> 1;
00113   rank_text = new DrawSurface(ttf->createText(OptionMenu_web, font_size,
00114                                               Black, Back), true);
00115   win->add((new LabelComponent(rank_text))
00116            ->setPosition(Grid(16, win->h -40), Bottom), ForeDepth);
00117   int left_width = win->w - (rank_text->w +32 +8);
00118   rank_web =
00119     new TextInputComponent(*ttf, font_size,
00120                            Rect(left_width, font_size+1), White, Black);
00121   rank_web->setText("http://");
00122   rank_web->setPosition(Grid(24 + rank_text->w, win->h -40), Bottom);
00123   rank_web->setBufferMax(120);
00124   rank_web->disable(true);
00125   win->add(rank_web, ForeDepth);
00126 
00127   return 0;
00128 }
00129 
00130 
00131 int OptionMenu::MainLoop(void) {
00132   bool quit = false;
00133   do {
00134     win->lock();
00135 
00136     if (options->isDecided()) {
00137       int index = options->getDecidedRow();
00138       if (index == 4) {
00139         // 戻る
00140         quit = true;
00141       }
00142     }
00143 
00144     UserInput::userInput_t ui = UserInput::getInputed();
00145     quit |= ui.quit | ui.isPressedCode(SDLK_ESCAPE);
00146     win->unlock();
00147 
00148     SDL_Delay(10);
00149   } while (!quit);
00150 
00151   // 設定情報を property に反映
00152   property->user->roman_convert = options->getSelected(0) ? false : true;
00153   property->user->auto_next = options->getSelected(1) ? false : true;
00154   property->user->learn_mode = options->getSelected(2) ? false : true;
00155   property->user->send_ranking = options->getSelected(3) ? false : true;
00156   // !!! property->user->rank_page = ;
00157 
00158   return 0;
00159 }
00160 

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