#include "guiEngine.h"
+#include <fstream>
#include <IGUIStaticText.h>
#include <ICameraSceneNode.h>
#include "scripting_mainmenu.h"
#include "version.h"
#include "porting.h"
#include "filesys.h"
-#include "main.h"
#include "settings.h"
#include "guiMainMenu.h"
#include "sound.h"
#include "httpfetch.h"
#include "log.h"
#include "fontengine.h"
+#include "guiscalingfilter.h"
+#include "irrlicht_changes/static_text.h"
#ifdef __ANDROID__
#include "client/tile.h"
}
/******************************************************************************/
-void TextDestGuiEngine::gotText(std::map<std::string, std::string> fields)
+void TextDestGuiEngine::gotText(const StringMap &fields)
{
m_engine->getScriptIface()->handleMainMenuButtons(fields);
}
/******************************************************************************/
-void TextDestGuiEngine::gotText(std::wstring text)
+void TextDestGuiEngine::gotText(const std::wstring &text)
{
- m_engine->getScriptIface()->handleMainMenuEvent(wide_to_narrow(text));
+ m_engine->getScriptIface()->handleMainMenuEvent(wide_to_utf8(text));
}
/******************************************************************************/
/** GUIEngine */
/******************************************************************************/
GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
+ JoystickController *joystick,
gui::IGUIElement* parent,
IMenuManager *menumgr,
scene::ISceneManager* smgr,
m_sound_manager = &dummySoundManager;
//create topleft header
- std::wstring t = narrow_to_wide(std::string("Minetest ") +
- minetest_version_hash);
+ m_toplefttext = L"";
- core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(t), g_fontengine->getTextHeight());
+ core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()),
+ g_fontengine->getTextHeight());
rect += v2s32(4, 0);
m_irr_toplefttext =
- m_device->getGUIEnvironment()->addStaticText(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));
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();
/******************************************************************************/
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;
unsigned int text_height = g_fontengine->getTextHeight();
- while(m_device->run() && (!m_startgame) && (!m_kill))
- {
+ irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screenW"),
+ g_settings->getU16("screenH"));
+
+ while (m_device->run() && (!m_startgame) && (!m_kill)) {
+
+ const irr::core::dimension2d<u32> ¤t_screen_size =
+ m_device->getVideoDriver()->getScreenSize();
+ // Verify if window size has changed and save it if it's the case
+ // Ensure evaluating settings->getBool after verifying screensize
+ // First condition is cheaper
+ if (previous_screen_size != current_screen_size &&
+ current_screen_size != irr::core::dimension2d<u32>(0,0) &&
+ g_settings->getBool("autosave_screensize")) {
+ g_settings->setU16("screenW", current_screen_size.Width);
+ g_settings->setU16("screenH", current_screen_size.Height);
+ previous_screen_size = current_screen_size;
+ }
+
//check if we need to update the "upper left corner"-text
if (text_height != g_fontengine->getTextHeight()) {
updateTopLeftTextSize();
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;
/******************************************************************************/
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
u32 busytime_u32;
{
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);
}
/* 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);
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<s32>(0, 0, screensize.X, screensize.Y),
core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
NULL, NULL, true);
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) {
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);
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);
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)
{
}
/******************************************************************************/
-bool GUIEngine::downloadFile(std::string url, std::string target)
+bool GUIEngine::downloadFile(const std::string &url, const std::string &target)
{
#if USE_CURL
std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary);
}
/******************************************************************************/
-void GUIEngine::setTopleftText(std::string append)
+void GUIEngine::setTopleftText(const std::string &text)
{
- std::wstring toset = narrow_to_wide( std::string("Minetest ") +
- minetest_version_hash);
-
- if (append != "")
- {
- toset += L" / ";
- toset += narrow_to_wide(append);
- }
-
- m_irr_toplefttext->setText(toset.c_str());
+ m_toplefttext = utf8_to_wide(text);
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);
+ core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()),
+ 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);
+ addStaticText(m_device->getGUIEnvironment(), m_toplefttext,
+ rect, false, true, 0, -1);
}
/******************************************************************************/
}
/******************************************************************************/
-unsigned int GUIEngine::queueAsync(std::string serialized_func,
- std::string serialized_params)
+unsigned int GUIEngine::queueAsync(const std::string &serialized_func,
+ const std::string &serialized_params)
{
return m_script->queueAsync(serialized_func, serialized_params);
}