]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/guiEngine.cpp
make formspec textarea wordwrap
[dragonfireclient.git] / src / guiEngine.cpp
index 547f393a49ef76375433ee1da8b775ce1990c96b..bba0006403a5e859a84617e8208469162b8277b5 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "scripting_mainmenu.h"
 #include "config.h"
+#include "version.h"
 #include "porting.h"
 #include "filesys.h"
 #include "main.h"
@@ -29,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "sound.h"
 #include "sound_openal.h"
 #include "clouds.h"
+#include "httpfetch.h"
 
 #include <IGUIStaticText.h>
 #include <ICameraSceneNode.h>
@@ -155,9 +157,9 @@ GUIEngine::GUIEngine(       irr::IrrlichtDevice* dev,
                m_sound_manager = &dummySoundManager;
 
        //create topleft header
-       core::rect<s32> rect(0, 0, 500, 40);
+       core::rect<s32> rect(0, 0, 500, 20);
        rect += v2s32(4, 0);
-       std::string t = "Minetest " VERSION_STRING;
+       std::string t = std::string("Minetest ") + minetest_version_hash;
 
        m_irr_toplefttext =
                m_device->getGUIEnvironment()->addStaticText(narrow_to_wide(t).c_str(),
@@ -224,7 +226,8 @@ bool GUIEngine::loadMainMenuScript()
                }
                else {
                        infostream
-                               << "GUIEngine: execution of custom menu failed!"
+                               << "GUIEngine: execution of custom menu: \""
+                               << menuscript << "\" failed!"
                                << std::endl
                                << "\tfalling back to builtin menu"
                                << std::endl;
@@ -285,6 +288,8 @@ void GUIEngine::run()
                        cloudPostProcess();
                else
                        sleep_ms(25);
+
+               m_script->Step();
        }
 }
 
@@ -389,7 +394,7 @@ void GUIEngine::drawBackground(video::IVideoDriver* driver)
        }
 
        /* Draw background texture */
-       v2u32 sourcesize = texture->getSize();
+       v2u32 sourcesize = texture->getOriginalSize();
        driver->draw2DImage(texture,
                core::rect<s32>(0, 0, screensize.X, screensize.Y),
                core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
@@ -408,7 +413,7 @@ void GUIEngine::drawOverlay(video::IVideoDriver* driver)
                return;
 
        /* Draw background texture */
-       v2u32 sourcesize = texture->getSize();
+       v2u32 sourcesize = texture->getOriginalSize();
        driver->draw2DImage(texture,
                core::rect<s32>(0, 0, screensize.X, screensize.Y),
                core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
@@ -426,7 +431,7 @@ void GUIEngine::drawHeader(video::IVideoDriver* driver)
        if(!texture)
                return;
 
-       f32 mult = (((f32)screensize.Width / 2)) /
+       f32 mult = (((f32)screensize.Width / 2.0)) /
                        ((f32)texture->getOriginalSize().Width);
 
        v2s32 splashsize(((f32)texture->getOriginalSize().Width) * mult,
@@ -444,7 +449,7 @@ void GUIEngine::drawHeader(video::IVideoDriver* driver)
 
        driver->draw2DImage(texture, splashrect,
                core::rect<s32>(core::position2d<s32>(0,0),
-               core::dimension2di(texture->getSize())),
+               core::dimension2di(texture->getOriginalSize())),
                NULL, NULL, true);
        }
 }
@@ -476,7 +481,7 @@ void GUIEngine::drawFooter(video::IVideoDriver* driver)
 
                driver->draw2DImage(texture, rect,
                        core::rect<s32>(core::position2d<s32>(0,0),
-                       core::dimension2di(texture->getSize())),
+                       core::dimension2di(texture->getOriginalSize())),
                        NULL, NULL, true);
        }
 }
@@ -504,56 +509,42 @@ bool GUIEngine::setTexture(texture_layer layer,std::string texturepath) {
 }
 
 /******************************************************************************/
-#if USE_CURL
-static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
-{
-       FILE* targetfile = (FILE*) userp;
-       fwrite(contents,size,nmemb,targetfile);
-       return size * nmemb;
-}
-#endif
 bool GUIEngine::downloadFile(std::string url,std::string target) {
 #if USE_CURL
-       //download file via curl
-       CURL *curl;
+       bool retval = true;
 
-       curl = curl_easy_init();
+       FILE* targetfile = fopen(target.c_str(),"wb");
 
-       if (curl)
-       {
-               CURLcode res;
-               bool retval = true;
-
-               FILE* targetfile = fopen(target.c_str(),"wb");
+       if (targetfile) {
+               HTTPFetchRequest fetchrequest;
+               HTTPFetchResult fetchresult;
+               fetchrequest.url = url;
+               fetchrequest.caller = HTTPFETCH_SYNC;
+               httpfetch_sync(fetchrequest,fetchresult);
 
-               if (targetfile) {
-                       curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-                       curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-                       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
-                       curl_easy_setopt(curl, CURLOPT_WRITEDATA, targetfile);
-
-                       res = curl_easy_perform(curl);
-                       if (res != CURLE_OK) {
-                               errorstream << "File at url \"" << url
-                                       <<"\" not found (" << curl_easy_strerror(res) << ")" <<std::endl;
+               if (fetchresult.succeeded) {
+                       if (fwrite(fetchresult.data.c_str(),1,fetchresult.data.size(),targetfile) != fetchresult.data.size()) {
                                retval = false;
                        }
-                       fclose(targetfile);
                }
                else {
                        retval = false;
                }
-
-               curl_easy_cleanup(curl);
-               return retval;
+               fclose(targetfile);
        }
-#endif
+       else {
+               retval = false;
+       }
+
+       return retval;
+#else
        return false;
+#endif
 }
 
 /******************************************************************************/
 void GUIEngine::setTopleftText(std::string append) {
-       std::string toset = "Minetest " VERSION_STRING;
+       std::string toset = std::string("Minetest ") + minetest_version_hash;
 
        if (append != "") {
                toset += " / ";
@@ -575,3 +566,9 @@ void GUIEngine::stopSound(s32 handle)
 {
        m_sound_manager->stopSound(handle);
 }
+
+/******************************************************************************/
+unsigned int GUIEngine::DoAsync(std::string serialized_fct,
+               std::string serialized_params) {
+       return m_script->DoAsync(serialized_fct,serialized_params);
+}