QStandardItem *HappinessColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); QString pixmap_name = QString(":status/img/%1.png").arg(Dwarf::happiness_name(d->get_happiness())); if(pixmap_name=="") pixmap_name = ":img/question-frame.png"; item->setData(QIcon(pixmap_name), Qt::DecorationRole); item->setData(CT_HAPPINESS, DwarfModel::DR_COL_TYPE); item->setData(d->get_raw_happiness(), DwarfModel::DR_SORT_VALUE); QString tooltip = QString("<center><h3>%1</h3><h4>%2 (%3)</h4></center><p>%4</p>%5") .arg(m_title) .arg(Dwarf::happiness_name(d->get_happiness())) .arg(d->get_raw_happiness()) .arg(d->get_thought_desc()) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); QColor bg = m_colors[d->get_happiness()]; // item->setBackground(QBrush(bg)); item->setData(bg,Qt::BackgroundColorRole); return item; }
QStandardItem *EquipmentColumn::build_cell(Dwarf *d){ QStandardItem *item = init_cell(d); QColor rating_color = QColor(69,148,21); float rating = d->get_uniform_rating(); float coverage = d->get_coverage_rating(); if(coverage < 100){ //prioritize coverage rating = coverage; rating_color = Item::color_uncovered(); }else{ if(rating < 100) //missing uniform items rating_color = Item::color_missing(); } float sort_val = rating - d->get_inventory_wear(); item->setData(d->get_inventory_wear(),DwarfModel::DR_SPECIAL_FLAG); item->setBackground(QBrush(rating_color)); item->setData(CT_EQUIPMENT, DwarfModel::DR_COL_TYPE); item->setData(rating, DwarfModel::DR_RATING); //other drawing 0-100 item->setData(sort_val, DwarfModel::DR_SORT_VALUE); set_export_role(DwarfModel::DR_RATING); QString tooltip = QString("<center><h3>%1</h3></center>%2%3") .arg(m_title) .arg(build_tooltip_desc(d)) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *TraitColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); item->setData(CT_TRAIT, DwarfModel::DR_COL_TYPE); item->setData(0, DwarfModel::DR_SPECIAL_FLAG); //default, special flag stores the alpha for the border short raw_value = d->trait(m_trait_id); short rating = raw_value; QStringList infos; if (m_trait){ infos << m_trait->level_message(raw_value).append(m_trait->belief_conficts_msgs(raw_value,d->trait_conflicts(m_trait_id))); }else{ infos << tr("Unknown trait"); } if(raw_value < 0){ infos << tr("This unit doesn't have this trait!"); } if (d->trait_is_active(m_trait_id)==false) infos << tr("Not an active trait for this dwarf."); int conflicting_belief_count = 0; if (m_trait){ infos << m_trait->skill_conflicts_msgs(raw_value); infos << m_trait->special_messages(raw_value); conflicting_belief_count = m_trait->get_conflicting_beliefs().count(); if(conflicting_belief_count > 0){ infos << tr("<br/>This trait can conflict with %1").arg(m_trait->belief_conflicts_names()); } if(m_trait->valued_inversely()){ infos << Trait::inverted_message; if(raw_value != -1) rating = 100 - raw_value; } } infos.removeAll(""); if(d->trait_is_conflicted(m_trait_id) && conflicting_belief_count > 0){ int alpha = 255 * ((float)d->trait_conflicts(m_trait_id).count() / (float)conflicting_belief_count); item->setData(alpha, DwarfModel::DR_SPECIAL_FLAG); } item->setText(QString::number(raw_value)); item->setData(rating, DwarfModel::DR_SORT_VALUE); item->setData(rating, DwarfModel::DR_RATING); item->setData(rating, DwarfModel::DR_DISPLAY_RATING); item->setData(raw_value, DwarfModel::DR_EXPORT); set_export_role(DwarfModel::DR_EXPORT); QString tooltip = QString("<center><h3>%1</h3> %2</center><br/>%3<br/>%4") .arg(m_title) .arg(tr("<b>Raw Value: %1</b>").arg(raw_value)) .arg(infos.join("<br/>")) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *TrainedColumn::build_cell(Dwarf *d){ QStandardItem *item = init_cell(d); QString desc = get_animal_trained_descriptor(d->trained_level()); float rating = (float)d->trained_level(); float sort_val = rating; QString draw_rating = QString::number(rating); QChar sym_master(0x263C); //masterwork symbol in df QChar sym_exceptional(0x2261); //3 horizontal lines QFontMetrics fm(DT->user_settings()->value("options/grid/font", QFont(DefaultFonts::getRowFontName(), DefaultFonts::getRowFontSize())).value<QFont>()); bool symbols_ok = false; if(fm.inFont(sym_master) && fm.inFont(sym_exceptional)){ symbols_ok = true; } if(rating == 7){ //tame rating = 50.0f; //don't draw tame animals, this has to be within the uberdelegate's ignore range sort_val = -1; draw_rating = tr(""); }else if(rating >= 1 && rating <= 6){ //trained levels if(symbols_ok){ if(rating == 1) draw_rating = tr("T"); else if(rating == 2) draw_rating = tr("-"); else if(rating == 3) draw_rating = tr("+"); else if(rating == 4) draw_rating = tr("*"); else if(rating == 5) draw_rating = sym_exceptional; else if(rating == 6) draw_rating = sym_master; } rating = (rating / 6.0f * 100.0f / 2.0f) + 50.0f; //scale from 50 to 100 }else if(rating == 0){ //semi-wild (medium red square) rating = 30.0f; draw_rating = tr("Sw"); }else{ //wild, unknown (large red square) rating = 5.0f; sort_val = -2; draw_rating = tr("W"); } // item->setBackground(QBrush(QColor(225,225,225))); item->setData(CT_TRAINED, DwarfModel::DR_COL_TYPE); item->setData(draw_rating, DwarfModel::DR_DISPLAY_RATING); //numeric drawing, single digits item->setData(rating, DwarfModel::DR_RATING); //other drawing 0-100 item->setData(sort_val, DwarfModel::DR_SORT_VALUE); set_export_role(DwarfModel::DR_RATING); QString tooltip = QString("<center><h3>%1</h3></center>%2") .arg(desc) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *AttributeColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); Attribute a = d->get_attribute(m_attribute_type); QString descriptor = a.get_descriptor(); float rating = a.rating() * 100.0f; //if this is an animal, we won't have any caste balanced ratings, so just take a rating out of an arbitrary absolute of 2250 //that means any rating over 2250 will essentially be 100%, which is pretty reasonable, since //scaling to 0-5000 makes the drawn squares fairly small if(d->is_animal()) rating = (float)(a.get_value() / 2250.0f * 100.0f); //the rating is used for drawing, should be between 0-100 for attributes item->setData(rating, DwarfModel::DR_RATING); item->setData(roundf(rating), DwarfModel::DR_DISPLAY_RATING); //flag so we know if we need to draw a border or not item->setData(a.syndrome_names().count(),DwarfModel::DR_SPECIAL_FLAG); if(DT->multiple_castes()){ descriptor != "" ? descriptor = "(" + descriptor + ")" : ""; } item->setData(CT_ATTRIBUTE, DwarfModel::DR_COL_TYPE); refresh_sort(d,m_current_sort); if(!descriptor.isEmpty()){ descriptor = QString("%1%2").arg("<br/>").arg(descriptor); } QString syn_desc = a.get_syndrome_desc(); if(!syn_desc.isEmpty()){ syn_desc = QString("%1%1%2").arg("<br/>").arg(syn_desc); } QString tooltip = QString("<center><h3>%1</h3><b>%2</b>%3%4%5</center>") .arg(m_title) .arg(a.get_value_display()) .arg(descriptor) .arg(syn_desc) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *AttributeColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); Attribute a = d->get_attribute((int)m_attribute_type); short rawVal = a.value(); QString descriptor = a.get_descriptor(); float rating = a.rating() * 100.0f; //if this is an animal, we won't have any caste balanced ratings, so just take a rating out of an arbitrary absolute of 2250 //that means any rating over 2250 will essentially be 100%, which is pretty reasonable, since //scaling to 0-5000 makes the drawn squares fairly small if(d->is_animal()) rating = (float)(a.value() / 2250.0f * 100.0f); //the rating is used for drawing, should be between 0-100 for attributes item->setData(rating, DwarfModel::DR_RATING); item->setData(roundf(rating), DwarfModel::DR_DISPLAY_RATING); //if no descriptor (middle ranges) then set the rating to a middle (hidden) value //this is primarily for vanilla, as the mid ranges don't have a description and are hidden in game //for multiple castes, we may as well draw everything as the descriptors can be different for each caste //since multiple castes append 'for a <caste name>' to the descriptor, this will only ever affect vanilla for now if(!DT->multiple_castes && a.get_descriptor_rank() == 4){ item->setData(50.0f, DwarfModel::DR_RATING); //49-51 aren't drawn for attributes }else{ descriptor != "" ? descriptor = "(" + descriptor + ")" : ""; } //sort on the raw value item->setData(rawVal, DwarfModel::DR_SORT_VALUE); item->setData(CT_ATTRIBUTE, DwarfModel::DR_COL_TYPE); QString tooltip = QString("<center><h3>%1</h3></center><b>%2</b> %3%4") .arg(m_title) .arg(a.get_value_display()) .arg(descriptor) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *TraitColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); item->setData(CT_TRAIT, DwarfModel::DR_COL_TYPE); short score = d->trait(m_trait_id); QString msg = "???"; if (m_trait) msg = tr("%1 (Raw: %2)").arg(m_trait->level_message(score)).arg(score); if (d->trait_is_active(m_trait_id)==false) msg += tr("<br/><br/>Not an active trait for this dwarf."); QString temp = m_trait->conflicts_messages(score); if(!temp.isEmpty()) msg += tr("<br/><br/>%1").arg(temp); temp = m_trait->special_messages(score); if(!temp.isEmpty()) msg += tr("<br/><br/>%1").arg(temp); int rating = score; QString warning = ""; if(GameDataReader::ptr()->get_trait(m_trait_id)->inverted){ warning = tr("<br/><h5 style=\"margin:0;\"><font color=red>*This trait's score should be valued inversely!</font></h5>"); rating = 100 - score; } item->setText(QString::number(score)); item->setData(rating, DwarfModel::DR_SORT_VALUE); item->setData(rating, DwarfModel::DR_RATING); item->setData(rating, DwarfModel::DR_DISPLAY_RATING); QString tooltip = QString("<center><h3>%1</h3></center>%2<br>%3%4") .arg(m_title) .arg(msg) .arg(warning) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *FlagColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); item->setData(CT_FLAGS, DwarfModel::DR_COL_TYPE); item->setData(0,DwarfModel::DR_STATE); //default QString info_msg = ""; QString info_col_name = ""; short rating = 0; if(d->get_flag_value(m_bit_pos)) rating = 1; //check to fix butchering pets. currently this will cause the butchered parts to still be recognized as a pet //and they'll put them into a burial recepticle, but won't use them as a food source ViewColumn::CELL_STATE state = STATE_TOGGLE; if(m_bit_pos == FLAG_BUTCHER){ if(d->is_pet()){ info_msg = tr("<b>Pets cannot be slaughtered!</b>"); state = STATE_DISABLED; }else if(!d->get_caste() || !d->get_caste()->flags().has_flag(BUTCHERABLE)){ info_msg = tr("<b>This caste cannot be slaughtered!</b>"); state = STATE_DISABLED; }else if(rating == 1){ info_msg = tr("<b>This creature has been marked for slaughter.</b>"); state = STATE_PENDING; }else if(d->trained_level() >= Dwarf::unknown_trained){ info_msg = tr("<b>Captured wild animals cannot be butchered!</b>"); state = STATE_DISABLED; }else{ state = STATE_TOGGLE; } }else if(m_bit_pos == FLAG_GELD){ if(d->get_gender() != Dwarf::SEX_M){ info_msg = tr("<b>Only males can be gelded!</b>"); state = STATE_DISABLED; }else if(d->has_health_issue(eHealth::HI_GELDED,0)){ info_msg = tr("<b>This creature has already been gelded!</b>"); state = STATE_ACTIVE; }else if(rating == 1){ info_msg = tr("<b>This creature has been marked for gelding.</b>"); state = STATE_PENDING; }else if(!d->get_caste()->is_geldable()){ //check last as it's the most expensive info_msg = tr("<b>This caste is not geldable!</b>"); state = STATE_DISABLED; }else{ state = STATE_TOGGLE; } } item->setData(state,DwarfModel::DR_STATE); info_col_name = get_state_color(state).name();//item->data(Qt::BackgroundColorRole).value<QColor>().name(); item->setData(rating, DwarfModel::DR_SORT_VALUE); item->setData(m_bit_pos, DwarfModel::DR_OTHER_ID); item->setData(m_set->name(), DwarfModel::DR_SET_NAME); QString tooltip = QString("<center><h3>%1</h3>%2</center>%3") .arg(m_title) .arg(QString("<font color=%1>%2</font>").arg(info_col_name).arg(info_msg)) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *CurrentJobColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); short job_id = d->current_job_id(); QString pixmap_name(":img/question-frame.png"); DwarfJob *job = GameDataReader::ptr()->get_job(job_id); if (job) { int pref_id = -1; if(!job->reactionClass.isEmpty() && !d->current_sub_job_id().isEmpty()) { Reaction* reaction = d->get_reaction(); if(reaction!=0) { //job_type = DwarfJob::get_type(reaction->skill()); pref_id = GameDataReader::ptr()->get_pref_from_skill(reaction->skill_id()); } } if(pref_id != -1) { pixmap_name = ":/profession/img/profession icons/prof_" + QString::number(pref_id+1) + ".png"; //offset for the image name item->setData(QColor(50,50,50), DwarfModel::DR_DEFAULT_BG_COLOR); //shade the background } else { DwarfJob::DWARF_JOB_TYPE job_type = job->type; TRACE << "Dwarf: " << d->nice_name() << " job -" << job_id << ": (" << job->description << "," << job_type << ")"; switch (job_type) { case DwarfJob::DJT_IDLE: pixmap_name = ":status/img/cross-small.png"; break; case DwarfJob::DJT_ON_BREAK: pixmap_name = ":status/img/hourglass.png"; break; case DwarfJob::DJT_SOLDIER: pixmap_name = ":status/img/exclamation-shield-frame.png"; break; case DwarfJob::DJT_DIG: pixmap_name = ":status/img/shovel.png"; break; case DwarfJob::DJT_CUT: pixmap_name = ":status/img/tree--minus.png"; break; case DwarfJob::DJT_SLEEP: pixmap_name = ":status/img/moon.png"; break; case DwarfJob::DJT_DRINK: pixmap_name = ":status/img/ale.png"; break; case DwarfJob::DJT_FOOD: pixmap_name = ":status/img/cutlery.png"; break; case DwarfJob::DJT_BUILD: pixmap_name = ":status/img/hammer--plain.png"; break; case DwarfJob::DJT_HAUL: pixmap_name = ":status/img/cart-box.png"; break; case DwarfJob::DJT_FIGHT: pixmap_name = ":status/img/crossed-swords.png"; break; case DwarfJob::DJT_MOOD: pixmap_name = ":img/exclamation-red-frame.png"; break; case DwarfJob::DJT_FORGE: pixmap_name = ":status/img/status_forge.png"; break; case DwarfJob::DJT_MEDICAL: pixmap_name = ":status/img/first_aid_kit.png"; break; case DwarfJob::DJT_WAX_WORKING: pixmap_name = ":status/img/lump.png"; break; case DwarfJob::DJT_POTTERY: pixmap_name = ":status/img/pot.png"; break; case DwarfJob::DJT_PRESSING: pixmap_name = ":status/img/cup2.png"; break; case DwarfJob::DJT_SPINNING: pixmap_name = ":status/img/spinning.png"; break; case DwarfJob::DJT_BEE_KEEPING: pixmap_name = ":status/img/bee_i_guess.png"; break; case DwarfJob::DJT_STAIRS: pixmap_name = ":status/img/stairs.png"; break; case DwarfJob::DJT_FORTIFICATION: pixmap_name = ":status/img/wall-brick.png"; break; case DwarfJob::DJT_ENGRAVE: pixmap_name = ":status/img/paint-brush.png"; break; case DwarfJob::DJT_LEAF: pixmap_name = ":status/img/leaf.png"; break; case DwarfJob::DJT_BUILD_REMOVE: pixmap_name = ":status/img/hammer--minus.png"; break; case DwarfJob::DJT_BAG_ADD: pixmap_name = ":status/img/paper-bag--plus.png"; break; case DwarfJob::DJT_MONEY: pixmap_name = ":status/img/money-coin.png"; break; case DwarfJob::DJT_TAX: pixmap_name = ":status/img/money--arrow.png"; break; case DwarfJob::DJT_RETURN: pixmap_name = ":status/img/arrow-return.png"; break; case DwarfJob::DJT_PARTY: pixmap_name = ":status/img/rubber-balloons.png"; break; case DwarfJob::DJT_SOAP: pixmap_name = ":status/img/soap.png"; break; case DwarfJob::DJT_SEEK: pixmap_name = ":status/img/eye--arrow.png"; break; case DwarfJob::DJT_GEM_CUT: pixmap_name = ":status/img/diamond.png"; break; case DwarfJob::DJT_GEM_ENCRUST: pixmap_name = ":status/img/ruby.png"; break; case DwarfJob::DJT_SEEDS: pixmap_name = ":status/img/beans.png"; break; case DwarfJob::DJT_LEAF_ARROW: pixmap_name = ":status/img/leaf--arrow.png"; break; case DwarfJob::DJT_WATER_ARROW: pixmap_name = ":status/img/water--arrow.png"; break; case DwarfJob::DJT_TOMBSTONE: pixmap_name = ":status/img/headstone-rip.png"; break; case DwarfJob::DJT_ANIMAL: pixmap_name = ":status/img/animal.png"; break; case DwarfJob::DJT_BOOK_OPEN: pixmap_name = ":status/img/book-open-list.png"; break; case DwarfJob::DJT_HANDSHAKE: pixmap_name = ":status/img/hand-shake.png"; break; case DwarfJob::DJT_CONSTRUCT: pixmap_name = ":status/img/hammer-screwdriver.png"; break; case DwarfJob::DJT_ABACUS: pixmap_name = ":status/img/abacus.png"; break; case DwarfJob::DJT_FURNACE: pixmap_name = ":status/img/fire.png"; break; case DwarfJob::DJT_REPORT: pixmap_name = ":status/img/balloon-prohibition.png"; break; case DwarfJob::DJT_JUSTICE: pixmap_name = ":status/img/balance.png"; break; case DwarfJob::DJT_SHIELD: pixmap_name = ":status/img/shield.png"; break; case DwarfJob::DJT_DEPOT: pixmap_name = ":status/img/wooden-box--arrow.png"; break; case DwarfJob::DJT_BROOM: pixmap_name = ":status/img/broom.png"; break; case DwarfJob::DJT_SWITCH: pixmap_name = ":status/img/switch.png"; break; case DwarfJob::DJT_CHAIN: pixmap_name = ":status/img/chain.png"; break; case DwarfJob::DJT_UNCHAIN: pixmap_name = ":status/img/chain-unchain.png"; break; case DwarfJob::DJT_FILL_WATER: pixmap_name = ":status/img/water--plus.png"; break; case DwarfJob::DJT_MARKET: pixmap_name = ":status/img/store-market-stall.png"; break; case DwarfJob::DJT_KNIFE: pixmap_name = ":status/img/knife_bloody.png"; break; case DwarfJob::DJT_BOW: pixmap_name = ":status/img/bow.png"; break; case DwarfJob::DJT_CHEESE: pixmap_name = ":status/img/cheese.png"; break; case DwarfJob::DJT_HELM: pixmap_name = ":status/img/helm.png"; break; case DwarfJob::DJT_GLOVE: pixmap_name = ":status/img/glove.png"; break; case DwarfJob::DJT_BOOT: pixmap_name = ":status/img/boot.png"; break; case DwarfJob::DJT_ARMOR: pixmap_name = ":status/img/armor.png"; break; case DwarfJob::DJT_FISH: pixmap_name = ":status/img/carp.png"; break; case DwarfJob::DJT_RAW_FISH: pixmap_name = ":status/img/fish.png"; break; case DwarfJob::DJT_MILK: pixmap_name = ":status/img/milk.png"; break; case DwarfJob::DJT_REST: pixmap_name = ":status/img/bandaid--exclamation.png"; break; case DwarfJob::DJT_COOKING: pixmap_name = ":status/img/meat.png"; break; case DwarfJob::DJT_BUCKET_POUR: pixmap_name = ":status/img/paint-can--arrow.png"; break; case DwarfJob::DJT_GIVE_LOVE: pixmap_name = ":status/img/heart--arrow.png"; break; case DwarfJob::DJT_DYE: pixmap_name = ":status/img/color--plus.png"; break; case DwarfJob::DJT_WEAPON: pixmap_name = ":status/img/weapon.png"; break; case DwarfJob::DJT_SWITCH_CONNECT: pixmap_name = ":status/img/switch-network.png"; break; case DwarfJob::DJT_ZONE_ADD: pixmap_name = ":status/img/zone--plus.png"; break; case DwarfJob::DJT_CRAFTS: pixmap_name = ":status/img/crown.png"; break; case DwarfJob::DJT_GEAR: pixmap_name = ":status/img/gear-small.png"; break; case DwarfJob::DJT_TROUBLE: pixmap_name = ":status/img/hand-finger.png"; break; case DwarfJob::DJT_STORAGE: pixmap_name = ":status/img/box--plus.png"; break; case DwarfJob::DJT_STORE_OWNED: pixmap_name = ":status/img/safe--plus.png"; break; case DwarfJob::DJT_CABINET_MAKE: pixmap_name = ":status/img/drawer--plus.png"; break; case DwarfJob::DJT_CABINET_STORE: pixmap_name = ":status/img/drawer-open.png"; break; case DwarfJob::DJT_DOOR_MAKE: pixmap_name = ":status/img/door--plus.png"; break; case DwarfJob::DJT_CHAIR_MAKE: pixmap_name = ":status/img/chair--plus.png"; break; case DwarfJob::DJT_BREW: pixmap_name = ":status/img/ale--plus.png"; break; default: case DwarfJob::DJT_DEFAULT: pixmap_name = ":status/img/control_play_blue.png"; break; } } } item->setData(QIcon(pixmap_name), Qt::DecorationRole); item->setData(CT_IDLE, DwarfModel::DR_COL_TYPE); item->setData(d->current_job_id(), DwarfModel::DR_SORT_VALUE); // QColor bg = QColor(175,175,175); // if(DT->user_settings()->value("options/grid/shade_cells",true)==false) // bg = QColor(255,255,255); // item->setData(bg,Qt::BackgroundColorRole); QString tooltip = QString("<center><h3>%1</h3>%2 (%3)%4</center>") .arg(m_title) .arg(d->current_job()) .arg(d->current_job_id()) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }