int BTSerializedEditor::setup(ObjectSerializer &serial, BitField &active, std::vector<BTDisplay::selectItem> &items) { size_t current = 0; for (int i = 0; i < entries; ++i) { if (!active.isSet(i)) continue; XMLAction *curField = serial.find(field[i], NULL); if (current >= entries) items.push_back(BTDisplay::selectItem()); if (curField->getType() == XMLTYPE_OBJECT) { XMLObject *obj = reinterpret_cast<XMLObject*>(curField->object); items[current].name = std::string(description[i]) + ": " + obj->createString(); items[current].value = i; ++current; } else if (curField->getType() == XMLTYPE_CREATE) { XMLArray *obj = reinterpret_cast<XMLArray*>(curField->object); for (size_t k = 0; k < obj->size(); k++) { if (current >= items.size()) items.push_back(BTDisplay::selectItem()); items[current].name = std::string(description[i]) + ": " + obj->get(k)->createString(); items[current].value = i; ++current; } if (current >= items.size()) items.push_back(BTDisplay::selectItem()); items[current].name = std::string(description[i]) + ": <New>"; items[current].value = i; ++current; } else if (curField->getType() == XMLTYPE_VECTORSTRING) { std::vector<std::string> *obj = reinterpret_cast<std::vector<std::string>*>(curField->object); for (size_t k = 0; k < obj->size(); k++) { if (current >= items.size()) items.push_back(BTDisplay::selectItem()); items[current].name = std::string(description[i]) + ": " + (*obj)[k]; items[current].value = i; ++current; } if (current >= items.size()) items.push_back(BTDisplay::selectItem()); items[current].name = std::string(description[i]) + ": <New>"; items[current].value = i; ++current; } else { items[current].name = std::string(description[i]) + ": " + curField->createString(); items[current].value = i; ++current; } } return current; }
void BTStatBlock::draw(BTDisplay &d, int x, int y, ObjectSerializer *pc) { int xMult, yMult; SDL_Rect dst; d.getMultiplier(xMult, yMult); dst.x = (x + position.x) * xMult; dst.y = (y + position.y) * yMult; dst.w = position.w * xMult; dst.h = position.h * yMult; XMLAction *state = pc->find(attribute, NULL); if (state) { switch(state->getType()) { case XMLTYPE_BOOL: if (*(reinterpret_cast<bool*>(state->object))) d.drawFont("true", dst, d.getBlack(), (BTDisplay::alignment)align); else d.drawFont("false", dst, d.getBlack(), (BTDisplay::alignment)align); break; case XMLTYPE_INT: if (state->data) { d.drawFont(reinterpret_cast<ValueLookup*>(state->data)->getName(*(reinterpret_cast<int*>(state->object))).c_str(), dst, d.getBlack(), (BTDisplay::alignment)align); } else { int val = *(reinterpret_cast<int*>(state->object)) + modifier; if (negate) val *= -1; if ((maxValue != -1) && (maxValue < val)) { d.drawFont(overflow, dst, d.getBlack(), (BTDisplay::alignment)align); } else { char tmp[40]; snprintf(tmp, 40, "%d", val); d.drawFont(tmp, dst, d.getBlack(), (BTDisplay::alignment)align); } } break; case XMLTYPE_UINT: { /* char tmp[40]; snprintf(tmp, 40, "%u", *(reinterpret_cast<unsigned int*>(state->object))); line.back() += tmp;*/ break; } case XMLTYPE_STRING: d.drawFont(*(reinterpret_cast<char**>(state->object)), dst, d.getBlack(), (BTDisplay::alignment)align); break; case XMLTYPE_BITFIELD: default: break; } } }
bool BTCheckBit::compare(ObjectSerializer *pc) const { XMLAction *state = pc->find(attribute, NULL); if ((state) && (XMLTYPE_BITFIELD == state->getType())) { return reinterpret_cast<BitField*>(state->object)->isSet(bit); } return false; }
void BTSerializedEditor::edit(BTDisplay &d, ObjectSerializer &serial) { BTDisplayConfig *oldConfig = d.getConfig(); BTDisplayConfig config; XMLSerializer parser; config.serialize(&parser); parser.parse(BTDisplay::applyDisplayDir("data/specialedit.xml").c_str(), true); d.setConfig(&config); int start(0); int current(0); BitField active; std::vector<BTDisplay::selectItem> list(entries); initActive(serial, active); int len = setup(serial, active, list); d.addSelection(list.data(), len, start, current); int key; char extra[2] = {BTKEY_DEL, 0}; while (27 != (key = d.process(extra))) { d.clearText(); XMLAction *curField = NULL; if (list[current].value < entries) curField = serial.find(field[list[current].value], NULL); if (key == BTKEY_DEL) { if (curField) { int where = 0; if (curField->getType() == XMLTYPE_CREATE) { XMLArray *obj = reinterpret_cast<XMLArray*>(curField->object); int where = 0; for (int i = current - 1; (i >= 0) && (list[i].value == list[current].value); --i) { ++where; } if (where < obj->size()) { obj->erase(where); for (int i = current; i < len - 1; ++i) { list[i].name = list[i + 1].name; list[i].value = list[i + 1].value; } --len; } } else if (curField->getType() == XMLTYPE_VECTORSTRING) { std::vector<std::string> *obj = reinterpret_cast<std::vector<std::string>*>(curField->object); int where = 0; for (int i = current - 1; (i >= 0) && (list[i].value == list[current].value); --i) { ++where; } if (where < obj->size()) { obj->erase(obj->begin() + where); for (int i = current; i < len - 1; ++i) { list[i].name = list[i + 1].name; list[i].value = list[i + 1].value; } --len; } } } else { delSpecialField(d, serial, list[current].value); } } else { if (curField) { int where = 0; if (curField->getType() == XMLTYPE_CREATE) { XMLArray *obj = reinterpret_cast<XMLArray*>(curField->object); for (int i = current - 1; (i >= 0) && (list[i].value == list[current].value); --i) { ++where; } if (where >= obj->size()) { obj->push_back((*reinterpret_cast<XMLObject::create>(curField->data))(field[list[current].value], NULL)); list.push_back(BTDisplay::selectItem()); for (int i = list.size() - 1; i > current; --i) { list[i].name = list[i - 1].name; list[i].value = list[i - 1].value; } len++; } } else if (curField->getType() == XMLTYPE_VECTORSTRING) { std::vector<std::string> *obj = reinterpret_cast<std::vector<std::string>*>(curField->object); for (int i = current - 1; (i >= 0) && (list[i].value == list[current].value); --i) { ++where; } if (where >= obj->size()) { obj->push_back(std::string()); list.push_back(BTDisplay::selectItem()); for (int i = list.size() - 1; i > current; --i) { list[i].name = list[i - 1].name; list[i].value = list[i - 1].value; } len++; } } editField(d, serial, description[list[current].value], curField, list[current].value, where); if (curField->getType() == XMLTYPE_OBJECT) { XMLObject *obj = reinterpret_cast<XMLObject*>(curField->object); BTDice *dice = dynamic_cast<BTDice*>(obj); if (dice) list[current].name = std::string(description[list[current].value]) + ": " + dice->createString(); } else if (curField->getType() == XMLTYPE_VECTORSTRING) { std::vector<std::string> *obj = reinterpret_cast<std::vector<std::string>*>(curField->object); list[current].name = std::string(description[list[current].value]) + ": " + (*obj)[where]; } else if (curField->getType() != XMLTYPE_CREATE) { list[current].name = std::string(description[list[current].value]) + ": " + curField->createString(); } else { XMLArray *obj = reinterpret_cast<XMLArray*>(curField->object); list[current].name = std::string(description[list[current].value]) + ": " + obj->get(where)->createString(); } } else { handleSpecialField(d, serial, list[current].value); } } if (updateActive(serial, active, list[current].value)) len = setup(serial, active, list); d.addSelection(list.data(), len, start, current); } complete(serial); d.clearText(); d.setConfig(oldConfig); }
void BTStatBlock::draw(BTBackgroundAndScreen &d, int x, int y, ObjectSerializer *pc) { int xMult, yMult; SDL_Rect dst; std::string color("black"); d.getDisplay()->getMultiplier(xMult, yMult); dst.x = (x + position.x) * xMult; dst.y = (y + position.y) * yMult; dst.w = position.w * xMult; dst.h = position.h * yMult; XMLAction *state = pc->find(attribute, NULL); if (state) { switch(state->getType()) { case XMLTYPE_BOOL: if (*(reinterpret_cast<bool*>(state->object))) d.drawFont("true", dst, d.getColor(color), (BTAlignment::alignment)align); else d.drawFont("false", dst, d.getColor(color), (BTAlignment::alignment)align); break; case XMLTYPE_INT: if (compare.attribute != "") { XMLAction *cmpState = pc->find(compare.attribute.c_str(), NULL); if ((cmpState) && (cmpState->getType() == XMLTYPE_INT)) { int curVal = *(reinterpret_cast<int*>(state->object)); int maxVal = *(reinterpret_cast<int*>(cmpState->object)); if (maxVal == curVal) color = compare.full; else if (curVal < (maxVal / 2)) color = compare.half; } } if (state->data) { d.drawFont(reinterpret_cast<ValueLookup*>(state->data)->getName(*(reinterpret_cast<int*>(state->object))).c_str(), dst, d.getColor(color), (BTAlignment::alignment)align); } else { int val = *(reinterpret_cast<int*>(state->object)) + modifier; if (negate) val *= -1; if ((maxValue != -1) && (maxValue < val)) { d.drawFont(overflow, dst, d.getColor(color), (BTAlignment::alignment)align); } else { char tmp[40]; snprintf(tmp, 40, "%d", val); d.drawFont(tmp, dst, d.getColor(color), (BTAlignment::alignment)align); } } break; case XMLTYPE_UINT: { /* char tmp[40]; snprintf(tmp, 40, "%u", *(reinterpret_cast<unsigned int*>(state->object))); line.back() += tmp;*/ break; } case XMLTYPE_STRING: d.drawFont(*(reinterpret_cast<char**>(state->object)), dst, d.getColor(color), (BTAlignment::alignment)align); break; case XMLTYPE_BITFIELD: default: break; } } }