]> git.lizzy.rs Git - minetest.git/blobdiff - src/guiEngine.cpp
Fix missing #include
[minetest.git] / src / guiEngine.cpp
index 0a1d722069ebd6c573bf5381b9839e14a0693057..c616bc3222883947719500b3c16112759a8a8bf2 100644 (file)
@@ -19,26 +19,30 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "guiEngine.h"
 
+#include <fstream>
+#include <IGUIStaticText.h>
+#include <ICameraSceneNode.h>
 #include "scripting_mainmenu.h"
+#include "util/numeric.h"
 #include "config.h"
 #include "version.h"
 #include "porting.h"
 #include "filesys.h"
-#include "main.h"
 #include "settings.h"
 #include "guiMainMenu.h"
 #include "sound.h"
 #include "sound_openal.h"
 #include "clouds.h"
 #include "httpfetch.h"
-#include "util/numeric.h"
+#include "log.h"
+#include "fontengine.h"
+#include "guiscalingfilter.h"
+
 #ifdef __ANDROID__
-#include "tile.h"
+#include "client/tile.h"
 #include <GLES/gl.h>
 #endif
 
-#include <IGUIStaticText.h>
-#include <ICameraSceneNode.h>
 
 /******************************************************************************/
 /** TextDestGuiEngine                                                         */
@@ -49,7 +53,7 @@ TextDestGuiEngine::TextDestGuiEngine(GUIEngine* engine)
 }
 
 /******************************************************************************/
-void TextDestGuiEngine::gotText(std::map<std::string, std::string> fields)
+void TextDestGuiEngine::gotText(const StringMap &fields)
 {
        m_engine->getScriptIface()->handleMainMenuButtons(fields);
 }
@@ -57,7 +61,7 @@ void TextDestGuiEngine::gotText(std::map<std::string, std::string> fields)
 /******************************************************************************/
 void TextDestGuiEngine::gotText(std::wstring text)
 {
-       m_engine->getScriptIface()->handleMainMenuEvent(wide_to_narrow(text));
+       m_engine->getScriptIface()->handleMainMenuEvent(wide_to_utf8(text));
 }
 
 /******************************************************************************/
@@ -168,12 +172,14 @@ GUIEngine::GUIEngine(     irr::IrrlichtDevice* dev,
                m_sound_manager = &dummySoundManager;
 
        //create topleft header
-       core::rect<s32> rect(0, 0, 500, 20);
+       std::wstring t = utf8_to_wide(std::string(PROJECT_NAME_C " ") +
+                       g_version_hash);
+
+       core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(t), g_fontengine->getTextHeight());
        rect += v2s32(4, 0);
-       std::string t = std::string("Minetest ") + minetest_version_hash;
 
        m_irr_toplefttext =
-               m_device->getGUIEnvironment()->addStaticText(narrow_to_wide(t).c_str(),
+               m_device->getGUIEnvironment()->addStaticText(t.c_str(),
                rect,false,true,0,-1);
 
        //create formspecsource
@@ -189,7 +195,8 @@ GUIEngine::GUIEngine(       irr::IrrlichtDevice* dev,
                        m_texture_source,
                        m_formspecgui,
                        m_buttonhandler,
-                       NULL);
+                       NULL,
+                       false);
 
        m_menu->allowClose(false);
        m_menu->lockSize(true,v2u32(800,600));
