graphics: add a picture to store/show some errors,

Scene Editor: try to do not end with a fatal errors if a terrain's picture or
  map picture does not exist, to be improved...
This commit is contained in:
ALONSO Laurent
2021-10-17 16:23:06 +02:00
committed by Celtic Minstrel
parent dbe6482568
commit e4d220799e
7 changed files with 56 additions and 18 deletions

View File

@@ -353,15 +353,38 @@ static void fill_ter_info(cDialog& me, short ter){
cTerrain& ter_type = scenario.ter_types[ter];
{
cPict& pic_ctrl = dynamic_cast<cPict&>(me["graphic"]);
pic_ctrl.setPict(ter_type.get_picture_num());
bool bad=false;
if (ter_type.get_picture_num().type==ePicType::PIC_TER) {
// REMOVEME when setPict will not do fatal error
try {
*ResMgr::textures.get("ter" + std::to_string(1 + ter_type.get_picture_num().num / 50));
}
catch(...) {
bad=true;
}
}
if (!bad)
pic_ctrl.setPict(ter_type.get_picture_num());
else
pic_ctrl.setPict(cPictNum(1999,ePicType::PIC_CUSTOM_TER));
me["pict"].setTextToNum(ter_type.picture);
}{
cPict& pic_ctrl = dynamic_cast<cPict&>(me["seemap"]);
pic_num_t pic = ter_type.map_pic;
if(pic < 1000)
pic_ctrl.setPict(pic, PIC_TER_MAP);
else pic_ctrl.setPict(pic, PIC_CUSTOM_TER_MAP);
me["map"].setTextToNum(pic);
bool bad=false;
if (ter_type.get_map_picture_num().type==ePicType::PIC_TER) {
// REMOVEME when setPict will not do fatal error
try {
*ResMgr::textures.get("ter" + std::to_string(1 + ter_type.get_map_picture_num().num / 50));
}
catch(...) {
bad=true;
}
}
if (!bad) // FIXME the picture size is bad if we revert to the main picture
pic_ctrl.setPict(ter_type.get_map_picture_num());
else
pic_ctrl.setPict(cPictNum(1999,ePicType::PIC_CUSTOM_TER));
me["map"].setTextToNum(ter_type.map_pic);
}
me["number"].setTextToNum(ter);
me["name"].setText(ter_type.name);

View File

@@ -318,7 +318,7 @@ static std::vector<short> get_small_icons(location at, ter_num_t t_to_draw) {
}
static bool get_terrain_picture(cPictNum pict, Texture &source, rectangle &from_rect)
{
try {
source=Texture();
ePicType type=pict.type;
if (pict.num<0)
@@ -336,8 +336,14 @@ static bool get_terrain_picture(cPictNum pict, Texture &source, rectangle &from_
break;
case ePicType::PIC_TER_MAP:
source=*ResMgr::textures.get("termap");
from_rect.left = 12*(pict.num%20);
from_rect.top = 12*(pict.num/20);
if (pict.num<960) {
from_rect.left = 12*(pict.num%20);
from_rect.top = 12*(pict.num/20);
}
else {
from_rect.left = 12*20;
from_rect.top = 12*(pict.num-960);
}
from_rect.right = from_rect.left+12;
from_rect.bottom = from_rect.top+12;
break;
@@ -350,10 +356,17 @@ static bool get_terrain_picture(cPictNum pict, Texture &source, rectangle &from_
default:
break;
}
if (bool(source))
return true;
if (!source)
throw "can not find image";
return true;
}
catch (...) {
if (pict.num==-1) // ok no picture
return false;
std::cerr << "Error[get_terrain_picture]: can not find picture id=" << pict.num << "type=" << int(pict.type)<< "\n";
return false;
source = *ResMgr::textures.get("errors");
from_rect={0,0,40,40};
return true;
}
void Set_up_win() {