fix crashes when the selected element is NULL (via lua), add gfx.getHexColor (inverse of gfx.getColors)
This commit is contained in:
parent
89ffa60529
commit
c44e734abe
@ -338,7 +338,7 @@ if not GetOption('clean'):
|
|||||||
findLibs(env, conf)
|
findLibs(env, conf)
|
||||||
env = conf.Finish()
|
env = conf.Finish()
|
||||||
else:
|
else:
|
||||||
import os, shutil
|
import shutil
|
||||||
try:
|
try:
|
||||||
shutil.rmtree("generated/")
|
shutil.rmtree("generated/")
|
||||||
except:
|
except:
|
||||||
|
@ -558,7 +558,7 @@ bool GameController::MouseDown(int x, int y, unsigned button)
|
|||||||
x = point.X;
|
x = point.X;
|
||||||
y = point.Y;
|
y = point.Y;
|
||||||
if (ret && y<YRES && x<XRES && !gameView->GetPlacingSave())
|
if (ret && y<YRES && x<XRES && !gameView->GetPlacingSave())
|
||||||
if (gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
|
if (gameModel->GetActiveTool(0) && gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
|
||||||
{
|
{
|
||||||
sign * foundSign = GetSignAt(x, y);
|
sign * foundSign = GetSignAt(x, y);
|
||||||
if(foundSign && splitsign(foundSign->text.c_str()))
|
if(foundSign && splitsign(foundSign->text.c_str()))
|
||||||
@ -575,7 +575,7 @@ bool GameController::MouseUp(int x, int y, unsigned button)
|
|||||||
y = point.Y;
|
y = point.Y;
|
||||||
if (ret && y<YRES && x<XRES && !gameView->GetPlacingSave())
|
if (ret && y<YRES && x<XRES && !gameView->GetPlacingSave())
|
||||||
{
|
{
|
||||||
if (gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
|
if (gameModel->GetActiveTool(0) && gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking
|
||||||
{
|
{
|
||||||
sign * foundSign = GetSignAt(x, y);
|
sign * foundSign = GetSignAt(x, y);
|
||||||
if(foundSign) {
|
if(foundSign) {
|
||||||
|
@ -379,15 +379,21 @@ void GameModel::BuildMenus()
|
|||||||
|
|
||||||
Tool * GameModel::GetToolFromIdentifier(std::string identifier)
|
Tool * GameModel::GetToolFromIdentifier(std::string identifier)
|
||||||
{
|
{
|
||||||
for(std::vector<Menu*>::iterator iter = menuList.begin(), end = menuList.end(); iter != end; ++iter)
|
for (std::vector<Menu*>::iterator iter = menuList.begin(), end = menuList.end(); iter != end; ++iter)
|
||||||
{
|
{
|
||||||
std::vector<Tool*> menuTools = (*iter)->GetToolList();
|
std::vector<Tool*> menuTools = (*iter)->GetToolList();
|
||||||
for(std::vector<Tool*>::iterator titer = menuTools.begin(), tend = menuTools.end(); titer != tend; ++titer)
|
for (std::vector<Tool*>::iterator titer = menuTools.begin(), tend = menuTools.end(); titer != tend; ++titer)
|
||||||
{
|
{
|
||||||
if(identifier == (*titer)->GetIdentifier())
|
if (identifier == (*titer)->GetIdentifier())
|
||||||
return *titer;
|
return *titer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (std::vector<Tool*>::iterator iter = extraElementTools.begin(), end = extraElementTools.end(); iter != end; ++iter)
|
||||||
|
{
|
||||||
|
if (identifier == (*iter)->GetIdentifier())
|
||||||
|
return *iter;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2395,6 +2395,7 @@ void LuaScriptInterface::initGraphicsAPI()
|
|||||||
{"drawCircle", graphics_drawCircle},
|
{"drawCircle", graphics_drawCircle},
|
||||||
{"fillCircle", graphics_fillCircle},
|
{"fillCircle", graphics_fillCircle},
|
||||||
{"getColors", graphics_getColors},
|
{"getColors", graphics_getColors},
|
||||||
|
{"getHexColor", graphics_getHexColor},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
luaL_register(l, "graphics", graphicsAPIMethods);
|
luaL_register(l, "graphics", graphicsAPIMethods);
|
||||||
@ -2563,7 +2564,7 @@ int LuaScriptInterface::graphics_fillCircle(lua_State * l)
|
|||||||
|
|
||||||
int LuaScriptInterface::graphics_getColors(lua_State * l)
|
int LuaScriptInterface::graphics_getColors(lua_State * l)
|
||||||
{
|
{
|
||||||
int color = lua_tointeger(l, 1);
|
unsigned int color = lua_tointeger(l, 1);
|
||||||
|
|
||||||
int a = color >> 24;
|
int a = color >> 24;
|
||||||
int r = (color >> 16)&0xFF;
|
int r = (color >> 16)&0xFF;
|
||||||
@ -2577,6 +2578,20 @@ int LuaScriptInterface::graphics_getColors(lua_State * l)
|
|||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::graphics_getHexColor(lua_State * l)
|
||||||
|
{
|
||||||
|
int r = lua_tointeger(l, 1);
|
||||||
|
int g = lua_tointeger(l, 2);
|
||||||
|
int b = lua_tointeger(l, 3);
|
||||||
|
int a = 0;
|
||||||
|
if (lua_gettop(l) >= 4)
|
||||||
|
a = lua_tointeger(l, 4);
|
||||||
|
unsigned int color = (a<<24) + (r<<16) + (g<<8) + b;
|
||||||
|
|
||||||
|
lua_pushinteger(l, color);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void LuaScriptInterface::initFileSystemAPI()
|
void LuaScriptInterface::initFileSystemAPI()
|
||||||
{
|
{
|
||||||
//Methods
|
//Methods
|
||||||
@ -2819,14 +2834,19 @@ bool LuaScriptInterface::OnBrushChanged(int brushType, int rx, int ry)
|
|||||||
|
|
||||||
bool LuaScriptInterface::OnActiveToolChanged(int toolSelection, Tool * tool)
|
bool LuaScriptInterface::OnActiveToolChanged(int toolSelection, Tool * tool)
|
||||||
{
|
{
|
||||||
|
std::string identifier;
|
||||||
|
if (tool)
|
||||||
|
identifier = tool->GetIdentifier();
|
||||||
|
else
|
||||||
|
identifier = "";
|
||||||
if (toolSelection == 0)
|
if (toolSelection == 0)
|
||||||
luacon_selectedl = tool->GetIdentifier();
|
luacon_selectedl = identifier;
|
||||||
else if (toolSelection == 1)
|
else if (toolSelection == 1)
|
||||||
luacon_selectedr = tool->GetIdentifier();
|
luacon_selectedr = identifier;
|
||||||
else if (toolSelection == 2)
|
else if (toolSelection == 2)
|
||||||
luacon_selectedalt = tool->GetIdentifier();
|
luacon_selectedalt = identifier;
|
||||||
else if (toolSelection == 3)
|
else if (toolSelection == 3)
|
||||||
luacon_selectedreplace = tool->GetIdentifier();
|
luacon_selectedreplace = identifier;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +132,7 @@ class LuaScriptInterface: public CommandInterface
|
|||||||
static int graphics_drawCircle(lua_State * l);
|
static int graphics_drawCircle(lua_State * l);
|
||||||
static int graphics_fillCircle(lua_State * l);
|
static int graphics_fillCircle(lua_State * l);
|
||||||
static int graphics_getColors(lua_State * l);
|
static int graphics_getColors(lua_State * l);
|
||||||
|
static int graphics_getHexColor(lua_State * l);
|
||||||
|
|
||||||
void initFileSystemAPI();
|
void initFileSystemAPI();
|
||||||
static int fileSystem_list(lua_State * l);
|
static int fileSystem_list(lua_State * l);
|
||||||
|
Reference in New Issue
Block a user