1+ #include " GPFeedbackLayer.hpp"
2+
3+ void GPFeedbackLayer::KeyBackClicked () {
4+ CCDirector::get ()->popScene ();
5+ }
6+
7+ CCScene* GPFeedbackLayer::scene () {
8+ auto scene = CCScene::create ();
9+ scene->addChild (GPFeedbackLayer::create ());
10+ return scene;
11+ }
12+
13+ CCScene* GPFeedbackLayer::garageScene () {
14+ auto scene = CCScene::create ();
15+ scene->addChild (GJGarageLayer::scene ());
16+ return scene;
17+ }
18+
19+ GPFeedbackLayer* GPFeedbackLayer::create () {
20+ GPFeedbackLayer* ret = new GPFeedbackLayer ();
21+ if (ret && ret->init ()) {
22+ ret->autorelease ();
23+ return ret;
24+ }
25+ delete ret;
26+ return nullptr ;
27+ }
28+
29+ void GPFeedbackLayer::onFeedbackClick (CCObject* sender) {
30+ auto descInput = dynamic_cast <CCTextInputNode*>(this ->getChildByID (" descInput" ));
31+ if (!descInput)
32+ return ;
33+
34+ std::string feedback = descInput->getString ();
35+ std::string username = " Anonymous" ;
36+
37+ if (GJAccountManager::get ()->m_accountID != 0 ) {
38+ username = std::string (GJAccountManager::get ()->m_username .c_str ());
39+ }
40+
41+ if (feedback.empty ()) {
42+ log::error (" Feedback cannot be empty." );
43+ geode::createQuickPopup (
44+ " Garage Plus" ,
45+ " Feedback cannot be empty." ,
46+ " OK" , nullptr ,
47+ nullptr // No action on Exit button click
48+ );
49+ return ;
50+ }
51+
52+ std::string payload = " {\" username\" : \" " + username + " \" , \" feedback\" : \" " + feedback + " \" }" ;
53+
54+ web::WebRequest request;
55+ request.header (" Content-Type" , " application/json" );
56+ request.bodyString (payload);
57+ request.timeout (std::chrono::seconds (30 ));
58+
59+ std::string url = " https://script.google.com/macros/s/AKfycbxQPpe9LzY11VCbCdr0A8Qb-cRaGyYhxo3jkpvSYSWgsSHfl6127SNI8sQdK-Y2A--krg/exec" ; // Replace with your Google Apps Script web app URL
60+
61+ m_listener.bind ([this ](web::WebTask::Event* e) {
62+ if (web::WebResponse* res = e->getValue ()) {
63+ if (res->ok ()) {
64+ log::debug (" Feedback sent successfully!" );
65+ geode::createQuickPopup (
66+ " Garage Plus" ,
67+ " Feedback sent successfully!" ,
68+ " Exit" , nullptr ,
69+ [this ](auto , bool btn1) {
70+ this ->onClick (nullptr );
71+ }
72+ );
73+ } else {
74+ log::error (" Request failed with status code: {}" , res->code ());
75+ log::error (" Response body: {}" , res->string ().unwrapOr (" No response body" ));
76+ }
77+ } else if (web::WebProgress* progress = e->getProgress ()) {
78+ // log::debug("Progress: ", progress->downloadProgress());
79+ } else if (e->isCancelled ()) {
80+ log::error (" The request was cancelled." );
81+ }
82+ });
83+
84+ log::debug (" Sending POST request to URL: {}" , url);
85+ m_listener.setFilter (request.post (url));
86+ }
87+
88+ bool GPFeedbackLayer::init () {
89+ if (!CCLayer::init ())
90+ return false ;
91+
92+ setKeypadEnabled (true );
93+
94+ auto winSize = CCDirector::sharedDirector ()->getWinSize ();
95+ auto menu = CCMenu::create ();
96+ menu->setID (" menu" );
97+
98+ auto corner1 = CCSprite::createWithSpriteFrameName (" GJ_sideArt_001.png" );
99+ corner1->setPosition (CCPoint (winSize.width * -0.5 , winSize.height * -0.5 ));
100+ corner1->setAnchorPoint (CCPoint (0 , 0 ));
101+ corner1->setID (" corner1" );
102+ menu->addChild (corner1);
103+
104+ auto corner2 = CCSprite::createWithSpriteFrameName (" GJ_sideArt_001.png" );
105+ corner2->setPosition (CCPoint (winSize.width * 0.5 , winSize.height * -0.5 ));
106+ corner2->setAnchorPoint (CCPoint (1 , 0 ));
107+ corner2->setFlipX (true );
108+ corner2->setID (" corner2" );
109+ menu->addChild (corner2);
110+
111+ auto gameBgSpr = CCSprite::create (" game_bg_01_001.png" );
112+ gameBgSpr->setScale (2 .f );
113+ gameBgSpr->setZOrder (-1 );
114+ gameBgSpr->setPositionY (winSize.height / -2 );
115+ gameBgSpr->setID (" background" );
116+ menu->addChild (gameBgSpr);
117+
118+ auto squareSpr = CCScale9Sprite::create (" GJ_square01.png" );
119+ squareSpr->setPosition (CCPoint (winSize.width * 0 , winSize.height * 0 ));
120+ squareSpr->setContentSize (CCPoint (winSize.width * 0.8 , winSize.height * 0.8 ));
121+ squareSpr->setID (" squareSpr" );
122+ squareSpr->setZOrder (1 );
123+ menu->addChild (squareSpr);
124+
125+ auto backBtn = CCMenuItemSpriteExtra::create (
126+ CCSprite::createWithSpriteFrameName (" GJ_arrow_01_001.png" ),
127+ this ,
128+ menu_selector (GPFeedbackLayer::onClick)
129+ );
130+ backBtn->setPosition (winSize.width * -0.45 , winSize.height * 0.4 );
131+ backBtn->setID (" back-btn" );
132+ menu->addChild (backBtn);
133+
134+ auto infoBtn = CCMenuItemSpriteExtra::create (
135+ CCSprite::createWithSpriteFrameName (" GJ_infoIcon_001.png" ),
136+ this ,
137+ menu_selector (GPFeedbackLayer::onInfoClick)
138+ );
139+ infoBtn->setPosition (winSize.width * 0.45 , winSize.height * 0.45 );
140+ infoBtn->setID (" info-btn" );
141+ menu->addChild (infoBtn);
142+
143+ auto title = CCLabelBMFont::create (" Garage Plus Feedback" , " goldFont.fnt" );
144+ title->setZOrder (1 );
145+ title->setPositionY (winSize.width * 0.185 );
146+ title->setID (" title" );
147+ menu->addChild (title);
148+
149+ auto descBg = CCScale9Sprite::create (" square02b_001.png" );
150+ descBg->setPosition (CCPoint (winSize.width * 0.5 , winSize.height * 0.5 ));
151+ descBg->setContentSize (CCPoint (winSize.width * 0.6 , winSize.height * 0.5 ));
152+ descBg->setID (" descBg" );
153+ descBg->setZOrder (1 );
154+ descBg->setColor (ccColor3B (0 , 0 , 0 ));
155+ descBg->setOpacity (60 );
156+ this ->addChild (descBg);
157+
158+ auto descInput = CCTextInputNode::create (winSize.width * 0.6 , winSize.height * 0.5 , " Type your feedback or feature request here..." , " chatFont.fnt" );
159+ descInput->setPosition (CCPoint (winSize.width * 0.5 , winSize.height * 0.5 ));
160+ descInput->setZOrder (2 );
161+ descInput->setID (" descInput" );
162+ descInput->setAllowedChars (" !\" #$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\ ]^_`abcdefghijklmnopqrstuvwxyz{|}~" );
163+ descInput->setMaxLabelWidth (winSize.width * 0.6 );
164+ this ->addChild (descInput);
165+
166+ auto submitSpr = ButtonSprite::create (" Submit" );
167+ auto submitBtn = CCMenuItemSpriteExtra::create (
168+ submitSpr, this , menu_selector (GPFeedbackLayer::onFeedbackClick)
169+ );
170+ submitBtn->setPosition (CCPoint (winSize.width * 0 , winSize.height * -0.325 ));
171+ submitBtn->setZOrder (1 );
172+ submitBtn->setID (" submit-btn" );
173+ menu->addChild (submitBtn);
174+
175+ this ->addChild (menu);
176+ return true ;
177+ }
178+
179+ void GPFeedbackLayer::onClick (CCObject* sender) {
180+ auto scenePrev = CCTransitionFade::create (0 .5f , GPFeedbackLayer::garageScene ());
181+ CCDirector::sharedDirector ()->replaceScene (scenePrev);
182+ }
183+
184+ void GPFeedbackLayer::onInfoClick (CCObject* sender) {
185+ auto winSize = CCDirector::sharedDirector ()->getWinSize ();
186+ FLAlertLayer::create (
187+ nullptr , // No delegate needed
188+ " Garage Plus" , // Title
189+ " By submitting your feedback, you agree to the collection and transmission of your username and feedback to a private spreadsheet accessible only to the developer of this mod, OmgRod. This data will be used solely for improving the mod.\n\n You may disable the feedback button in this mod's settings at any time to add extra space.\n\n Your data will be stored securely and will not be shared with third parties.\n\n Thank you for your feedback!\n\n -OmgRod" , // Description
190+ " OK" , // Button 1 (OK)
191+ nullptr , // Button 2 (no second button)
192+ winSize.width * 0.75 , // Width (adjust as necessary)
193+ true , // Scrolling enabled
194+ winSize.height * 0.75 , // Height (adjust as necessary)
195+ 1 .0f // Text scale (adjust as necessary)
196+ )->show ();
197+ }
0 commit comments