Beispiel #1
0
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;
}
Beispiel #2
0
int BTSpellEditor::setup(ObjectSerializer &serial, BitField &active, std::vector<BTDisplay::selectItem> &items)
{
 int current = BTSerializedEditor::setup(serial, active, items);
 XMLAction *manifestField = serial.find("manifest", NULL);
 XMLArray *manifestArray = (reinterpret_cast<XMLArray*>(manifestField->object));
 XMLVector<BTManifest*> *manifest = dynamic_cast<XMLVector<BTManifest*> *>(manifestArray);
 extra.clear();
 int extraVal = 100;
 for (size_t i = 0; i < manifest->size(); ++i)
 {
  if (current == items.size())
   items.push_back(BTDisplay::selectItem());
  BTManifest *manifestObj = dynamic_cast<BTManifest*>(manifest->get(i));
  extra.push_back(BTSpellEditor::extraItems(manifestObj, "type", -1));
  items[current].name = std::string("Effect: ") + spellTypeLookup.getName(manifestObj->type);
  items[current].value = extraVal++;
  current++;
  int manifestEntries = manifestObj->getEditFieldNumber();
  if (manifestEntries > 0)
  {
   ObjectSerializer serialSub;
   manifestObj->serialize(&serialSub);
   for (int n = 0; n < manifestEntries; ++n)
   {
    if (current == items.size())
     items.push_back(BTDisplay::selectItem());
    extra.push_back(BTSpellEditor::extraItems(manifestObj, manifestObj->getEditField(n), n));
    XMLAction *curField = serialSub.find(manifestObj->getEditField(n), NULL);
    items[current].name = std::string("  ") + std::string(manifestObj->getEditFieldDescription(n)) + ": " + curField->createString();
    items[current].value = extraVal++;
    current++;
   }
  }
 }
 if (current == items.size())
  items.push_back(BTDisplay::selectItem());
 items[current].name = std::string("<New Effect>");
 items[current].value = extraVal++;
 current++;
 return current;
}
Beispiel #3
0
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);
}