Skip to content

Commit

Permalink
weapon column fix, diagnosis fix,
Browse files Browse the repository at this point in the history
- fixed an issue where re-connecting could cause DT to crash on exit
- fixed diagnosis required from showing in the health grid when it
wasn't required
  • Loading branch information
splintermind committed Feb 1, 2015
1 parent 085086c commit 872e861
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
6 changes: 5 additions & 1 deletion inc/grid_view/weaponcolumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ THE SOFTWARE.
#define WEAPONCOLUMN_H

#include "viewcolumn.h"
#include <QPointer>

class ItemWeaponSubtype;

Expand All @@ -42,8 +43,11 @@ class WeaponColumn : public ViewColumn {
//override
void write_to_ini(QSettings &s);

public slots:
void check_weapon();

private:
ItemWeaponSubtype *m_weapon;
QPointer<ItemWeaponSubtype> m_weapon;
int m_sub_type_id;
QString m_weapon_name; //name saved
};
Expand Down
4 changes: 0 additions & 4 deletions src/grid_view/cellcolors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ void CellColors::set_color(int idx, QColor c){
//current color def is custom, replace it with the default color def
QSharedPointer<CellColorDef> def = get_default_color_def(idx);
m_color_defs[idx].swap(def);
}else{
//current color is already default, do nothing
}
}
}else{
//invalid color, do nothing
}
}
22 changes: 18 additions & 4 deletions src/grid_view/weaponcolumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ WeaponColumn::WeaponColumn(QSettings &s, ViewColumnSet *set, QObject *parent)
, m_sub_type_id(s.value("sub_type_id",-1).toInt())
, m_weapon_name(s.value("weapon_name","").toString())
{
init();
connect(DT,SIGNAL(units_refreshed()),this,SLOT(check_weapon()));
}

WeaponColumn::WeaponColumn(const QString &title, const int sub_type, ViewColumnSet *set, QObject *parent)
Expand All @@ -46,6 +48,8 @@ WeaponColumn::WeaponColumn(const QString &title, const int sub_type, ViewColumnS
, m_sub_type_id(sub_type)
, m_weapon_name(title)
{
init();
connect(DT,SIGNAL(units_refreshed()),this,SLOT(check_weapon()));
}

WeaponColumn::~WeaponColumn(){
Expand All @@ -59,7 +63,7 @@ void WeaponColumn::init(){
if(m_sub_type_id >= 0){
m_weapon = qobject_cast<ItemWeaponSubtype*>(DT->get_DFInstance()->get_item_subtype(WEAPON,m_sub_type_id));
}
if(m_weapon == 0 || QString::compare(m_weapon_name, m_weapon->name_plural(),Qt::CaseInsensitive) != 0){
if(m_weapon.isNull() || QString::compare(m_weapon_name, m_weapon->name_plural(),Qt::CaseInsensitive) != 0){
m_weapon = DT->get_DFInstance()->find_weapon_subtype(m_weapon_name);
if(m_weapon)
m_sub_type_id = m_weapon->subType();
Expand All @@ -69,7 +73,7 @@ void WeaponColumn::init(){
QStandardItem *WeaponColumn::build_cell(Dwarf *d) {
QStandardItem *item = init_cell(d);

init();
check_weapon();

item->setData(CT_WEAPON, DwarfModel::DR_COL_TYPE);
item->setData(0, DwarfModel::DR_RATING);
Expand Down Expand Up @@ -172,10 +176,20 @@ QStandardItem *WeaponColumn::build_aggregate(const QString &group_name, const QV
return item;
}

void WeaponColumn::check_weapon(){
if(m_weapon.isNull()){
init();
}
}

void WeaponColumn::write_to_ini(QSettings &s){
ViewColumn::write_to_ini(s);
s.setValue("sub_type_id", m_sub_type_id);
if(m_weapon){
s.setValue("weapon_name", m_weapon->name_plural());
if(!m_weapon.isNull()){
s.setValue("weapon_name", m_weapon->name_plural());
}else if(!m_weapon_name.isEmpty()){
s.setValue("weapon_name", m_weapon_name);
}else{
LOGW << "weapon name could not be found for weapon column:" << m_title;
}
}
2 changes: 1 addition & 1 deletion src/itemarmorsubtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void ItemArmorSubtype::read_data(){
}else{
m_layer = -1;
m_armor_flags = FlagArray();
LOGE << "Failed to read armor properties" << m_name;
LOGW << "Failed to read armor properties" << m_name;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/unithealth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void UnitHealth::read_health_info(){
short sh_counter = 0;
QList<short> vals;

bool needs_diagnosis = health_flags;
bool needs_diagnosis = (health_flags & 1);
add_info(eHealth::HI_DIAGNOSIS,false,needs_diagnosis);
add_info(eHealth::HI_IMMOBILIZATION, health_flags & (1 << 3));
add_info(eHealth::HI_DRESSING, health_flags & (1 << 4));
Expand Down

0 comments on commit 872e861

Please sign in to comment.