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 - dlogbtnsm.png
- dlogbtntall.png - dlogbtntall.png
- dlogpics.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) - edsplash.png (by James Ernest)
- fighthelp.png - fighthelp.png
- invenbtns.png (the coin was cropped from an item graphic) - 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; else if(numSheets == 0) valid = false;
if(!valid) { if(!valid) {
INVALID: INVALID:
auto const &blank = *ResMgr::textures.get("blank", true); auto const &error = *ResMgr::textures.get("errors", true);
return std::make_pair(blank, rectangle(0,0,36,28)); return std::make_pair(error, rectangle(0,0,40,40));
} }
short sheet = which_rect / 100; short sheet = which_rect / 100;
if(is_old || party) sheet = 0; if(is_old || party) sheet = 0;

View File

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

View File

@@ -438,10 +438,10 @@ cPictNum cTerrain::get_map_picture_num() const
{ {
if (map_pic<0) if (map_pic<0)
return get_picture_num(); return get_picture_num();
if (map_pic<1000) if (map_pic < 1000)
return cPictNum(map_pic+(map_pic<960 ? 0 : 400-960),PIC_TER_MAP); return cPictNum(map_pic,PIC_TER_MAP);
if(map_pic < 2000) if(map_pic < 2000)
return cPictNum(map_pic-1000,PIC_CUSTOM_TER); return cPictNum(map_pic-1000,PIC_CUSTOM_TER_MAP);
return cPictNum(map_pic-2000,PIC_CUSTOM_TER_ANIM); return cPictNum(map_pic-2000,PIC_CUSTOM_TER_MAP);
// checkme add force PIC_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]; cTerrain& ter_type = scenario.ter_types[ter];
{ {
cPict& pic_ctrl = dynamic_cast<cPict&>(me["graphic"]); 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); me["pict"].setTextToNum(ter_type.picture);
}{ }{
cPict& pic_ctrl = dynamic_cast<cPict&>(me["seemap"]); cPict& pic_ctrl = dynamic_cast<cPict&>(me["seemap"]);
pic_num_t pic = ter_type.map_pic; bool bad=false;
if(pic < 1000) if (ter_type.get_map_picture_num().type==ePicType::PIC_TER) {
pic_ctrl.setPict(pic, PIC_TER_MAP); // REMOVEME when setPict will not do fatal error
else pic_ctrl.setPict(pic, PIC_CUSTOM_TER_MAP); try {
me["map"].setTextToNum(pic); *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["number"].setTextToNum(ter);
me["name"].setText(ter_type.name); 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) static bool get_terrain_picture(cPictNum pict, Texture &source, rectangle &from_rect)
{ try {
source=Texture(); source=Texture();
ePicType type=pict.type; ePicType type=pict.type;
if (pict.num<0) if (pict.num<0)
@@ -336,8 +336,14 @@ static bool get_terrain_picture(cPictNum pict, Texture &source, rectangle &from_
break; break;
case ePicType::PIC_TER_MAP: case ePicType::PIC_TER_MAP:
source=*ResMgr::textures.get("termap"); source=*ResMgr::textures.get("termap");
from_rect.left = 12*(pict.num%20); if (pict.num<960) {
from_rect.top = 12*(pict.num/20); 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.right = from_rect.left+12;
from_rect.bottom = from_rect.top+12; from_rect.bottom = from_rect.top+12;
break; break;
@@ -350,10 +356,17 @@ static bool get_terrain_picture(cPictNum pict, Texture &source, rectangle &from_
default: default:
break; break;
} }
if (bool(source)) if (!source)
return true; 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"; 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() { void Set_up_win() {