SuperMarioOdysseyOnline/source/layouts/HideAndSeekIcon.cpp

140 lines
3.6 KiB
C++
Raw Normal View History

2022-06-16 21:33:18 +00:00
#include "layouts/HideAndSeekIcon.h"
#include <cstdio>
#include <cstring>
#include "puppets/PuppetInfo.h"
#include "al/string/StringTmp.h"
#include "prim/seadSafeString.h"
#include "server/gamemode/GameModeTimer.hpp"
2022-08-07 21:42:56 +00:00
#include "server/hns/HideAndSeekMode.hpp"
2022-06-16 21:33:18 +00:00
#include "server/Client.hpp"
#include "al/util.hpp"
#include "logger.hpp"
#include "rs/util.hpp"
#include "main.hpp"
HideAndSeekIcon::HideAndSeekIcon(const char* name, const al::LayoutInitInfo& initInfo) : al::LayoutActor(name) {
al::initLayoutActor(this, initInfo, "HideAndSeekIcon", 0);
2022-08-07 21:42:56 +00:00
mInfo = GameModeManager::instance()->getInfo<HideAndSeekInfo>();
2022-06-16 21:33:18 +00:00
initNerve(&nrvHideAndSeekIconEnd, 0);
al::hidePane(this, "SeekingIcon");
al::hidePane(this, "HidingIcon");
kill();
}
void HideAndSeekIcon::appear() {
al::startAction(this, "Appear", 0);
al::setNerve(this, &nrvHideAndSeekIconAppear);
al::LayoutActor::appear();
}
bool HideAndSeekIcon::tryEnd() {
if (!al::isNerve(this, &nrvHideAndSeekIconEnd)) {
al::setNerve(this, &nrvHideAndSeekIconEnd);
return true;
}
return false;
}
bool HideAndSeekIcon::tryStart() {
if (!al::isNerve(this, &nrvHideAndSeekIconWait) && !al::isNerve(this, &nrvHideAndSeekIconAppear)) {
appear();
return true;
}
return false;
}
void HideAndSeekIcon::exeAppear() {
if (al::isActionEnd(this, 0)) {
al::setNerve(this, &nrvHideAndSeekIconWait);
}
}
void HideAndSeekIcon::exeWait() {
if (al::isFirstStep(this)) {
al::startAction(this, "Wait", 0);
}
GameTime &curTime = mInfo->mHidingTime;
if (curTime.mHours > 0) {
al::setPaneStringFormat(this, "TxtCounter", "%01d:%02d:%02d", curTime.mHours, curTime.mMinutes,
curTime.mSeconds);
} else {
al::setPaneStringFormat(this, "TxtCounter", "%02d:%02d", curTime.mMinutes,
curTime.mSeconds);
}
int playerCount = Client::getMaxPlayerCount();
2022-06-16 21:33:18 +00:00
if (playerCount > 0) {
char playerNameBuf[0x100] = {0}; // max of 16 player names if player name size is 0x10
new hide & seek players list Cherry picked this from the original commit and did the romfs change for all languages (not just for `USen`). All players are shown now with an icon indicating their gamemode role. I also changed the approach on how to change the font. Instead of changing existing characters I added completely new characters to the font (in all languages). That way the game icons don't appear unintended elsewhere in the game. It's also possible to do it for all languages now (`%`, &`, and `©` aren't available in all languages). Sadly I couldn't get UTF-32 characters to work (e.g. to use unicode codes for emojis that fit the icon). So I had to limit myself to UTF-16 and chose the private use area of unicode: - 0xE000 for a penguin icon (why not? :D) - 0xE001 for the hider icon (formerly `%`) - 0xE002 for the seeker icon (formerly `&`) - 0xE003 for the sardine icon (formerly `©`) - 0xE004 for the sardines can icon (formerly `@`) I included the sardines icons already, because in the future I might create separate PRs to get these gamemodes into the main mod. The font changes are inside `romfs/LocalizedData/${lang}/LayoutData/FontData.szs`. The update in the `romfs/LayoutData/HideAndSeekIcon.szs` changes the title for the players list from `Teammates` to `Players`. It also adds a shadow to the font of the list to increase readability. https://github.com/Amethyst-szs/SuperMarioOdysseyOnline/commit/f8eef7fb9762c8266ca4ef87d40112355d70d1a2 https://github.com/Amethyst-szs/SuperMarioOdysseyOnline/commit/2a0d0e77246dd54e128a704c0fe7118c81d20d35 (cherry picked from commit f8eef7fb9762c8266ca4ef87d40112355d70d1a2) (cherry picked from commit 2a0d0e77246dd54e128a704c0fe7118c81d20d35) Co-authored-by: Robin C. Ladiges <rcl.git@blackpinguin.de>
2022-11-03 18:58:07 +00:00
sead::BufferedSafeStringBase<char> playerList = sead::BufferedSafeStringBase<char>(playerNameBuf, 0x200);
// Add your own name to the list at the top
playerList.appendWithFormat("%s %s\n", mInfo->mIsPlayerIt ? "\uE002" : "\uE001", Client::instance()->getClientName());
// Add all seekers to the list
for (int i = 0; i < playerCount; i++) {
PuppetInfo* curPuppet = Client::getPuppetInfo(i);
if (curPuppet && curPuppet->isConnected && curPuppet->isIt) {
playerList.appendWithFormat("\uE002 %s\n", curPuppet->puppetName);
}
}
// Add all hiders to the list
for (int i = 0; i < playerCount; i++) {
2022-06-16 21:33:18 +00:00
PuppetInfo* curPuppet = Client::getPuppetInfo(i);
new hide & seek players list Cherry picked this from the original commit and did the romfs change for all languages (not just for `USen`). All players are shown now with an icon indicating their gamemode role. I also changed the approach on how to change the font. Instead of changing existing characters I added completely new characters to the font (in all languages). That way the game icons don't appear unintended elsewhere in the game. It's also possible to do it for all languages now (`%`, &`, and `©` aren't available in all languages). Sadly I couldn't get UTF-32 characters to work (e.g. to use unicode codes for emojis that fit the icon). So I had to limit myself to UTF-16 and chose the private use area of unicode: - 0xE000 for a penguin icon (why not? :D) - 0xE001 for the hider icon (formerly `%`) - 0xE002 for the seeker icon (formerly `&`) - 0xE003 for the sardine icon (formerly `©`) - 0xE004 for the sardines can icon (formerly `@`) I included the sardines icons already, because in the future I might create separate PRs to get these gamemodes into the main mod. The font changes are inside `romfs/LocalizedData/${lang}/LayoutData/FontData.szs`. The update in the `romfs/LayoutData/HideAndSeekIcon.szs` changes the title for the players list from `Teammates` to `Players`. It also adds a shadow to the font of the list to increase readability. https://github.com/Amethyst-szs/SuperMarioOdysseyOnline/commit/f8eef7fb9762c8266ca4ef87d40112355d70d1a2 https://github.com/Amethyst-szs/SuperMarioOdysseyOnline/commit/2a0d0e77246dd54e128a704c0fe7118c81d20d35 (cherry picked from commit f8eef7fb9762c8266ca4ef87d40112355d70d1a2) (cherry picked from commit 2a0d0e77246dd54e128a704c0fe7118c81d20d35) Co-authored-by: Robin C. Ladiges <rcl.git@blackpinguin.de>
2022-11-03 18:58:07 +00:00
if (curPuppet && curPuppet->isConnected && !curPuppet->isIt) {
playerList.appendWithFormat("\uE001 %s\n", curPuppet->puppetName);
2022-06-16 21:33:18 +00:00
}
}
new hide & seek players list Cherry picked this from the original commit and did the romfs change for all languages (not just for `USen`). All players are shown now with an icon indicating their gamemode role. I also changed the approach on how to change the font. Instead of changing existing characters I added completely new characters to the font (in all languages). That way the game icons don't appear unintended elsewhere in the game. It's also possible to do it for all languages now (`%`, &`, and `©` aren't available in all languages). Sadly I couldn't get UTF-32 characters to work (e.g. to use unicode codes for emojis that fit the icon). So I had to limit myself to UTF-16 and chose the private use area of unicode: - 0xE000 for a penguin icon (why not? :D) - 0xE001 for the hider icon (formerly `%`) - 0xE002 for the seeker icon (formerly `&`) - 0xE003 for the sardine icon (formerly `©`) - 0xE004 for the sardines can icon (formerly `@`) I included the sardines icons already, because in the future I might create separate PRs to get these gamemodes into the main mod. The font changes are inside `romfs/LocalizedData/${lang}/LayoutData/FontData.szs`. The update in the `romfs/LayoutData/HideAndSeekIcon.szs` changes the title for the players list from `Teammates` to `Players`. It also adds a shadow to the font of the list to increase readability. https://github.com/Amethyst-szs/SuperMarioOdysseyOnline/commit/f8eef7fb9762c8266ca4ef87d40112355d70d1a2 https://github.com/Amethyst-szs/SuperMarioOdysseyOnline/commit/2a0d0e77246dd54e128a704c0fe7118c81d20d35 (cherry picked from commit f8eef7fb9762c8266ca4ef87d40112355d70d1a2) (cherry picked from commit 2a0d0e77246dd54e128a704c0fe7118c81d20d35) Co-authored-by: Robin C. Ladiges <rcl.git@blackpinguin.de>
2022-11-03 18:58:07 +00:00
2022-06-16 21:33:18 +00:00
al::setPaneStringFormat(this, "TxtPlayerList", playerList.cstr());
}
}
void HideAndSeekIcon::exeEnd() {
if (al::isFirstStep(this)) {
al::startAction(this, "End", 0);
}
if (al::isActionEnd(this, 0)) {
kill();
}
}
void HideAndSeekIcon::showHiding() {
al::hidePane(this, "SeekingIcon");
al::showPane(this, "HidingIcon");
}
void HideAndSeekIcon::showSeeking() {
al::hidePane(this, "HidingIcon");
al::showPane(this, "SeekingIcon");
}
namespace {
NERVE_IMPL(HideAndSeekIcon, Appear)
NERVE_IMPL(HideAndSeekIcon, Wait)
NERVE_IMPL(HideAndSeekIcon, End)
}