Continue to try to clean code...
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
cPictChoice::cPictChoice(const std::vector<pic_num_t>& pics,ePicType t,cDialog* parent) : cPictChoice(pics.begin(), pics.end(), t, parent) {}
|
||||
|
||||
cPictChoice::cPictChoice(const std::vector<std::pair<pic_num_t,ePicType>>& pics,cDialog* parent) : dlg("choose-pict",parent) {
|
||||
cPictChoice::cPictChoice(const std::vector<cPictNum>& pics,cDialog* parent) : dlg("choose-pict",parent) {
|
||||
picts = pics;
|
||||
attachHandlers();
|
||||
}
|
||||
@@ -26,7 +26,7 @@ cPictChoice::cPictChoice(
|
||||
cDialog* parent
|
||||
) : dlg("choose-pict",parent) {
|
||||
for(auto iter = begin; iter != end; iter++) {
|
||||
picts.push_back({*iter,t});
|
||||
picts.push_back(cPictNum(*iter,t));
|
||||
}
|
||||
attachHandlers();
|
||||
}
|
||||
@@ -88,8 +88,9 @@ void cPictChoice::fillPage(){
|
||||
cPict& pic = dynamic_cast<cPict&>(dlg[sout.str()]);
|
||||
if(page * per_page + i < picts.size()){
|
||||
pic.show();
|
||||
ePicType tp = picts[per_page * page + i].second;
|
||||
pic.setPict(picts[per_page * page + i].first, tp);
|
||||
auto const &pict=picts[per_page * page + i];
|
||||
ePicType const tp = pict.type;
|
||||
pic.setPict(pict, true);
|
||||
rectangle b = pic.getBounds();
|
||||
if(tp == PIC_DLOG_LG || tp == PIC_CUSTOM_DLOG_LG || tp == PIC_SCEN_LG) {
|
||||
pic.setFormat(TXT_WRAP, false);
|
||||
@@ -141,12 +142,8 @@ bool cPictChoice::onSelect(bool losing) {
|
||||
return true;
|
||||
}
|
||||
|
||||
pic_num_t cPictChoice::getPicChosen() {
|
||||
return dlg.getResult<std::pair<pic_num_t,ePicType>>().first;
|
||||
}
|
||||
|
||||
ePicType cPictChoice::getPicChosenType() {
|
||||
return dlg.getResult<std::pair<pic_num_t,ePicType>>().second;
|
||||
cPictNum cPictChoice::getPicChosen() {
|
||||
return dlg.getResult<cPictNum>();
|
||||
}
|
||||
|
||||
size_t cPictChoice::getSelected() {
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include "global.hpp"
|
||||
#include "dialog.hpp"
|
||||
#include "ledgroup.hpp"
|
||||
#include "pict.hpp"
|
||||
#include "pictypes.hpp"
|
||||
|
||||
/// A dialog that presents a list of icons with LEDs and allows you to choose one.
|
||||
@@ -31,7 +32,7 @@ class cPictChoice {
|
||||
bool onOkay();
|
||||
bool onSelect(bool losing);
|
||||
void fillPage();
|
||||
std::vector<std::pair<pic_num_t,ePicType>> picts;
|
||||
std::vector<cPictNum> picts;
|
||||
size_t page, cur;
|
||||
cLedGroup* leds;
|
||||
std::function<void(cPictChoice&,int)> select_handler;
|
||||
@@ -44,7 +45,7 @@ public:
|
||||
/// Initializes a dialog from a list of icons.
|
||||
/// @param pics A list of all icons in the dialog as {num,type} pairs.
|
||||
/// @param parent Optionally, a parent dialog.
|
||||
cPictChoice(const std::vector<std::pair<pic_num_t,ePicType>>& pics, cDialog* parent = nullptr);
|
||||
cPictChoice(const std::vector<cPictNum>& pics, cDialog* parent = nullptr);
|
||||
/// Initializes a dialog from an iterator pair.
|
||||
/// @param begin An iterator to the first icon in the dialog.
|
||||
/// @param end An iterator to one past the last icon in the dialog.
|
||||
@@ -68,11 +69,8 @@ public:
|
||||
/// @return false if the user clicked Cancel, true otherwise.
|
||||
bool show(size_t cur_sel);
|
||||
/// Get the chosen icon.
|
||||
/// @return The number of the chosen icon.
|
||||
pic_num_t getPicChosen();
|
||||
/// Get the chosen icon.
|
||||
/// @return The type of the chosen icon.
|
||||
ePicType getPicChosenType();
|
||||
/// @return The number and the type of the chosen icon.
|
||||
cPictNum getPicChosen();
|
||||
/// Get the index of the selected icon in the original list.
|
||||
/// @return The index
|
||||
size_t getSelected();
|
||||
|
@@ -23,7 +23,7 @@
|
||||
|
||||
class cPictNum {
|
||||
public:
|
||||
explicit cPictNum(pic_num_t nNum=-1, ePicType nType=ePicType::PIC_NONE)
|
||||
cPictNum(pic_num_t nNum=-1, ePicType nType=ePicType::PIC_NONE)
|
||||
: num(nNum)
|
||||
, type(nType)
|
||||
{
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
/// 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, bool updateResultType=true);
|
||||
void setPict(cPictNum const &num) { setPict(num.num, num.type, false); }
|
||||
void setPict(cPictNum const &num, bool updateResultType=false) { setPict(num.num, num.type, updateResultType); }
|
||||
/// Set the pict's icon.
|
||||
/// @param num The new icon index.
|
||||
void setPict(pic_num_t num);
|
||||
|
@@ -808,30 +808,9 @@ void refresh_shopping() {
|
||||
}
|
||||
|
||||
static ePicType get_monst_pictype(mon_num_t monst) {
|
||||
ePicType type = PIC_MONST;
|
||||
short n;
|
||||
if(monst >= 10000)
|
||||
n = univ.party.get_summon(monst - 10000).picture_num;
|
||||
else n = univ.scenario.get_monster(monst).picture_num;
|
||||
if(n >= 1000){
|
||||
type += PIC_CUSTOM;
|
||||
switch(n / 1000){
|
||||
case 2:
|
||||
type += PIC_WIDE;
|
||||
break;
|
||||
case 3:
|
||||
type += PIC_TALL;
|
||||
break;
|
||||
case 4:
|
||||
type += PIC_WIDE;
|
||||
type += PIC_TALL;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
if(m_pic_index[n].x == 2) type += PIC_WIDE;
|
||||
if(m_pic_index[n].y == 2) type += PIC_TALL;
|
||||
}
|
||||
return type;
|
||||
return univ.party.get_summon(monst - 10000).get_picture_num().type;
|
||||
return univ.scenario.get_monster(monst).get_picture_num().type;
|
||||
}
|
||||
|
||||
static void place_talk_face() {
|
||||
|
@@ -2188,7 +2188,7 @@ bool pick_pc_graphic(short pc_num,short mode,cDialog* parent) {
|
||||
if(mode == 0 && !madeChoice && univ.party[pc_num].main_status < eMainStatus::ABSENT)
|
||||
univ.party[pc_num].main_status = eMainStatus::ABSENT;
|
||||
else if(madeChoice)
|
||||
univ.party[pc_num].which_graphic = pcPic.getPicChosen();
|
||||
univ.party[pc_num].which_graphic = pcPic.getPicChosen().num;
|
||||
|
||||
return madeChoice;
|
||||
}
|
||||
|
@@ -413,6 +413,48 @@ cMonster::cMonster(){
|
||||
m_type = eRace::HUMAN;
|
||||
}
|
||||
|
||||
cPictNum cMonster::get_picture_num(pic_num_t pic)
|
||||
{
|
||||
if (pic>=20000)
|
||||
return cPictNum(pic, ePicType::PIC_NONE);
|
||||
if (pic < m_pic_index.size()) {
|
||||
ePicType resultType = PIC_MONST;
|
||||
if(m_pic_index[pic].x == 2) resultType += PIC_WIDE;
|
||||
if(m_pic_index[pic].y == 2) resultType += PIC_TALL;
|
||||
return cPictNum(pic, resultType);
|
||||
}
|
||||
if (pic<1000)
|
||||
return cPictNum(pic, ePicType::PIC_NONE);
|
||||
ePicType resultType = pic>=10000 ? PIC_PARTY_MONST : PIC_CUSTOM_MONST;
|
||||
short size_g = pic / 1000;
|
||||
switch(size_g%10){
|
||||
case 2:
|
||||
resultType += PIC_WIDE;
|
||||
break;
|
||||
case 3:
|
||||
resultType += PIC_TALL;
|
||||
break;
|
||||
case 4:
|
||||
resultType += PIC_LARGE;
|
||||
break;
|
||||
}
|
||||
return cPictNum(pic%1000, resultType);
|
||||
}
|
||||
|
||||
|
||||
pic_num_t cMonster::get_num_for_picture(cPictNum const &pic)
|
||||
{
|
||||
if (pic.type<100)
|
||||
return pic.num;
|
||||
pic_num_t res=pic.num+1000;
|
||||
if (pic.type>=200) res+=10000;
|
||||
if (pic.type & PIC_WIDE)
|
||||
res+=1000;
|
||||
if (pic.type & PIC_TALL)
|
||||
res+=1000;
|
||||
return res;
|
||||
}
|
||||
|
||||
cTownperson::cTownperson() {
|
||||
start_loc = {80,80};
|
||||
number = 0;
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include <iosfwd>
|
||||
|
||||
#include "monster_abilities.hpp"
|
||||
#include "pict.hpp"
|
||||
#include "race.hpp"
|
||||
#include "location.hpp"
|
||||
|
||||
@@ -72,7 +73,12 @@ public:
|
||||
|
||||
std::map<eMonstAbil,uAbility>::iterator addAbil(eMonstAbilTemplate what, int param = 0);
|
||||
int addAttack(unsigned short dice, unsigned short sides, eMonstMelee type = eMonstMelee::SWING);
|
||||
|
||||
cPictNum get_picture_num() const {
|
||||
return get_picture_num(picture_num);
|
||||
}
|
||||
static cPictNum get_picture_num(pic_num_t pic);
|
||||
static pic_num_t get_num_for_picture(cPictNum const &pic);
|
||||
|
||||
void import_legacy(legacy::monster_record_type const &old);
|
||||
cMonster();
|
||||
void writeTo(std::ostream& file) const;
|
||||
|
@@ -581,24 +581,7 @@ bool edit_ter_type(ter_num_t which) {
|
||||
static void put_monst_info_in_dlog(cDialog& me, cMonster& monst, mon_num_t which) {
|
||||
std::ostringstream strb;
|
||||
|
||||
if(monst.picture_num < 1000)
|
||||
dynamic_cast<cPict&>(me["icon"]).setPict(monst.picture_num,PIC_MONST);
|
||||
else {
|
||||
ePicType type_g = PIC_CUSTOM_MONST;
|
||||
short size_g = monst.picture_num / 1000;
|
||||
switch(size_g){
|
||||
case 2:
|
||||
type_g += PIC_WIDE;
|
||||
break;
|
||||
case 3:
|
||||
type_g += PIC_TALL;
|
||||
break;
|
||||
case 4:
|
||||
type_g += PIC_LARGE;
|
||||
break;
|
||||
}
|
||||
dynamic_cast<cPict&>(me["icon"]).setPict(monst.picture_num,type_g);
|
||||
}
|
||||
dynamic_cast<cPict&>(me["icon"]).setPict(monst.get_picture_num(), true);
|
||||
dynamic_cast<cPict&>(me["talkpic"]).setPict(monst.default_facial_pic, PIC_TALK);
|
||||
me["num"].setTextToNum(which);
|
||||
me["name"].setText(monst.m_name);
|
||||
@@ -688,29 +671,25 @@ static bool check_monst_pic(cDialog& me, std::string id, bool losing, cMonster&
|
||||
if(cre(pic,0,max_preset,error,"",&me)) return false;
|
||||
monst.x_width = m_pic_index[monst.picture_num].x;
|
||||
monst.y_width = m_pic_index[monst.picture_num].y;
|
||||
icon.setPict(pic, PIC_MONST);
|
||||
break;
|
||||
case 1:
|
||||
monst.x_width = 1;
|
||||
monst.y_width = 1;
|
||||
icon.setPict(pic, PIC_MONST);
|
||||
break;
|
||||
case 2:
|
||||
monst.x_width = 2;
|
||||
monst.y_width = 1;
|
||||
icon.setPict(pic, PIC_MONST_WIDE);
|
||||
break;
|
||||
case 3:
|
||||
monst.x_width = 1;
|
||||
monst.y_width = 2;
|
||||
icon.setPict(pic, PIC_MONST_TALL);
|
||||
break;
|
||||
case 4:
|
||||
monst.x_width = 2;
|
||||
monst.y_width = 2;
|
||||
icon.setPict(pic, PIC_MONST_LG);
|
||||
break;
|
||||
}
|
||||
icon.setPict(cMonster::get_picture_num(pic), true);
|
||||
std::ostringstream strb;
|
||||
strb << "Width = " << int(monst.x_width);
|
||||
me["w"].setText(strb.str());
|
||||
|
@@ -206,26 +206,18 @@ pic_num_t choose_graphic(short cur_choice,ePicType g_type,cDialog* parent) {
|
||||
return NO_PIC;
|
||||
case PIC_MONST: case PIC_MONST_WIDE:
|
||||
case PIC_MONST_TALL: case PIC_MONST_LG:
|
||||
std::vector<std::pair<pic_num_t,ePicType>> pics;
|
||||
std::vector<cPictNum> pics;
|
||||
for(m_pic_index_t m_pic : m_pic_index) {
|
||||
// TODO: Put the added monster graphics in m_pic_index to allow picking them
|
||||
ePicType type = PIC_MONST;
|
||||
if(m_pic.x == 2) type += PIC_WIDE;
|
||||
if(m_pic.y == 2) type += PIC_TALL;
|
||||
pics.push_back({i++, type});
|
||||
}
|
||||
for(size_t i = 0; i < scenario.custom_graphics.size(); i++) {
|
||||
if(scenario.custom_graphics[i] == PIC_MONST)
|
||||
pics.push_back({1000 + i, PIC_CUSTOM_MONST});
|
||||
else if(scenario.custom_graphics[i] == PIC_MONST_WIDE)
|
||||
pics.push_back({2000 + i, PIC_CUSTOM_MONST_WIDE});
|
||||
else if(scenario.custom_graphics[i] == PIC_MONST_TALL)
|
||||
pics.push_back({3000 + i, PIC_CUSTOM_MONST_TALL});
|
||||
else if(scenario.custom_graphics[i] == PIC_MONST_LG)
|
||||
pics.push_back({4000 + i, PIC_CUSTOM_MONST_LG});
|
||||
if(cur_choice == pics.back().first)
|
||||
cur_choice = pics.size() - 1;
|
||||
pics.push_back({pic_num_t(i++), type});
|
||||
}
|
||||
for(size_t i = 0; i < scenario.custom_graphics.size(); i++)
|
||||
pics.push_back(cMonster::get_picture_num(scenario.custom_graphics[i]));
|
||||
if(cur_choice >= pics.size())
|
||||
cur_choice = pics.size() - 1;
|
||||
pic_dlg = new cPictChoice(pics, parent);
|
||||
break;
|
||||
}
|
||||
@@ -257,7 +249,9 @@ pic_num_t choose_graphic(short cur_choice,ePicType g_type,cDialog* parent) {
|
||||
pic_dlg = new cPictChoice(all_pics, g_type, parent);
|
||||
}
|
||||
bool made_choice = pic_dlg->show(cur_choice);
|
||||
pic_num_t item_hit = pic_dlg->getPicChosen();
|
||||
pic_num_t item_hit = pic_dlg->getPicChosen().num;
|
||||
if (g_type==PIC_MONST || g_type==PIC_MONST_WIDE || g_type==PIC_MONST_TALL || g_type==PIC_MONST_LG)
|
||||
item_hit=cMonster::get_num_for_picture(pic_dlg->getPicChosen());
|
||||
delete pic_dlg;
|
||||
return made_choice ? item_hit : NO_PIC;
|
||||
}
|
||||
@@ -689,7 +683,7 @@ short choose_field_type(short cur, cDialog* parent, bool includeSpec) {
|
||||
"Small Blood", "Medium Blood", "Large Blood", "Small Slime", "Large Slime", "Ash", "Bones", "Rubble",
|
||||
"Force Cage", "Cleanse Space", "Crumble Walls",
|
||||
};
|
||||
std::vector<std::pair<pic_num_t,ePicType>> pics = {
|
||||
std::vector<cPictNum> pics = {
|
||||
{8, PIC_FIELD}, {9, PIC_FIELD}, {10, PIC_FIELD}, {11, PIC_FIELD},
|
||||
{12, PIC_FIELD}, {13, PIC_FIELD}, {14, PIC_FIELD},
|
||||
{3, PIC_FIELD}, {5, PIC_FIELD}, {6, PIC_FIELD}, {7, PIC_FIELD},
|
||||
@@ -762,8 +756,7 @@ static pic_num_t choose_boom_type(short cur, cDialog* parent) {
|
||||
me->getControl("help").setText(boomNames[std::min<short>(n,preset_booms)]);
|
||||
});
|
||||
bool made_choice = pic_dlg.show(cur);
|
||||
size_t item_hit = pic_dlg.getPicChosen();
|
||||
return made_choice ? item_hit : prev;
|
||||
return made_choice ? pic_dlg.getPicChosen().num : prev;
|
||||
}
|
||||
|
||||
pic_num_t choose_status_effect(short cur, bool party, cDialog* parent) {
|
||||
|
Reference in New Issue
Block a user