diff options
Diffstat (limited to 'src/koopatlas/hud.cpp')
-rw-r--r-- | src/koopatlas/hud.cpp | 433 |
1 files changed, 127 insertions, 306 deletions
diff --git a/src/koopatlas/hud.cpp b/src/koopatlas/hud.cpp index 3989a1c..cd52beb 100644 --- a/src/koopatlas/hud.cpp +++ b/src/koopatlas/hud.cpp @@ -1,28 +1,5 @@ #include "koopatlas/hud.h" -void CharToWChar(const char *input, wchar_t *output, int length) { for (int i = 0; i < length; i++) output[i] = input[i]; } - -int getStarCoinCount() { - - SaveBlock *save = GetSaveFile()->GetBlock(-1); - int coinsSpent = save->credits_hiscore; - int coinsEarned = 0; - - for (int w = 0; w < 10; w++) { - for (int l = 0; l < 10; l++) { - u32 conds = save->GetLevelCondition(w, l); - - if (conds & COND_COIN1) { coinsEarned++; } - if (conds & COND_COIN2) { coinsEarned++; } - if (conds & COND_COIN3) { coinsEarned++; } - } - } - - int coinsLeft = coinsEarned - coinsSpent; - return coinsLeft; -} - - dWMHud_c *dWMHud_c::instance = 0; dWMHud_c *dWMHud_c::build() { @@ -39,25 +16,19 @@ dWMHud_c::dWMHud_c() { layoutLoaded = false; } +enum WMHudAnimation { + SHOW_LIVES = 0, + SHOW_HEADER, + SHOW_FOOTER +}; -// TODO: Need to define these in a better way, somehow -#define ANIM_BUTTON_1 0 -#define ANIM_BUTTON_2 1 -#define ANIM_BOTTOM_SHOW 2 -#define ANIM_BOTTOM_HIDE 3 -#define ANIM_TOP_SHOW 4 -#define ANIM_TOP_HIDE 5 int dWMHud_c::onCreate() { if (!layoutLoaded) { - bool gotFile = layout.loadArc("maphud.arc", false); + bool gotFile = layout.loadArc("MapHUD.arc", false); if (!gotFile) return false; - //static const char *brlanNames[3] = {"maphud_hitbutton.brlan", "maphud_in.brlan", "maphud_out.brlan"}; - static const char *brlanNames[5] = {"maphud_hitbutton.brlan", "bottom_in.brlan", "bottom_out.brlan", "top_in.brlan", "top_out.brlan"}; - static const char *groupNames[6] = {"B01_Button", "B02_Button", "A00_Window", "A00_Window", "A01_Window", "A01_Window"}; - bool output = layout.build("maphud.brlyt"); if (!IsWideScreen()) { @@ -70,19 +41,41 @@ int dWMHud_c::onCreate() { layout.layout.rootPane->scale.y = 0.7711f; } - layout.loadAnimations(brlanNames, 5); - layout.loadGroups(groupNames, (int[6]){0, 0, 1, 2, 3, 4}, 6); + static const char *brlanNames[2] = {"MapHUD_ShowMain.brlan", "MapHUD_ShowHeader.brlan"}; + static const char *groupNames[3] = {"G_Lives", "G_Header", "G_Footer"}; + + layout.loadAnimations(brlanNames, 2); + layout.loadGroups(groupNames, (int[3]){0, 1, 0}, 3); layout.disableAllAnimations(); - layout.enableNonLoopAnim(ANIM_BOTTOM_SHOW); - hidePointBar(); - setWorldText(" "); - setWorldName(); + layout.enableNonLoopAnim(SHOW_LIVES); + layout.enableNonLoopAnim(SHOW_FOOTER); + layout.resetAnim(SHOW_HEADER); + + static const char *tbNames[2] = {"MenuButtonInfo", "ItemsButtonInfo"}; + layout.setLangStrings(tbNames, (int[2]){12, 15}, 4, 2); + + static const char *pictureNames[7] = { + "Header_Centre", "Header_Right", + "NormalExitFlag", "SecretExitFlag", + "StarCoinOn0", "StarCoinOn1", "StarCoinOn2" + }; + layout.getPictures(pictureNames, &Header_Centre, 7); - if (dScKoopatlas_c::instance->pathManager.mustComplainToMapCreator) - dWMHud_c::instance->setLevelText("Please Fix Your Missing Entrance. Thanks"); + static const char *textBoxNames[7] = { + "LevelName", "LevelNameS", + "LevelNumber", "LevelNumberS", + "WorldName", "WorldNameS", + "StarCoinCounter" + }; + layout.getTextBoxes(textBoxNames, &LevelName, 7); layoutLoaded = true; + + willShowHeader = false; + + if (!dScKoopatlas_c::instance->pathManager.isMoving) + enteredNode(); } return true; @@ -90,15 +83,22 @@ int dWMHud_c::onCreate() { int dWMHud_c::onDelete() { + if (!layoutLoaded) + return true; + return layout.free(); } int dWMHud_c::onExecute() { - updateLives(); - setWorldName(); - checkPointStatus(); - setPointName(); + if (!layoutLoaded) + return true; + + if (willShowHeader && (!(layout.isAnimOn(SHOW_HEADER)))) { + willShowHeader = false; + loadHeaderInfo(); + playShowHeaderAnim(); + } layout.execAnimations(); layout.update(); @@ -108,303 +108,124 @@ int dWMHud_c::onExecute() { int dWMHud_c::onDraw() { + if (!layoutLoaded) + return true; + layout.scheduleForDrawing(); return true; } -void dWMHud_c::updateLives() { - - static const char *textID[4] = {"M", "L", "B", "Y"}; - static const char *picID[4] = {"P_mariopic", "P_luigipic", "P_toadBlue", "P_toadyellow"}; - - for (int i = 0; i < 4; i++) { - - char boxName [13]; - sprintf(boxName, "T_%slifes_01", textID[i]); - nw4r::lyt::TextBox *box = layout.findTextBoxByName(boxName); - nw4r::lyt::Pane *pic = layout.findPictureByName(picID[i]); - - if (Player_Active[i] != 0) { - box->alpha = 0xFF; - pic->alpha = 0xFF; - - char lives [3]; - sprintf(lives, "%02d", Player_Lives[Player_ID[i]]); - const char *loaves = lives; - wchar_t life; - - CharToWChar(loaves, &life, 3); - - box->SetString(&life); - } - else { - box->alpha = 0; - pic->alpha = 0; - } - } - - nw4r::lyt::TextBox *coinbox = layout.findTextBoxByName("T_coin_count_01"); - - char stars [4]; - int starCoinCount = getStarCoinCount(); - sprintf(stars, "%03d", starCoinCount); - const char *scoins = stars; - wchar_t wcoins; - - CharToWChar(scoins, &wcoins, 4); - - coinbox->SetString(&wcoins); -} - -void dWMHud_c::setLevelText(const char *str, int length) { - if (str == 0) { - setLevelText("--NULL STRING--"); - return; - } - - if (length == -1) { - length = strlen(str); - } - - wchar_t newString[128]; - - int i; - for (i = 0; i < length && i < 128; i++) { - newString[i] = str[i]; - } - newString[i] = 0; - - setLevelText(newString, i); -} - -void dWMHud_c::setLevelText(const wchar_t *str, int length) { - if (str == 0) { - setLevelText("--NULL STRING--"); - return; - } - - if (length == -1) { - length = wcslen(str); - } - - nw4r::lyt::TextBox *box = layout.findTextBoxByName("T_levelname_01"); - - nw4r::ut::TextWriter tw; - tw.font = box->font; - tw.SetFontSize(box->fontSizeX, box->fontSizeY); - tw.somethingRelatedToLineHeight = box->lineSpace; - tw.charSpace = box->charSpace; - if (box->tagProc != 0) - tw.tagProcessorMaybe = box->tagProc; - - float width = tw.CalcStringWidth(str, length); - SpammyReport("Text width: %f\n", width); - layout.findWindowByName("W_levelname")->size.x = width + 22; - layout.findPictureByName("P_topleftboxbg")->size.x = width; - layout.findPictureByName("P_topthinboxbg")->size.x = 597 - width; - box->SetString(str); +void dWMHud_c::playShowHeaderAnim() { + layout.enableNonLoopAnim(SHOW_HEADER); } - -void dWMHud_c::setPointName() { - // figure this out... - dKPNode_s *node = dScKoopatlas_c::instance->pathManager.currentNode; - - if (node->type == dKPNode_s::LEVEL) { - dLevelInfo_c *li = &dScKoopatlas_c::instance->levelInfo; - dLevelInfo_c::entry_s *entry = li->search(node->levelNumber[0] - 1, node->levelNumber[1] - 1); - - setLevelText(li->getNameForLevel(entry)); - } else { - setLevelText(" "); - hidePointBar(); +void dWMHud_c::playHideHeaderAnim() { + if (!layout.isAnimOn(SHOW_HEADER)) { + layout.enableNonLoopAnim(SHOW_HEADER, true); } + layout.grpHandlers[SHOW_HEADER].frameCtrl.flags = 3; // NO_LOOP | REVERSE } -void dWMHud_c::checkPointStatus() { - dKPNode_s *node = dScKoopatlas_c::instance->pathManager.currentNode; - - if ((node->type == dKPNode_s::LEVEL) && ((node->levelNumber[1] < 30) || (node->levelNumber[1] > 37))) { - SaveBlock *save = GetSaveFile()->GetBlock(-1); - - int world = node->levelNumber[0]; - int level = node->levelNumber[1]; - - u32 conds = save->GetLevelCondition(world-1, level-1); - nw4r::lyt::Pane *pic; - - if (conds & COND_COIN1) { - pic = layout.findPictureByName("P_coin_on_01"); - pic->alpha = 0xFF; - - pic = layout.findPictureByName("P_coin_off_01"); - pic->alpha = 0; - } - else { - pic = layout.findPictureByName("P_coin_on_01"); - pic->alpha = 0; - - pic = layout.findPictureByName("P_coin_off_01"); - pic->alpha = 0xFF; - } - - if (conds & COND_COIN2) { - pic = layout.findPictureByName("P_coin_on_02"); - pic->alpha = 0xFF; - - pic = layout.findPictureByName("P_coin_off_02"); - pic->alpha = 0; - } - else { - pic = layout.findPictureByName("P_coin_on_02"); - pic->alpha = 0; - - pic = layout.findPictureByName("P_coin_off_02"); - pic->alpha = 0xFF; - } - - if (conds & COND_COIN3) { - pic = layout.findPictureByName("P_coin_on_03"); - pic->alpha = 0xFF; - - pic = layout.findPictureByName("P_coin_off_03"); - pic->alpha = 0; - } - else { - pic = layout.findPictureByName("P_coin_on_03"); - pic->alpha = 0; - - pic = layout.findPictureByName("P_coin_off_03"); - pic->alpha = 0xFF; - } - - if (conds & COND_NORMAL) { - pic = layout.findPictureByName("P_normalexitflag"); - pic->alpha = 0xFF; - } - else { - pic = layout.findPictureByName("P_normalexitflag"); - pic->alpha = 0; - } - - if (conds & COND_SECRET) { - pic = layout.findPictureByName("P_secretexitflag"); - pic->alpha = 0xFF; - } - else { - pic = layout.findPictureByName("P_secretexitflag"); - pic->alpha = 0; - } - - u8 deaths = save->death_counts[world-1][level-1]; - nw4r::lyt::TextBox *deathbox = layout.findTextBoxByName("T_death_01"); - char die [4]; - sprintf(die, "%03d", deaths); - const char *dies = die; - wchar_t wdie; - CharToWChar(dies, &wdie, 4); - deathbox->SetString(&wdie); - - } else { - nw4r::lyt::Pane *pic; - - static const char *picNames[8] = {"P_coin_on_01", "P_coin_off_01", "P_coin_on_02", "P_coin_off_02", - "P_coin_on_03", "P_coin_off_03", "P_normalexitflag", "P_secretexitflag"}; - - for (int i = 0; i < 8; i++) { - pic = layout.findPictureByName(picNames[i]); - pic->alpha = 0; - } +void dWMHud_c::loadHeaderInfo() { + dLevelInfo_c *levelInfo = &dScKoopatlas_c::instance->levelInfo; - nw4r::lyt::TextBox *deathbox = layout.findTextBoxByName("T_death_01"); - wchar_t noDie; - CharToWChar("---", &noDie, 4); - deathbox->SetString(&noDie); - } -} + dLevelInfo_c::entry_s *infEntry = levelInfo->search( + nodeForHeader->levelNumber[0]-1, nodeForHeader->levelNumber[1]-1); -void dWMHud_c::setWorldText(const char *str, int length) { - if (str == 0) { - setWorldText("--NULL STRING--"); + if (infEntry == 0) { + LevelName->SetString(L"Unknown Level Name!"); + LevelNameS->SetString(L"Unknown Level Name!"); return; } - if (length == -1) { - length = strlen(str); + // LEVEL NAME + wchar_t convertedLevelName[100]; + const char *sourceLevelName = levelInfo->getNameForLevel(infEntry); + int charCount = 0; + + while (*sourceLevelName != 0 && charCount < 99) { + convertedLevelName[charCount] = *sourceLevelName; + sourceLevelName++; + charCount++; + } + convertedLevelName[charCount] = 0; + + LevelName->SetString(convertedLevelName); + LevelNameS->SetString(convertedLevelName); + + // LEVEL NUMBER + wchar_t levelNumber[6]; + levelNumber[0] = '0' + nodeForHeader->levelNumber[0]; + levelNumber[1] = '-'; + if (nodeForHeader->levelNumber[1] >= 10) { + levelNumber[2] = '0' + (nodeForHeader->levelNumber[1] / 10); + levelNumber[3] = '0' + (nodeForHeader->levelNumber[1] % 10); + levelNumber[4] = 0; + } else { + levelNumber[2] = '0' + nodeForHeader->levelNumber[1]; + levelNumber[3] = 0; } - wchar_t newString[128]; + LevelNumber->SetString(levelNumber); + LevelNumberS->SetString(levelNumber); - int i; - for (i = 0; i < length && i < 128; i++) { - newString[i] = str[i]; - } - newString[i] = 0; + // INFO + int w = nodeForHeader->levelNumber[0] - 1; + int l = nodeForHeader->levelNumber[1] - 1; - setWorldText(newString, i); -} - -void dWMHud_c::setWorldText(const wchar_t *str, int length) { - if (str == 0) { - setWorldText("--NULL STRING--"); - return; - } - - if (length == -1) { - length = wcslen(str); - } - - nw4r::lyt::TextBox *box = layout.findTextBoxByName("T_area_01"); + u32 conds = GetSaveFile()->GetBlock(-1)->GetLevelCondition(w, l); + NormalExitFlag->SetVisible(conds & COND_NORMAL); + SecretExitFlag->SetVisible(conds & COND_SECRET); + StarCoinOn[0]->SetVisible(conds & COND_COIN1); + StarCoinOn[1]->SetVisible(conds & COND_COIN2); + StarCoinOn[2]->SetVisible(conds & COND_COIN3); + // SIZE THING nw4r::ut::TextWriter tw; - tw.font = box->font; - tw.SetFontSize(box->fontSizeX, box->fontSizeY); - tw.somethingRelatedToLineHeight = box->lineSpace; - tw.charSpace = box->charSpace; - if (box->tagProc != 0) - tw.tagProcessorMaybe = box->tagProc; + tw.font = LevelName->font; + tw.SetFontSize(LevelName->fontSizeX, LevelName->fontSizeY); + tw.lineSpace = LevelName->lineSpace; + tw.charSpace = LevelName->charSpace; + if (LevelName->tagProc != 0) + tw.tagProcessor = LevelName->tagProc; - float width = tw.CalcStringWidth(str, length); - SpammyReport("Text width: %f\n", width); - - box->SetString(str); + float width = tw.CalcStringWidth(convertedLevelName, charCount); + float totalWidth = width + LevelName->trans.x - 20.0f; + if (totalWidth < 270.0f) + totalWidth = 270.0f; + Header_Centre->size.x = totalWidth; + Header_Right->trans.x = totalWidth; } -void dWMHud_c::setWorldName() { - // figure this out... - dKPNode_s *node = dScKoopatlas_c::instance->pathManager.currentNode; - if (node->type == dKPNode_s::LEVEL) { - int world = node->levelNumber[0]; - int level = node->levelNumber[1]; - setWorldText(NewerWorldName(NewerWorldForLevelID(world, level))); - } -} - -void dWMHud_c::showPointBar() { - dKPNode_s *node = dScKoopatlas_c::instance->pathManager.currentNode; +void dWMHud_c::enteredNode(dKPNode_s *node) { + if (node == 0) + node = dScKoopatlas_c::instance->pathManager.currentNode; if (node->type == dKPNode_s::LEVEL) { - isPointBarShown = true; - - layout.enableNonLoopAnim(ANIM_TOP_SHOW); + willShowHeader = true; + nodeForHeader = node; } } +void dWMHud_c::leftNode() { + if (layout.grpHandlers[SHOW_HEADER].frameCtrl.currentFrame > 0.1f) { + // not hidden -void dWMHud_c::hidePointBar() { - if (isPointBarShown) { - isPointBarShown = false; - - layout.enableNonLoopAnim(ANIM_TOP_HIDE); + if ((layout.isAnimOn(SHOW_HEADER) && (layout.grpHandlers[SHOW_HEADER].frameCtrl.flags & 2)) + || (!layout.isAnimOn(SHOW_HEADER))) { + // currently being shown, OR fully shown already + playHideHeaderAnim(); + } } } + |