From badb2bf6bc25f47e711fc483e0c551b4fc18759f Mon Sep 17 00:00:00 2001 From: Treeki Date: Fri, 21 Sep 2012 00:08:14 +0200 Subject: fixes, header cleanups, and part of the code for the new HUD --- include/game.h | 69 ++++++++++++++++++++----- kamek_pal.x | 6 ++- src/koopatlas/hud.cpp | 122 ++++++++++++++++++++++++++++++++++++++++++++- src/koopatlas/hud.h | 18 ++++++- src/koopatlas/starcoin.cpp | 4 +- 5 files changed, 199 insertions(+), 20 deletions(-) diff --git a/include/game.h b/include/game.h index 7e8456d..2dc64a6 100755 --- a/include/game.h +++ b/include/game.h @@ -505,6 +505,20 @@ namespace lyt { class Group; class GroupContainer; + namespace detail { + class TexCoordAry { + public: + TexCoordAry(); + void Free(); + void Reserve(u8 count); + void SetSize(u8 count); + void Copy(const void *source, u8 count); + + u8 reservedSize, usedSize; + void *data; + }; + } + class Layout { public: Layout(); @@ -636,11 +650,17 @@ namespace lyt { u8 flag; char name[0x11]; - char userdata[8]; + char userdata[9]; - u8 _D5; u8 paneIsOwnedBySomeoneElse; u8 _D7; + + void SetVisible(bool value) { + if (value) + flag |= 1; + else + flag &= ~1; + } }; class TextBox : public Pane { @@ -657,7 +677,7 @@ namespace lyt { uchar GetVtxColorElement(ulong id) const; void SetVtxColorElement(ulong id, uchar value); - virtual void LoadMtx(const DrawInfo &info); + void LoadMtx(const DrawInfo &info); virtual void AllocStringBuffer(u16 size); virtual void FreeStringBuffer(); @@ -681,6 +701,26 @@ namespace lyt { u8 alignment; u8 flags; }; + + class Picture : public Pane { + public: + Picture(void *, void *); // todo: Picture((res::Picture const *,ResBlockSet const &)) + ~Picture(); + + void *GetRuntimeTypeInfo() const; + + void DrawSelf(const DrawInfo &info); + + ut::Color GetVtxColor(ulong id) const; + void SetVtxColor(ulong id, ut::Color color); + uchar GetVtxColorElement(ulong id) const; + void SetVtxColorElement(ulong id, uchar value); + + virtual void Append(const GXTexObj &obj); + + ut::Color colours[4]; + detail::TexCoordAry texCoords; + }; } @@ -2482,7 +2522,10 @@ namespace nw4r { void SetupGXWithColorMapping(Color c1, Color c2); public: - Color colors[8]; // todo: document + Color minColMapping, maxColMapping; + Color vtxColours[4]; + Color topColour, bottomColour; + u32 modeOfSomeKind; float scaleX; float scaleY; @@ -2517,12 +2560,12 @@ namespace nw4r { bool IsDrawFlagSet(ulong, ulong) const; - float _4C; + float widthLimit; float charSpace; - float somethingRelatedToLineHeight; - u32 _58; + float lineSpace; + u32 tabWidth; u32 drawFlag; - void *tagProcessorMaybe; + void *tagProcessor; }; } } @@ -2662,7 +2705,7 @@ namespace m2d { nw4r::lyt::Pane *getRootPane(); nw4r::lyt::Pane *findPaneByName(const char *name) const; nw4r::lyt::TextBox *findTextBoxByName(const char *name) const; - nw4r::lyt::Pane *findPictureByName(const char *name) const; // TODO: change to others + nw4r::lyt::Picture *findPictureByName(const char *name) const; nw4r::lyt::Pane *findWindowByName(const char *name) const; void animate(); @@ -2700,10 +2743,10 @@ namespace m2d { // does NSMBW even use consts? I have no idea. maybe not - void getPanes(const char **names, nw4r::lyt::Pane *output, int count) const; - void getWindows(const char **names, nw4r::lyt::Pane *output, int count) const; // TODO: change to others - void getPictures(const char **names, nw4r::lyt::Pane *output, int count) const; - void getTextBoxes(const char **names, nw4r::lyt::TextBox *output, int count) const; + void getPanes(const char **names, nw4r::lyt::Pane **output, int count) const; + void getWindows(const char **names, nw4r::lyt::Pane **output, int count) const; // TODO: change to others + void getPictures(const char **names, nw4r::lyt::Picture **output, int count) const; + void getTextBoxes(const char **names, nw4r::lyt::TextBox **output, int count) const; void setLangStrings(const char **names, const int *msgIDs, int category, int count); diff --git a/kamek_pal.x b/kamek_pal.x index 4955575..169d0b4 100644 --- a/kamek_pal.x +++ b/kamek_pal.x @@ -738,6 +738,11 @@ SECTIONS { __ct__Q23m2d13EmbedLayout_cFv = 0x800C89A0; __dt__Q23m2d13EmbedLayout_cFv = 0x800C89F0; loadArc__Q23m2d13EmbedLayout_cFPCcb = 0x800C8D00; + getPanes__Q23m2d13EmbedLayout_cCFPPCcPPQ34nw4r3lyt4Panei = 0x800C8E50; + getWindows__Q23m2d13EmbedLayout_cCFPPCcPPQ34nw4r3lyt6Windowi = 0x800C8EC0; + getPictures__Q23m2d13EmbedLayout_cCFPPCcPPQ34nw4r3lyt7Picturei = 0x800C8F30; + getTextBoxes__Q23m2d13EmbedLayout_cCFPPCcPPQ34nw4r3lyt7TextBoxi = 0x800C8FA0; + setLangStrings__Q23m2d13EmbedLayout_cFPPCcPCiii = 0x800C9010; loadAnimations__Q23m2d13EmbedLayout_cFPPCci = 0x800C90A0; loadGroups__Q23m2d13EmbedLayout_cFPPCcPii = 0x800C91E0; enableNonLoopAnim__Q23m2d13EmbedLayout_cFib = 0x800C93E0; @@ -746,7 +751,6 @@ SECTIONS { disableAllAnimations__Q23m2d13EmbedLayout_cFv = 0x800C95F0; isAnimOn__Q23m2d13EmbedLayout_cFi = 0x800C9700; isAnyAnimOn__Q23m2d13EmbedLayout_cFv = 0x800C9730; - setLangStrings__Q23m2d13EmbedLayout_cFPPCcPCiii = 0x800C9010; free__Q23m2d13EmbedLayout_cFv = 0x800C9A20; execAnimations__Q23m2d13EmbedLayout_cFv = 0x800C9650; diff --git a/src/koopatlas/hud.cpp b/src/koopatlas/hud.cpp index b7e40d2..266c284 100644 --- a/src/koopatlas/hud.cpp +++ b/src/koopatlas/hud.cpp @@ -54,7 +54,24 @@ int dWMHud_c::onCreate() { 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); + + static const char *textBoxNames[7] = { + "LevelName", "LevelNameS", + "LevelNumber", "LevelNumberS", + "WorldName", "WorldNameS", + "StarCoinCounter" + }; + layout.getTextBoxes(textBoxNames, &LevelName, 7); + layoutLoaded = true; + + willShowHeader = false; } return true; @@ -73,6 +90,12 @@ int dWMHud_c::onExecute() { if (!layoutLoaded) return true; + if (willShowHeader && (!(layout.isAnimOn(SHOW_HEADER)))) { + willShowHeader = false; + loadHeaderInfo(); + playShowHeaderAnim(); + } + layout.execAnimations(); layout.update(); @@ -97,9 +120,104 @@ void dWMHud_c::playShowHeaderAnim() { } void dWMHud_c::playHideHeaderAnim() { - if (layout.isAnimOn(SHOW_HEADER)) { + if (!layout.isAnimOn(SHOW_HEADER)) { layout.enableNonLoopAnim(SHOW_HEADER, true); } - layout.grpHandlers[SHOW_HEADER].frameCtrl.flags = 2; // NO_LOOP | REVERSE + layout.grpHandlers[SHOW_HEADER].frameCtrl.flags = 3; // NO_LOOP | REVERSE +} + + +void dWMHud_c::loadHeaderInfo() { + dLevelInfo_c *levelInfo = &dScKoopatlas_c::instance->levelInfo; + + dLevelInfo_c::entry_s *infEntry = levelInfo->search( + nodeForHeader->levelNumber[0], nodeForHeader->levelNumber[1]); + + if (infEntry == 0) { + LevelName->SetString(L"Unknown Level Name!"); + LevelNameS->SetString(L"Unknown Level Name!"); + return; + } + + // 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; + } + + LevelNumber->SetString(levelNumber); + LevelNumberS->SetString(levelNumber); + + // INFO + int w = nodeForHeader->levelNumber[0] - 1; + int l = nodeForHeader->levelNumber[1] - 1; + + 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 = 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(convertedLevelName, charCount); + Header_Centre->size.x = width + LevelName->trans.x - 20.0f; + Header_Right->trans.x = Header_Centre->size.x; +} + + + +void dWMHud_c::enteredNode() { + dKPNode_s *node = dScKoopatlas_c::instance->pathManager.currentNode; + + if (node->type == dKPNode_s::LEVEL) { + willShowHeader = true; + nodeForHeader = node; + } +} + +void dWMHud_c::leftNode() { + if (layout.grpHandlers[SHOW_HEADER].frameCtrl.currentFrame > 0.1f) { + // not hidden + + if ((layout.isAnimOn(SHOW_HEADER) && (layout.grpHandlers[SHOW_HEADER].frameCtrl.flags & 2)) + || (!layout.isAnimOn(SHOW_HEADER))) { + // currently being shown, OR fully shown already + playHideHeaderAnim(); + } + } } + + + diff --git a/src/koopatlas/hud.h b/src/koopatlas/hud.h index 87f731b..632a078 100644 --- a/src/koopatlas/hud.h +++ b/src/koopatlas/hud.h @@ -19,11 +19,25 @@ class dWMHud_c : public dBase_c { static dWMHud_c *instance; - bool showingHeader; - + void enteredNode(); + void leftNode(); + private: void playShowHeaderAnim(); void playHideHeaderAnim(); + void loadHeaderInfo(); + + bool willShowHeader; + dKPNode_s *nodeForHeader; + + + nw4r::lyt::Picture *Header_Centre, *Header_Right; + nw4r::lyt::Picture *NormalExitFlag, *SecretExitFlag; + nw4r::lyt::Picture *StarCoinOn[3]; + nw4r::lyt::TextBox *LevelName, *LevelNameS; + nw4r::lyt::TextBox *LevelNumber, *LevelNumberS; + nw4r::lyt::TextBox *WorldName, *WorldNameS; + nw4r::lyt::TextBox *StarCoinCounter; }; #endif diff --git a/src/koopatlas/starcoin.cpp b/src/koopatlas/starcoin.cpp index d4bdbd8..3842f87 100644 --- a/src/koopatlas/starcoin.cpp +++ b/src/koopatlas/starcoin.cpp @@ -326,10 +326,10 @@ void dWMStarCoin::setText(const char *str, const char *name) { nw4r::ut::TextWriter tw; tw.font = box->font; tw.SetFontSize(box->fontSizeX, box->fontSizeY); - tw.somethingRelatedToLineHeight = box->lineSpace; + tw.lineSpace = box->lineSpace; tw.charSpace = box->charSpace; if (box->tagProc != 0) - tw.tagProcessorMaybe = box->tagProc; + tw.tagProcessor = box->tagProc; float width = tw.CalcStringWidth(newString, wlength); SpammyReport("Text width: %f\n", width); -- cgit v1.2.3