Skip to content

Commit 78b351c

Browse files
authored
Merge pull request #4 from Arlind-dev/feat/port-to-v5
feat!: port to v5.3.0 and 2.2081
2 parents 2d853e1 + 96d38c7 commit 78b351c

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

mod.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
{
2-
"geode": "4.10.2",
2+
"geode": "5.3.0",
33
"gd": {
4-
"win": "2.2074",
5-
"mac": "2.2074",
6-
"ios": "2.2074",
7-
"android": "2.2074"
4+
"win": "2.2081",
5+
"mac": "2.2081",
6+
"ios": "2.2081",
7+
"android": "2.2081"
88
},
99
"id": "zsa.edit-attempts",
1010
"name": "Edit Attempts",
11-
"version": "v1.0.3",
11+
"version": "v1.0.4",
1212
"developer": "ZSA",
13+
"links": {
14+
"source": "https://github.com/wlagos3/edit-attempts"
15+
},
16+
"repository": "https://github.com/wlagos3/edit-attempts",
1317
"description": "Set level attempts",
18+
"issues": {
19+
"info": "Message me on Discord if you find any issues @zsa_"
20+
},
21+
"tags": ["utility"],
1422
"resources": {
1523
"sprites": ["resources/editAttemptsButton.png"]
1624
},
1725
"dependencies": {
18-
"geode.node-ids": ">=1.17.0"
26+
"geode.node-ids": ">=1.23.0"
1927
}
2028
}

src/main.cpp

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#include <Geode/modify/EditLevelLayer.hpp>
22
#include <Geode/modify/LevelInfoLayer.hpp>
33
#include <Geode/Geode.hpp>
4+
#include <Geode/ui/TextInput.hpp>
45

56
using namespace geode::prelude;
67

