From 6fbd54ae609ce74d8d3a1f6c307ec3d0fd35c0df Mon Sep 17 00:00:00 2001 From: KiritoDev Date: Tue, 22 Jun 2021 00:31:10 -0500 Subject: [PATCH] Moon64 v1.0.1 --- src/game/ingame_menu.c | 5 +- src/moon/achievements/achievements.cpp | 10 ++-- src/moon/ui/screens/options/main-view.cpp | 14 +++++ src/moon/ui/screens/options/main-view.h | 7 ++- src/moon/ui/utils/moon-draw-utils.cpp | 2 +- src/moon/ui/widgets/mw-value.cpp | 8 ++- src/pc/discord/discordrpc.cpp | 67 ++++++++++++++++++++--- 7 files changed, 96 insertions(+), 17 deletions(-) diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index 719bf87f..d292d807 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -30,6 +30,7 @@ #include #include "pc/gfx/gfx_pc.h" #include "moon/utils/moon-gfx.h" +#include "moon/ui/screens/options/main-view.h" u16 gDialogColorFadeTimer; s8 gLastDialogLineNum; @@ -1252,7 +1253,7 @@ void render_pause_red_coins(void) { s8 x; for (x = 0; x < gRedCoinsCollected; x++) { - print_animated_red_coin(GFX_DIMENSIONS_FROM_RIGHT_EDGE(30) - x * 20, 16); + print_animated_red_coin(GFX_DIMENSIONS_FROM_RIGHT_EDGE(12) - x * 20, 30); } } @@ -1538,6 +1539,7 @@ s16 render_pause_courses_and_castle(void) { case DIALOG_STATE_VERTICAL: shade_screen(); render_pause_my_score_coins(); + drawIngameMenuButtons(); render_pause_red_coins(); /* Added support for the "Exit course at any time" cheat */ @@ -1563,6 +1565,7 @@ s16 render_pause_courses_and_castle(void) { case DIALOG_STATE_HORIZONTAL: shade_screen(); print_hud_pause_colorful_str(); + drawIngameMenuButtons(); render_pause_castle_menu_box(160, 143); render_pause_castle_main_strings(104, 60); diff --git a/src/moon/achievements/achievements.cpp b/src/moon/achievements/achievements.cpp index 22b22277..86d4bc1b 100644 --- a/src/moon/achievements/achievements.cpp +++ b/src/moon/achievements/achievements.cpp @@ -51,8 +51,8 @@ namespace AchievementList { Achievement* GET_6_LEVEL_STARS = MoonAchievements::bind(new Achievement("achievement.get6MainStars", "textures/moon/achievements/ranks.f.rgba16", "F Rank", "Get all 6 Main Stars in One Level", false, 0, 150, nullptr)); Achievement* GET_100_COIN_STAR = MoonAchievements::bind(new Achievement("achievement.get100CoinStar", "textures/moon/achievements/ranks.e.rgba16", "E Rank", "Get a 100 Coin Star in One Level", false, 0, 150, nullptr)); Achievement* GET_ALL_LVL_COINS = MoonAchievements::bind(new Achievement("achievement.getAllCoins", "textures/moon/achievements/ranks.d.rgba16", "D Rank", "Get all Coins in One Level", false, 0, 150, nullptr)); - Achievement* GET_FLOOR_0_STARS = MoonAchievements::bind(new Achievement("achievement.getAllStarsInBasement", "textures/moon/achievements/ranks.b.rgba16", "B Rank", "Get all Main Stars in the Basement", false, 0, 150, nullptr)); - Achievement* GET_FLOOR_1_STARS = MoonAchievements::bind(new Achievement("achievement.getAllStarsInFloor1", "textures/moon/achievements/ranks.c.rgba16", "C Rank", "Get all Main Stars in the First Floor", false, 0, 150, nullptr)); + Achievement* GET_FLOOR_0_STARS = MoonAchievements::bind(new Achievement("achievement.getAllStarsInBasement", "textures/moon/achievements/ranks.b.rgba16", "B Rank", "Get all Main Stars in the First Floor", false, 0, 150, nullptr)); + Achievement* GET_FLOOR_1_STARS = MoonAchievements::bind(new Achievement("achievement.getAllStarsInFloor1", "textures/moon/achievements/ranks.c.rgba16", "C Rank", "Get all Main Stars in the Basement", false, 0, 150, nullptr)); Achievement* GET_FLOOR_2_STARS = MoonAchievements::bind(new Achievement("achievement.getAllStarsInFloor2", "textures/moon/achievements/ranks.a.rgba16", "A Rank", "Get all Main Stars in the Second Floor", false, 0, 150, nullptr)); Achievement* GET_FLOOR_3_STARS = MoonAchievements::bind(new Achievement("achievement.getAllStarsInFloor3", "textures/moon/achievements/ranks.s.rgba16", "S Rank", "Get all Main Stars in the Third Floor", false, 0, 150, nullptr)); Achievement* GET_CASTLE_STARS = MoonAchievements::bind(new Achievement("achievement.getAllCastleStars", "textures/moon/achievements/ranks.splus.rgba16", "S+ Rank", "Get all Castle Secret Stars", false, 0, 150, nullptr)); @@ -73,7 +73,7 @@ namespace AchievementList { /* Death Achievements */ Achievement* DEATH_BY_BOSS = MoonAchievements::bind(new Achievement("achievement.deathByBoss", "textures/moon/achievements/deaths.boss.rgba16", "Git Gud", "Get killed by a boss", false, 0, 150, nullptr)); Achievement* DEATH_BY_FALLING = MoonAchievements::bind(new Achievement("achievement.deathByFalling", "textures/moon/achievements/deaths.falling.rgba16", "My Leg!", "Die by falling", false, 0, 150, nullptr)); - Achievement* DEATH_BY_SAND = MoonAchievements::bind(new Achievement("achievement.deathBySand", "textures/moon/achievements/deaths.quicksand.rgba16", "Sinreked", "Die by sinking sand", false, 0, 150, nullptr)); + Achievement* DEATH_BY_SAND = MoonAchievements::bind(new Achievement("achievement.deathBySand", "textures/moon/achievements/deaths.quicksand.rgba16", "Sinked", "Die in the quicksand", false, 0, 150, nullptr)); Achievement* DEATH_BY_CRUSHING = MoonAchievements::bind(new Achievement("achievement.deathByCrushing", "textures/moon/achievements/deaths.crushed.rgba16", "Space Jam", "Get crushed", false, 0, 150, nullptr)); Achievement* DEATH_BY_BOWSER = MoonAchievements::bind(new Achievement("achievement.deathByBowser", "textures/moon/achievements/deaths.bowser.rgba16", "Bad Ending", "Get killed by Bowser", false, 0, 150, nullptr)); Achievement* DEATH_BY_ENEMY = MoonAchievements::bind(new Achievement("achievement.deathByEnemy", "textures/moon/achievements/deaths.standard.rgba16", "Classic Way", "Get killed by a normal enemy", false, 0, 150, nullptr)); @@ -87,7 +87,7 @@ namespace AchievementList { Achievement* TALK_25_TIMES = MoonAchievements::bind(new Achievement("achievement.talk25Times", "textures/moon/achievements/extras.talker.rgba16", "Olympic Talker", "Talk 25 times with npcs", false, 0, 150, nullptr)); Achievement* JUMP_1000_TIMES = MoonAchievements::bind(new Achievement("achievement.jump1000Times", "textures/moon/achievements/extras.swimmer.rgba16", "Olympic Swimmer", "Grab every star that needs Metal Cap without it", false, 0, 150, nullptr)); Achievement* WATCH_END_CREDITS = MoonAchievements::bind(new Achievement("achievement.watchEndCredits", "textures/moon/achievements/extras.cake.rgba16", "The Cake Is A Lie?!", "Watch the end credits", false, 0, 150, nullptr)); - Achievement* RELEASE_CHAIN_CHOMP = MoonAchievements::bind(new Achievement("achievement.releaseChainChomp", "textures/moon/achievements/extras.chain-chomp.rgba16", "Who Let The Dog Out?", "Get killed by a boss", false, 0, 150, nullptr)); + Achievement* RELEASE_CHAIN_CHOMP = MoonAchievements::bind(new Achievement("achievement.releaseChainChomp", "textures/moon/achievements/extras.chain-chomp.rgba16", "Chain-Chomp Unleashed", "Unleash the Chain-Chomp", false, 0, 150, nullptr)); Achievement* CHEATER = MoonAchievements::bind(new Achievement("achievement.cheater", "mod-icons://Moon64", "What a loser!", "You turned on cheats", false, 0, 150, nullptr)); }; @@ -339,7 +339,9 @@ namespace Moon { if(cheatsGotEnabled || gCurrDemoInput) return; if(find_if(entries[gCurrSaveFileNum - 1].begin(), entries[gCurrSaveFileNum - 1].end(), [&cae = achievement] (auto &m) -> bool { return cae->id == m->achievement->id; }) != entries[gCurrSaveFileNum - 1].end()) return; + #ifdef GAME_DEBUG cout << "Achievement got triggered: " << achievement->title << endl; + #endif entries[gCurrSaveFileNum - 1].push_back(new AchievementEntry({ .launchTime = 0, .dead = false, .achievement = achievement, .entryID = entries.size() })); } diff --git a/src/moon/ui/screens/options/main-view.cpp b/src/moon/ui/screens/options/main-view.cpp index d1405aec..fd00a133 100644 --- a/src/moon/ui/screens/options/main-view.cpp +++ b/src/moon/ui/screens/options/main-view.cpp @@ -142,6 +142,20 @@ void MoonOptMain::Draw(){ MoonScreen::Draw(); } +extern "C" { + void drawIngameMenuButtons(){ + + if(!(gGlobalTimer % 20)) + stickAnim = !stickAnim; + + string basePath = "textures/moon/controller/"; + + basePath.append(stickAnim ? "stick-down.rgba16" : "stick-up.rgba16"); + MoonDrawButton(5, GetScreenHeight() - 24, "Move", basePath, 16, 0, false, false); + + MoonDrawButton(7, GetScreenHeight() - 24, "Open settings", "textures/moon/controller/r-btn.rgba16", 10, 4, true, false); + } +} void MoonOptMain::Dispose(){ configfile_save(configfile_name()); diff --git a/src/moon/ui/screens/options/main-view.h b/src/moon/ui/screens/options/main-view.h index 269fb9d2..f0c8783b 100644 --- a/src/moon/ui/screens/options/main-view.h +++ b/src/moon/ui/screens/options/main-view.h @@ -1,7 +1,8 @@ #ifndef MoonScreenTest #define MoonScreenTest -#include "moon/ui/interfaces/moon-screen.h" +#ifdef __cplusplus +#include "moon/ui/interfaces/moon-screen.h" class MoonOptMain : public MoonScreen { public: void Init(); @@ -13,6 +14,10 @@ private: void setCategory(int index); bool stickAnim = 0; }; +#else +void drawIngameMenuButtons(); + +#endif #endif \ No newline at end of file diff --git a/src/moon/ui/utils/moon-draw-utils.cpp b/src/moon/ui/utils/moon-draw-utils.cpp index 9851ff4a..c680bf50 100644 --- a/src/moon/ui/utils/moon-draw-utils.cpp +++ b/src/moon/ui/utils/moon-draw-utils.cpp @@ -118,7 +118,7 @@ void MoonDrawButton(int x, int y, std::string text, std::string texture, int siz x = GetScreenWidth(false) - x; int txtWidth = MoonGetTextWidth(text, 0.8, false); - MoonDrawTexture(GFX_DIMENSIONS_FROM_LEFT_EDGE(x) - txtWidth - size - 3, y - 3 + offset, size, size, sys_strdup(texture.c_str())); + MoonDrawTexture(GFX_DIMENSIONS_FROM_LEFT_EDGE(x) - txtWidth - size - 5, y - 3 + offset, size, size, sys_strdup(texture.c_str())); MoonDrawText(x - txtWidth, y, text, 0.8, {255, 255, 255, 255}, true, false); } } \ No newline at end of file diff --git a/src/moon/ui/widgets/mw-value.cpp b/src/moon/ui/widgets/mw-value.cpp index 598ee391..7863b6f9 100644 --- a/src/moon/ui/widgets/mw-value.cpp +++ b/src/moon/ui/widgets/mw-value.cpp @@ -147,6 +147,11 @@ void unselectWidget(MWValue* base){ } void MWValue::Update(){ + if(IsBtnPressed(MoonButtons::A_BTN) && this->bind.btn != nullptr && this->selected){ + this->bind.btn(); + return; + } + if(!this->focused) return; float xStick = GetStickValue(MoonButtons::L_STICK, false); @@ -154,8 +159,8 @@ void MWValue::Update(){ bool isArray = this->bind.values != NULL && this->bind.index != NULL; bool isFloat = this->bind.fvar != NULL; bool isInt = this->bind.ivar != NULL; - bool isBtn = this->bind.btn != NULL; bool isBind = this->bind.bindKeys != NULL; + bool isBtn = this->bind.btn != NULL; float maxValue = isArray ? (*this->bind.values).size() - 1 : this->bind.max - int(isBind); float minValue = isArray || isBind ? 0 : this->bind.min; @@ -163,7 +168,6 @@ void MWValue::Update(){ if(IsBtnPressed(MoonButtons::A_BTN)){ if(isBtn){ - unselectWidget(this); this->bind.btn(); return; } diff --git a/src/pc/discord/discordrpc.cpp b/src/pc/discord/discordrpc.cpp index b66219f0..9a7f0f1e 100644 --- a/src/pc/discord/discordrpc.cpp +++ b/src/pc/discord/discordrpc.cpp @@ -14,6 +14,13 @@ #include "moon/texts/moon-loader.h" #include "moon/utils/moon-env.h" +#include "moon/achievements/achievements.h" + +extern "C" { +#include "pc/platform.h" +#include "game/level_update.h" +} + #define DISCORDLIBFILE "libdiscord-rpc" // Thanks Microsoft for being non posix compliant @@ -35,8 +42,8 @@ #endif #define DISCORDLIB DISCORDLIBFILE DISCORDLIBEXT -#define DISCORD_APP_ID "709083908708237342" -#define DISCORD_UPDATE_RATE 5 +#define DISCORD_APP_ID "856717153431453716" +#define DISCORD_UPDATE_RATE 3 using namespace std; @@ -60,6 +67,12 @@ Discord_Shutdown discordShutdown; Discord_ClearPresence discordClearPresence; Discord_UpdatePresence discordUpdatePresence; +static s16 lastHealth = -1; + +static s16 lastStarAmount = 0; +static s16 lastAchievements = 0; + + static s16 lastCourseNum = -1; static s16 lastActNum = -1; bool reloadRPC = false; @@ -197,19 +210,55 @@ static void set_state(void) { } } -void set_logo(void) { - if (lastCourseNum) - snprintf(largeImageKey, sizeof(largeImageKey), "%d", lastCourseNum); - else - strcpy(largeImageKey, "0"); +string getLevelLogo(){ + switch(lastCourseNum){ + case 0: + return "level-peach"; + case 6: + return "moon64-logo"; + case 9: + return "level-3"; + case 16: + case 17: + case 18: + return "level-bowser"; + default: + return "level-"+to_string(lastCourseNum); + } +} - discordRichPresence.largeImageKey = largeImageKey; +void set_logo(void) { + discordRichPresence.largeImageKey = sys_strdup(getLevelLogo().data()); } void DiscordReloadPresence() { reloadRPC = true; } +void set_health(){ + if(gCurrCourseNum == 0) return; + if(lastHealth != gHudDisplay.wedges){ + lastHealth = gHudDisplay.wedges; + string new_health_icon = "health-"+to_string(lastHealth); + string new_health_text = to_string(lastHealth) + " HP"; + discordRichPresence.smallImageKey = sys_strdup(new_health_icon.data()); + discordRichPresence.smallImageText = sys_strdup(new_health_text.data()); + } +} + +void set_image_key(){ + if(gCurrCourseNum == 0) return; + int size = entries[gCurrSaveFileNum - 1].size(); + if(lastAchievements != size || lastStarAmount != gHudDisplay.stars){ + lastAchievements = size; + lastStarAmount = gHudDisplay.stars; + + string new_text = to_string(lastStarAmount) + "/120 Stars - " + to_string(lastAchievements) + "/" + to_string(registeredAchievements.size()) + " Achievements"; + + discordRichPresence.largeImageText = sys_strdup(new_text.data()); + } +} + void DiscordUpdatePresence(){ if (!configDiscordRPC || !initd) return; if (time(NULL) < lastUpdatedTime + DISCORD_UPDATE_RATE) return; @@ -219,6 +268,8 @@ void DiscordUpdatePresence(){ set_state(); set_details(); set_logo(); + set_health(); + set_image_key(); discordUpdatePresence(&discordRichPresence); reloadRPC = false; }