Skip to content

Commit 57b67b7

Browse files
committed
Fixes
1 parent 5dbd0f0 commit 57b67b7

8 files changed

Lines changed: 80 additions & 36 deletions

File tree

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.2
2+
- <c-dddddd>Fix a crash</c>
3+
- <c-dddddd>Speed up Object Search loading</c>
4+
15
# 1.0.1
26
- <c-dddddd>Rewrite zoom logic to hopefully resolve some bugs</c>
37
- <c-dddddd>Lazy load search tab</c>

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"id": "alphalaneous.tinker",
1010
"name": "Tinker",
11-
"version": "v1.0.1",
11+
"version": "v1.0.2",
1212
"developer": "Alphalaneous",
1313
"description": "Editor Revamped",
1414
"dependencies": {

src/Utils.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,31 @@ namespace tinker::utils {
317317
}
318318

319319
}
320+
321+
class Timestamp {
322+
public:
323+
Timestamp(ZStringView id) : m_id(id) {
324+
m_start = m_last = std::chrono::steady_clock::now();
325+
}
326+
327+
void snapshot(ZStringView label) {
328+
auto now = std::chrono::steady_clock::now();
329+
330+
auto total = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_start).count();
331+
auto delta = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_last).count();
332+
333+
log::debug("[{}] ({}) +{} ms (total {} ms)", m_id, label, delta, total);
334+
335+
m_last = now;
336+
}
337+
338+
~Timestamp() {
339+
snapshot("end");
340+
}
341+
342+
private:
343+
std::string m_id;
344+
std::chrono::time_point<std::chrono::steady_clock> m_start;
345+
std::chrono::time_point<std::chrono::steady_clock> m_last;
346+
};
320347
}

src/modules/ObjectSearch/ObjectSearch.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "../../ObjectNames.hpp"
33
#include "../LiveColors/LiveColors.hpp"
44
#include "SearchField.hpp"
5+
#include "../ScrollableObjects.hpp"
56
#include <alphalaneous.alphas-ui-pack/include/API.hpp>
67
#include <alphalaneous.editortab_api/include/EditorTabAPI.hpp>
78
#include <raydeeux.gameobjectidstacksize/include/api.hpp>
@@ -29,7 +30,6 @@ bool OSEditorUI::init(LevelEditorLayer* editorLayer) {
2930

3031
auto winSize = CCDirector::get()->getWinSize();
3132

32-
3333
alpha::editor_tabs::addTab("all-objects"_spr, alpha::editor_tabs::BUILD, [this, fields] () {
3434
fields->m_searchBar = alpha::editor_tabs::createEditButtonBar({});
3535
fields->m_searchBar->m_hasCreateItems = true;
@@ -57,6 +57,15 @@ bool OSEditorUI::init(LevelEditorLayer* editorLayer) {
5757
LiveColors::get()->showMenu(true);
5858
}
5959
}
60+
if (state && !fields->m_initialLoaded) {
61+
auto arr = fields->m_searchField->generateItemArrayForSearch("");
62+
63+
auto cols = GameManager::get()->getIntGameVariable(GameVar::EditorButtonsPerRow);
64+
auto rows = GameManager::get()->getIntGameVariable(GameVar::EditorButtonRows);
65+
66+
fields->m_searchBar->loadFromItems(arr, cols, rows, false);
67+
fields->m_initialLoaded = true;
68+
}
6069
});
6170

6271
runAction(CallFuncExt::create([this, fields, objectSearch] {
@@ -92,13 +101,6 @@ bool OSEditorUI::init(LevelEditorLayer* editorLayer) {
92101
fields->m_orderedItems.push_back(&fields->m_items[cmi->m_objectID]);
93102
}
94103
}
95-
96-
auto arr = fields->m_searchField->generateItemArrayForSearch("");
97-
98-
auto cols = GameManager::get()->getIntGameVariable(GameVar::EditorButtonsPerRow);
99-
auto rows = GameManager::get()->getIntGameVariable(GameVar::EditorButtonRows);
100-
101-
fields->m_searchBar->loadFromItems(arr, cols, rows, false);
102104
}));
103105

104106
return true;
@@ -337,23 +339,9 @@ void OSEditButtonBar::loadFromItems(cocos2d::CCArray* objects, int rows, int col
337339
checkPage();
338340
}
339341

340-
void OSEditButtonBar::goToPage(int page) {
341-
EditButtonBar::goToPage(page);
342-
checkPage();
343-
}
344-
345-
void OSEditButtonBar::onLeft(cocos2d::CCObject* sender) {
346-
EditButtonBar::onLeft(sender);
347-
checkPage();
348-
}
349-
350-
void OSEditButtonBar::onRight(cocos2d::CCObject* sender) {
351-
EditButtonBar::onRight(sender);
352-
checkPage();
353-
}
354-
355342
void OSEditButtonBar::checkPage() {
356343
if (!m_hasCreateItems) return;
344+
if (ScrollableObjects::isEnabled()) return;
357345

358346
auto pageNum = getPage();
359347
for (auto node : m_buttonArray->asExt<CreateMenuItem>()) {
@@ -362,4 +350,13 @@ void OSEditButtonBar::checkPage() {
362350
oCmi->loadRender();
363351
}
364352
}
353+
}
354+
355+
void OSBoomScrollLayer::instantMoveToPage(int page) {
356+
BoomScrollLayer::instantMoveToPage(page);
357+
358+
if (auto ebb = typeinfo_cast<EditButtonBar*>(getParent())) {
359+
auto sEbb = static_cast<OSEditButtonBar*>(ebb);
360+
sEbb->checkPage();
361+
}
365362
}