7-
class ModifyAttemptCountPopup : public geode::Popup<GJGameLevel*> {
8+
class ModifyAttemptCountPopup : public geode::Popup {
89
geode::SeedValueRSV* attempts;
9-
CCTextInputNode* inputNode;
10+
TextInput* inputNode;
1011
protected:
1112
bool boundsCheck(int num){
1213
if ((*attempts > 0 && num > std::numeric_limits<int>::max() - *attempts) ||
@@ -32,7 +33,7 @@ class ModifyAttemptCountPopup : public geode::Popup<GJGameLevel*> {
3233
}
3334
void onSetButtonClick(CCObject* sender){
3435
if(inputNode->getString().empty()){return;}
35-
int val = geode::numFromString<int>(inputNode->getString()).unwrapOr(-1);
36+
int val = numFromString<int>(inputNode->getString()).unwrapOr(-1);
3637
if (val > -1) {
3738
setAttempts(val);
3839
this->onClose(nullptr);
@@ -42,7 +43,7 @@ class ModifyAttemptCountPopup : public geode::Popup<GJGameLevel*> {
4243
}
4344
void onPlusButtonClick(CCObject* sender){
4445
if(inputNode->getString().empty()){return;}
45-
int val = geode::numFromString<int>(inputNode->getString()).unwrapOr(-1);
46+
int val = numFromString<int>(inputNode->getString()).unwrapOr(-1);
4647
if (val > -1) {
4748
addAttempts(val);
4849
this->onClose(nullptr);
@@ -52,26 +53,24 @@ class ModifyAttemptCountPopup : public geode::Popup<GJGameLevel*> {
5253
}
5354
void onMinusButtonClick(CCObject* sender){
5455
if(inputNode->getString().empty()){return;}
55-
int val = geode::numFromString<int>(inputNode->getString()).unwrapOr(-1);
56+
int val = numFromString<int>(inputNode->getString()).unwrapOr(-1);
5657
if (val > -1) {
5758
subtractAttempts(val);
5859
this->onClose(nullptr);
5960
} else {
6061
geode::Notification::create("Input is not a valid number", NotificationIcon::Error, 2.f)->show();
6162
}
6263
}
63-
bool setup(GJGameLevel* level) override {
64-
auto winSize = CCDirector::sharedDirector()->getWinSize();
64+
bool init(GJGameLevel* level) {
65+
if (!Popup::init(240.f, 160.f)) return false;
6566
attempts = &level->m_attempts;
6667

6768
this->setTitle("Modify Attempt Count");
6869

6970
auto menu = CCMenu::create();
7071

71-
auto input = CCTextInputNode::create(100, 100, "Attempts", "bigFont.fnt");
72-
input->setScale(0.75);
73-
input->setPosition(CCPoint(this->m_mainLayer->getContentWidth() / 2.f, 170 ));
74-
input->setAllowedChars("0123456789");
72+
auto input = TextInput::create(160.f, "Attempts");
73+
input->setFilter("0123456789");
7574
inputNode = input;
7675

7776
auto setSprite = ButtonSprite::create("Set");
@@ -97,16 +96,20 @@ class ModifyAttemptCountPopup : public geode::Popup<GJGameLevel*> {
9796
menu->addChildAtPosition(addButton, Anchor::Center, CCPoint(40, -50));
9897
menu->addChildAtPosition(removeButton, Anchor::Center, CCPoint(-39, -50));
9998
menu->updateLayout();
100-
this->addChild(input);
101-
this->addChild(menu);
99+
this->m_mainLayer->addChildAtPosition(input, Anchor::Center, CCPoint(0.f, 15.f));
100+
this->m_mainLayer->addChildAtPosition(menu, Anchor::Center, CCPoint(0.f, 15.f));
102101

103102
return true;
104103
}
104+
void onClose(CCObject* sender) override {
105+
inputNode->getInputNode()->detachWithIME();
106+
Popup::onClose(sender);
107+
}
105108

106109
public:
107110
static ModifyAttemptCountPopup* create(GJGameLevel* level) {
108111
auto ret = new ModifyAttemptCountPopup();
109-
if (ret->initAnchored(240.f, 160.f, level)) {
112+
if (ret->init(level)) {
110113
ret->autorelease();
111114
return ret;
112115
}
@@ -120,15 +123,11 @@ class $modify (AttemptSetterEditLevelLayer, EditLevelLayer){
120123
void onAttemptSetButtonClick(CCObject* sender){
121124
auto modifyAttemptCountPopup = ModifyAttemptCountPopup::create(m_level);
122125

123-
modifyAttemptCountPopup->m_scene = this;
124-
modifyAttemptCountPopup->m_noElasticity = true;
125126
modifyAttemptCountPopup->show();
126127
}
127128
bool init(GJGameLevel* level){
128129
if(!EditLevelLayer::init(level)) return false;
129130

130-
auto menu = CCMenu::create();
131-
std::string input = std::to_string(level->m_attempts);
132131
auto spr = CCSprite::create("editAttemptsButton.png"_spr);
133132

134133
auto folderMenu = getChildByID("folder-menu");
@@ -147,15 +146,11 @@ class $modify (AttemptSetterLevelInfoLayer, LevelInfoLayer){
147146
void onAttemptSetButtonClick(CCObject* sender){
148147
auto modifyAttemptCountPopup = ModifyAttemptCountPopup::create(m_level);
149148

150-
modifyAttemptCountPopup->m_scene = this;
151-
modifyAttemptCountPopup->m_noElasticity = true;
152149
modifyAttemptCountPopup->show();
153150
}
154151
bool init(GJGameLevel* level, bool challenge){
155152
if(!LevelInfoLayer::init(level, challenge)) return false;
156153

157-
auto menu = CCMenu::create();
158-
std::string input = std::to_string(level->m_attempts);
159154
auto spr = CCSprite::create("editAttemptsButton.png"_spr);
160155

161156

@@ -174,4 +169,3 @@ class $modify (AttemptSetterLevelInfoLayer, LevelInfoLayer){
174169

175170

176171

177-

0 commit comments

Comments
 (0)