Exemple #1
0
void PropertiesWindow::saveAttributesPanel()
{
	edit_item->clearAllAttributes();
	for(int32_t rowIndex = 0; rowIndex < attributesGrid->GetNumberRows(); ++rowIndex) {
		ItemAttribute attr;
		wxString type = attributesGrid->GetCellValue(rowIndex, 1);
		if(type == "String") {
			attr.set(nstr(attributesGrid->GetCellValue(rowIndex, 2)));
		} else if(type == "Float") {
			double value;
			if(attributesGrid->GetCellValue(rowIndex, 2).ToDouble(&value)) {
				attr.set(value);
			}
		} else if(type == "Number") {
			long value;
			if(attributesGrid->GetCellValue(rowIndex, 2).ToLong(&value)) {
				attr.set(static_cast<int32_t>(value));
			}
		} else if(type == "Boolean") {
			attr.set(attributesGrid->GetCellValue(rowIndex, 2) == "1");
		} else {
			continue;
		}
		edit_item->setAttribute(nstr(attributesGrid->GetCellValue(rowIndex, 0)), attr);
	}
}
Exemple #2
0
void PropertiesWindow::SetGridValue(wxGrid* grid, int rowIndex, std::string label, const ItemAttribute& attr)
{
	wxArrayString types;
	types.Add(wxT("Number"));
	types.Add(wxT("Float"));
	types.Add(wxT("Boolean"));
	types.Add(wxT("String"));

	grid->SetCellValue(label, rowIndex, 0);
	switch (attr.type)
	{
	case ItemAttribute::STRING:
		{
			grid->SetCellValue(wxT("String"), rowIndex, 1);
			grid->SetCellValue(wxstr(*attr.getString()), rowIndex, 2);
			break;
		}
	case ItemAttribute::INTEGER:
		{
			grid->SetCellValue(wxT("Number"), rowIndex, 1);
			grid->SetCellValue(i2ws(*attr.getInteger()), rowIndex, 2);
			grid->SetCellEditor(rowIndex, 2, new wxGridCellNumberEditor);
			break;
		}
	case ItemAttribute::DOUBLE:
	case ItemAttribute::FLOAT:
		{
			grid->SetCellValue(wxT("Float"), rowIndex, 1);
			wxString f;
			f << *attr.getFloat();
			grid->SetCellValue(f, rowIndex, 2);
			grid->SetCellEditor(rowIndex, 2, new wxGridCellFloatEditor);
			break;
		}
	case ItemAttribute::BOOLEAN:
		{
			grid->SetCellValue(wxT("Boolean"), rowIndex, 1);
			grid->SetCellValue(*attr.getBoolean() ? wxT("1") : wxT(""), rowIndex, 2);
			grid->SetCellRenderer(rowIndex, 2, new wxGridCellBoolRenderer);
			grid->SetCellEditor(rowIndex, 2, new wxGridCellBoolEditor);
			break;
		}
	default:
		{
			grid->SetCellValue(wxT("Unknown"), rowIndex, 1);
			grid->SetCellBackgroundColour(*wxLIGHT_GREY, rowIndex, 1);
			grid->SetCellBackgroundColour(*wxLIGHT_GREY, rowIndex, 2);
			grid->SetReadOnly(rowIndex, 1, true);
			grid->SetReadOnly(rowIndex, 2, true);
			break;
		}
	}
	grid->SetCellEditor(rowIndex, 1, new wxGridCellChoiceEditor(types));
}
Exemple #3
0
bool ItemAttributes::unserializeAttributeMap(PropStream& stream)
{

  uint16_t n;
  if(stream.GET_USHORT(n)){
    createAttributes();

    std::string key;
    ItemAttribute attrib;

    while(n--){
      if(!stream.GET_STRING(key))
        return false;
      if(!attrib.unserialize(stream))
        return false;
      (*attributes)[key] = attrib;
    }
  }
  return true;
}
Exemple #4
0
void PropertiesWindow::OnGridValueChanged(wxGridEvent& event)
{
	if(event.GetCol() == 1) {
		wxString newType = attributesGrid->GetCellValue(event.GetRow(), 1);
		if(newType == event.GetString()) {
			return;
		}

		ItemAttribute attr;
		if(newType == "String") {
			attr.set("");
		} else if(newType == "Float") {
			attr.set(0.0f);
		} else if(newType == "Number") {
			attr.set(0);
		} else if(newType == "Boolean") {
			attr.set(false);
		}
		SetGridValue(attributesGrid, event.GetRow(), nstr(attributesGrid->GetCellValue(event.GetRow(), 0)), attr);
	}
}
bool ItemAttributes::unserializeMap(PropStream& stream)
{
	uint16_t n;
	if(!stream.getShort(n))
		return true;

	createAttributes();
	while(n--)
	{
		std::string key;
		if(!stream.getString(key))
			return false;

		ItemAttribute attr;
		if(!attr.unserialize(stream))
			return false;

		(*attributes)[key] = attr;
	}

	return true;
}