コード例 #1
0
void BTSerializedEditor::editField(BTDisplay &d, ObjectSerializer &serial, const char *text, XMLAction *curField, int modField, int where)
{
 int key;
 switch (curField->getType())
 {
  case XMLTYPE_STDSTRING:
  {
   std::string val = curField->createString();
   d.addReadString(std::string(text) + ": ", 100, val);
   key = d.process();
   if ('\r' == key)
    *(reinterpret_cast<std::string*>(curField->object)) = val;
   break;
  }
  case XMLTYPE_STRING:
  {
   std::string val = curField->createString();
   d.addReadString(std::string(text) + ": ", 100, val);
   key = d.process();
   if ('\r' == key)
   {
    char *str = *(reinterpret_cast<char**>(curField->object));
    if (str)
    {
     delete [] str;
    }
    int len = val.length();
    str = new char[len + 1];
    strncpy(str, val.c_str(), len);
    str[len] = 0;
    *(reinterpret_cast<char**>(curField->object)) = str;
   }
   break;
  }
  case XMLTYPE_BOOL:
  {
   BTDisplay::selectItem vals[2];
   vals[0].name = "false";
   vals[1].name = "true";
   int lookupStart(0);
   int lookupCurrent((*(reinterpret_cast<bool*>(curField->object)) ? 1 : 0));
   d.addSelection(vals, 2, lookupStart, lookupCurrent);
   if (27 != d.process())
   {
    *(reinterpret_cast<bool*>(curField->object)) = lookupCurrent;
   }
   break;
  }
  case XMLTYPE_BITFIELD:
  {
   ValueLookup *lookup = reinterpret_cast<ValueLookup*>(curField->data);
   BitField *bits = reinterpret_cast<BitField*>(curField->object);
   BTDisplay::selectItem lookupItem[lookup->size()];
   for (int i = 0; i < lookup->size(); ++i)
   {
    lookupItem[i].name = lookup->getName(i);
    if (bits->isSet(i))
     lookupItem[i].first = '*';
   }
   int lookupStart(0);
   int lookupCurrent(0);
   d.addSelection(lookupItem, lookup->size(), lookupStart, lookupCurrent);
   int key;
   while (27 != (key = d.process()))
   {
    if (bits->toggle(lookupCurrent))
     lookupItem[lookupCurrent].first = '*';
    else
     lookupItem[lookupCurrent].first = 0;
   }
   break;
  }
  case XMLTYPE_INT:
  {
   if (curField->data)
   {
    ValueLookup *lookup = reinterpret_cast<ValueLookup*>(curField->data);
    bool extra = ((curField->extra == EXTRA_NONE) ? false : true);
    BTDisplay::selectItem lookupItem[lookup->size() + (extra ? 1 : 0)];
    int i = 0;
    if (extra)
    {
     lookupItem[0].name = curField->extraText;
     lookupItem[0].value = -1;
     ++i;
    }
    int endIndex = lookup->getEndIndex();
    int lookupCurrent(0);
    int valIndex((*(reinterpret_cast<int*>(curField->object))) + (extra ? 1 : 0));
    for (int curIndex = lookup->getFirstIndex(); curIndex != endIndex; curIndex = lookup->getNextIndex(curIndex))
    {
     lookupItem[i].name = lookup->getName(curIndex);
     lookupItem[i].value = curIndex;
     if (curIndex == valIndex)
      lookupCurrent = i;
     ++i;
    }
    int lookupStart(0);
    d.addSelection(lookupItem, lookup->size() + (extra ? 1 : 0), lookupStart, lookupCurrent);
    if (27 != d.process())
    {
     *(reinterpret_cast<int*>(curField->object)) = lookupItem[lookupCurrent].value;
    }
   }
   else
   {
    std::string val = curField->createString();
    d.addReadString(std::string(text) + ": ", 100, val);
    key = d.process();
    if ('\r' == key)
     *(reinterpret_cast<int*>(curField->object)) = atol(val.c_str());
   }
   break;
  }
  case XMLTYPE_UINT:
  {
   std::string val = curField->createString();
   d.addReadString(std::string(text) + ": ", 100, val);
   key = d.process();
   if ('\r' == key)
    *(reinterpret_cast<unsigned int*>(curField->object)) = atol(val.c_str());
   break;
  }
  case XMLTYPE_INT16:
  {
   std::string val = curField->createString();
   d.addReadString(std::string(text) + ": ", 100, val);
   key = d.process();
   if ('\r' == key)
    *(reinterpret_cast<int16_t*>(curField->object)) = atol(val.c_str());
   break;
  }
  case XMLTYPE_VECTORUINT:
  {
   std::vector<unsigned int> *vec = reinterpret_cast<std::vector<unsigned int> *>(curField->object);
   std::string val;
   for (size_t i = 0; i < vec->size(); ++i)
   {
    if (i != 0)
     val += ",";
    char convert[30];
    sprintf(convert, "%u", (*vec)[i]);
    val += convert;
   }
   d.addReadString(std::string(text) + ": ", 100, val);
   key = d.process();
   if ('\r' == key)
   {
    size_t i = 0;
    const char *start = val.c_str();
    for (const char *comma = strchr(val.c_str(), ','); (start) && (*start); ++i)
    {
     if (i < vec->size())
      (*vec)[i] = atol(start);
     else
      vec->push_back(atol(start));
     start = comma;
     if (start)
     {
      if ((*start) == ',')
       ++start;
      comma = strchr(start, ',');
     }
    }
    if (i < vec->size())
     vec->resize(i);
   }
   break;
  }
  case XMLTYPE_OBJECT:
  {
   XMLObject *obj = reinterpret_cast<XMLObject*>(curField->object);
   BTDice *dice = dynamic_cast<BTDice*>(obj);
   if (dice)
   {
    std::ostringstream stream;
    stream << dice->getNumber();
    std::string val = stream.str();
    d.addReadString(std::string(text) + "- Number of Dice: ", 100, val);
    key = d.process();
    if ('\r' == key)
     dice->setNumber(atol(val.c_str()));
    d.clearText();
    stream.str("");
    stream << dice->getType();
    val = stream.str();
    d.addReadString(std::string(text) + "- Type of Dice: ", 100, val);
    key = d.process();
    if ('\r' == key)
     dice->setType(atol(val.c_str()));
    d.clearText();
    stream.str("");
    stream << dice->getModifier();
    val = stream.str();
    d.addReadString(std::string(text) + "- Modifier to Roll: ", 100, val);
    key = d.process();
    if ('\r' == key)
     dice->setModifier(atol(val.c_str()));
   }
   else
    printf("Unsuppported type: %d\n", curField->getType());
   break;
  }
  case XMLTYPE_CREATE:
  {
   XMLArray *obj = reinterpret_cast<XMLArray*>(curField->object);
   handleObject(d, obj->get(where), modField);
   break;
  }
  case XMLTYPE_PICTURE:
  {
   BTDisplayConfig *oldConfig = d.getConfig();
   BTDisplayConfig config;
   XMLSerializer parser;
   config.serialize(&parser);
   parser.parse(BTDisplay::applyDisplayDir("data/pictureselect.xml").c_str(), true);
   d.setConfig(&config);
   d.clearText();
   d.addText(text);
   int val(reinterpret_cast<PictureIndex*>(curField->object)->value);
   d.addSelectImage(val);
   key = d.process();
   if ('\r' == key)
    reinterpret_cast<PictureIndex*>(curField->object)->value = val;
   d.clearImage();
   d.setConfig(oldConfig);
   break;
  }
  case XMLTYPE_VECTORSTRING:
  {
   std::vector<std::string> *obj = reinterpret_cast<std::vector<std::string>*>(curField->object);
   std::string val = (*obj)[where];
   d.addReadString(std::string(text) + ": ", 100, val);
   key = d.process();
   if ('\r' == key)
    (*obj)[where] = val;
   break;
  }
  default:
   printf("Unsuppported type: %d\n", curField->getType());
   break;
 }
 d.clearText();
}