Skip to content

Commit 3ed019c

Browse files
committed
update(main): Rewrite FriendsProfilePage & implement color indice
1 parent e413a37 commit 3ed019c

File tree

2 files changed

+38
-40
lines changed

2 files changed

+38
-40
lines changed

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "4.6.0",
2+
"geode": "4.8.0",
33
"version": "v1.5.3",
44
"gd": {
55
"win": "2.2074",

src/Utils/FriendsProfilePage.cpp

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,32 @@ const char* toLowerCase(const char* str) {
2020
class SearchUserLayer : public BrownAlertDelegate {
2121
protected:
2222
virtual void setup() {
23+
// Set up the alert layer
2324
input_username->setMaxCharCount(20);
2425
input_username->setPlaceholder("");
25-
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
2626
input_username->setPositionY(10);
27+
2728
this->m_buttonMenu->addChild(input_username);
29+
30+
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
31+
32+
// Add search button
2833
auto validate_spr = ButtonSprite::create("Search", 60, true, "bigFont.fnt", "GJ_button_01.png", 30, .5F);
2934
auto validate_btn = CCMenuItemSpriteExtra::create(
3035
validate_spr,
3136
this,
3237
menu_selector(SearchUserLayer::onValidate)
3338
);
34-
3539
validate_btn->setPosition({
3640
0,
3741
-35
3842
});
3943
this->m_buttonMenu->addChild(validate_btn, 1);
44+
45+
// Add the menu to the layer
4046
this->m_mainLayer->addChild(this->m_buttonMenu);
47+
48+
// Enable touch
4149
setTouchEnabled(true);
4250
}
4351
cocos2d::CCSize m_sScrLayerSize;
@@ -64,8 +72,11 @@ class SearchUserLayer : public BrownAlertDelegate {
6472

6573
class $modify(FriendPage, FriendsProfilePage) {
6674
bool init(UserListType type) {
75+
// If the base init fails, stop here
6776
if (!FriendsProfilePage::init(type)) return false;
77+
// If the setting is disabled, stop here
6878
if (!Mod::get()->template getSettingValue<bool>("friendSearch")) return true;
79+
6980
auto menu = this->m_buttonMenu;
7081

7182
auto searchSpr = CCSprite::createWithSpriteFrameName("gj_findBtn_001.png");
@@ -105,6 +116,8 @@ class $modify(FriendPage, FriendsProfilePage) {
105116
break;
106117
}
107118
}
119+
120+
// If we couldn't find the comment list layer, return
108121
if (test2 == nullptr) {
109122
// safeguard from crashing
110123
FLAlertLayer::create(nullptr,
@@ -119,6 +132,7 @@ class $modify(FriendPage, FriendsProfilePage) {
119132

120133
auto test3 = static_cast<CCLayer*>(test2->getChildren()->objectAtIndex(0));
121134

135+
// If you don't have friend, show alert (sorry for you)
122136
if (test3->getChildrenCount() <= 0) {
123137
// another safeguard
124138
FLAlertLayer::create(nullptr,
@@ -130,6 +144,7 @@ class $modify(FriendPage, FriendsProfilePage) {
130144
)->show();
131145
return nullptr;
132146
}
147+
133148
return static_cast<TableView*>(test3->getChildren()->objectAtIndex(0));
134149
}
135150

@@ -138,60 +153,44 @@ class $modify(FriendPage, FriendsProfilePage) {
138153
auto sceneChildren = scene->getChildren();
139154
auto customList = getCustomList(sceneChildren);
140155

156+
// If the list is null, return
141157
if (customList == nullptr) return;
142158

143159
CCContentLayer* contentLayer = static_cast<CCContentLayer*>(
144160
customList->getChildren()->objectAtIndex(0)
145161
);
162+
146163
int counter_page = 0;
147164
bool found = false;
165+
166+
// Iterate through all cells in the list
148167
for (int i = 0; i < contentLayer->getChildrenCount(); i++) {
149-
CCMenu* cell;
150-
CCLabelBMFont* label;
151-
cell = typeinfo_cast<CCMenu*>(
152-
reinterpret_cast<CCLayer*>(
153-
reinterpret_cast<CCLayer*>(
154-
reinterpret_cast<CCLayer*>(
155-
contentLayer->getChildren()->objectAtIndex(i)
156-
)
157-
)->getChildren()->objectAtIndex(1)
158-
)->getChildren()->objectAtIndex(0)
168+
GJUserCell* cell = static_cast<GJUserCell*>(
169+
contentLayer->getChildren()->objectAtIndex(i)
159170
);
160171

161-
if (cell == nullptr) {
162-
label = reinterpret_cast<CCLabelBMFont*>(
163-
reinterpret_cast<CCLayer*>(
164-
reinterpret_cast<CCLayer*>(
165-
reinterpret_cast<CCLayer*>(
166-
reinterpret_cast<CCLayer*>(
167-
reinterpret_cast<CCLayer*>(
168-
contentLayer->getChildren()->objectAtIndex(i)
169-
)
170-
)->getChildren()->objectAtIndex(1)
171-
)->getChildren()->objectAtIndex(1)
172-
)->getChildren()->objectAtIndex(0)
173-
)->getChildren()->objectAtIndex(0)
174-
);
175-
} else {
176-
label = reinterpret_cast<CCLabelBMFont*>(
177-
reinterpret_cast<CCLayer*>(
178-
reinterpret_cast<CCLayer*>(
179-
cell->getChildren()->objectAtIndex(0)
180-
)->getChildren()->objectAtIndex(0)
181-
)
182-
);
183-
}
184-
const char* str1 = label->getString();
172+
const char* str1 = cell->m_userScore->m_userName.c_str();
173+
174+
// If username is found in the cell's username (case insensitive)
185175
if (strstr(toLowerCase(str1), toLowerCase(username)) != nullptr) {
186176
customList->scrollLayer(-9999999);
187177
customList->scrollLayer(counter_page);
188178

189179
found = true;
190180

181+
// Pulse only one time cell color animation
182+
auto originalColor = cell->getChildByType<cocos2d::CCLayerColor>(0)->getColor();
183+
auto tintTo1 = CCTintTo::create(0.2f, 0, 255, 0); // Change to green
184+
auto tintTo2 = CCTintTo::create(0.5f, originalColor.r, originalColor.g, originalColor.b); // Change back to original color
185+
auto sequence = CCSequence::create(tintTo1, tintTo2, nullptr);
186+
cell->getChildByType<cocos2d::CCLayerColor>(0)->runAction(sequence);
187+
191188
break;
192189
}
193190
counter_page += 45;
194191
}
192+
193+
// If user not found, show alert
195194
if (!found) {
196195
std::string str = username;
197196
FLAlertLayer::create(nullptr,
@@ -219,6 +218,7 @@ class $modify(FriendPage, FriendsProfilePage) {
219218

220219
auto menu = this->m_buttonMenu;
221220

221+
// Add custom scrollbar
222222
auto scrollBar = Scrollbar::create(this->m_listLayer->m_list->m_tableView);
223223
scrollBar->setPosition(390, -140);
224224
scrollBar->setID("friendsScrollBar");
@@ -235,6 +235,4 @@ class $modify(FriendPage, FriendsProfilePage) {
235235
void SearchUserLayer::onValidate(CCObject* pSender) {
236236
FriendPage::searchUser(input_username->getString().c_str());
237237
BrownAlertDelegate::onClose(pSender);
238-
}
239-
240-
// Utils
238+
}

0 commit comments

Comments
 (0)