Fix regression dirt texture not beeing default in non cloud menu

This commit is contained in:
sapier 2014-05-17 12:06:36 +02:00
parent 5b3bbde1ef
commit 7b3602bab3
6 changed files with 133 additions and 57 deletions

@ -60,9 +60,12 @@ function mm_texture.reset()
mm_texture.set_generic("footer") mm_texture.set_generic("footer")
mm_texture.set_generic("header") mm_texture.set_generic("header")
if not have_bg and if not have_bg then
core.setting_getbool("menu_clouds") then if core.setting_getbool("menu_clouds") then
core.set_clouds(true) core.set_clouds(true)
else
mm_texture.set_dirt_bg()
end
end end
end end
@ -83,9 +86,13 @@ function mm_texture.update_game(gamedetails)
mm_texture.clear("footer") mm_texture.clear("footer")
core.set_clouds(false) core.set_clouds(false)
if not have_bg and if not have_bg then
core.setting_getbool("menu_clouds") then
if core.setting_getbool("menu_clouds") then
core.set_clouds(true) core.set_clouds(true)
else
mm_texture.set_dirt_bg()
end
end end
mm_texture.set_game("footer",gamedetails) mm_texture.set_game("footer",gamedetails)
@ -144,3 +151,16 @@ function mm_texture.set_game(identifier,gamedetails)
return false return false
end end
function mm_texture.set_dirt_bg()
if mm_texture.texturepack ~= nil then
local path = mm_texture.texturepack .. DIR_DELIM .."default_dirt.png"
if core.set_background("background", path, true, 128) then
return true
end
end
--use base pack
local minimalpath = defaulttexturedir .. "dirt_bg.png"
core.set_background("background", minimalpath, true, 128)
end

