X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2FguiEngine.cpp;h=03fee6b967e4c712f959b15d706b40a4960a8f6b;hb=984e063374c032ed17764931fd00c19afb92ebb9;hp=e53b52b01ab9dd57cc72636a814a1c4fffd2584f;hpb=b49e5cfc7013cef7e9af79d17e04f7e7e4c377d4;p=oweals%2Fminetest.git diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index e53b52b01..03fee6b96 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiEngine.h" +#include #include #include #include "scripting_mainmenu.h" @@ -27,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "version.h" #include "porting.h" #include "filesys.h" -#include "main.h" #include "settings.h" #include "guiMainMenu.h" #include "sound.h" @@ -35,8 +35,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "clouds.h" #include "httpfetch.h" #include "log.h" +#include "fontengine.h" +#include "guiscalingfilter.h" +#include "irrlicht_changes/static_text.h" + #ifdef __ANDROID__ -#include "tile.h" +#include "client/tile.h" #include #endif @@ -50,7 +54,7 @@ TextDestGuiEngine::TextDestGuiEngine(GUIEngine* engine) } /******************************************************************************/ -void TextDestGuiEngine::gotText(std::map fields) +void TextDestGuiEngine::gotText(const StringMap &fields) { m_engine->getScriptIface()->handleMainMenuButtons(fields); } @@ -58,7 +62,7 @@ void TextDestGuiEngine::gotText(std::map fields) /******************************************************************************/ void TextDestGuiEngine::gotText(std::wstring text) { - m_engine->getScriptIface()->handleMainMenuEvent(wide_to_narrow(text)); + m_engine->getScriptIface()->handleMainMenuEvent(wide_to_utf8(text)); } /******************************************************************************/ @@ -127,6 +131,7 @@ void MenuMusicFetcher::fetchSounds(const std::string &name, /** GUIEngine */ /******************************************************************************/ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, + JoystickController *joystick, gui::IGUIElement* parent, IMenuManager *menumgr, scene::ISceneManager* smgr, @@ -169,28 +174,30 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, m_sound_manager = &dummySoundManager; //create topleft header - core::rect rect(0, 0, 500, 20); + m_toplefttext = L""; + + core::rect rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()), + 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(), - rect,false,true,0,-1); + addStaticText(m_device->getGUIEnvironment(), m_toplefttext, + rect, false, true, 0, -1); //create formspecsource m_formspecgui = new FormspecFormSource(""); /* Create menu */ m_menu = new GUIFormSpecMenu(m_device, + joystick, m_parent, -1, m_menumanager, NULL /* &client */, - NULL /* gamedef */, m_texture_source, m_formspecgui, m_buttonhandler, - NULL); + false); m_menu->allowClose(false); m_menu->lockSize(true,v2u32(800,600)); @@ -202,21 +209,18 @@ 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; + errorstream << "No future without main menu!" << std::endl; abort(); } run(); - } - catch(LuaError &e) { - errorstream << "MAINMENU ERROR: " << e.what() << std::endl; - m_data->errormessage = e.what(); + } catch (LuaError &e) { + errorstream << "Main menu error: " << e.what() << std::endl; + m_data->script_data.errormessage = e.what(); } m_menu->quitMenu(); @@ -227,21 +231,21 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, /******************************************************************************/ bool GUIEngine::loadMainMenuScript() { - // Try custom menu script (main_menu_path) - + // Set main menu path (for core.get_mainmenu_path()) m_scriptdir = g_settings->get("main_menu_path"); if (m_scriptdir.empty()) { - m_scriptdir = porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "mainmenu"; + m_scriptdir = porting::path_share + DIR_DELIM + "builtin" + DIR_DELIM + "mainmenu"; } + // Load builtin (which will load the main menu script) std::string script = porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "init.lua"; - if (m_script->loadScript(script)) { + try { + m_script->loadScript(script); // Menu script loaded return true; - } else { - infostream - << "GUIEngine: execution of menu script in: \"" - << m_scriptdir << "\" failed!" << std::endl; + } catch (const ModError &e) { + errorstream << "GUIEngine: execution of menu script failed: " + << e.what() << std::endl; } return false; @@ -256,7 +260,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 +304,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; @@ -349,17 +362,16 @@ void GUIEngine::cloudPreProcess() /******************************************************************************/ void GUIEngine::cloudPostProcess() { - float fps_max = g_settings->getFloat("fps_max"); + float fps_max = g_settings->getFloat("pause_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 +408,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(x, y, x+tilesize.X, y+tilesize.Y), core::rect(0, 0, sourcesize.X, sourcesize.Y), NULL, NULL, true); @@ -406,7 +418,7 @@ void GUIEngine::drawBackground(video::IVideoDriver* driver) } /* Draw background texture */ - driver->draw2DImage(texture, + draw2DImageFilterScaled(driver, texture, core::rect(0, 0, screensize.X, screensize.Y), core::rect(0, 0, sourcesize.X, sourcesize.Y), NULL, NULL, true); @@ -419,13 +431,13 @@ void GUIEngine::drawOverlay(video::IVideoDriver* driver) video::ITexture* texture = m_textures[TEX_LAYER_OVERLAY].texture; - /* If no texture, draw background of solid color */ + /* If no texture, draw nothing */ if(!texture) return; /* Draw background texture */ v2u32 sourcesize = texture->getOriginalSize(); - driver->draw2DImage(texture, + draw2DImageFilterScaled(driver, texture, core::rect(0, 0, screensize.X, screensize.Y), core::rect(0, 0, sourcesize.X, sourcesize.Y), NULL, NULL, true); @@ -448,7 +460,7 @@ void GUIEngine::drawHeader(video::IVideoDriver* driver) v2s32 splashsize(((f32)texture->getOriginalSize().Width) * mult, ((f32)texture->getOriginalSize().Height) * mult); - // Don't draw the header is there isn't enough room + // Don't draw the header if there isn't enough room s32 free_space = (((s32)screensize.Height)-320)/2; if (free_space > splashsize.Y) { @@ -458,7 +470,7 @@ void GUIEngine::drawHeader(video::IVideoDriver* driver) video::SColor bgcolor(255,50,50,50); - driver->draw2DImage(texture, splashrect, + draw2DImageFilterScaled(driver, texture, splashrect, core::rect(core::position2d(0,0), core::dimension2di(texture->getOriginalSize())), NULL, NULL, true); @@ -490,7 +502,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(core::position2d(0,0), core::dimension2di(texture->getOriginalSize())), NULL, NULL, true); @@ -502,7 +514,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) { @@ -556,16 +568,24 @@ bool GUIEngine::downloadFile(std::string url, std::string target) } /******************************************************************************/ -void GUIEngine::setTopleftText(std::string append) +void GUIEngine::setTopleftText(const std::string &text) { - std::string toset = std::string("Minetest ") + minetest_version_hash; + m_toplefttext = utf8_to_wide(text); - if (append != "") { - toset += " / "; - toset += append; - } + updateTopLeftTextSize(); +} - m_irr_toplefttext->setText(narrow_to_wide(toset).c_str()); +/******************************************************************************/ +void GUIEngine::updateTopLeftTextSize() +{ + core::rect rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()), + g_fontengine->getTextHeight()); + rect += v2s32(4, 0); + + m_irr_toplefttext->remove(); + m_irr_toplefttext = + addStaticText(m_device->getGUIEnvironment(), m_toplefttext, + rect, false, true, 0, -1); } /******************************************************************************/