cPict: begin to differentiate the picture type and the dialog type

+ begin to merge the drawing functions, to be continued
all: try to use the pict.cpp functions to draw items..
This commit is contained in:
ALONSO Laurent
2021-10-20 10:19:00 +02:00
committed by Celtic Minstrel
parent 3451c70fec
commit a7a24e7e7a
12 changed files with 206 additions and 227 deletions

View File

@@ -349,37 +349,15 @@ static bool fill_ter_flag_info(cDialog& me, std::string id, bool losing){
return true;
}
// REMOVEME when setPict will not do fatal error
bool check_picture_num(cPictNum const &pic, bool noneIsOk)
try {
if (noneIsOk && pic.num==-1)
return true;
if (pic.num<0)
return false;
if (pic.type==ePicType::PIC_TER)
// REMOVEME when setPict will not do fatal error
*ResMgr::textures.get("ter" + std::to_string(1 + pic.num / 50));
return true;
}
catch(...) {
return false;
}
static void fill_ter_info(cDialog& me, short ter){
cTerrain const & ter_type = scenario.get_terrain(ter);
{
cPict& pic_ctrl = dynamic_cast<cPict&>(me["graphic"]);
if (check_picture_num(ter_type.get_picture_num(), false)) // REMOVEME
pic_ctrl.setPict(ter_type.get_picture_num());
else
pic_ctrl.setPict(cPictNum(1999,ePicType::PIC_CUSTOM_TER));
pic_ctrl.setPict(ter_type.get_picture_num());
me["pict"].setTextToNum(ter_type.picture);
}{
cPict& pic_ctrl = dynamic_cast<cPict&>(me["seemap"]);
if (check_picture_num(ter_type.get_map_picture_num(), false)) // REMOVEME
pic_ctrl.setPict(ter_type.get_map_picture_num());
else
pic_ctrl.setPict(cPictNum(1999,ePicType::PIC_CUSTOM_TER));
pic_ctrl.setPict(ter_type.get_map_picture_num());
me["map"].setTextToNum(ter_type.map_pic);
}
me["number"].setTextToNum(ter);
@@ -503,10 +481,7 @@ static bool edit_ter_obj(cDialog& me, ter_num_t which_ter) {
for(int x = 0; x < 4; x++) {
for(int y = 0; y < 4; y++) {
std::string id = "x" + std::to_string(x) + "y" + std::to_string(y);
if (check_picture_num(cTerrain::get_picture_num_for_terrain(obj[x][y]), true))
dynamic_cast<cPict&>(me[id]).setPict(cTerrain::get_picture_num_for_terrain(obj[x][y]));
else
dynamic_cast<cPict&>(me[id]).setPict(cPictNum(1999,ePicType::PIC_CUSTOM_TER));
dynamic_cast<cPict&>(me[id]).setPict(cTerrain::get_picture_num_for_terrain(obj[x][y]));
}
}
return true;
@@ -1408,13 +1383,11 @@ cMonster edit_monst_abil(cMonster initial,short which,cDialog& parent) {
return initial;
}
static void put_item_info_in_dlog(cDialog& me, cItem& item, short which) {
static void put_item_info_in_dlog(cDialog& me, cItem const &item, short which) {
me["num"].setTextToNum(which);
me["full"].setText(item.full_name);
me["short"].setText(item.name);
if(item.graphic_num >= 1000) // was 150
dynamic_cast<cPict&>(me["pic"]).setPict(item.graphic_num, PIC_CUSTOM_ITEM);
else dynamic_cast<cPict&>(me["pic"]).setPict(item.graphic_num, PIC_ITEM);
dynamic_cast<cPict&>(me["pic"]).setPict(item.get_picture_num(false));
me["picnum"].setTextToNum(item.graphic_num);
bool missile = false, weapon = false;
@@ -2177,7 +2150,7 @@ bool edit_quest(size_t which_quest) {
static bool put_shop_item_in_dlog(cPict& pic, cControl& num, cControl& title, const cShop& shop, int which) {
cShopItem entry = shop.getItem(which);
num.setTextToNum(which);
pic.setPict(entry.item.graphic_num);
pic.setPict(entry.item.get_picture_num(false));
if(entry.type == eShopItemType::EMPTY) {
title.setText("");
return false;

View File

@@ -22,7 +22,6 @@ void edit_scenario_events();
bool build_scenario();
bool edit_vehicle(class cVehicle& what, int num, bool is_boat);
bool check_picture_num(cPictNum const &pic, bool noneIsOk);
bool check_range_msg(cDialog& me,std::string id,bool losing,long min_val,long max_val,std::string fld_name,std::string xtra);
bool check_range(cDialog& me,std::string id,bool losing,long min_val,long max_val,std::string fld_name);
bool pick_string(std::string from_file, cDialog& parent, std::string result_fld, std::string str_fld);

View File

@@ -533,7 +533,7 @@ void set_up_terrain_buttons(bool reset) {
break;
}
Texture source_gworld;
if (cPict::get_terrain_picture(scenario.get_terrain(i).get_picture_num(), source_gworld, ter_from))
if (cPict::get_picture(scenario.get_terrain(i).get_picture_num(), source_gworld, ter_from))
rect_draw_some_item(source_gworld,ter_from, mainPtr, draw_rect);
small_i = get_small_icon(i);
tiny_from = base_small_button_from;
@@ -647,18 +647,11 @@ void set_up_terrain_buttons(bool reset) {
}
break;
case DRAW_ITEM:
pic = scenario.get_item(i).graphic_num;
Texture source_gworld;
tiny_to = draw_rect;
frame_rect(mainPtr, tiny_to, sf::Color::Black);
if(pic >= 1000) {
Texture source_gworld;
std::tie(source_gworld,ter_from) = spec_scen_g.find_graphic(pic % 1000);
if (cPict::get_picture(scenario.get_item(i).get_picture_num(true), source_gworld, ter_from))
rect_draw_some_item(source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
} else {
tiny_from = {0,0,18,18};
tiny_from.offset((pic % 10) * 18,(pic / 10) * 18);
rect_draw_some_item(*ResMgr::textures.get("tinyobj"), tiny_from, mainPtr, tiny_to, sf::BlendAlpha);
}
break;
}
}
@@ -1022,61 +1015,36 @@ void draw_monsts() {
}
}
// Returns rect for drawing an item, if num < 25, rect is in big item template,
// otherwise in small item template
static rectangle get_item_template_rect (short type_wanted) {
rectangle store_rect;
if(type_wanted < 55) {
store_rect.top = (type_wanted / 5) * BITMAP_HEIGHT;
store_rect.bottom = store_rect.top + BITMAP_HEIGHT;
store_rect.left = (type_wanted % 5) * BITMAP_WIDTH;
store_rect.right = store_rect.left + BITMAP_WIDTH;
}
else {
store_rect.top = (type_wanted / 10) * 18;
store_rect.bottom = store_rect.top + 18;
store_rect.left = (type_wanted % 10) * 18;
store_rect.right = store_rect.left + 18;
}
return store_rect;
static void update_item_rectangle(cPictNum const &pict, rectangle &rect)
{
if (pict.type==ePicType::PIC_CUSTOM_ITEM || pict.num<45)
return;
rect.top += 9;
rect.bottom -= 9;
rect.left += 5;
rect.right -= 5;
}
void draw_items() {
rectangle source_rect,dest_rect;
rectangle dest_rect;
location where_draw;
short pic_num;
for(short i = 0; i < town->preset_items.size(); i++) {
if(town->preset_items[i].code >= 0) {
where_draw.x = town->preset_items[i].loc.x - cen_x + 4;
where_draw.y = town->preset_items[i].loc.y - cen_y + 4;
pic_num = scenario.get_item(town->preset_items[i].code).graphic_num;
if((where_draw.x >= 0) && (where_draw.x <= 8) &&
(where_draw.y >= 0) && (where_draw.y <= 8)) {
if(pic_num >= 1000) {
Texture source_gworld;
std::tie(source_gworld,source_rect)= spec_scen_g.find_graphic(pic_num - 1000);
dest_rect = calc_rect(where_draw.x,where_draw.y);
dest_rect.offset(8+TER_RECT_UL_X,8+TER_RECT_UL_Y);
rect_draw_some_item(source_gworld, source_rect, mainPtr, dest_rect, sf::BlendAlpha);
}
else {
source_rect = get_item_template_rect(pic_num);
dest_rect = calc_rect(where_draw.x,where_draw.y);
dest_rect.offset(8+TER_RECT_UL_X,8+TER_RECT_UL_Y);
if(pic_num >= 45) {
dest_rect.top += 9;
dest_rect.bottom -= 9;
dest_rect.left += 5;
dest_rect.right -= 5;
}
rect_draw_some_item(*ResMgr::textures.get((pic_num < 55) ? "objects" : "tinyobj"),
source_rect, mainPtr, dest_rect,sf::BlendAlpha);
}
}
if(town->preset_items[i].code < 0)
continue;
where_draw.x = town->preset_items[i].loc.x - cen_x + 4;
where_draw.y = town->preset_items[i].loc.y - cen_y + 4;
if(where_draw.x < 0 || where_draw.x > 8 || where_draw.y < 0 || where_draw.y > 8)
continue;
auto const &pic_num = scenario.get_item(town->preset_items[i].code).get_picture_num(false);
rectangle source_rect;
Texture source_gworld;
dest_rect = calc_rect(where_draw.x,where_draw.y);
dest_rect.offset(8+TER_RECT_UL_X,8+TER_RECT_UL_Y);
if (cPict::get_picture(pic_num, source_gworld, source_rect)) {
update_item_rectangle(pic_num, dest_rect);
rect_draw_some_item(source_gworld, source_rect, mainPtr, dest_rect, sf::BlendAlpha);
}
}
}
@@ -1095,7 +1063,7 @@ void draw_one_terrain_spot (short i,short j,ter_num_t terrain_to_draw) {
rectangle source_rect;
Texture source_gworld;
if (!cPict::cPict::get_terrain_picture(scenario.get_terrain(terrain_to_draw).get_picture_num(), source_gworld, source_rect))
if (!cPict::get_picture(scenario.get_terrain(terrain_to_draw).get_picture_num(), source_gworld, source_rect))
return;
location where_draw;
@@ -1116,7 +1084,7 @@ void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short
Texture source_gworld;
rectangle dest_rect = {0,0,size,size};
dest_rect.offset(8 + TER_RECT_UL_X + size * i, 8 + TER_RECT_UL_Y + size * j);
if (cPict::get_terrain_picture(scenario.get_terrain(terrain_to_draw).get_map_picture_num(), source_gworld, from_rect))
if (cPict::get_picture(scenario.get_terrain(terrain_to_draw).get_map_picture_num(), source_gworld, from_rect))
rect_draw_some_item(source_gworld, from_rect, mainPtr, dest_rect);
if(road) {
rectangle road_rect = dest_rect;
@@ -1201,7 +1169,7 @@ void draw_frames() {
static void place_selected_terrain(ter_num_t ter, rectangle draw_rect) {
rectangle source_rect;
Texture source_gworld;
if (cPict::get_terrain_picture(scenario.get_terrain(ter).get_picture_num(), source_gworld, source_rect))
if (cPict::get_picture(scenario.get_terrain(ter).get_picture_num(), source_gworld, source_rect))
rect_draw_some_item(source_gworld,source_rect, mainPtr,draw_rect);
short small_i = get_small_icon(ter);
@@ -1394,19 +1362,11 @@ void place_location() {
}
}
} else if(overall_mode == MODE_PLACE_ITEM || overall_mode == MODE_PLACE_SAME_ITEM) {
picture_wanted = scenario.get_item(mode_count).graphic_num;
if(picture_wanted >= 1000) {
Texture source_gworld;
std::tie(source_gworld,source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
cPictNum pic=scenario.get_item(mode_count).get_picture_num(false);
Texture source_gworld;
if (cPict::get_picture(pic,source_gworld, source_rect)) {
update_item_rectangle(pic, draw_rect);
rect_draw_some_item(source_gworld,source_rect,mainPtr,draw_rect,sf::BlendAlpha);
} else if(picture_wanted < 55) {
source_rect = calc_rect(picture_wanted % 5,picture_wanted / 5);
rect_draw_some_item(*ResMgr::textures.get("objects"),source_rect,mainPtr,draw_rect,sf::BlendAlpha);
} else {
draw_rect.inset(5, 9);
rectangle tiny_from = {0,0,18,18};
tiny_from.offset((picture_wanted % 10) * 18,(picture_wanted / 10) * 18);
rect_draw_some_item(*ResMgr::textures.get("tinyobj"),tiny_from,mainPtr,draw_rect,sf::BlendAlpha);
}
} else if(overall_mode == MODE_TOGGLE_SPECIAL_DOT) {
draw_field = true;

View File

@@ -247,7 +247,7 @@ static bool put_placed_item_in_dlog(cDialog& me, const cTown::cItem& item, const
if(item.contained)
dynamic_cast<cLed&>(me["contained"]).setState(led_red);
dynamic_cast<cPict&>(me["pic"]).setPict(base.graphic_num, PIC_ITEM);
dynamic_cast<cPict&>(me["pic"]).setPict(base.get_picture_num(false));
me["charges"].show();
me["charges-lbl"].show();
@@ -368,10 +368,7 @@ void edit_sign(sign_loc_t& which_sign,short num,short picture) {
cDialog sign_dlg("edit-sign");
sign_dlg["cancel"].attachClickHandler(std::bind(&cDialog::toast, &sign_dlg, false));
sign_dlg["okay"].attachClickHandler(std::bind(edit_sign_event_filter, _1, std::ref(which_sign)));
if (check_picture_num(cTerrain::get_picture_num_for_terrain(picture), false)) // REMOVEME
dynamic_cast<cPict&>(sign_dlg["pic"]).setPict(cTerrain::get_picture_num_for_terrain(picture)); // checkme: does this really need to be some terrain?
else
dynamic_cast<cPict&>(sign_dlg["pic"]).setPict(cPictNum(1999,ePicType::PIC_CUSTOM_TER));
dynamic_cast<cPict&>(sign_dlg["pic"]).setPict(cTerrain::get_picture_num_for_terrain(picture)); // checkme: does this really need to be some terrain?
sign_dlg["num"].setTextToNum(num);