@ -103,8 +103,11 @@ core.explode_textlist_event(string) -> table
^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click) ^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
GUI: GUI:
core.set_background(type, texturepath) core.set_background(type, texturepath,[tile],[minsize])
^ type: "background", "overlay", "header" or "footer" ^ type: "background", "overlay", "header" or "footer"
^ tile: tile the image instead of scaling (background only)
^ minsize: minimum tile size, images are scaled to at least this size prior
^ doing tiling (background only)
core.set_clouds(<true/false>) core.set_clouds(<true/false>)
core.set_topleft_text(text) core.set_topleft_text(text)
core.show_keys_menu() core.show_keys_menu()

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sound_openal.h" #include "sound_openal.h"
#include "clouds.h" #include "clouds.h"
#include "httpfetch.h" #include "httpfetch.h"
#include "util/numeric.h"
#include <IGUIStaticText.h> #include <IGUIStaticText.h>
#include <ICameraSceneNode.h> #include <ICameraSceneNode.h>
@ -140,7 +141,7 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
{ {
//initialize texture pointers //initialize texture pointers
for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) { for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
m_textures[i] = 0; m_textures[i].texture = NULL;
} }
// is deleted by guiformspec! // is deleted by guiformspec!
m_buttonhandler = new TextDestGuiEngine(this); m_buttonhandler = new TextDestGuiEngine(this);
@ -238,7 +239,6 @@ bool GUIEngine::loadMainMenuScript()
/******************************************************************************/ /******************************************************************************/
void GUIEngine::run() void GUIEngine::run()
{ {
// Always create clouds because they may or may not be // Always create clouds because they may or may not be
// needed based on the game selected // needed based on the game selected
video::IVideoDriver* driver = m_device->getVideoDriver(); video::IVideoDriver* driver = m_device->getVideoDriver();
@ -292,8 +292,8 @@ GUIEngine::~GUIEngine()
//clean up texture pointers //clean up texture pointers
for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) { for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
if (m_textures[i] != 0) if (m_textures[i].texture != NULL)
driver->removeTexture(m_textures[i]); driver->removeTexture(m_textures[i].texture);
} }
delete m_texture_source; delete m_texture_source;
@ -362,7 +362,7 @@ void GUIEngine::drawBackground(video::IVideoDriver* driver)
{ {
v2u32 screensize = driver->getScreenSize(); v2u32 screensize = driver->getScreenSize();
video::ITexture* texture = m_textures[TEX_LAYER_BACKGROUND]; video::ITexture* texture = m_textures[TEX_LAYER_BACKGROUND].texture;
/* If no texture, draw background of solid color */ /* If no texture, draw background of solid color */
if(!texture){ if(!texture){
@ -372,8 +372,27 @@ void GUIEngine::drawBackground(video::IVideoDriver* driver)
return; return;
} }
/* Draw background texture */
v2u32 sourcesize = texture->getOriginalSize(); v2u32 sourcesize = texture->getOriginalSize();
if (m_textures[TEX_LAYER_BACKGROUND].tile)
{
v2u32 tilesize(
MYMAX(sourcesize.X,m_textures[TEX_LAYER_BACKGROUND].minsize),
MYMAX(sourcesize.Y,m_textures[TEX_LAYER_BACKGROUND].minsize));
for (unsigned int x = 0; x < screensize.X; x += tilesize.X )
{
for (unsigned int y = 0; y < screensize.Y; y += tilesize.Y )
{
driver->draw2DImage(texture,
core::rect<s32>(x, y, x+tilesize.X, y+tilesize.Y),
core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
NULL, NULL, true);
}
}
return;
}
/* Draw background texture */
driver->draw2DImage(texture, driver->draw2DImage(texture,
core::rect<s32>(0, 0, screensize.X, screensize.Y), core::rect<s32>(0, 0, screensize.X, screensize.Y),
core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
@ -385,7 +404,7 @@ void GUIEngine::drawOverlay(video::IVideoDriver* driver)
{ {
v2u32 screensize = driver->getScreenSize(); v2u32 screensize = driver->getScreenSize();
video::ITexture* texture = m_textures[TEX_LAYER_OVERLAY]; video::ITexture* texture = m_textures[TEX_LAYER_OVERLAY].texture;
/* If no texture, draw background of solid color */ /* If no texture, draw background of solid color */
if(!texture) if(!texture)
@ -404,7 +423,7 @@ void GUIEngine::drawHeader(video::IVideoDriver* driver)
{ {
core::dimension2d<u32> screensize = driver->getScreenSize(); core::dimension2d<u32> screensize = driver->getScreenSize();
video::ITexture* texture = m_textures[TEX_LAYER_HEADER]; video::ITexture* texture = m_textures[TEX_LAYER_HEADER].texture;
/* If no texture, draw nothing */ /* If no texture, draw nothing */
if(!texture) if(!texture)
@ -438,7 +457,7 @@ void GUIEngine::drawFooter(video::IVideoDriver* driver)
{ {
core::dimension2d<u32> screensize = driver->getScreenSize(); core::dimension2d<u32> screensize = driver->getScreenSize();
video::ITexture* texture = m_textures[TEX_LAYER_FOOTER]; video::ITexture* texture = m_textures[TEX_LAYER_FOOTER].texture;
/* If no texture, draw nothing */ /* If no texture, draw nothing */
if(!texture) if(!texture)
@ -466,29 +485,38 @@ void GUIEngine::drawFooter(video::IVideoDriver* driver)
} }
/******************************************************************************/ /******************************************************************************/
bool GUIEngine::setTexture(texture_layer layer,std::string texturepath) { bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
bool tile_image, unsigned int minsize)
{
video::IVideoDriver* driver = m_device->getVideoDriver(); video::IVideoDriver* driver = m_device->getVideoDriver();
assert(driver != 0); assert(driver != 0);
if (m_textures[layer] != 0) if (m_textures[layer].texture != NULL)
{ {
driver->removeTexture(m_textures[layer]); driver->removeTexture(m_textures[layer].texture);
m_textures[layer] = 0; m_textures[layer].texture = NULL;
} }
if ((texturepath == "") || !fs::PathExists(texturepath)) if ((texturepath == "") || !fs::PathExists(texturepath))
{
return false; return false;
}
m_textures[layer] = driver->getTexture(texturepath.c_str()); m_textures[layer].texture = driver->getTexture(texturepath.c_str());
m_textures[layer].tile = tile_image;
m_textures[layer].minsize = minsize;
if (m_textures[layer] == 0) return false; if (m_textures[layer].texture == NULL)
{
return false;
}
return true; return true;
} }
/******************************************************************************/ /******************************************************************************/
bool GUIEngine::downloadFile(std::string url,std::string target) { bool GUIEngine::downloadFile(std::string url,std::string target)
{
#if USE_CURL #if USE_CURL
std::ofstream targetfile(target.c_str(), std::ios::out | std::ios::binary); std::ofstream targetfile(target.c_str(), std::ios::out | std::ios::binary);
@ -515,7 +543,8 @@ bool GUIEngine::downloadFile(std::string url,std::string target) {
} }
/******************************************************************************/ /******************************************************************************/
void GUIEngine::setTopleftText(std::string append) { void GUIEngine::setTopleftText(std::string append)
{
std::string toset = std::string("Minetest ") + minetest_version_hash; std::string toset = std::string("Minetest ") + minetest_version_hash;
if (append != "") { if (append != "") {
@ -541,7 +570,8 @@ void GUIEngine::stopSound(s32 handle)
/******************************************************************************/ /******************************************************************************/
unsigned int GUIEngine::queueAsync(std::string serialized_func, unsigned int GUIEngine::queueAsync(std::string serialized_func,
std::string serialized_params) { std::string serialized_params)
{
return m_script->queueAsync(serialized_func, serialized_params); return m_script->queueAsync(serialized_func, serialized_params);
} }

@ -41,6 +41,12 @@ typedef enum {
TEX_LAYER_MAX TEX_LAYER_MAX
} texture_layer; } texture_layer;
typedef struct {
video::ITexture* texture;
bool tile;
unsigned int minsize;
} image_definition;
/******************************************************************************/ /******************************************************************************/
/* forward declarations */ /* forward declarations */
/******************************************************************************/ /******************************************************************************/
@ -143,11 +149,11 @@ public:
* @param data struct to transfer data to main game handling * @param data struct to transfer data to main game handling
*/ */
GUIEngine( irr::IrrlichtDevice* dev, GUIEngine( irr::IrrlichtDevice* dev,
gui::IGUIElement* parent, gui::IGUIElement* parent,
IMenuManager *menumgr, IMenuManager *menumgr,
scene::ISceneManager* smgr, scene::ISceneManager* smgr,
MainMenuData* data, MainMenuData* data,
bool& kill); bool& kill);
/** default destructor */ /** default destructor */
virtual ~GUIEngine(); virtual ~GUIEngine();
@ -155,14 +161,16 @@ public:
/** /**
* return MainMenuScripting interface * return MainMenuScripting interface
*/ */
MainMenuScripting* getScriptIface() { MainMenuScripting* getScriptIface()
{
return m_script; return m_script;
} }
/** /**
* return dir of current menuscript * return dir of current menuscript
*/ */
std::string getScriptDir() { std::string getScriptDir()
{
return m_scriptdir; return m_scriptdir;
} }
@ -181,38 +189,38 @@ private:
void limitFrameRate(); void limitFrameRate();
/** device to draw at */ /** device to draw at */
irr::IrrlichtDevice* m_device; irr::IrrlichtDevice* m_device;
/** parent gui element */ /** parent gui element */
gui::IGUIElement* m_parent; gui::IGUIElement* m_parent;
/** manager to add menus to */ /** manager to add menus to */
IMenuManager* m_menumanager; IMenuManager* m_menumanager;
/** scene manager to add scene elements to */ /** scene manager to add scene elements to */
scene::ISceneManager* m_smgr; scene::ISceneManager* m_smgr;
/** pointer to data beeing transfered back to main game handling */ /** pointer to data beeing transfered back to main game handling */
MainMenuData* m_data; MainMenuData* m_data;
/** pointer to texture source */ /** pointer to texture source */
ISimpleTextureSource* m_texture_source; ISimpleTextureSource* m_texture_source;
/** pointer to soundmanager*/ /** pointer to soundmanager*/
ISoundManager* m_sound_manager; ISoundManager* m_sound_manager;
/** representation of form source to be used in mainmenu formspec */ /** representation of form source to be used in mainmenu formspec */
FormspecFormSource* m_formspecgui; FormspecFormSource* m_formspecgui;
/** formspec input receiver */ /** formspec input receiver */
TextDestGuiEngine* m_buttonhandler; TextDestGuiEngine* m_buttonhandler;
/** the formspec menu */ /** the formspec menu */
GUIFormSpecMenu* m_menu; GUIFormSpecMenu* m_menu;
/** reference to kill variable managed by SIGINT handler */ /** reference to kill variable managed by SIGINT handler */
bool& m_kill; bool& m_kill;
/** variable used to abort menu and return back to main game handling */ /** variable used to abort menu and return back to main game handling */
bool m_startgame; bool m_startgame;
/** scripting interface */ /** scripting interface */
MainMenuScripting* m_script; MainMenuScripting* m_script;
/** script basefolder */ /** script basefolder */
std::string m_scriptdir; std::string m_scriptdir;
/** /**
* draw background layer * draw background layer
@ -240,7 +248,8 @@ private:
* @param layer draw layer to specify texture * @param layer draw layer to specify texture
* @param texturepath full path of texture to load * @param texturepath full path of texture to load
*/ */
bool setTexture(texture_layer layer,std::string texturepath); bool setTexture(texture_layer layer, std::string texturepath,
bool tile_image, unsigned int minsize);
/** /**
* download a file using curl * download a file using curl
@ -250,7 +259,7 @@ private:
static bool downloadFile(std::string url,std::string target); static bool downloadFile(std::string url,std::string target);
/** array containing pointers to current specified texture layers */ /** array containing pointers to current specified texture layers */
video::ITexture* m_textures[TEX_LAYER_MAX]; image_definition m_textures[TEX_LAYER_MAX];
/** draw version string in topleft corner */ /** draw version string in topleft corner */
void drawVersion(); void drawVersion();
@ -274,19 +283,19 @@ private:
/** internam data required for drawing clouds */ /** internam data required for drawing clouds */
struct clouddata { struct clouddata {
/** delta time since last cloud processing */ /** delta time since last cloud processing */
f32 dtime; f32 dtime;
/** absolute time of last cloud processing */ /** absolute time of last cloud processing */
u32 lasttime; u32 lasttime;
/** pointer to cloud class */ /** pointer to cloud class */
Clouds* clouds; Clouds* clouds;
/** camera required for drawing clouds */ /** camera required for drawing clouds */
scene::ICameraSceneNode* camera; scene::ICameraSceneNode* camera;
}; };
/** is drawing of clouds enabled atm */ /** is drawing of clouds enabled atm */
bool m_clouds_enabled; bool m_clouds_enabled;
/** data used to draw clouds */ /** data used to draw clouds */
clouddata m_cloud; clouddata m_cloud;
/** start playing a sound and return handle */ /** start playing a sound and return handle */
s32 playSound(SimpleSoundSpec spec, bool looped); s32 playSound(SimpleSoundSpec spec, bool looped);

@ -146,22 +146,36 @@ int ModApiMainMenu::l_set_background(lua_State *L)
std::string backgroundlevel(luaL_checkstring(L, 1)); std::string backgroundlevel(luaL_checkstring(L, 1));
std::string texturename(luaL_checkstring(L, 2)); std::string texturename(luaL_checkstring(L, 2));
bool retval = false; bool tile_image = false;
bool retval = false;
unsigned int minsize = 16;
if (!lua_isnone(L, 3)) {
tile_image = lua_toboolean(L, 3);
}
if (!lua_isnone(L, 4)) {
minsize = lua_tonumber(L, 4);
}
if (backgroundlevel == "background") { if (backgroundlevel == "background") {
retval |= engine->setTexture(TEX_LAYER_BACKGROUND,texturename); retval |= engine->setTexture(TEX_LAYER_BACKGROUND, texturename,
tile_image, minsize);
} }
if (backgroundlevel == "overlay") { if (backgroundlevel == "overlay") {
retval |= engine->setTexture(TEX_LAYER_OVERLAY,texturename); retval |= engine->setTexture(TEX_LAYER_OVERLAY, texturename,
tile_image, minsize);
} }
if (backgroundlevel == "header") { if (backgroundlevel == "header") {
retval |= engine->setTexture(TEX_LAYER_HEADER,texturename); retval |= engine->setTexture(TEX_LAYER_HEADER, texturename,
tile_image, minsize);
} }
if (backgroundlevel == "footer") { if (backgroundlevel == "footer") {
retval |= engine->setTexture(TEX_LAYER_FOOTER,texturename); retval |= engine->setTexture(TEX_LAYER_FOOTER, texturename,
tile_image, minsize);
} }
lua_pushboolean(L,retval); lua_pushboolean(L,retval);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB