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:
@@ -95,30 +95,32 @@ bool cPict::manageFormat(eFormat prop, bool set, boost::any* val) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void cPict::setPict(pic_num_t num, ePicType type){
|
||||
void cPict::setPict(pic_num_t num, ePicType type, bool updateResultType){
|
||||
picNum = num;
|
||||
picType = type;
|
||||
if(picType == PIC_MONST && picNum < 1000) {
|
||||
if(m_pic_index[num].x == 2) picType += PIC_WIDE;
|
||||
if(m_pic_index[num].y == 2) picType += PIC_TALL;
|
||||
if (updateResultType)
|
||||
resultType = type;
|
||||
else
|
||||
fromType = type;
|
||||
if(type == PIC_MONST && resultType == PIC_MONST && picNum < 1000) {
|
||||
if(m_pic_index[num].x == 2) resultType += PIC_WIDE;
|
||||
if(m_pic_index[num].y == 2) resultType += PIC_TALL;
|
||||
}
|
||||
if(picType != PIC_FULL && picNum >= 1000) {
|
||||
if(updateResultType && resultType != PIC_FULL && picNum >= 1000) {
|
||||
if(picNum >= 10000) {
|
||||
picNum -= 10000;
|
||||
picType += PIC_PARTY;
|
||||
resultType += PIC_PARTY;
|
||||
} else {
|
||||
picType += PIC_CUSTOM;
|
||||
if(picType != PIC_CUSTOM_TER_MAP)
|
||||
picNum %= 1000;
|
||||
resultType += PIC_CUSTOM;
|
||||
picNum %= 1000;
|
||||
}
|
||||
}
|
||||
recalcRect();
|
||||
}
|
||||
|
||||
void cPict::setPict(pic_num_t num) {
|
||||
if(picType - PIC_LARGE == PIC_MONST)
|
||||
if(resultType - PIC_LARGE == PIC_MONST)
|
||||
setPict(num, PIC_MONST);
|
||||
else setPict(num, picType - PIC_CUSTOM);
|
||||
else setPict(num, resultType - PIC_CUSTOM);
|
||||
}
|
||||
|
||||
pic_num_t cPict::getPicNum(){
|
||||
@@ -126,17 +128,17 @@ pic_num_t cPict::getPicNum(){
|
||||
}
|
||||
|
||||
ePicType cPict::getPicType(){
|
||||
return picType;
|
||||
return resultType;
|
||||
}
|
||||
|
||||
// AsanU: unset
|
||||
cPict::cPict(cDialog& parent) :
|
||||
cControl(CTRL_PICT,parent), drawScaled(false) {
|
||||
cControl(CTRL_PICT,parent), fromType(ePicType::PIC_NONE), drawScaled(false) {
|
||||
setFormat(TXT_FRAME, FRM_SOLID);
|
||||
}
|
||||
|
||||
cPict::cPict(sf::RenderWindow& parent) :
|
||||
cControl(CTRL_PICT, parent), drawScaled(false) {
|
||||
cControl(CTRL_PICT, parent), fromType(ePicType::PIC_NONE), drawScaled(false) {
|
||||
setFormat(TXT_FRAME, FRM_SOLID);
|
||||
}
|
||||
|
||||
@@ -443,33 +445,33 @@ bool cPict::parseAttribute(ticpp::Attribute& attr, std::string tagName, std::str
|
||||
if(val == "blank")
|
||||
blank = true;
|
||||
else if(val == "ter")
|
||||
picType = PIC_TER;
|
||||
resultType = PIC_TER;
|
||||
else if(val == "teranim")
|
||||
picType = PIC_TER_ANIM;
|
||||
resultType = PIC_TER_ANIM;
|
||||
else if(val == "monst")
|
||||
picType = PIC_MONST;
|
||||
resultType = PIC_MONST;
|
||||
else if(val == "dlog")
|
||||
picType = PIC_DLOG;
|
||||
resultType = PIC_DLOG;
|
||||
else if(val == "talk")
|
||||
picType = PIC_TALK;
|
||||
resultType = PIC_TALK;
|
||||
else if(val == "scen")
|
||||
picType = PIC_SCEN;
|
||||
resultType = PIC_SCEN;
|
||||
else if(val == "item")
|
||||
picType = PIC_ITEM;
|
||||
resultType = PIC_ITEM;
|
||||
else if(val == "pc")
|
||||
picType = PIC_PC;
|
||||
resultType = PIC_PC;
|
||||
else if(val == "field")
|
||||
picType = PIC_FIELD;
|
||||
resultType = PIC_FIELD;
|
||||
else if(val == "boom")
|
||||
picType = PIC_BOOM;
|
||||
resultType = PIC_BOOM;
|
||||
else if(val == "missile")
|
||||
picType = PIC_MISSILE;
|
||||
resultType = PIC_MISSILE;
|
||||
else if(val == "full")
|
||||
picType = PIC_FULL;
|
||||
resultType = PIC_FULL;
|
||||
else if(val == "map")
|
||||
picType = PIC_TER_MAP;
|
||||
resultType = PIC_TER_MAP;
|
||||
else if(val == "status")
|
||||
picType = PIC_STATUS;
|
||||
resultType = PIC_STATUS;
|
||||
else throw xBadVal(tagName, name, val, attr.Row(), attr.Column(), fname);
|
||||
return true;
|
||||
} else if(name == "num") {
|
||||
@@ -514,21 +516,21 @@ void cPict::validatePostParse(ticpp::Element& who, std::string fname, const std:
|
||||
if(blank && attrs.count("num")) throw xBadAttr(who.Value(), "num", who.Row(), who.Column(), fname);
|
||||
else if(!blank && !attrs.count("num")) throw xMissingAttr(who.Value(), "num", who.Row(), who.Column(), fname);
|
||||
|
||||
if(blank) picType = PIC_MONST, picNum = BLANK;
|
||||
else if(tiny && picType == PIC_ITEM) picType = PIC_TINY_ITEM;
|
||||
else if(custom) picType += PIC_CUSTOM;
|
||||
if(blank) resultType = PIC_MONST, picNum = BLANK;
|
||||
else if(tiny && resultType == PIC_ITEM) resultType = PIC_TINY_ITEM;
|
||||
else if(custom) resultType += PIC_CUSTOM;
|
||||
|
||||
if(wide && tall) picType += PIC_LARGE;
|
||||
else if(wide) picType += PIC_WIDE;
|
||||
else if(tall) picType += PIC_TALL;
|
||||
if(wide && tall) resultType += PIC_LARGE;
|
||||
else if(wide) resultType += PIC_WIDE;
|
||||
else if(tall) resultType += PIC_TALL;
|
||||
|
||||
setPict(picNum, picType);
|
||||
setPict(picNum, resultType);
|
||||
return cControl::validatePostParse(who, fname, attrs, nodes);
|
||||
}
|
||||
|
||||
void cPict::recalcRect() {
|
||||
rectangle bounds = getBounds();
|
||||
switch(picType) {
|
||||
switch(resultType) {
|
||||
case NUM_PIC_TYPES: case PIC_NONE: break;
|
||||
case PIC_TER: case PIC_CUSTOM_TER:
|
||||
case PIC_TER_ANIM: case PIC_CUSTOM_TER_ANIM:
|
||||
@@ -684,12 +686,13 @@ void cPict::draw(){
|
||||
|
||||
if(picNum == BLANK) // Just fill with black
|
||||
fill_rect(*inWindow, rect, sf::Color::Black);
|
||||
else (this->*drawPict()[picType])(picNum,rect);
|
||||
else
|
||||
(this->*drawPict()[resultType])(picNum,rect);
|
||||
|
||||
drawFrame(2, frameStyle);
|
||||
}
|
||||
|
||||
bool cPict::get_terrain_picture(cPictNum pict, Texture &source, rectangle &from_rect, int anim)
|
||||
bool cPict::get_picture(cPictNum pict, Texture& source, rectangle &from_rect, int anim)
|
||||
try {
|
||||
source=Texture();
|
||||
ePicType type=pict.type;
|
||||
@@ -707,7 +710,7 @@ try {
|
||||
from_rect = calc_rect(4*(pict.num/5)+(anim%4),pict.num%5);
|
||||
break;
|
||||
case ePicType::PIC_TER_MAP:
|
||||
source=*ResMgr::textures.get("termap");
|
||||
source = *ResMgr::textures.get("termap");
|
||||
if (pict.num<960) {
|
||||
from_rect.left = 12*(pict.num%20);
|
||||
from_rect.top = 12*(pict.num/20);
|
||||
@@ -729,6 +732,26 @@ try {
|
||||
break;
|
||||
std::tie(source,from_rect) = spec_scen_g.find_graphic(pict.num+(anim%4));
|
||||
break;
|
||||
case ePicType::PIC_ITEM: // 0-54
|
||||
case ePicType::PIC_TINY_ITEM: // 0-139
|
||||
if (pict.num<55 && pict.type != ePicType::PIC_TINY_ITEM) {
|
||||
source = *ResMgr::textures.get("objects");
|
||||
from_rect = calc_rect(pict.num % 5, pict.num / 5);
|
||||
}
|
||||
else {
|
||||
source = *ResMgr::textures.get("tinyobj");
|
||||
from_rect.left=18 * (pict.num % 10);
|
||||
from_rect.top=18 * (pict.num / 10);
|
||||
from_rect.right = from_rect.left+18;
|
||||
from_rect.bottom = from_rect.top+18;
|
||||
}
|
||||
break;
|
||||
case ePicType::PIC_CUSTOM_ITEM:
|
||||
case ePicType::PIC_CUSTOM_TINY_ITEM:
|
||||
if (!spec_scen_g)
|
||||
break;
|
||||
std::tie(source,from_rect) = spec_scen_g.find_graphic(pict.num);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -739,30 +762,32 @@ try {
|
||||
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_picture]: can not find picture id=" << pict.num << ", type=" << int(pict.type)<< "\n";
|
||||
source = *ResMgr::textures.get("errors");
|
||||
from_rect={0,0,40,40};
|
||||
return true;
|
||||
}
|
||||
|
||||
void cPict::drawPresetTer(short num, rectangle to_rect){
|
||||
auto from_gw = getSheet(SHEET_TER, num / 50);
|
||||
if(!from_gw) return;
|
||||
num = num % 50;
|
||||
rectangle from_rect = calc_rect(num % 10, num / 10);
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_TER), source, source_rect, animFrame))
|
||||
return;
|
||||
if(to_rect.right - to_rect.left > 28)
|
||||
to_rect.inset(4,0);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect);
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect);
|
||||
}
|
||||
|
||||
void cPict::drawPresetTerAnim(short num, rectangle to_rect){
|
||||
rectangle from_rect = calc_rect(4 * (num / 5) + animFrame % 4, num % 5);
|
||||
auto from_gw = getSheet(SHEET_TER_ANIM);
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_TER_ANIM), source, source_rect, animFrame))
|
||||
return;
|
||||
if(to_rect.right - to_rect.left > 28) {
|
||||
to_rect.inset(4,0);
|
||||
to_rect.right = to_rect.left + 28;
|
||||
}
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect);
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect);
|
||||
}
|
||||
|
||||
static rectangle calcDefMonstRect(short i, short animFrame){
|
||||
@@ -872,6 +897,14 @@ void cPict::drawPresetMonstLg(short num, rectangle to_rect){
|
||||
void cPict::drawPresetDlog(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 36;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
if (fromType!=ePicType::PIC_NONE) {
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType), source, source_rect, animFrame))
|
||||
return;
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect);
|
||||
return;
|
||||
}
|
||||
auto from_gw = getSheet(SHEET_DLOG);
|
||||
rectangle from_rect = {0,0,36,36};
|
||||
from_rect.offset(36 * (num % 4),36 * (num / 4));
|
||||
@@ -918,27 +951,27 @@ void cPict::drawPresetItem(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
std::shared_ptr<const Texture> from_gw;
|
||||
rectangle from_rect = {0,0,18,18};
|
||||
if(num < 55) {
|
||||
from_gw = getSheet(SHEET_ITEM);
|
||||
from_rect = calc_rect(num % 5, num / 5);
|
||||
}else{
|
||||
from_gw = getSheet(SHEET_TINY_ITEM);
|
||||
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
auto sourceType=fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_ITEM;
|
||||
if (!get_picture(cPictNum(num, sourceType), source, source_rect, animFrame))
|
||||
return;
|
||||
if (sourceType==ePicType::PIC_ITEM && num>=55)
|
||||
to_rect.inset(5,9);
|
||||
from_rect.offset(18 * (num % 10), 18 * (num / 10));
|
||||
}
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
}
|
||||
|
||||
void cPict::drawPresetTinyItem(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 18;
|
||||
to_rect.bottom = to_rect.top + 18;
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
rectangle from_rect = {0,0,18,18};
|
||||
auto from_gw = getSheet(SHEET_TINY_ITEM);
|
||||
from_rect.offset(18 * (num % 10), 18 * (num / 10));
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_TINY_ITEM), source, source_rect, animFrame))
|
||||
return;
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
}
|
||||
|
||||
void cPict::drawPresetPc(short num, rectangle to_rect){
|
||||
@@ -994,15 +1027,14 @@ void cPict::drawPresetMissile(short num, rectangle to_rect){
|
||||
}
|
||||
|
||||
void cPict::drawPresetTerMap(short num, rectangle to_rect){
|
||||
rectangle from_rect = {0,0,12,12};
|
||||
auto from_gw = getSheet(SHEET_TER_MAP);
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_TER_MAP), source, source_rect, animFrame))
|
||||
return;
|
||||
// TODO: Should probably fill black somewhere in here...?
|
||||
to_rect.right = to_rect.left + 24;
|
||||
to_rect.bottom = to_rect.top + 24;
|
||||
if(num >= 960)
|
||||
from_rect.offset(12 * 20, 12 * (num - 960));
|
||||
else from_rect.offset(12 * (num % 20), 12 * (num / 20));
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect);
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect);
|
||||
}
|
||||
|
||||
void cPict::drawStatusIcon(short num, rectangle to_rect){
|
||||
@@ -1020,22 +1052,24 @@ void cPict::drawStatusIcon(short num, rectangle to_rect){
|
||||
}
|
||||
|
||||
void cPict::drawCustomTer(short num, rectangle to_rect){
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_CUSTOM_TER), source, source_rect, animFrame))
|
||||
return;
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
Texture from_gw;
|
||||
rectangle from_rect;
|
||||
std::tie(from_gw,from_rect) = spec_scen_g.find_graphic(num);
|
||||
rect_draw_some_item(from_gw, from_rect, *inWindow, to_rect);
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect);
|
||||
}
|
||||
|
||||
void cPict::drawCustomTerAnim(short num, rectangle to_rect){
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_CUSTOM_TER), source, source_rect, animFrame))
|
||||
return;
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
num += animFrame % 4;
|
||||
Texture from_gw;
|
||||
rectangle from_rect;
|
||||
std::tie(from_gw,from_rect) = spec_scen_g.find_graphic(num);
|
||||
rect_draw_some_item(from_gw, from_rect, *inWindow, to_rect);
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect);
|
||||
}
|
||||
|
||||
void cPict::drawCustomMonstSm(short num, rectangle to_rect){
|
||||
@@ -1174,21 +1208,25 @@ void cPict::drawCustomTalk(short num, rectangle to_rect){
|
||||
void cPict::drawCustomItem(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
Texture from_gw;
|
||||
rectangle from_rect;
|
||||
std::tie(from_gw,from_rect) = spec_scen_g.find_graphic(num);
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
rect_draw_some_item(from_gw, from_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_CUSTOM_ITEM), source, source_rect, animFrame))
|
||||
return;
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
}
|
||||
|
||||
void cPict::drawCustomTinyItem(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 18;
|
||||
to_rect.bottom = to_rect.top + 18;
|
||||
Texture from_gw;
|
||||
rectangle from_rect;
|
||||
std::tie(from_gw,from_rect) = spec_scen_g.find_graphic(num);
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
rect_draw_some_item(from_gw, from_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_CUSTOM_TINY_ITEM), source, source_rect, animFrame))
|
||||
return;
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
}
|
||||
|
||||
void cPict::drawCustomBoom(short num, rectangle to_rect){
|
||||
@@ -1215,16 +1253,11 @@ void cPict::drawCustomMissile(short num, rectangle to_rect){
|
||||
}
|
||||
|
||||
void cPict::drawCustomTerMap(short num, rectangle to_rect){
|
||||
Texture from_gw;
|
||||
rectangle from_rect;
|
||||
std::tie(from_gw,from_rect) = spec_scen_g.find_graphic(num % 1000);
|
||||
from_rect.right = from_rect.left + 12;
|
||||
from_rect.bottom = from_rect.top + 12;
|
||||
num /= 1000; num--;
|
||||
from_rect.offset((num / 3) * 12, (num % 3) * 12);
|
||||
to_rect.right = to_rect.left + 24;
|
||||
to_rect.bottom = to_rect.top + 24;
|
||||
rect_draw_some_item(from_gw, from_rect, *inWindow, to_rect);
|
||||
Texture source;
|
||||
rectangle source_rect;
|
||||
if (!get_picture(cPictNum(num, fromType!=ePicType::PIC_NONE ? fromType : ePicType::PIC_CUSTOM_TER_MAP), source, source_rect, animFrame))
|
||||
return;
|
||||
rect_draw_some_item(source, source_rect, *inWindow, to_rect);
|
||||
}
|
||||
|
||||
void cPict::drawPartyMonstSm(short num, rectangle to_rect){
|
||||
@@ -1335,7 +1368,7 @@ void cPict::drawAt(sf::RenderWindow& win, rectangle dest, pic_num_t which_g, ePi
|
||||
cControl::storage_t cPict::store() {
|
||||
storage_t storage = cControl::store();
|
||||
storage["pic-num"] = picNum;
|
||||
storage["pic-type"] = picType;
|
||||
storage["pic-type"] = resultType;
|
||||
return storage;
|
||||
}
|
||||
|
||||
@@ -1344,5 +1377,5 @@ void cPict::restore(storage_t to) {
|
||||
if(to.find("pic-num") != to.end())
|
||||
picNum = boost::any_cast<pic_num_t>(to["pic-num"]);
|
||||
if(to.find("pic-type") != to.end())
|
||||
picType = boost::any_cast<ePicType>(to["pic-type"]);
|
||||
resultType = boost::any_cast<ePicType>(to["pic-type"]);
|
||||
}
|
||||
|
@@ -55,8 +55,8 @@ public:
|
||||
/// - If num is 4 digits in decimal and type is not PIC_FULL, it automatically takes the remainder by 1000
|
||||
/// and applies the custom modifier. (If type is PIC_TER_MAP, it does not take the remainder by 1000.)
|
||||
/// - If num is 10000 or greater and type is PIC_TER_MAP, it automatically subtracts 10000 and applies the party modifier.
|
||||
void setPict(pic_num_t num, ePicType type);
|
||||
void setPict(cPictNum const &num) { setPict(num.num, num.type); }
|
||||
void setPict(pic_num_t num, ePicType type, bool updateResultType=true);
|
||||
void setPict(cPictNum const &num) { setPict(num.num, num.type, false); }
|
||||
/// Set the pict's icon.
|
||||
/// @param num The new icon index.
|
||||
void setPict(pic_num_t num);
|
||||
@@ -82,7 +82,8 @@ public:
|
||||
static void advanceAnim();
|
||||
virtual ~cPict();
|
||||
void draw();
|
||||
static bool get_terrain_picture(cPictNum pict, Texture &source, rectangle &from_rect, int anim=0);
|
||||
// only implemented for item and terrain pictures
|
||||
static bool get_picture(cPictNum pict, Texture &source, rectangle &from_rect, int anim=0);
|
||||
/// A utility function to draw an icon into an arbitrary window.
|
||||
/// @param win The window to draw in.
|
||||
/// @param dest The bounding rect to draw in (ignored for drawing the actual, but used for background fill and framing)
|
||||
@@ -105,7 +106,7 @@ private:
|
||||
static std::shared_ptr<const Texture> getSheet(eSheetType type, size_t n = 0);
|
||||
static short animFrame;
|
||||
pic_num_t picNum;
|
||||
ePicType picType;
|
||||
ePicType fromType, resultType;
|
||||
bool drawScaled;
|
||||
// Transient parse flags
|
||||
bool wide = false, tall = false, tiny = false, custom = false, blank = false;
|
||||
|
@@ -1143,7 +1143,7 @@ void draw_trim(short q,short r,short which_trim,ter_num_t ground_ter) {
|
||||
rectangle from_rect;
|
||||
Texture from_gworld;
|
||||
rectangle to_rect = coord_to_rect(q,r);
|
||||
if (!cPict::get_terrain_picture(univ.get_terrain(ground_ter).get_picture_num(), from_gworld, from_rect)) {
|
||||
if (!cPict::get_picture(univ.get_terrain(ground_ter).get_picture_num(), from_gworld, from_rect)) {
|
||||
fill_rect(terrain_screen_gworld, to_rect, sf::Color::Yellow);
|
||||
return; // CHECKME better to draw a bad image to indicate that there is a problem here
|
||||
}
|
||||
|
@@ -72,7 +72,12 @@ void draw_one_terrain_spot (short i,short j,short terrain_to_draw) {
|
||||
|
||||
rectangle source_rect;
|
||||
Texture source_gworld;
|
||||
if (!cPict::get_terrain_picture(univ.get_terrain(terrain_to_draw).get_picture_num(), source_gworld, source_rect, anim_ticks % 4)) {
|
||||
cPictNum pict;
|
||||
if (terrain_to_draw>=10000) // force using a specific graphic
|
||||
pict=cPictNum(terrain_to_draw-10000,ePicType::PIC_TER);
|
||||
else
|
||||
pict=univ.get_terrain(terrain_to_draw).get_picture_num();
|
||||
if (!cPict::get_picture(pict, source_gworld, source_rect, anim_ticks % 4)) {
|
||||
fill_rect(terrain_screen_gworld, where_draw, sf::Color::Yellow);
|
||||
return; // CHECKME better to draw an error image to indicate that there is a problem here
|
||||
}
|
||||
|
@@ -230,7 +230,7 @@ void draw(bool need_refresh) {
|
||||
if(expl == 0)
|
||||
continue;
|
||||
Texture src_gw;
|
||||
if (!cPict::get_terrain_picture(univ.get_terrain(what_ter).get_map_picture_num(), src_gw,custom_from))
|
||||
if (!cPict::get_picture(univ.get_terrain(what_ter).get_map_picture_num(), src_gw,custom_from))
|
||||
fill_rect(gworld, draw_rect, sf::Color::Yellow); // FIXME: show an error here
|
||||
else
|
||||
rect_draw_some_item(src_gw, custom_from, gworld, draw_rect);
|
||||
|
@@ -15,13 +15,13 @@
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
#include "oldstructs.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "fileio.hpp"
|
||||
|
||||
#include "damage.hpp"
|
||||
#include "spell.hpp"
|
||||
#include "fileio.hpp"
|
||||
#include "oldstructs.hpp"
|
||||
#include "pict.hpp"
|
||||
#include "race.hpp"
|
||||
#include "spell.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
static std::array<item_variety_t, 28> load_item_type_info() {
|
||||
std::multiset<eItemType> equippable = {
|
||||
@@ -238,6 +238,17 @@ cItem::cItem(eItemPreset preset) : cItem() {
|
||||
}
|
||||
}
|
||||
|
||||
cPictNum cItem::get_picture_num(bool tiny) const
|
||||
{
|
||||
if (graphic_num<0)
|
||||
return cPictNum(graphic_num, ePicType::PIC_NONE);
|
||||
if (graphic_num>=1000)
|
||||
return cPictNum(graphic_num-1000, tiny ? ePicType::PIC_CUSTOM_TINY_ITEM : ePicType::PIC_CUSTOM_ITEM);
|
||||
if (graphic_num<55 && !tiny)
|
||||
return cPictNum(graphic_num, ePicType::PIC_ITEM);
|
||||
return cPictNum(graphic_num, ePicType::PIC_TINY_ITEM);
|
||||
}
|
||||
|
||||
cItem::cItem(eAlchemy recipe) : cItem(ITEM_POTION) {
|
||||
full_name = get_str("magic-names", int(recipe) + 200);
|
||||
switch(recipe) {
|
||||
|
@@ -35,6 +35,8 @@ enum eItemPreset {
|
||||
ITEM_SHOP,
|
||||
};
|
||||
|
||||
class cPictNum;
|
||||
|
||||
class cItem {
|
||||
public:
|
||||
eItemType variety;
|
||||
@@ -76,6 +78,8 @@ public:
|
||||
cItem();
|
||||
explicit cItem(eItemPreset preset);
|
||||
explicit cItem(eAlchemy recipe);
|
||||
|
||||
cPictNum get_picture_num(bool tiny=false) const;
|
||||
void import_legacy(legacy::item_record_type const & old);
|
||||
void writeTo(std::ostream& file, std::string prefix = "") const;
|
||||
void readFrom(std::istream& sin);
|
||||
|
@@ -428,10 +428,7 @@ cPictNum cTerrain::get_picture_num_for_terrain(pic_num_t bigPicture)
|
||||
return cPictNum(bigPicture-960,PIC_TER_ANIM);
|
||||
if(bigPicture < 2000)
|
||||
return cPictNum(bigPicture-1000,PIC_CUSTOM_TER);
|
||||
if (bigPicture>=10000) // force to use PIC_TER
|
||||
return cPictNum(bigPicture-10000,PIC_TER);
|
||||
else
|
||||
return cPictNum(bigPicture-2000,PIC_CUSTOM_TER_ANIM);
|
||||
return cPictNum(bigPicture-2000,PIC_CUSTOM_TER_ANIM);
|
||||
}
|
||||
|
||||
cPictNum cTerrain::get_map_picture_num() const
|
||||
@@ -443,5 +440,4 @@ cPictNum cTerrain::get_map_picture_num() const
|
||||
if(map_pic < 2000)
|
||||
return cPictNum(map_pic-1000,PIC_CUSTOM_TER_MAP);
|
||||
return cPictNum(map_pic-2000,PIC_CUSTOM_TER_MAP);
|
||||
// checkme add force PIC_TER_MAP?
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user