Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
setup_geode_mod(${PROJECT_NAME})

CPMAddPackage("gh:dankmeme01/cue#main")
CPMAddPackage("gh:GlobedGD/argon@1.5.1")
target_link_libraries(${PROJECT_NAME} cue argon)
CPMAddPackage("gh:CubicCommunity/gdcord#main")
target_link_libraries(${PROJECT_NAME} cue gdcord)
50 changes: 22 additions & 28 deletions src/hooks/Mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,46 +61,40 @@ class $modify(MockMenuLayer, MenuLayer) {
ss->setAnchorPoint(anchor::center);
ss->setPosition({-192.f, getScaledContentHeight() / 2.f});

ss->setLoadCallback([self = WeakRef(this), screenshot = WeakRef(ss), percent](Result<> res) {
ss->setLoadCallback([this, ss, percent](Result<> res) {
if (res.isOk()) {
if (auto s = self.lock()) {
log::info("Sprite loaded successfully from save dir PNG");
log::info("Sprite loaded successfully from save dir PNG");

if (auto ss = screenshot.lock()) {
auto const percLabelText = fmt::format("{}%", percent);
auto const percLabelText = fmt::format("{}%", percent);

auto percLabel = Label::create(percLabelText.c_str(), font::big);
percLabel->setID("percentage");
percLabel->setPosition(ss->getScaledContentSize() / 2.f);
percLabel->ignoreAnchorPointForPosition(false);
percLabel->setAnchorPoint({0, 0});
percLabel->setScale(2.5);
auto percLabel = Label::create(percLabelText.c_str(), font::big);
percLabel->setID("percentage");
percLabel->setPosition(ss->getScaledContentSize() / 2.f);
percLabel->ignoreAnchorPointForPosition(false);
percLabel->setAnchorPoint({0, 0});
percLabel->setScale(2.5);

ss->addChild(percLabel);
ss->addChild(percLabel);

auto rA = rng::pc();
auto rB = rng::pc();
auto rA = rng::pc();
auto rB = rng::pc();

float yA = s->getScaledContentHeight() * rB; // starting height pos
float yB = s->getScaledContentHeight() * rA; // ending height pos
float yA = getScaledContentHeight() * rB; // starting height pos
float yB = getScaledContentHeight() * rA; // ending height pos

ss->setPositionY(s->getScaledContentHeight() * yA);
ss->setRotation(360.f * (yA * yB)); // random rotation
ss->setPositionY(getScaledContentHeight() * yA);
ss->setRotation(360.f * (yA * yB)); // random rotation

auto move = CCEaseIn::create(CCMoveTo::create(10.f, {s->getScaledContentWidth() + 192.f, s->getScaledContentHeight() * yB}), 1.f);
auto rotate = CCEaseOut::create(CCRotateBy::create(12.5f, 45.f), 1.f);
auto move = CCEaseIn::create(CCMoveTo::create(10.f, {getScaledContentWidth() + 192.f, getScaledContentHeight() * yB}), 1.f);
auto rotate = CCEaseOut::create(CCRotateBy::create(12.5f, 45.f), 1.f);

auto action = CCSpawn::createWithTwoActions(move, rotate);
ss->runAction(action);
auto action = CCSpawn::createWithTwoActions(move, rotate);
ss->runAction(action);

log::info("Animated sprite successfully");
} else {
log::error("Mocked sprite was destroyed before load callback");
};
};
log::info("Animated sprite successfully");
} else {
log::error("Sprite failed to load: {}", res.unwrapErr());
if (auto ss = screenshot.lock()) ss->removeFromParent();
ss->removeFromParent();
};
});

Expand Down
1 change: 1 addition & 0 deletions src/ui/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace horrible {
Menu();
~Menu();

void onEnter() override;
void onExit() override;

bool init() override;
Expand Down
7 changes: 0 additions & 7 deletions src/ui/MenuCredits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,11 @@ namespace horrible {
geode::Button::ButtonCallback callback;
};

private:
static MenuCredits* s_inst;

protected:
void onExit() override;

bool init(geode::ZStringView theme);

public:
static MenuCredits* create(geode::ZStringView theme);

static MenuCredits* get() noexcept;
};

class CreditsManager final : public base::Singleton<CreditsManager> {
Expand Down
76 changes: 14 additions & 62 deletions src/ui/MenuExtras.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

#include <util/Base.h>

#include <gdcord/gdc.h>

#include <Geode/Geode.hpp>

namespace horrible {
class MenuSuggest final : public geode::Popup {
private:
static MenuSuggest* s_inst;

static asp::Instant s_lastSuggest;

geode::TextInput* m_topicInput;
Expand All @@ -19,54 +19,23 @@ namespace horrible {
geode::LoadingSpinner* m_loading;

protected:
void onExit() override;

void processSuggestion(geode::Button* sender);

bool init(geode::ZStringView theme);

public:
static MenuSuggest* create(geode::ZStringView theme);

static MenuSuggest* get() noexcept;
};

struct DiscordLink final {
std::string id;
std::string username;
std::string avatar;
};
class SupporterState final : public base::Singleton<SupporterState> {
using Callback = geode::CopyableFunction<void(geode::Result<>)>;

class AuthState final : public base::Singleton<AuthState> {
private:
bool m_authorized = false;
bool m_discordLinked = false;

int m_accountID;
int m_userID;
std::string m_username;
std::string m_token;

DiscordLink m_discord;
bool m_supporter = false;

protected:
void setAuthInfo(int accountID, int userID, std::string username, std::string token);

public:
void startAuth(geode::CopyableFunction<void(geode::Result<>)>&& callback);

void setDiscordLinkInfo(DiscordLink discord);

bool isAuthorized() const noexcept;
bool isAuthValid() const;

int getAccountID() const noexcept;
int getUserID() const noexcept;
geode::ZStringView getUsername() const noexcept;
geode::ZStringView getToken() const noexcept;
void validateSupporter(Callback&& cb);

geode::Result<DiscordLink> getDiscord() const;
bool isSupporter() const noexcept;
};

Expand All @@ -75,20 +44,14 @@ namespace horrible {
std::string normalizeAvatarURL(std::string url) const;

protected:
bool init(DiscordLink const& profile);
bool init(gdc::DiscordLink const& profile);

public:
static MenuDiscordCell* create(DiscordLink const& profile);
static MenuDiscordCell* create(gdc::DiscordLink const& profile);
};

class MenuDiscord final : public geode::Popup {
private:
static MenuDiscord* s_inst;

std::string m_state;
asp::Instant m_since;
geode::async::TaskHolder<geode::utils::web::WebResponse> m_listener;

geode::Label* m_linkLabel = nullptr;
MenuDiscordCell* m_discordCell = nullptr;

Expand All @@ -97,39 +60,28 @@ namespace horrible {

ui::LabelArea* m_label = nullptr;

void setupAuthInterface();
void setupAuthInterface(bool forceHide = false);

protected:
void onExit() override;

void checkDiscordStatus(float);

bool init(geode::ZStringView theme);

public:
static MenuDiscord* create(geode::ZStringView theme);

static MenuDiscord* get() noexcept;
};

class MenuKofi final : public geode::Popup {
private:
static MenuKofi* s_inst;
ui::LabelArea* m_infoContainer = nullptr;
geode::LoadingSpinner* m_loading = nullptr;

protected:
void onExit() override;
geode::Button* m_linkBtn = nullptr;
geode::Label* m_linkLabel = nullptr;
geode::LoadingSpinner* m_linkLoading = nullptr;

protected:
bool init(geode::ZStringView theme);

public:
static MenuKofi* create(geode::ZStringView theme);

static MenuKofi* get() noexcept;
};
};

template <>
struct horrible::json::Serialize<horrible::DiscordLink> final {
static geode::Result<horrible::DiscordLink> fromJson(horrible::json::Value const& value);
static horrible::json::Value toJson(horrible::DiscordLink const& value);
};
46 changes: 24 additions & 22 deletions src/ui/src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,20 @@ void Menu::setupImageBackground(fs::path const& path) {
m_impl->themeBackground->setID("theme-bg");
m_impl->themeBackground->setPosition(m_bgSprite->getScaledContentSize() / 2.f);

m_impl->themeBackground->setLoadCallback([self = WeakRef(this), themeBg = WeakRef(m_impl->themeBackground)](Result<> res) {
if (auto s = self.lock()) {
if (auto bg = themeBg.lock()) {
if (res.isOk()) {
cue::rescaleToMatch(bg, s->m_bgSprite, true);
bg->setOpacity(100);

log::debug("Successfully loaded theme background");
} else if (res.isErr()) {
log::error("Failed to load theme background: {}", res.unwrapErr());
} else {
log::error("Failed to load theme background for an unknown reason");
};
m_impl->themeBackground->setLoadCallback([this, themeBg = WeakRef(m_impl->themeBackground)](Result<> res) {
if (auto bg = themeBg.lock()) {
if (res.isOk()) {
cue::rescaleToMatch(bg, m_bgSprite, true);
bg->setOpacity(100);

log::debug("Successfully loaded theme background");
} else if (res.isErr()) {
log::error("Failed to load theme background: {}", res.unwrapErr());
} else {
log::error("Theme background sprite was destroyed before load callback");
log::error("Failed to load theme background for an unknown reason");
};
} else {
log::error("Menu was destroyed before theme background load callback");
log::error("Theme background sprite was destroyed before load callback");
};
});

Expand Down Expand Up @@ -491,7 +487,7 @@ bool Menu::init() {
if (!m_impl->hasInternet) return Notification::create("An internet connection is required.", NotificationIcon::Error)->show()

#define NOTIFY_IF_LOGGED_OUT \
if (!AuthState::get()->isAuthValid()) return Notification::create("You must be logged in!", NotificationIcon::Warning)->show()
if (!argon::signedIn()) return Notification::create("You must be logged in!", NotificationIcon::Warning)->show()

auto socialBtns = std::to_array<SocialBtnData>(
{
Expand All @@ -517,7 +513,7 @@ bool Menu::init() {
[this](auto) {
NOTIFY_INTERNET_IF_OFFLINE;

if (!AuthState::get()->isAuthValid()) {
if (!argon::signedIn()) {
createQuickPopup(
"Discord",
"Join the <cf>Cubic Studios</c> <cj>official community Discord server</c>?",
Expand Down Expand Up @@ -608,11 +604,18 @@ bool Menu::init() {
return true;
};

void Menu::onEnter() {
Popup::onEnter();
s_inst = this;
};

void Menu::onExit() {
if (auto credits = MenuCredits::get()) credits->removeFromParent();
if (auto suggest = MenuSuggest::get()) suggest->removeFromParent();
if (auto discord = MenuDiscord::get()) discord->removeFromParent();
if (auto kofi = MenuKofi::get()) kofi->removeFromParent();
if (auto scene = CCScene::get()) {
if (auto credits = scene->getChildByType<MenuCredits>()) credits->removeFromParent();
if (auto suggest = scene->getChildByType<MenuSuggest>()) suggest->removeFromParent();
if (auto discord = scene->getChildByType<MenuDiscord>()) discord->removeFromParent();
if (auto kofi = scene->getChildByType<MenuKofi>()) kofi->removeFromParent();
};

s_inst = nullptr;

Expand All @@ -627,7 +630,6 @@ Menu* Menu::create() {
auto ret = new Menu();
if (ret->init()) {
ret->autorelease();
s_inst = ret;
return ret;
};

Expand Down
12 changes: 0 additions & 12 deletions src/ui/src/MenuCredits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ MenuPlayer* MenuPlayer::create(ZStringView name, int account, int icon, int colo
return nullptr;
};

MenuCredits* MenuCredits::s_inst = nullptr;

bool MenuCredits::init(ZStringView theme) {
auto btns = themes::getCircleBaseColor(theme);

Expand Down Expand Up @@ -378,20 +376,10 @@ bool MenuCredits::init(ZStringView theme) {
return true;
};

void MenuCredits::onExit() {
s_inst = nullptr;
Popup::onExit();
};

MenuCredits* MenuCredits::get() noexcept {
return s_inst;
};

MenuCredits* MenuCredits::create(ZStringView theme) {
auto ret = new MenuCredits();
if (ret->init(theme)) {
ret->autorelease();
s_inst = ret;
return ret;
};

Expand Down
Loading