1+ #include < Geode/Geode.hpp>
2+
3+ using namespace geode ::prelude;
4+
5+ #include < Geode/modify/LevelInfoLayer.hpp>
6+
7+ class $modify(AutoLevelRate, LevelInfoLayer) {
8+ void levelDownloadFinished (GJGameLevel* p0) {
9+ LevelInfoLayer::levelDownloadFinished (p0); // Run the original levelDownloadFinished code before running our custom code.
10+
11+ // Make sure we haven't rated the level yet.
12+ if (!m_starRateBtn) return ;
13+ if (!m_starRateBtn->isEnabled ()) return ;
14+
15+ // Make sure the user has the feature enabled.
16+ if (!Mod::get ()->getSettingValue <bool >(" enable-auto-rater" )) return ;
17+
18+ // Open the rate menu.
19+ m_starRateBtn->activate ();
20+
21+ RateStarsLayer* rateLayer = nullptr ;
22+
23+ auto & children = *getParent ()->getChildren ();
24+
25+ // Loop through the root of the game tree until we find the rate menu.
26+ for (int i = 0 ; i < children.count (); i++) {
27+ auto node = static_cast <CCNode*>(children.objectAtIndex (i));
28+
29+ if (auto rate = dynamic_cast <RateStarsLayer*>(node)) {
30+ rateLayer = rate;
31+ break ;
32+ }
33+ }
34+
35+ if (!rateLayer) {
36+ log::warn (" RateStarsLayer could not be found!" );
37+ return ;
38+ }
39+
40+ // We can just use the first object because it is the only object.
41+ auto mainLayer = static_cast <CCNode*>(rateLayer->getChildren ()->objectAtIndex (0 ));
42+
43+ if (!mainLayer) {
44+ log::warn (" Main Layer not found inside RateStarsLayer!" );
45+ return ;
46+ }
47+
48+ CCMenu* menuLayer = nullptr ;
49+
50+ auto & mainLayerChildren = *mainLayer->getChildren ();
51+
52+ // Loop through the root of the game tree until we find the main layer.
53+ for (int i = 0 ; i < mainLayerChildren.count (); i++) {
54+ auto node = static_cast <CCNode*>(mainLayerChildren.objectAtIndex (i));
55+
56+ if (auto menu = dynamic_cast <CCMenu*>(node)) {
57+ menuLayer = menu;
58+ break ;
59+ }
60+ }
61+
62+ if (!menuLayer) {
63+ log::warn (" Main CCMenu Layer could not be found!" );
64+ return ;
65+ }
66+
67+ CCMenuItemSpriteExtra* button;
68+
69+ int starsRated = 0 ; // Used to log the amount of stars that the level got rated
70+
71+ // Only rate the requested difficulty if the user doesn't have a difficulty override.
72+ if (!Mod::get ()->getSettingValue <bool >(" toggle-override-difficulty-rate" )){
73+ if (p0->m_starsRequested == 0 ) { // If they never requested any stars (N/A)
74+ button = static_cast <CCMenuItemSpriteExtra*>(menuLayer->getChildren ()->objectAtIndex (4 ));
75+ starsRated = 5 ;
76+ } else {
77+ button = static_cast <CCMenuItemSpriteExtra*>(menuLayer->getChildren ()->objectAtIndex (p0->m_starsRequested ));
78+ starsRated = p0->m_starsRequested ;
79+ }
80+ } else { // This is if the user specified a difficulty override.
81+ button = static_cast <CCMenuItemSpriteExtra*>(menuLayer->getChildren ()->objectAtIndex (Mod::get ()->getSettingValue <int >(" override-difficulty-rate" ) - 1 ));
82+ starsRated = Mod::get ()->getSettingValue <int >(" override-difficulty-rate" );
83+ }
84+
85+ // Check if the difficulty selection button exists
86+ if (!button) {
87+ log::warn (" Difficulty selection button not found!" );
88+ return ;
89+ }
90+
91+ button->activate ();
92+
93+ button = static_cast <CCMenuItemSpriteExtra*>(menuLayer->getChildren ()->objectAtIndex (11 ));
94+
95+ // Check if the submit rating button exists
96+ if (!button) {
97+ log::warn (" Submit rating button not found!" );
98+ return ;
99+ }
100+
101+ button->activate ();
102+
103+ CCSprite* disableButton = CCSprite::createWithSpriteFrameName (" GJ_starBtn2_001.png" );
104+
105+ // Check if the disable rate button sprite exists
106+ if (!disableButton) {
107+ log::warn (" Disabled Rate Button sprite not found!" );
108+ return ;
109+ }
110+
111+ m_starRateBtn->setSprite (disableButton);
112+ m_starRateBtn->m_bEnabled = false ;
113+
114+ log::info (" Successfully rated the level {}*!" , starsRated);
115+
116+ // yay we done :D
117+ }
118+ };
0 commit comments