| 1 | #include "Library/Play/Layout/SimpleLayoutText.h" |
| 2 | |
| 3 | #include <prim/seadStringUtil.h> |
| 4 | |
| 5 | #include "Library/Layout/LayoutActorUtil.h" |
| 6 | #include "Library/Layout/LayoutInitInfo.h" |
| 7 | #include "Library/LiveActor/ActorInitInfo.h" |
| 8 | #include "Library/Message/MessageHolder.h" |
| 9 | #include "Library/Nerve/NerveSetupUtil.h" |
| 10 | #include "Library/Nerve/NerveUtil.h" |
| 11 | |
| 12 | namespace { |
| 13 | using namespace al; |
| 14 | NERVE_IMPL(SimpleLayoutText, Wait); |
| 15 | NERVES_MAKE_NOSTRUCT(SimpleLayoutText, Wait); |
| 16 | |
| 17 | } // namespace |
| 18 | |
| 19 | namespace al { |
| 20 | |
| 21 | SimpleLayoutText::SimpleLayoutText(const LayoutInitInfo& info, const char* name, |
| 22 | const char* paneName, const char* archiveName) |
| 23 | : LayoutActor("テキストレイアウト" ), mPaneName(paneName) { |
| 24 | initLayoutActor(this, info, name, archiveName); |
| 25 | initNerve(&Wait, 0); |
| 26 | kill(); |
| 27 | } |
| 28 | |
| 29 | void SimpleLayoutText::start(const sead::Vector2f& pos, const char* str, s32 lifetime) { |
| 30 | setPos(pos); |
| 31 | mLifetime = lifetime; |
| 32 | |
| 33 | setText(str); |
| 34 | setNerve(user: this, nerve: &Wait); |
| 35 | appear(); |
| 36 | } |
| 37 | |
| 38 | void SimpleLayoutText::setPos(const sead::Vector2f& pos) { |
| 39 | setLocalTrans(this, pos); |
| 40 | } |
| 41 | |
| 42 | void SimpleLayoutText::setText(const char* text) { |
| 43 | sead::WFixedSafeString<256> utf16str; |
| 44 | |
| 45 | sead::StringUtil::convertUtf8ToUtf16(dst: utf16str.getBuffer(), dst_len: utf16str.getBufferSize(), src: text, src_len: -1); |
| 46 | |
| 47 | // doesn't match with call to setText(const char16*) |
| 48 | setPaneString(this, mPaneName, utf16str.cstr(), 0); |
| 49 | } |
| 50 | |
| 51 | void SimpleLayoutText::start(const sead::Vector2f& pos, const char16* str, s32 lifetime) { |
| 52 | setPos(pos); |
| 53 | mLifetime = lifetime; |
| 54 | setText(str); |
| 55 | setNerve(user: this, nerve: &Wait); |
| 56 | appear(); |
| 57 | } |
| 58 | |
| 59 | void SimpleLayoutText::setText(const char16* str) { |
| 60 | setPaneString(this, mPaneName, str, 0); |
| 61 | } |
| 62 | |
| 63 | void SimpleLayoutText::start(const sead::Vector2f& pos, const char* category, const char* key, |
| 64 | s32 lifetime) { |
| 65 | const char16* localizedStr = getSystemMessageString(this, category, key); |
| 66 | start(pos, str: localizedStr, lifetime); |
| 67 | } |
| 68 | |
| 69 | void SimpleLayoutText::setScale(f32 scale) { |
| 70 | setLocalScale(this, scale); |
| 71 | } |
| 72 | |
| 73 | void SimpleLayoutText::setColor(const sead::Color4u8& color) { |
| 74 | setPaneVtxColor(this, mPaneName, color); |
| 75 | } |
| 76 | |
| 77 | void SimpleLayoutText::setPositionCenterH() { |
| 78 | setTextPositionCenterH(this, mPaneName); |
| 79 | } |
| 80 | |
| 81 | void SimpleLayoutText::exeWait() { |
| 82 | if (mLifetime >= 0 && !isLessStep(user: this, step: mLifetime)) |
| 83 | kill(); |
| 84 | } |
| 85 | |
| 86 | SimpleLayoutText* createSimpleLayoutText(const ActorInitInfo& info, const char* name, |
| 87 | const char* paneName, const char* archiveName) { |
| 88 | return new SimpleLayoutText(*info.layoutInitInfo, name, paneName, archiveName); |
| 89 | } |
| 90 | |
| 91 | } // namespace al |
| 92 | |