mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-25 04:11:42 -04:00
add MDPopup for Markdown FLAlertLayers + support info & button to mods
This commit is contained in:
parent
e4a63d428f
commit
e2cb16d919
9 changed files with 133 additions and 9 deletions
loader
include/Geode
resources
src
|
@ -106,6 +106,12 @@ namespace geode {
|
|||
* <Geode/ui/MDTextArea.hpp>) for more info
|
||||
*/
|
||||
std::string m_changelog = "";
|
||||
/**
|
||||
* Support info for the mod; this means anything to show ways to
|
||||
* support the mod's development, like donations. Written in Markdown
|
||||
* (see <Geode/ui/MDTextArea.hpp>) for more info
|
||||
*/
|
||||
std::string m_supportInfo = "";
|
||||
/**
|
||||
* Git Repository of the mod.
|
||||
*/
|
||||
|
|
32
loader/include/Geode/ui/MDPopup.hpp
Normal file
32
loader/include/Geode/ui/MDPopup.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include "MDTextArea.hpp"
|
||||
#include "Popup.hpp"
|
||||
|
||||
namespace geode {
|
||||
/**
|
||||
* FLAlertLayer with support for Markdown. See <Geode/ui/MDTextArea.hpp>
|
||||
* for details on what features of MD are supported.
|
||||
*/
|
||||
class MDPopup : public Popup<
|
||||
std::string const&,
|
||||
std::string const&,
|
||||
std::string const&
|
||||
> {
|
||||
protected:
|
||||
bool setup(
|
||||
std::string const& title,
|
||||
std::string const& info,
|
||||
std::string const& btn
|
||||
) override;
|
||||
|
||||
static float estimateHeight(std::string const& content);
|
||||
|
||||
public:
|
||||
static MDPopup* create(
|
||||
std::string const& title,
|
||||
std::string const& content,
|
||||
std::string const& button
|
||||
);
|
||||
};
|
||||
}
|
|
@ -14,7 +14,8 @@ namespace geode {
|
|||
float width,
|
||||
float height,
|
||||
InitArgs... args,
|
||||
const char* bg = "GJ_square01.png"
|
||||
const char* bg = "GJ_square01.png",
|
||||
cocos2d::CCRect bgRect = { 0, 0, 80, 80 }
|
||||
) {
|
||||
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
|
||||
m_size = cocos2d::CCSize { width, height };
|
||||
|
@ -23,7 +24,7 @@ namespace geode {
|
|||
m_mainLayer = cocos2d::CCLayer::create();
|
||||
this->addChild(m_mainLayer);
|
||||
|
||||
m_bgSprite = cocos2d::extension::CCScale9Sprite::create(bg, { 0, 0, 80, 80 });
|
||||
m_bgSprite = cocos2d::extension::CCScale9Sprite::create(bg, bgRect);
|
||||
m_bgSprite->setContentSize(m_size);
|
||||
m_bgSprite->setPosition(winSize.width / 2, winSize.height / 2);
|
||||
m_mainLayer->addChild(m_bgSprite);
|
||||
|
@ -70,7 +71,12 @@ namespace geode {
|
|||
this->removeFromParentAndCleanup(true);
|
||||
}
|
||||
|
||||
void setTitle(const char* title, const char* font = "goldFont.fnt") {
|
||||
void setTitle(
|
||||
const char* title,
|
||||
const char* font = "goldFont.fnt",
|
||||
float scale = .7f,
|
||||
float offset = 20.f
|
||||
) {
|
||||
if (m_title) {
|
||||
m_title->setString(title);
|
||||
} else {
|
||||
|
@ -78,11 +84,11 @@ namespace geode {
|
|||
m_title = cocos2d::CCLabelBMFont::create(title, font);
|
||||
m_title->setPosition(
|
||||
winSize.width / 2,
|
||||
winSize.height / 2 + m_size.height / 2 - 20.f
|
||||
winSize.height / 2 + m_size.height / 2 - offset
|
||||
);
|
||||
m_mainLayer->addChild(m_title, 2);
|
||||
}
|
||||
m_title->limitLabelWidth(m_size.width - 20.f, .7f, .1f);
|
||||
m_title->limitLabelWidth(m_size.width - 20.f, scale, .1f);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
BIN
loader/resources/gift.png
Normal file
BIN
loader/resources/gift.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 8.1 KiB |
BIN
loader/resources/github.png
Normal file
BIN
loader/resources/github.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 7.7 KiB |
|
@ -1,6 +1,11 @@
|
|||
#include "InternalMod.hpp"
|
||||
#include "about.hpp"
|
||||
|
||||
static auto SUPPORT_INFO = R"MD(
|
||||
**Geode** is funded through your gracious <cy>**donations**</c>!
|
||||
You can support our work by sending <cp>**catgirl pictures**</c> to [HJfod](user:104257) :))
|
||||
)MD";
|
||||
|
||||
static ModInfo getInternalModInfo() {
|
||||
ModInfo info;
|
||||
|
||||
|
@ -10,6 +15,7 @@ static ModInfo getInternalModInfo() {
|
|||
info.m_description = "The mod loader";
|
||||
info.m_details = LOADER_ABOUT_MD;
|
||||
info.m_version = LOADER_VERSION;
|
||||
info.m_supportInfo = SUPPORT_INFO;
|
||||
info.m_repository = "https://github.com/geode-sdk/geode";
|
||||
info.m_supportsDisabling = false;
|
||||
info.m_spritesheets = {
|
||||
|
|
|
@ -226,8 +226,9 @@ Result<ModInfo> ModInfo::createFromGeodeFile(ghc::filesystem::path const& path)
|
|||
// unzip known MD files
|
||||
using God = std::initializer_list<std::pair<std::string, std::string*>>;
|
||||
for (auto [file, target] : God {
|
||||
{ "about.md", &info.m_details },
|
||||
{ "about.md", &info.m_details },
|
||||
{ "changelog.md", &info.m_changelog },
|
||||
{ "support.md", &info.m_supportInfo },
|
||||
}) {
|
||||
if (unzip.fileExists(file)) {
|
||||
unsigned long readSize = 0;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <Geode/ui/Scrollbar.hpp>
|
||||
#include <Geode/utils/WackyGeodeMacros.hpp>
|
||||
#include <Geode/ui/IconButtonSprite.hpp>
|
||||
#include <Geode/ui/MDPopup.hpp>
|
||||
#include "../settings/ModSettingsPopup.hpp"
|
||||
#include <InternalLoader.hpp>
|
||||
|
||||
|
@ -215,10 +216,9 @@ bool ModInfoLayer::init(ModObject* obj, ModListView* list) {
|
|||
}
|
||||
|
||||
if (m_mod->getModInfo().m_repository.size()) {
|
||||
auto repoSpr = CCSprite::createWithSpriteFrameName("github.png"_spr);
|
||||
|
||||
auto repoBtn = CCMenuItemSpriteExtra::create(
|
||||
repoSpr, this, makeMenuSelector([this](CCObject*) {
|
||||
CCSprite::createWithSpriteFrameName("github.png"_spr),
|
||||
this, makeMenuSelector([this](CCObject*) {
|
||||
web::openLinkInBrowser(m_mod->getModInfo().m_repository);
|
||||
})
|
||||
);
|
||||
|
@ -229,6 +229,24 @@ bool ModInfoLayer::init(ModObject* obj, ModListView* list) {
|
|||
m_buttonMenu->addChild(repoBtn);
|
||||
}
|
||||
|
||||
if (m_mod->getModInfo().m_supportInfo.size()) {
|
||||
auto supportBtn = CCMenuItemSpriteExtra::create(
|
||||
CCSprite::createWithSpriteFrameName("gift.png"_spr),
|
||||
this, makeMenuSelector([this](CCObject*) {
|
||||
MDPopup::create(
|
||||
"Support " + m_mod->getName(),
|
||||
m_mod->getModInfo().m_supportInfo,
|
||||
"OK"
|
||||
)->show();
|
||||
})
|
||||
);
|
||||
supportBtn->setPosition(
|
||||
size.width / 2 - 60.f,
|
||||
-size.height / 2 + 25.f
|
||||
);
|
||||
m_buttonMenu->addChild(supportBtn);
|
||||
}
|
||||
|
||||
|
||||
auto enableBtnSpr = ButtonSprite::create(
|
||||
"Enable", "bigFont.fnt", "GJ_button_01.png", .6f
|
||||
|
|
55
loader/src/ui/nodes/MDPopup.cpp
Normal file
55
loader/src/ui/nodes/MDPopup.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <Geode/ui/MDPopup.hpp>
|
||||
#include <Geode/utils/string.hpp>
|
||||
|
||||
USE_GEODE_NAMESPACE();
|
||||
|
||||
bool MDPopup::setup(
|
||||
std::string const& title,
|
||||
std::string const& info,
|
||||
std::string const& btnText
|
||||
) {
|
||||
this->setTitle(title.c_str(), "goldFont.fnt", .9f, 33.f);
|
||||
|
||||
auto winSize = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
auto contentSize = CCSize {
|
||||
m_size.width - 70.f,
|
||||
m_size.height - 120.f,
|
||||
};
|
||||
auto content = MDTextArea::create(info, contentSize);
|
||||
content->setPosition(winSize / 2 - contentSize / 2);
|
||||
m_mainLayer->addChild(content);
|
||||
|
||||
auto btnSpr = ButtonSprite::create(btnText.c_str());
|
||||
btnSpr->setScale(1.f);
|
||||
|
||||
auto btn = CCMenuItemSpriteExtra::create(
|
||||
btnSpr, this, menu_selector(MDPopup::onClose)
|
||||
);
|
||||
btn->setPosition(.0f, -m_size.height / 2 + 35.f);
|
||||
m_buttonMenu->addChild(btn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float MDPopup::estimateHeight(std::string const& content) {
|
||||
return clamp(string::count(content, '\n') * 30.f, 200.f, 360.f);
|
||||
}
|
||||
|
||||
MDPopup* MDPopup::create(
|
||||
std::string const& title,
|
||||
std::string const& content,
|
||||
std::string const& button
|
||||
) {
|
||||
auto ret = new MDPopup();
|
||||
if (ret && ret->init(
|
||||
320.f, MDPopup::estimateHeight(content),
|
||||
title, content, button,
|
||||
"square01_001.png", { 0, 0, 94, 94 }
|
||||
)) {
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(ret);
|
||||
return nullptr;
|
||||
}
|
Loading…
Add table
Reference in a new issue