@@ -201,10 +208,8 @@ GUIEngine::GUIEngine(      irr::IrrlichtDevice* dev,
        m_script = new MainMenuScripting(this);
 
        try {
-               if (m_data->errormessage != "") {
-                       m_script->setMainMenuErrorMessage(m_data->errormessage);
-                       m_data->errormessage = "";
-               }
+               m_script->setMainMenuData(&m_data->script_data);
+               m_data->script_data.errormessage = "";
 
                if (!loadMainMenuScript()) {
                        errorstream << "No future without mainmenu" << std::endl;
@@ -212,15 +217,13 @@ GUIEngine::GUIEngine(     irr::IrrlichtDevice* dev,
                }
 
                run();
-       }
-       catch(LuaError &e) {
+       } catch (LuaError &e) {
                errorstream << "MAINMENU ERROR: " << e.what() << std::endl;
-               m_data->errormessage = e.what();
+               m_data->script_data.errormessage = e.what();
        }
 
        m_menu->quitMenu();
-       m_menu->remove();
-       delete m_menu;
+       m_menu->drop();
        m_menu = NULL;
 }
 
@@ -256,7 +259,16 @@ void GUIEngine::run()
 
        cloudInit();
 
-       while(m_device->run() && (!m_startgame) && (!m_kill)) {
+       unsigned int text_height = g_fontengine->getTextHeight();
+
+       while(m_device->run() && (!m_startgame) && (!m_kill))
+       {
+               //check if we need to update the "upper left corner"-text
+               if (text_height != g_fontengine->getTextHeight()) {
+                       updateTopLeftTextSize();
+                       text_height = g_fontengine->getTextHeight();
+               }
+
                driver->beginScene(true, true, video::SColor(255,140,186,250));
 
                if (m_clouds_enabled)
@@ -291,7 +303,7 @@ void GUIEngine::run()
 GUIEngine::~GUIEngine()
 {
        video::IVideoDriver* driver = m_device->getVideoDriver();
-       assert(driver != 0);
+       FATAL_ERROR_IF(driver == 0, "Could not get video driver");
 
        if(m_sound_manager != &dummySoundManager){
                delete m_sound_manager;
@@ -351,15 +363,14 @@ void GUIEngine::cloudPostProcess()
 {
        float fps_max = g_settings->getFloat("fps_max");
        // Time of frame without fps limit
-       float busytime;
        u32 busytime_u32;
+
        // not using getRealTime is necessary for wine
        u32 time = m_device->getTimer()->getTime();
        if(time > m_cloud.lasttime)
                busytime_u32 = time - m_cloud.lasttime;
        else
                busytime_u32 = 0;
-       busytime = busytime_u32 / 1000.0;
 
        // FPS limiter
        u32 frametime_min = 1000./fps_max;
@@ -396,7 +407,7 @@ void GUIEngine::drawBackground(video::IVideoDriver* driver)
                {
                        for (unsigned int y = 0; y < screensize.Y; y += tilesize.Y )
                        {
-                               driver->draw2DImage(texture,
+                               draw2DImageFilterScaled(driver, texture,
                                        core::rect<s32>(x, y, x+tilesize.X, y+tilesize.Y),
                                        core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
                                        NULL, NULL, true);
@@ -406,7 +417,7 @@ void GUIEngine::drawBackground(video::IVideoDriver* driver)
        }
 
        /* Draw background texture */
-       driver->draw2DImage(texture,
+       draw2DImageFilterScaled(driver, texture,
                core::rect<s32>(0, 0, screensize.X, screensize.Y),
                core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
                NULL, NULL, true);
@@ -425,7 +436,7 @@ void GUIEngine::drawOverlay(video::IVideoDriver* driver)
 
        /* Draw background texture */
        v2u32 sourcesize = texture->getOriginalSize();
-       driver->draw2DImage(texture,
+       draw2DImageFilterScaled(driver, texture,
                core::rect<s32>(0, 0, screensize.X, screensize.Y),
                core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
                NULL, NULL, true);
@@ -458,7 +469,7 @@ void GUIEngine::drawHeader(video::IVideoDriver* driver)
 
        video::SColor bgcolor(255,50,50,50);
 
-       driver->draw2DImage(texture, splashrect,
+       draw2DImageFilterScaled(driver, texture, splashrect,
                core::rect<s32>(core::position2d<s32>(0,0),
                core::dimension2di(texture->getOriginalSize())),
                NULL, NULL, true);
@@ -490,7 +501,7 @@ void GUIEngine::drawFooter(video::IVideoDriver* driver)
                rect += v2s32(screensize.Width/2,screensize.Height-footersize.Y);
                rect -= v2s32(footersize.X/2, 0);
 
-               driver->draw2DImage(texture, rect,
+               draw2DImageFilterScaled(driver, texture, rect,
                        core::rect<s32>(core::position2d<s32>(0,0),
                        core::dimension2di(texture->getOriginalSize())),
                        NULL, NULL, true);
@@ -502,7 +513,7 @@ bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
                bool tile_image, unsigned int minsize)
 {
        video::IVideoDriver* driver = m_device->getVideoDriver();
-       assert(driver != 0);
+       FATAL_ERROR_IF(driver == 0, "Could not get video driver");
 
        if (m_textures[layer].texture != NULL)
        {
@@ -528,27 +539,26 @@ bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
 }
 
 /******************************************************************************/
-bool GUIEngine::downloadFile(std::string url,std::string target)
+bool GUIEngine::downloadFile(std::string url, std::string target)
 {
 #if USE_CURL
-       std::ofstream targetfile(target.c_str(), std::ios::out | std::ios::binary);
+       std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary);
 
-       if (!targetfile.good()) {
+       if (!target_file.good()) {
                return false;
        }
 
-       HTTPFetchRequest fetchrequest;
-       HTTPFetchResult fetchresult;
-       fetchrequest.url = url;
-       fetchrequest.caller = HTTPFETCH_SYNC;
-       fetchrequest.timeout = g_settings->getS32("curl_file_download_timeout");
-       httpfetch_sync(fetchrequest, fetchresult);
+       HTTPFetchRequest fetch_request;
+       HTTPFetchResult fetch_result;
+       fetch_request.url = url;
+       fetch_request.caller = HTTPFETCH_SYNC;
+       fetch_request.timeout = g_settings->getS32("curl_file_download_timeout");
+       httpfetch_sync(fetch_request, fetch_result);
 
-       if (fetchresult.succeeded) {
-               targetfile << fetchresult.data;
-       } else {
+       if (!fetch_result.succeeded) {
                return false;
        }
+       target_file << fetch_result.data;
 
        return true;
 #else
@@ -559,14 +569,32 @@ bool GUIEngine::downloadFile(std::string url,std::string target)
 /******************************************************************************/
 void GUIEngine::setTopleftText(std::string append)
 {
-       std::string toset = std::string("Minetest ") + minetest_version_hash;
+       std::wstring toset = utf8_to_wide(std::string(PROJECT_NAME_C " ") +
+               g_version_hash);
 
-       if (append != "") {
-               toset += " / ";
-               toset += append;
+       if (append != "")
+       {
+               toset += L" / ";
+               toset += utf8_to_wide(append);
        }
 
-       m_irr_toplefttext->setText(narrow_to_wide(toset).c_str());
+       m_irr_toplefttext->setText(toset.c_str());
+
+       updateTopLeftTextSize();
+}
+
+/******************************************************************************/
+void GUIEngine::updateTopLeftTextSize()
+{
+       std::wstring text = m_irr_toplefttext->getText();
+
+       core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(text), g_fontengine->getTextHeight());
+               rect += v2s32(4, 0);
+
+       m_irr_toplefttext->remove();
+       m_irr_toplefttext =
+               m_device->getGUIEnvironment()->addStaticText(text.c_str(),
+               rect,false,true,0,-1);
 }
 
 /******************************************************************************/