src/modules/ObjectSearch/ObjectSearch.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <Geode/modify/EditorUI.hpp>
66
#include <Geode/modify/CreateMenuItem.hpp>
77
#include <Geode/modify/EditButtonBar.hpp>
8+
#include <Geode/modify/BoomScrollLayer.hpp>
89
#include "SearchField.hpp"
910

1011
class $globalModule(ObjectSearch) {};
@@ -17,6 +18,7 @@ class $modify(OSEditorUI, EditorUI) {
1718
tinker::ui::SearchField* m_searchField;
1819
std::map<unsigned int, tinker::ui::SearchField::ItemInformation> m_items;
1920
std::vector<tinker::ui::SearchField::ItemInformation*> m_orderedItems;
21+
bool m_initialLoaded = false;
2022
};
2123

2224
bool init(LevelEditorLayer* editorLayer);
@@ -48,7 +50,10 @@ class $modify(OSEditButtonBar, EditButtonBar) {
4850
void checkPage();
4951

5052
void loadFromItems(cocos2d::CCArray* objects, int rows, int columns, bool keepPage);
51-
void goToPage(int page);
52-
void onLeft(cocos2d::CCObject* sender);
53-
void onRight(cocos2d::CCObject* sender);
53+
};
54+
55+
class $modify(OSBoomScrollLayer, BoomScrollLayer) {
56+
$registerGlobalHooks(ObjectSearch)
57+
58+
void instantMoveToPage(int page);
5459
};

src/modules/ObjectSearch/SearchField.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Result<SearchField::ItemInformation> SearchField::infoForID(unsigned int id) {
2626

2727
CCArray* SearchField::generateItemArrayForSearch(const std::string& search) {
2828
auto fields = m_editorUI->m_fields.self();
29-
3029
auto arr = CCArray::createWithCapacity(fields->m_orderedItems.size());
3130

3231
if (search.empty()) {

src/modules/ScrollableObjects.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,15 @@ bool SOEditorUI::init(LevelEditorLayer* editorLayer) {
6060
}
6161
}));
6262

63+
m_fields->m_shouldLoadBars = true;
64+
6365
return true;
6466
}
6567

68+
bool SOEditorUI::shouldLoadBars() {
69+
return m_fields->m_shouldLoadBars;
70+
}
71+
6672
bool ScrollableObjects::canScroll() {
6773
auto editorUI = EditorUI::get();
6874
if (!editorUI) return false;
@@ -163,6 +169,10 @@ void SOEditButtonBar::loadFromItems(cocos2d::CCArray* objects, int columns, int
163169
fields->m_items.clear();
164170
}
165171

172+
setUserFlag("alphalaneous.editortab_api/disable-rewrite");
173+
auto editorUI = EditorUI::get();
174+
if (!editorUI || !static_cast<SOEditorUI*>(editorUI)->shouldLoadBars()) return;
175+
166176
float currentX = 0;
167177

168178
if (fields->m_scrollLayer) {
@@ -191,14 +201,9 @@ void SOEditButtonBar::loadFromItems(cocos2d::CCArray* objects, int columns, int
191201
fields->m_widthOffset = -26.f;
192202
}
193203

194-
setUserFlag("alphalaneous.editortab_api/disable-rewrite");
195204
setAnchorPoint({0.5f, 0.f});
196205

197-
auto editorUI = EditorUI::get();
198-
if (!editorUI) return;
199-
200206
fields->m_initialized = true;
201-
202207
auto widthOffset = 180;
203208

204209
auto spacerLeft = editorUI->getChildByID("spacer-line-left");
@@ -254,17 +259,19 @@ void SOEditButtonBar::loadFromItems(cocos2d::CCArray* objects, int columns, int
254259

255260
float width = 0;
256261

262+
257263
for (auto object : objects->asExt<CCNode>()) {
258264
rIdx--;
259265
object->removeFromParentAndCleanup(false);
260266
object->setScale(1);
261267
object->setVisible(true);
262268

263-
if (auto cmi = typeinfo_cast<CreateMenuItem*>(object)) {
269+
if (m_hasCreateItems) {
270+
auto cmi = static_cast<CreateMenuItem*>(object);
264271
cmi->m_tabIndex = m_tabIndex;
272+
cmi->m_baseScale = 1.f;
265273
}
266-
267-
if (auto item = typeinfo_cast<CCMenuItemSpriteExtra*>(object)) {
274+
else if (auto item = typeinfo_cast<CCMenuItemSpriteExtra*>(object)) {
268275
item->m_baseScale = 1.f;
269276
}
270277

src/modules/ScrollableObjects.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ class $globalModule(ScrollableObjects) {
1414
class $modify(SOEditorUI, EditorUI) {
1515
$registerGlobalHooks(ScrollableObjects, true)
1616

17+
struct Fields {
18+
bool m_shouldLoadBars;
19+
};
20+
1721
bool init(LevelEditorLayer* editorLayer);
1822
void updateCreateMenu(bool selectTab);
23+
bool shouldLoadBars();
1924

2025
static void _onModify(auto& self) {
2126
(void) self.setHookPriorityAfterPost("EditorUI::init", "alphalaneous.editortab_api");

0 commit comments

Comments
 (0)