00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <nds.h>
00021 #include <string>
00022 #include "definitions.h"
00023 #include "card.h"
00024 #include "textbox.h"
00025 #include "textboxhandler.h"
00026 #include "graphics.h"
00027 #include "screenshandler.h"
00028 #include "mainscreenhandler.h"
00029
00030 using namespace Types;
00031
00032 MainScreenHandler::MainScreenHandler()
00033 {
00034 videoSetMode (MODE_5_2D);
00035 vramSetBankA (VRAM_A_MAIN_BG_0x06000000);
00036
00037 bgid_ = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);
00038
00039 screens_handler_ = NULL;
00040 }
00041
00048 void MainScreenHandler::Init (MainScreenMode::mode screen_mode,
00049 GameMode::mode game_mode,
00050 ScreensHandler* screens_handler,
00051 int boxes_number)
00052 {
00053 SetMode(screen_mode, game_mode, screens_handler, boxes_number);
00054 }
00055
00061 void MainScreenHandler::SwitchMode (MainScreenMode::mode screen_mode,
00062 GameMode::mode game_mode,
00063 int boxes_number)
00064 {
00065 ClearMembers ();
00066 SetMode(screen_mode, game_mode, screens_handler_, boxes_number);
00067 }
00068
00075 void MainScreenHandler::SetMode (MainScreenMode::mode screen_mode,
00076 GameMode::mode game_mode,
00077 ScreensHandler* screens_handler,
00078 int boxes_number)
00079 {
00080 screens_handler_ = screens_handler;
00081 game_mode_ = game_mode;
00082 screen_mode_ = screen_mode;
00083 boxes_number_ = boxes_number;
00084
00085
00086 if (screen_mode_ == MainScreenMode::KANJI)
00087 {
00088 caption_kanji_ = screens_handler_->tbh()->
00089 NewTextBox (Screen::MAIN, bgid_, CAPTION_FONT, KM_CAPTION_SIZE,
00090 KM_CAPTION_KANJI_X, KM_CAPTION_KANJI_Y);
00091 kanji_ = screens_handler_->tbh()->
00092 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT, KM_KANJI_SIZE,
00093 KM_KANJI_X, KM_KANJI_Y);
00094 kanji_->floats(true);
00095 caption_on_reading_ = screens_handler_->tbh()->
00096 NewTextBox (Screen::MAIN, bgid_, CAPTION_FONT, KM_CAPTION_SIZE,
00097 KM_CAPTION_ON_READING_X, KM_CAPTION_ON_READING_Y);
00098 on_reading_ = screens_handler_->tbh()->
00099 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT, KM_NORMAL_SIZE,
00100 KM_ON_READING_X, KM_ON_READING_Y);
00101 caption_kun_reading_ = screens_handler_->tbh()->
00102 NewTextBox (Screen::MAIN, bgid_, CAPTION_FONT, KM_CAPTION_SIZE,
00103 KM_CAPTION_KUN_READING_X, KM_CAPTION_KUN_READING_Y);
00104 kun_reading_ = screens_handler_->tbh()->
00105 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT, KM_NORMAL_SIZE,
00106 KM_KUN_READING_X, KM_KUN_READING_Y);
00107 caption_translation_ = screens_handler_->tbh()->
00108 NewTextBox (Screen::MAIN, bgid_, CAPTION_FONT, KM_CAPTION_SIZE,
00109 KM_CAPTION_TRANSLATION_X, KM_CAPTION_TRANSLATION_Y);
00110 translation_ = screens_handler_->tbh()->
00111 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT, KM_NORMAL_SIZE,
00112 KM_TRANSLATION_X, KM_TRANSLATION_Y);
00113 caption_example_ = screens_handler_->tbh()->
00114 NewTextBox (Screen::MAIN, bgid_, CAPTION_FONT, KM_CAPTION_SIZE,
00115 KM_CAPTION_EXAMPLE_X, KM_CAPTION_EXAMPLE_Y);
00116 example_kanji_ = screens_handler_->tbh()->
00117 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT, KM_NORMAL_SIZE,
00118 KM_EXAMPLE_KANJI_X, KM_EXAMPLE_KANJI_Y);
00119 example_reading_ = screens_handler_->tbh()->
00120 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT, KM_NORMAL_SIZE,
00121 KM_EXAMPLE_READING_X, KM_EXAMPLE_READING_Y);
00122 example_translation_ = screens_handler_->tbh()->
00123 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT, KM_NORMAL_SIZE,
00124 KM_EXAMPLE_TRANSLATION_X, KM_EXAMPLE_TRANSLATION_X);
00125
00126
00127 caption_kanji_->text("Kanji");
00128 caption_on_reading_->text("on reading");
00129 caption_kun_reading_->text("kun reading");
00130 caption_translation_->text("Translation");
00131 caption_example_->text("Example");
00132
00133
00134 caption_on_reading_->visible(false);
00135 caption_kun_reading_->visible(false);
00136 caption_translation_->visible(false);
00137 caption_example_->visible(false);
00138 on_reading_->visible(false);
00139 kun_reading_->visible(false);
00140 translation_->visible(false);
00141 example_kanji_->visible(false);
00142 example_reading_->visible(false);
00143 example_translation_->visible(false);
00144 }
00145
00146 else if (screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES ||
00147 screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES_VISIBLE)
00148 {
00149 if (boxes_number_ >= 1)
00150 {
00151 caption_box1_ = screens_handler_->tbh()->
00152 NewTextBox (Screen::MAIN, bgid_, CAPTION_FONT, VTB_CAPTION_SIZE,
00153 VTB_CAPTION_BOX1_X, VTB_CAPTION_BOX1_Y);
00154 box1_ = screens_handler_->tbh()->
00155 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT, VTB_NORMAL_SIZE,
00156 VTB_BOX1_X, VTB_BOX1_Y);
00157 if (boxes_number_ >= 2)
00158 {
00159 caption_box2_ = screens_handler_->tbh()->
00160 NewTextBox (Screen::MAIN, bgid_, CAPTION_FONT,
00161 VTB_CAPTION_SIZE, VTB_CAPTION_BOX2_X,
00162 VTB_CAPTION_BOX2_Y);
00163 box2_ = screens_handler_->tbh()->
00164 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT,
00165 VTB_NORMAL_SIZE, VTB_BOX2_X, VTB_BOX2_Y);
00166 if (boxes_number_ >= 3)
00167 {
00168 caption_box3_ = screens_handler_->tbh()->
00169 NewTextBox (Screen::MAIN, bgid_, CAPTION_FONT,
00170 VTB_CAPTION_SIZE, VTB_CAPTION_BOX3_X,
00171 VTB_CAPTION_BOX3_Y);
00172 box3_ = screens_handler_->tbh()->
00173 NewTextBox (Screen::MAIN, bgid_, NORMAL_FONT,
00174 VTB_NORMAL_SIZE, VTB_BOX3_X, VTB_BOX3_Y);
00175 }
00176 }
00177 }
00178 }
00179
00180 if (screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES)
00181 {
00182 if (boxes_number_ >= 2)
00183 {
00184 caption_box2_->visible(false);
00185 box2_->visible(false);
00186 if (boxes_number_>= 3)
00187 {
00188 caption_box3_->visible(false);
00189 box3_->visible(false);
00190 }
00191 }
00192 }
00193
00194 DrawBgImage ();
00195 Graphics::SetColors();
00196 }
00197
00198 void MainScreenHandler::PrintCard (const Card& card, bool convert_to_romaji)
00199 {
00200 DrawBgImage ();
00201 ResetTextBoxesPositions ();
00202 if (screen_mode_ == MainScreenMode::KANJI)
00203 {
00204 kanji_->text(card.symbol());
00205 on_reading_->text(card.reading(), convert_to_romaji);
00206 kun_reading_->text(card.reading2(), convert_to_romaji);
00207 translation_->text(card.translation());
00208 example_kanji_->text(card.example_symbol());
00209 example_reading_->text(card.example_reading(), convert_to_romaji);
00210 example_translation_->text(card.example_translation());
00211
00212
00213 caption_on_reading_->visible(false);
00214 caption_kun_reading_->visible(false);
00215 caption_translation_->visible(false);
00216 caption_example_->visible(false);
00217 on_reading_->visible(false);
00218 kun_reading_->visible(false);
00219 translation_->visible(false);
00220 example_kanji_->visible(false);
00221 example_reading_->visible(false);
00222 example_translation_->visible(false);
00223
00224 screens_handler_->tbh()->PrintAll(Screen::MAIN);
00225 }
00226 else if (screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES ||
00227 screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES_VISIBLE)
00228 {
00229 bool convert_to_romaji1, convert_to_romaji2, convert_to_romaji3;
00230 convert_to_romaji1 = convert_to_romaji2 = convert_to_romaji3 = false;
00231 std::string box1text, box2text, box3text;
00232 if (game_mode_ == GameMode::KANJI_QUIZ)
00233 {
00234 box1text = card.translation();
00235 box2text = card.reading();
00236 box3text = card.reading2();
00237 convert_to_romaji2 = convert_to_romaji3 = convert_to_romaji;
00238 }
00239 else if (game_mode_ == GameMode::VOCABULARY)
00240 {
00241 box1text = card.symbol();
00242 box2text = card.reading();
00243 box3text = card.translation();
00244 convert_to_romaji2 = convert_to_romaji;
00245 }
00246 else if (game_mode_ == GameMode::VOCABULARY_QUIZ)
00247 {
00248 box1text = card.translation();
00249 box2text = card.reading();
00250 convert_to_romaji2 = convert_to_romaji;
00251 }
00252
00253 if (boxes_number_ >= 1)
00254 {
00255 box1_->text(box1text, convert_to_romaji1);
00256 if (boxes_number_ >= 2)
00257 {
00258 box2_->text(box2text, convert_to_romaji2);
00259 if (boxes_number_ >= 3)
00260 box3_->text(box3text, convert_to_romaji3);
00261 }
00262 }
00263
00264 if (screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES)
00265 {
00266 if (boxes_number_ >= 2)
00267 {
00268 caption_box2_->visible(false);
00269 box2_->visible(false);
00270 if (boxes_number_>= 3)
00271 {
00272 caption_box3_->visible(false);
00273 box3_->visible(false);
00274 }
00275 }
00276 }
00277
00278 screens_handler_->tbh()->PrintAll(Screen::MAIN);
00279 }
00280 }
00281
00282 void MainScreenHandler::Scroll (int sx, int sy)
00283 {
00284 if (scroll_y_ != sy)
00285 {
00286 bgSetScroll(bgid_,sx,sy);
00287 bgUpdate();
00288 scroll_y_ = sy;
00289 }
00290 }
00291
00292 void MainScreenHandler::Captions (std::string box1, std::string box2,
00293 std::string box3)
00294 {
00295 if (boxes_number_ >= 1)
00296 {
00297 caption_box1_->text(box1);
00298 if (boxes_number_ >= 2)
00299 {
00300 caption_box2_->text(box2);
00301 if (boxes_number_ >= 3)
00302 caption_box3_->text(box3);
00303 }
00304 }
00305 }
00306
00307 bool MainScreenHandler::ViewNext ()
00308 {
00309 bool all_visible = false;
00310 if (screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES)
00311 {
00312 if (boxes_number_ >= 2 && box2_->visible())
00313 if (boxes_number_ >= 3 && !box3_->visible())
00314 {
00315 caption_box3_->visible(true);
00316 caption_box3_->Print();
00317 box3_->visible(true);
00318 box3_->Print();
00319 }
00320 else
00321 all_visible = true;
00322 else if (boxes_number_ >= 2)
00323 {
00324 caption_box2_->visible(true);
00325 caption_box2_->Print();
00326 box2_->visible(true);
00327 box2_->Print();
00328 }
00329 else
00330 all_visible = true;
00331 }
00332 else if (screen_mode_ == MainScreenMode::KANJI)
00333 {
00334 if (on_reading_->visible())
00335 {
00336 if (kun_reading_->visible())
00337 {
00338 if (translation_->visible())
00339 {
00340 if (example_kanji_->visible())
00341 all_visible = true;
00342 else
00343 {
00344 caption_example_->visible(true);
00345 example_kanji_->visible(true);
00346 example_reading_->visible(true);
00347 example_translation_->visible(true);
00348 screens_handler_->tbh()->PrintTextBox(caption_example_);
00349 screens_handler_->tbh()->PrintTextBox(example_kanji_);
00350 screens_handler_->tbh()->PrintTextBox(example_reading_);
00351 screens_handler_->tbh()->PrintTextBox(example_translation_);
00352 }
00353 }
00354 else
00355 {
00356 caption_translation_->visible(true);
00357 screens_handler_->tbh()->PrintTextBox(caption_translation_);
00358 translation_->visible(true);
00359 screens_handler_->tbh()->PrintTextBox(translation_);
00360 }
00361 }
00362 else
00363 {
00364 caption_kun_reading_->visible(true);
00365 screens_handler_->tbh()->PrintTextBox(caption_kun_reading_);
00366 kun_reading_->visible(true);
00367 screens_handler_->tbh()->PrintTextBox(kun_reading_);
00368 }
00369 }
00370 else
00371 {
00372 caption_on_reading_->visible(true);
00373 screens_handler_->tbh()->PrintTextBox(caption_on_reading_);
00374 on_reading_->visible(true);
00375 screens_handler_->tbh()->PrintTextBox(on_reading_);
00376 }
00377 }
00378 return all_visible;
00379 }
00380
00381
00382 void MainScreenHandler::DrawBgImage ()
00383 {
00384 Scroll(0,0);
00385 scroll_y_ = 0;
00386 if (screen_mode_ == MainScreenMode::SPLASH_SCREEN)
00387 Graphics::SplashImage(Graphics::GetBitmapPtr(screen_mode_),
00388 Graphics::GetPalPtr(screen_mode_),
00389 Screen::MAIN, bgid_, Graphics::SplashEffect::APPEAR);
00390 else
00391 {
00392 dmaCopy(Graphics::GetBitmapPtr(screen_mode_), bgGetGfxPtr(bgid_), 256*256);
00393 dmaCopy(Graphics::GetPalPtr(screen_mode_), BG_PALETTE, 256*2);
00394 }
00395 }
00396
00397 void MainScreenHandler::Fill (unsigned short color)
00398 {
00399 Graphics::Fill (color, Screen::MAIN);
00400 }
00401
00402 void MainScreenHandler::ResetTextBoxesPositions ()
00403 {
00404 if (screens_handler_)
00405 {
00406 if (screen_mode_ == MainScreenMode::KANJI)
00407 {
00408 caption_kanji_->SetProperties(KM_CAPTION_KANJI_X,
00409 KM_CAPTION_KANJI_Y, 0, 0);
00410 kanji_->SetProperties(KM_KANJI_X, KM_KANJI_Y, 0, 0);
00411 caption_on_reading_->SetProperties(KM_CAPTION_ON_READING_X,
00412 KM_CAPTION_ON_READING_Y, 0, 0);
00413 on_reading_->SetProperties(KM_ON_READING_X, KM_ON_READING_Y, 0, 0);
00414 caption_kun_reading_->SetProperties(KM_CAPTION_KUN_READING_X,
00415 KM_CAPTION_KUN_READING_Y, 0, 0);
00416 kun_reading_->SetProperties(KM_KUN_READING_X, KM_KUN_READING_Y, 0, 0);
00417 caption_translation_->SetProperties(KM_CAPTION_TRANSLATION_X,
00418 KM_CAPTION_TRANSLATION_Y, 0, 0);
00419 translation_->SetProperties(KM_TRANSLATION_X, KM_TRANSLATION_Y, 0, 0);
00420 caption_example_->SetProperties(KM_CAPTION_EXAMPLE_X,
00421 KM_CAPTION_EXAMPLE_Y, 0, 0);
00422 example_kanji_->SetProperties(KM_EXAMPLE_KANJI_X,
00423 KM_EXAMPLE_KANJI_Y, 0, 0);
00424 example_reading_->SetProperties(KM_EXAMPLE_READING_X,
00425 KM_EXAMPLE_READING_Y, 0, 0);
00426 example_translation_->SetProperties(KM_EXAMPLE_TRANSLATION_X,
00427 KM_EXAMPLE_TRANSLATION_Y, 0, 0);
00428 }
00429 else if (screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES ||
00430 screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES_VISIBLE)
00431 {
00432 if (boxes_number_ >= 1)
00433 {
00434 caption_box1_->SetProperties(VTB_CAPTION_BOX1_X,
00435 VTB_CAPTION_BOX1_Y, 0, 0);
00436 box1_->SetProperties(VTB_BOX1_X, VTB_BOX1_Y, 0, 0);
00437 if (boxes_number_ >= 2)
00438 {
00439 caption_box2_->SetProperties(VTB_CAPTION_BOX2_X,
00440 VTB_CAPTION_BOX2_Y, 0, 0);
00441 box2_->SetProperties(VTB_BOX2_X, VTB_BOX2_Y, 0, 0);
00442 if (boxes_number_ >= 3)
00443 {
00444 caption_box3_->SetProperties(VTB_CAPTION_BOX3_X,
00445 VTB_CAPTION_BOX3_Y, 0, 0);
00446 box3_->SetProperties(VTB_BOX3_X, VTB_BOX3_Y, 0, 0);
00447 }
00448 }
00449 }
00450 }
00451 }
00452 }
00453
00454 void MainScreenHandler::ClearMembers ()
00455 {
00456 if (screens_handler_)
00457 {
00458 if (screen_mode_ == MainScreenMode::KANJI)
00459 {
00460 screens_handler_->tbh()->DestroyTextBox(caption_kanji_);
00461 screens_handler_->tbh()->DestroyTextBox(kanji_);
00462 screens_handler_->tbh()->DestroyTextBox(caption_on_reading_);
00463 screens_handler_->tbh()->DestroyTextBox(on_reading_);
00464 screens_handler_->tbh()->DestroyTextBox(caption_kun_reading_);
00465 screens_handler_->tbh()->DestroyTextBox(kun_reading_);
00466 screens_handler_->tbh()->DestroyTextBox(caption_translation_);
00467 screens_handler_->tbh()->DestroyTextBox(translation_);
00468 screens_handler_->tbh()->DestroyTextBox(caption_example_);
00469 screens_handler_->tbh()->DestroyTextBox(example_kanji_);
00470 screens_handler_->tbh()->DestroyTextBox(example_reading_);
00471 screens_handler_->tbh()->DestroyTextBox(example_translation_);
00472 }
00473 else if (screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES ||
00474 screen_mode_ == MainScreenMode::VERTICAL_TEXTBOXES_VISIBLE)
00475 {
00476 if (boxes_number_ >= 1)
00477 {
00478 screens_handler_->tbh()->DestroyTextBox(box1_);
00479 screens_handler_->tbh()->DestroyTextBox(caption_box1_);
00480 if (boxes_number_ >= 2)
00481 {
00482 screens_handler_->tbh()->DestroyTextBox(box2_);
00483 screens_handler_->tbh()->DestroyTextBox(caption_box2_);
00484 if (boxes_number_ >= 3)
00485 {
00486 screens_handler_->tbh()->DestroyTextBox(box3_);
00487 screens_handler_->tbh()->DestroyTextBox(caption_box3_);
00488 }
00489 }
00490 }
00491 }
00492 }
00493 }
00494
00495 MainScreenHandler::~MainScreenHandler()
00496 {
00497 ClearMembers();
00498 }