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

@@ -20,6 +20,7 @@ though in some cases rearranged a little:
- dlogbtnsm.png
- dlogbtntall.png
- dlogpics.png
- errors.png ( "Under Construction Grunge Sign" by Free Grunge Textures - www.freestock.ca is licensed under CC BY 2.0 )
- edsplash.png (by James Ernest)
- fighthelp.png
- invenbtns.png (the coin was cropped from an item graphic)

BIN
rsrc/graphics/errors.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -29,8 +29,8 @@ Texture_pos cCustomGraphics::find_graphic(pic_num_t which_rect, bool party) {
else if(numSheets == 0) valid = false;
if(!valid) {
INVALID:
auto const &blank = *ResMgr::textures.get("blank", true);
return std::make_pair(blank, rectangle(0,0,36,28));
auto const &error = *ResMgr::textures.get("errors", true);
return std::make_pair(error, rectangle(0,0,40,40));
}
short sheet = which_rect / 100;
if(is_old || party) sheet = 0;

View File

@@ -78,6 +78,7 @@ struct Texture {
{ "dlogscrollwh", {64,64} },
{ "edbuttons", {251,164} },
{ "edsplash", {640,480} },
{ "errors", {40,40} },
{ "fields", {224,144} },
{ "fighthelp", {320,125} },
{ "icon", {38,38} },

View File

@@ -438,10 +438,10 @@ cPictNum cTerrain::get_map_picture_num() const
{
if (map_pic<0)
return get_picture_num();
if (map_pic<1000)
return cPictNum(map_pic+(map_pic<960 ? 0 : 400-960),PIC_TER_MAP);
if (map_pic < 1000)
return cPictNum(map_pic,PIC_TER_MAP);
if(map_pic < 2000)
return cPictNum(map_pic-1000,PIC_CUSTOM_TER);
return cPictNum(map_pic-2000,PIC_CUSTOM_TER_ANIM);
return cPictNum(map_pic-1000,PIC_CUSTOM_TER_MAP);
return cPictNum(map_pic-2000,PIC_CUSTOM_TER_MAP);
// checkme add force PIC_TER_MAP?
}

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() {