1+ #pragma once
2+
13#include < Geode/Geode.hpp>
24#include < Geode/modify/FLAlertLayer.hpp>
3- #include < Geode/utils/web.hpp>
4- #include < Geode/binding/LoadingCircle.hpp>
55#include < string>
6+
67#include " ../Tags.hpp"
7- #include " ../ImageCache.hpp"
88
99using namespace geode ::prelude;
1010
1111class GYScreenshotPopup : public geode ::Popup<int const &> {
1212protected:
13- CCClippingNode* m_clippingNode;
14- LoadingCircle* m_loadingCircle;
15- CCImage* m_image;
16- int m_layerID;
17- geode::EventListener<web::WebTask> m_downloadListener;
18-
1913 bool setup (int const & layer) override {
2014 Tags tags;
2115 auto layerName = tags.getStringFromTag (layer);
@@ -26,7 +20,6 @@ class GYScreenshotPopup : public geode::Popup<int const&> {
2620 }
2721
2822 std::string result = extractLastSegment (layerName);
29- m_layerID = layer;
3023
3124 auto winSize = CCDirector::sharedDirector ()->getWinSize ();
3225 if (!m_mainLayer) {
@@ -38,118 +31,51 @@ class GYScreenshotPopup : public geode::Popup<int const&> {
3831 m_mainLayer->setContentSize ({ winSize.width * 0 .6f , winSize.height * 0 .7f });
3932 m_mainLayer->updateLayout ();
4033
41- // Create a border
42- auto border = CCScale9Sprite::create (" GJ_square07.png" );
43- border->setContentSize (m_mainLayer->getContentSize ());
44- border->setPosition (m_mainLayer->getContentSize () / 2 );
45- border->setZOrder (2 );
46- m_mainLayer->addChild (border);
47-
48- // Create a mask for clipping
49- auto mask = CCLayerColor::create ({255 , 255 , 255 });
50- mask->setContentSize ({391 , 220 });
51- mask->setPosition ({m_mainLayer->getContentSize ().width / 2 - 391 / 2 , m_mainLayer->getContentSize ().height / 2 - 220 / 2 });
52-
53- // Create a clipping node
54- m_clippingNode = CCClippingNode::create ();
55- m_clippingNode->setContentSize (m_mainLayer->getContentSize ());
56- m_clippingNode->setStencil (mask);
57- m_clippingNode->setZOrder (1 );
58- m_mainLayer->addChild (m_clippingNode);
59-
60- // Initialize and show the loading circle
61- m_loadingCircle = LoadingCircle::create ();
62- m_loadingCircle->setPosition (m_mainLayer->getContentSize () / 2 );
63- m_loadingCircle->setScale (1 .0f );
64- m_loadingCircle->show ();
65- m_mainLayer->addChild (m_loadingCircle);
66-
67- // Check if the image is already cached
68- if (CCImage* image = ImageCache::get ()->getImage (fmt::format (" thumb-{}" , m_layerID))) {
69- m_image = image;
70- m_loadingCircle->removeFromParent ();
71- imageCreationFinished (m_image);
72- return true ;
34+ /* auto sprite = CCSprite::createWithSpriteFrameName(fmt::format("{}Preview.png"_spr, layerName).c_str());
35+ if (!sprite) {
36+ log::error("Sprite not found for frame: {}", fmt::format("{}Preview.png", layerName));
37+ return false;
7338 }
7439
75- // Download the image
76- std::string URL = fmt::format (" https://raw.githubusercontent.com/OmgRod/Geodify/refs/heads/master/res/previews/{}Preview.png" , layerName);
77- auto req = web::WebRequest ();
78- auto downloadTask = req.get (URL);
79- m_downloadListener.bind ([this ](web::WebTask::Event* e) {
80- if (auto res = e->getValue ()) {
81- if (!res->ok ()) {
82- onDownloadFail ();
83- } else {
84- auto data = res->data ();
85- std::thread imageThread = std::thread ([data, this ]() {
86- m_image = new CCImage ();
87- m_image->autorelease ();
88- m_image->initWithImageData (const_cast <uint8_t *>(data.data ()), data.size ());
89- geode::Loader::get ()->queueInMainThread ([this ]() {
90- ImageCache::get ()->addImage (m_image, fmt::format (" thumb-{}" , m_layerID));
91- imageCreationFinished (m_image);
92- });
93- });
94- imageThread.detach ();
95- }
96- }
97- });
98- m_downloadListener.setFilter (downloadTask);
40+ log::debug("Loading sprite: {}", fmt::format("omgrod.geodify/{}Preview.png", layerName));
9941
100- return true ;
101- }
42+ auto maxWidth = m_mainLayer->getContentSize().width * 0.75f ;
43+ auto maxHeight = m_mainLayer->getContentSize().height * 0.75f;
10244
103- void imageCreationFinished (CCImage* image) {
104- auto texture = new CCTexture2D ();
105- texture->autorelease ();
106- texture->initWithImage (image);
107- onDownloadFinished (CCSprite::createWithTexture (texture));
108- }
45+ auto spriteWidth = sprite->getContentSize().width;
46+ auto spriteHeight = sprite->getContentSize().height;
10947
110- void onDownloadFinished (CCSprite* image) {
111- float maxHeight = m_mainLayer->getContentSize ().height * 0 .75f ;
112- float scale = maxHeight / image->getContentSize ().height ;
113- image->setScale (scale);
114- image->setPosition (m_mainLayer->getContentSize () / 2 );
115- m_clippingNode->addChild (image);
116- if (m_loadingCircle) {
117- m_loadingCircle->removeFromParent ();
118- }
119- }
48+ float scale = std::min(maxWidth / spriteWidth, maxHeight / spriteHeight);
49+ sprite->setScale(scale);
12050
121- void onDownloadFail () {
122- auto image = CCSprite::create (" noThumb.png" );
123- float maxHeight = m_mainLayer->getContentSize ().height * 0 .75f ;
124- float scale = maxHeight / image->getContentSize ().height ;
125- image->setScale (scale);
126- image->setPosition (m_mainLayer->getContentSize () / 2 );
127- m_clippingNode->addChild (image);
128- if (m_loadingCircle) {
129- m_loadingCircle->removeFromParent ();
130- }
51+ m_mainLayer->addChildAtPosition(sprite, Anchor::Center);*/
52+
53+ auto warning = CCLabelBMFont::create (" This feature is not yet implemented. Check back later." , " bigFont.fnt" );
54+ warning->setPosition ({ winSize.width * .3f , winSize.height * .35f });
55+ warning->setScale (0 .3f );
56+
57+ m_mainLayer->addChild (warning);
58+
59+ return true ;
13160 }
13261
13362public:
134- struct Fields {
135- EventListener<web::WebTask> m_listener;
136- };
137-
13863 std::string extractLastSegment (const std::string& input) {
13964 size_t lastDash = input.rfind (' -' );
14065 if (lastDash != std::string::npos) {
14166 return input.substr (lastDash + 1 );
14267 }
14368 return input;
14469 }
145-
146- static GYScreenshotPopup* create (int const & layer) {
70+ static GYScreenshotPopup* create (int const & text) {
14771 auto ret = new GYScreenshotPopup ();
148- if (ret->initAnchored (395 , 225 , layer)) {
72+ auto winSize = CCDirector::sharedDirector ()->getWinSize ();
73+ if (ret->initAnchored (winSize.width * .6f , winSize.height * .7f , text)) {
14974 ret->autorelease ();
15075 return ret;
15176 }
152- CC_SAFE_DELETE (ret);
77+
78+ delete ret;
15379 return nullptr ;
15480 }
15581};
0 commit comments