Skip to content

Commit 4c1fee8

Browse files
committed
fix #10
1 parent 34f430d commit 4c1fee8

10 files changed

Lines changed: 492 additions & 219 deletions

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "5.0.0",
2+
"geode": "5.3.0",
33
"gd": {
44
"win": "2.2081",
55
"android": "2.2081",

src/config.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
#define MAX_ZOOM 10
1313
#define MIN_ZOOM 0.01
1414
#define ROLE_COUNT 4
15+
#define RULES_VERSION 1

src/nodes/ExtPreviewBG.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
#include "ExtPreviewBG.hpp"
22
#include "../ui/ObjectWorkshop.hpp"
33
#include "../config.hpp"
4-
bool ExtPreviewBG::init(LevelEditorLayer* editorLayer, std::string data, CCSize contentSize) {
5-
if (!CCLayer::init()) return false;
6-
this->setContentSize(contentSize);
7-
this->setAnchorPoint({0.5, 0.5});
8-
Build<CCScale9Sprite>::create("square02_small.png").opacity(60).contentSize(this->getContentSize()).with([](auto node) {
9-
Build<CCLabelBMFont>::create("Preview", "goldFont.fnt").scale(0.425F).parentAtPos(node, Anchor::Top, {0, -8});
10-
}).store(m_bg).parentAtPos(this, Anchor::Center);
11-
CCLayerColor* mask = CCLayerColor::create({255, 255, 255});
12-
mask->setContentSize(m_bg->getContentSize());
13-
m_clippingNode = CCClippingNode::create();
14-
m_clippingNode->setContentSize(m_bg->getContentSize());
15-
m_clippingNode->setAnchorPoint({0.5, 0.5});
4+
5+
void ExtPreviewBG::setNewPreview(std::string data) {
6+
if (m_clippingNode) {
7+
m_clippingNode->removeAllChildrenWithCleanup(true);
8+
}
169
if (!data.empty()) {
10+
m_data = data;
1711
unsigned int objectCount = std::count(data.begin(), data.end(), ';');
1812
int renderLimit = Mod::get()->getSettingValue<int64_t>("render-objects");
1913
int preRender = Mod::get()->getSettingValue<int64_t>("prerender-objects");
2014
auto smartBlock = CCArray::create();
2115
if (objectCount >= preRender && Mod::get()->getSettingValue<bool>("prerender-full")) {
22-
auto sprite = editorLayer->m_editorUI->spriteFromObjectString(data, false, false, renderLimit, smartBlock, (CCArray *)0x0,(GameObject *)0x0);
23-
editorLayer->updateObjectColors(smartBlock);
16+
auto sprite = m_editorLayer->m_editorUI->spriteFromObjectString(data, false, false, renderLimit, smartBlock, (CCArray *)0x0,(GameObject *)0x0);
17+
m_editorLayer->updateObjectColors(smartBlock);
2418

2519
CCSize contentSize = sprite->getContentSize();
2620
sprite->setPosition(contentSize / 2);
@@ -32,15 +26,31 @@ bool ExtPreviewBG::init(LevelEditorLayer* editorLayer, std::string data, CCSize
3226
objSprite->setContentSize(sprite->getContentSize());
3327
objSprite->addChildAtPosition(tex, Anchor::Center);
3428
} else {
35-
objSprite = editorLayer->m_editorUI->spriteFromObjectString(data, false, false, renderLimit, smartBlock, (CCArray *)0x0,(GameObject *)0x0);
36-
editorLayer->updateObjectColors(smartBlock);
29+
objSprite = m_editorLayer->m_editorUI->spriteFromObjectString(data, false, false, renderLimit, smartBlock, (CCArray *)0x0,(GameObject *)0x0);
30+
m_editorLayer->updateObjectColors(smartBlock);
3731
}
3832

3933
objSprite->setScale((m_clippingNode->getContentSize().height - 20) / objSprite->getContentSize().height);
4034
m_oldScale = objSprite->getScale();
4135
m_clippingNode->addChildAtPosition(objSprite, Anchor::Center, {0, -5});
4236
m_oldPos = objSprite->getPosition();
4337
}
38+
}
39+
40+
bool ExtPreviewBG::init(LevelEditorLayer* editorLayer, std::string data, CCSize contentSize) {
41+
if (!CCLayer::init()) return false;
42+
m_editorLayer = editorLayer;
43+
this->setContentSize(contentSize);
44+
this->setAnchorPoint({0.5, 0.5});
45+
Build<CCScale9Sprite>::create("square02_small.png").opacity(60).contentSize(this->getContentSize()).with([](auto node) {
46+
Build<CCLabelBMFont>::create("Preview", "goldFont.fnt").scale(0.425F).parentAtPos(node, Anchor::Top, {0, -8});
47+
}).store(m_bg).parentAtPos(this, Anchor::Center);
48+
CCLayerColor* mask = CCLayerColor::create({255, 255, 255});
49+
mask->setContentSize(m_bg->getContentSize());
50+
m_clippingNode = CCClippingNode::create();
51+
m_clippingNode->setContentSize(m_bg->getContentSize());
52+
m_clippingNode->setAnchorPoint({0.5, 0.5});
53+
setNewPreview(data);
4454
m_clippingNode->setStencil(mask);
4555
m_clippingNode->setZOrder(1);
4656
this->addChildAtPosition(m_clippingNode, Anchor::Center);

src/nodes/ExtPreviewBG.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ class ExtPreviewBG : public CCLayer {
1212
float m_oldScale;
1313
CCPoint m_oldPos;
1414
float m_currentZoom = 1.0F;
15+
LevelEditorLayer* m_editorLayer;
16+
std::string m_data;
1517

1618
void touchFinished();
1719
virtual bool init(LevelEditorLayer* editorLayer, std::string objData, CCSize);
1820
bool ccTouchBegan(CCTouch*, CCEvent*) override;
1921
void ccTouchMoved(CCTouch*, CCEvent*) override;
2022
public:
23+
std::string getData() const {
24+
return m_data;
25+
}
2126
void updateZoom(float amount);
2227
void setZoom(float amount = 1.0F);
2328
void resetZoom();
29+
void setNewPreview(std::string objData);
2430
static ExtPreviewBG* create(LevelEditorLayer* editorLayer, std::string objData, CCSize contentSize = {124.F, 82.F});
2531
};

src/nodes/ObjectItem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,6 @@ ObjectItem* ObjectItem::create(LevelEditorLayer* editorLayer, ObjectData data) {
191191
return pRet;
192192
}
193193
}
194-
CC_SAFE_DELETE(pRet);
194+
delete pRet;
195195
return nullptr;
196196
};

src/nodes/ScrollLayerExt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ ScrollLayerExt::ScrollLayerExt(CCRect const& rect, bool scrollWheelEnabled, bool
159159

160160
this->setMouseEnabled(true);
161161
this->setTouchEnabled(true);
162+
this->setUserFlag("alk.better-touch-prio/steals-touch");
162163
}
163164

164165
void ScrollLayerExt::visit() {

src/ui/ObjectWorkshop.cpp

Lines changed: 4 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "../config.hpp"
22
#include "ObjectWorkshop.hpp"
33
#include "Geode/ui/Scrollbar.hpp"
4+
#include "popups/ObjUploadPopup.hpp"
45
#include "popups/WarningPopup.hpp"
56
#include "popups/includes.h"
67
#include "admin/AdminPopup.hpp"
@@ -279,6 +280,9 @@ bool ObjectWorkshop::init(bool authenticated) {
279280
}
280281
}
281282
);
283+
Build<CCSprite>::createSpriteName("GJ_shareBtn_001.png").scale(0.5f).intoMenuItem([this]() {
284+
ObjUploadPopup::create(m_user)->show();
285+
}).parentAtPos(m_buttonMenu, Anchor::BottomRight, {22, 20});
282286
}
283287
Build<CCSprite>::createSpriteName("GJ_arrow_01_001.png").scale(0.8f).intoMenuItem([this]() {
284288
if (m_currentPage > 1) {
@@ -1100,197 +1104,7 @@ T* clonePointer(const T* original) {
11001104
}
11011105

11021106
void ObjectWorkshop::onUploadBtn(CCObject*) {
1103-
if (!m_inEditor) {
1104-
FLAlertLayer::create("Error", "You cannot <cy>upload objects</c> if you aren't in the <cl>Editor</c>!", "OK")->show();
1105-
return;
1106-
}
1107-
m_filterTags.clear();
1108-
m_currentMenu = 1;
1109-
rightBg->setVisible(false);
1110-
m_pageLabel->setVisible(false);
1111-
obj_backBtn->setVisible(true);
1112-
1113-
auto middleBg = CCScale9Sprite::create("square02_small.png");
1114-
middleBg->setOpacity(25);
1115-
middleBg->setContentSize({360, 238});
1116-
objectInfoNode->addChildAtPosition(middleBg, Anchor::Center, {0, 5});
1117-
1118-
auto previewBG = CCScale9Sprite::create("square02_small.png");
1119-
previewBG->setOpacity(60);
1120-
previewBG->setContentSize({ 360.F - 20.F, 82.F });
1121-
auto previewLabel = CCLabelBMFont::create("Select an Object", "goldFont.fnt");
1122-
previewLabel->setScale(0.425F);
1123-
previewBG->addChildAtPosition(previewLabel, Anchor::Top, {0,-8});
1124-
middleBg->addChildAtPosition(previewBG, Anchor::Top, {0, -50});
1125-
1126-
auto bottomBg = CCScale9Sprite::create("square02_small.png");
1127-
bottomBg->setOpacity(25);
1128-
bottomBg->setContentSize({275, 120});
1129-
middleBg->addChildAtPosition(bottomBg, Anchor::Center, {0, -45});
1130-
1131-
m_objName = TextInput::create(300.0F, "Object Name", "bigFont.fnt");
1132-
m_objName->setScale(0.8);
1133-
m_objName->setMaxCharCount(64);
1134-
m_objName->setCommonFilter(CommonFilter::Any);
1135-
bottomBg->addChildAtPosition(m_objName, Anchor::Top, {0, -20});
1136-
1137-
/*
1138-
m_objDesc = TextInputNode::create("Description [Optional]", 300, {270, 60}, 90);//{270.F, 30.F}, 90);
1139-
m_objDesc->getInput()->setScale(0.5F);
1140-
bottomBg->addChildAtPosition(m_objDesc, Anchor::Center, {-1, -3});
1141-
m_objDesc->addChildAtPosition(m_objDesc->getInput(), Anchor::Center);
1142-
m_objDesc->setUpdateCallback([this](std::string text) {
1143-
m_objDesc->getInput()->m_textArea->m_width = 300.0F / Utils::calculateScale(text, 50, 300, 1.0F, 0.5F);
1144-
m_objDesc->getInput()->setScale(Utils::calculateScale(text, 50, 300, 0.75F, 0.45F));
1145-
m_objDesc->getInput()->setPosition({
1146-
Utils::calculateScale(text, 50, 300, 100, 60),
1147-
Utils::calculateScale(text, 50, 300, 25, 20)
1148-
});
1149-
});
1150-
//m_objDesc->getBackground()->setScale(0.5F);
1151-
/\*m_objDesc->getBackground()->setContentSize({
1152-
(m_objDesc->getSize().width - 20.F) * 2.F,
1153-
(m_objDesc->getSize().height + 20.F) * 2.F
1154-
});*\/
1155-
/\*m_objDesc->getBackground()->setContentSize({
1156-
520, 100
1157-
});*/
1158-
1159-
#ifndef GEODE_IS_ANDROID32
1160-
auto textArea = TextArea::create("", "chatFont.fnt", 1.0F, 270.0F, {0.5, 0.5}, 20.0F, true);
1161-
// TextArea::create(&local_64,"chatFont.fnt",,0x439d8000,this_03,0x41a00000,1);
1162-
#endif
1163-
m_objDesc = TextInput::create(270.0F, "Description [Optional]", "chatFont.fnt");
1164-
#ifndef GEODE_IS_ANDROID32
1165-
m_objDesc->getInputNode()->addTextArea(textArea);
1166-
m_objDesc->getInputNode()->m_cursor->setOpacity(0);
1167-
#endif
1168-
m_objDesc->getBGSprite()->setContentSize({520.0F, 100.0F});
1169-
m_objDesc->setMaxCharCount(300);
1170-
m_objDesc->setCommonFilter(CommonFilter::Any);
1171-
bottomBg->addChildAtPosition(m_objDesc, Anchor::Center, {0, -3});
1172-
#ifndef GEODE_IS_ANDROID32
1173-
m_objDesc->setCallback(
1174-
[this, textArea](std::string p0) {
1175-
m_objDesc->getInputNode()->m_textLabel->setOpacity((p0.empty()) ? 255 : 0);
1176-
textArea->setScale(Utils::calculateScale(p0, 50, 300, 0.9F, 0.35F));
1177-
textArea->m_width = 220.0F / Utils::calculateScale(p0, 50, 300, 1.0F, 0.32F);
1178-
textArea->setString(m_objDesc->getInputNode()->getString());
1179-
//textArea->setString(p0.data());
1180-
}
1181-
);
1182-
#endif
1183-
auto rulesSpr = ButtonSprite::create("Rules", "bigFont.fnt", "GJ_button_03.png");
1184-
rulesSpr->setScale(0.8F);
1185-
auto uploadSpr = ButtonSprite::create("Upload", "bigFont.fnt", "GJ_button_01.png");
1186-
uploadSpr->setScale(0.8F);
1187-
auto uploadBtn = CCMenuItemSpriteExtra::create(
1188-
uploadSpr,
1189-
this,
1190-
menu_selector(ObjectWorkshop::onUpload)
1191-
);
1192-
auto rulesBtn = CCMenuItemSpriteExtra::create(
1193-
rulesSpr,
1194-
this,
1195-
menu_selector(ObjectWorkshop::onRulesBtn)
1196-
);
1197-
uploadBtn->setID("uploadbtn"_spr);
1198-
rulesBtn->setID("rulesbtn"_spr);
1199-
auto filterSpr = ButtonSprite::create(
1200-
CCSprite::createWithSpriteFrameName("GJ_filterIcon_001.png"),
1201-
30,
1202-
0,
1203-
.0F,
1204-
1.0F,
1205-
false,
1206-
"GJ_button_04.png",
1207-
false
1208-
);
1209-
filterSpr->setScale(0.75F);
1210-
auto filterBtn = CCMenuItemSpriteExtra::create(
1211-
filterSpr,
1212-
this,
1213-
menu_selector(ObjectWorkshop::onUploadFilterBtn)
1214-
);
1215-
filterBtn->setID("tagbtn"_spr);
1216-
1217-
m_buttonMenu->addChildAtPosition(filterBtn, Anchor::Bottom, {-60, 57});
1218-
m_buttonMenu->addChildAtPosition(uploadBtn, Anchor::BottomRight, {-85, 57});
1219-
m_buttonMenu->addChildAtPosition(rulesBtn, Anchor::BottomRight, {-195, 57});
1220-
//bottomBg->addChildAtPosition(textArea, Anchor::Center, {0, -20});
1221-
if (auto editor = CustomObjects::get()) {
1222-
auto scrollLayer = ScrollLayerExt::create({ 0, 0, 275.0F, 280.0F }, true);
1223-
scrollLayer->setContentSize({275.0F, 60.0F});
1224-
scrollLayer->setAnchorPoint({0.5, 1.0});
1225-
auto content = CCMenu::create();
1226-
content->setScale(0.675F);
1227-
content->setZOrder(2);
1228-
content->setPositionX(20);
1229-
content->registerWithTouchDispatcher();
1230-
1231-
scrollLayer->m_contentLayer->addChild(content);
1232-
scrollLayer->setTouchEnabled(true);
1233-
1234-
if (m_oldCustomObjectButtonArray == nullptr) {
1235-
m_oldCustomObjectButtonArray = editor->m_customObjectButtonArray;
1236-
}
1237-
CCArrayExt<CreateMenuItem*> customItems = editor->createCustomItems();
1238-
int size = customItems.size() - 4;
1239-
for (int i = 0; i < size; i++) {
1240-
customItems[i]->setID(fmt::format("{}", i));
1241-
if (i > 17) {
1242-
customItems[i]->setEnabled(false);
1243-
}
1244-
content->addChild(customItems[i]);
1245-
}
1246-
previewBG->addChild(scrollLayer);
1247-
content->setLayout(
1248-
RowLayout::create()
1249-
->setAxisAlignment(AxisAlignment::Start)
1250-
->setCrossAxisAlignment(AxisAlignment::End)
1251-
->setAutoScale(true)
1252-
->setCrossAxisOverflow(false)
1253-
->setGap(5)
1254-
->setGrowCrossAxis(true)
1255-
);
1256-
content->setContentSize({400.0F, 400.0F});
1257-
content->setAnchorPoint({0.5, 1.0});
1258-
content->setPosition({137, 280});
1259-
//content->setContentSize({265.0F, 230.0F});
1260-
content->updateLayout();
1261-
scrollLayer->moveToTop();
1262-
scrollLayer->fixTouchPrio();
1263-
scrollLayer->setCallbackMove([size, content]() {
1264-
if (content == nullptr) return;
1265-
for (int i = 0; i < size; i++) {
1266-
if (auto child = typeinfo_cast<CreateMenuItem*>(content->getChildByID(fmt::format("{}", i)))) {
1267-
child->setEnabled(false);
1268-
}
1269-
}
1270-
});
1271-
scrollLayer->setCallbackEnd([size, content, scrollLayer]() {
1272-
if (content == nullptr) return;
1273-
for (int i = 0; i < size; i++) {
1274-
if (auto child = typeinfo_cast<CreateMenuItem*>(content->getChildByID(fmt::format("{}", i)))) {
1275-
float contentYPos = scrollLayer->m_contentLayer->getPositionY();
1276-
float childYPos = (child->getPositionY());
1277-
1278-
child->setEnabled(!Utils::isInScrollSnapRange(contentYPos, childYPos));
1279-
1280-
//float index = -(contentYPos + 220) / 30.F;
1281-
//float lower_bound = 380.F + index * 35.F;
1282-
//float upper_bound = lower_bound - 35;
1283-
1284-
//child->setEnabled(upper_bound <= childYPos <= lower_bound);
12851107

1286-
// 60
1287-
}
1288-
}
1289-
if (scrollLayer->m_contentLayer->getPositionY() > -220.F) {
1290-
scrollLayer->m_contentLayer->setPositionY(Utils::getSnappedYPosition(scrollLayer->m_contentLayer->getPositionY(), 300)); // or 290
1291-
}
1292-
});
1293-
}
12941108
}
12951109

12961110
void ObjectWorkshop::onSearchBtn(CCObject*) {

src/ui/ObjectWorkshop.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "../nodes/ScrollLayerExt.hpp"
1010
#include "../nodes/ExtPreviewBG.hpp"
1111
#include "../nodes/TextInputNode.hpp"
12-
#include "../nodes/ScrollLayerExt.hpp"
1312
#include "popups/WarningPopup.hpp"
1413

1514
using namespace geode::prelude;
@@ -161,16 +160,6 @@ class ObjectWorkshop : public geode::Popup, public TextInputDelegate {
161160
bool m_selectedFeatured;
162161
void onUpload(CCObject*);
163162
void onUploadFilterBtn(CCObject*);
164-
void onRulesBtn(CCObject*) {
165-
FLAlertLayer::create(
166-
nullptr,
167-
"Rules",
168-
"1. Do not <cy>upload spam, duplicate, or useless objects.</c>\n2. Do not upload <cy>any stolen art</c>, objects that <cy>violate copyright</c>, or objects <cy>without the creators permission.</c>\n3. Do not upload objects that relate to anything that is <cy>inappropriate, explicit, sexual, or violent.</c>\n4. Use an <cy>appropriate name, and tags</c> when uploading.\n\nBreaking these rules will result in a <cr>temporary ban</c>, and possibly a <cr>permanent one</c> if <cy>too severe or repeated.</c>",
169-
"OK",
170-
nullptr,
171-
400.0F
172-
)->show();
173-
};
174163
void handleRequest1(web::WebResponse res);
175164
void handleRequest2(web::WebResponse res);
176165

0 commit comments

Comments
 (0)