@@ -17,9 +17,10 @@ class $modify(EventPage, DailyLevelPage) {
1717
1818 // Put on the corner top left of the background
1919 auto menu = as<CCMenu*>(this ->m_mainLayer ->getChildByIDRecursive (" main-menu" ));
20- infoBtn->setPosition ({ 14 , -83 });
21-
22- menu->addChild (infoBtn);
20+ if (menu) {
21+ infoBtn->setPosition ({ 14 , -83 });
22+ menu->addChild (infoBtn);
23+ }
2324
2425 return true ;
2526 }
@@ -30,7 +31,7 @@ void EventLevelInformation::scene() {
3031
3132 if (popup && popup->initAnchored (400 .0f , 225 .0f , " GJ_square02.png" )) {
3233 popup->autorelease ();
33- CCDirector::sharedDirector ()->getRunningScene ()->addChild (popup, 200 );
34+ CCDirector::sharedDirector ()->getRunningScene ()->addChild (popup, 1000 );
3435 } else {
3536 CC_SAFE_DELETE (popup);
3637 }
@@ -49,11 +50,65 @@ bool EventLevelInformation::setup() {
4950}
5051
5152void EventLevelInformation::loadPage () {
52- auto image_spr = CCSprite::createWithSpriteFrameName (" ncs_album.png" _spr);
53+ // Make loading circle
54+ loading_circle = LoadingCircle::create ();
55+ loading_circle->setZOrder (25 );
56+ loading_circle->setParentLayer (this );
57+ loading_circle->show ();
58+
59+ // Load the image
60+ std::string URL = " https://clarifygdps.com/gdutils/event_info/image_banner.png?randome=" + std::to_string (static_cast <unsigned int >(time (nullptr )));
61+
62+ auto req = web::WebRequest ();
63+ m_downloadListener.bind ([this ](web::WebTask::Event* e){
64+ if (auto res = e->getValue ()){
65+ if (!res->ok ()) {
66+ onDownloadFail ();
67+ } else {
68+ auto data = res->data ();
69+ std::thread imageThread = std::thread ([data,this ](){
70+ m_image = new CCImage ();
71+ m_image->autorelease ();
72+ m_image->initWithImageData (const_cast <uint8_t *>(data.data ()),data.size ());
73+ geode::Loader::get ()->queueInMainThread ([this ](){
74+ imageCreationFinished (m_image);
75+ });
76+ });
77+ imageThread.detach ();
78+ }
79+ }
80+ });
81+
82+ auto downloadTask = req.header (" Cache-Control" , " no-cache" ).header (" Pragma" , " no-cache" ).get (URL);
83+ m_downloadListener.setFilter (downloadTask);
84+ }
85+
86+ void EventLevelInformation::imageCreationFinished (CCImage* image) {
87+ fadeLoadingCircle ();
5388
5489 auto size = this ->m_mainLayer ->getContentSize ();
90+ auto texture = new CCTexture2D ();
91+ texture->initWithImage (image);
92+ auto spr = CCSprite::createWithTexture (texture);
93+ texture->autorelease ();
94+ spr->setPosition ({ size.width / 2 , size.height / 2 });
95+ spr->setScale (1 .1f );
96+
97+ this ->m_mainLayer ->addChild (spr);
98+ }
99+
100+ void EventLevelInformation::onDownloadFail () {
101+ fadeLoadingCircle ();
102+
103+ auto size = this ->m_mainLayer ->getContentSize ();
104+ auto failLabel = CCLabelBMFont::create (" No event banner found." , " bigFont.fnt" , 0 .0f , kCCTextAlignmentCenter );
105+ failLabel->setPosition ({ size.width / 2 , size.height / 2 });
106+ failLabel->setScale (0 .7f );
107+
108+ this ->m_mainLayer ->addChild (failLabel);
109+ }
55110
56- image_spr-> setPosition ({ size. width / 2 , size. height / 2 });
57- image_spr-> setScale ( 1 . 1f ) ;
58- this -> m_mainLayer -> addChild (image_spr );
59- }
111+ void EventLevelInformation::fadeLoadingCircle () {
112+ if (loading_circle == nullptr ) return ;
113+ loading_circle-> fadeAndRemove ( );
114+ };
0 commit comments