CVec2PropertyDescription::CVec2PropertyDescription(CSerializer* pSerializer) : super(NULL) { SetType(eRPT_Vec2F); SetMaxCount(VEC_COUNT); SetFixed(true); CPropertyDescriptionBase* pFloatProperty = CComponentProxyManager::GetInstance()->CreateProperty(eRPT_Float, NULL); SetTemplateProperty(pFloatProperty); TString InitValue = _T("0,0"); if (pSerializer != NULL) { InitValue.clear(); for (size_t i = 0; i < VEC_COUNT; ++i) { float fValue = 0; (*pSerializer) >> fValue; InitValue.append(wxString::Format(_T("%f"),fValue)); if (i != VEC_COUNT - 1) { InitValue.append(_T(",")); } CPropertyDescriptionBase* pChild = AddChild(NULL); pChild->InitializeValue(fValue); } ResetChildName(); }
CVec4PropertyDescription::CVec4PropertyDescription(CSerializer* pSerializer) : super(NULL) { SetType(eRPT_Vec4F); SetMaxCount(VEC_COUNT); CFloatPropertyDescription* pFloatProperty = down_cast<CFloatPropertyDescription*>(CComponentProxyManager::GetInstance()->CreateProperty(eRPT_Float, NULL)); pFloatProperty->SetSpinStep(0.1f); SetTemplateProperty(pFloatProperty); TString InitValue = _T("0,0,0,0"); if (pSerializer != NULL) { InitValue.clear(); for (uint32_t i = 0; i < VEC_COUNT; ++i) { float fValue = 0; (*pSerializer) >> fValue; InitValue.append(wxString::Format(_T("%f"),fValue)); if (i != VEC_COUNT - 1) { InitValue.append(_T(",")); } CPropertyDescriptionBase* pChild = InsertChild(NULL); pChild->InitializeValue(fValue); } ResetChildName(); }
bool CArmatureData::OnPropertyChange(void* pVariableAddr, CSerializer* pSerializer) { bool bRet = super::OnPropertyChange(pVariableAddr, pSerializer); if(!bRet) { if(pVariableAddr == &m_pDisplayData) { m_pDisplayData = (CDisplayData*)pSerializer; if(m_pDisplayData) { m_pDisplayData->SetChange(true); } bRet = true; } else if(pVariableAddr == &m_strCfgFilePath) { DeserializeVariable(m_strCfgFilePath, pSerializer); ReLoadData(); CComponentProxy* pProxy = static_cast<CComponentProxy*>(CComponentProxyManager::GetInstance()->GetComponentInstance(this->GetId(), this->GetGuid())); BEATS_ASSERT(pProxy != NULL, _T("Can't get proxy with id: %d guid:0x%x"), GetId(), GetGuid()); CPropertyDescriptionBase* pProperty = pProxy->GetPropertyDescription(GET_VAR_NAME(m_strBoneName)); BEATS_ASSERT(pProperty != NULL, _T("Get property %s failed!"), GET_VAR_NAME(m_strBoneName)); pProperty->SetValueList(m_boneNameList); bRet = true; } } return bRet; }
bool CMenuEditor::OnEvent(wxPropertyGrid* propGrid, wxPGProperty* property, wxWindow* /*ctrl*/, wxEvent& event) const { CPropertyDescriptionBase* pPropertyDescription = (CPropertyDescriptionBase*)(property->GetClientData()); if (event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED) { if (pPropertyDescription->GetType() == eRPT_RandomColor) { CRandomColorPropertyDescription* pRandomColorProperty = down_cast<CRandomColorPropertyDescription*>(pPropertyDescription); wxArrayString displayString; int nInitSelection = (int)pRandomColorProperty->GetColorType(); if (!pRandomColorProperty->IsOnlyGradient()) { displayString.Add("color"); displayString.Add("random color"); } if (!pRandomColorProperty->IsOnlyColor()) { displayString.Add("spline"); displayString.Add("random spline"); } if (nInitSelection > (int)displayString.size()) { nInitSelection = 0; } int nSelection = wxGetSingleChoiceIndex("选取类型", "选取类型", displayString, nInitSelection); if (nSelection != 0xFFFFFFFF) { wxPGProperty* pMinProperty = nullptr; pRandomColorProperty->SetColorType(ERandomColorType(nSelection)); ERandomColorType realColorType = pRandomColorProperty->GetColorType();// may not be the same to nSelection. wxPGProperty* pMaxProperty = pRandomColorProperty->CreateRandomColorProperty(realColorType, pMinProperty); property->DeleteChildren(); if (pMinProperty) { property->InsertChild(-1, pMinProperty); } property->InsertChild(-1, pMaxProperty); propGrid->RefreshProperty(property); wxVariant tmp((int)realColorType); pRandomColorProperty->SetValue(tmp); } } } return true; }
wxPGWindowList wxPtrButtonEditor::CreateControls( wxPropertyGrid* propGrid, wxPGProperty* property, const wxPoint& pos, const wxSize& sz ) const { wxPGMultiButton* buttons = new wxPGMultiButton( propGrid, sz ); void* pClientData = property->GetClientData(); BEATS_ASSERT(pClientData != NULL); CPropertyDescriptionBase* pPropertyDescription = static_cast<CPropertyDescriptionBase*>(pClientData); if (pPropertyDescription->GetType() == eRPT_Ptr) { CPtrPropertyDescription* pPtrProperty = static_cast<CPtrPropertyDescription*>(pPropertyDescription); buttons->Add( pPtrProperty->GetInstanceComponent() == NULL ? _T("+") : _T("-")); } else if (pPropertyDescription->IsContainerProperty()) { buttons->Add(_T("+")); if (property->GetChildCount() > 0) { buttons->Add(_T("-")); } } CPropertyDescriptionBase* pParent = pPropertyDescription->GetParent(); // it is a list element. if (pParent && pParent->IsContainerProperty()) { buttons->Add(_T("x")); } wxPGWindowList wndList = wxPGTextCtrlEditor::CreateControls( propGrid, property, pos, buttons->GetPrimarySize() ); buttons->Finalize(propGrid, pos); wndList.SetSecondary( buttons ); return wndList; }
int CPropertyGridEditor::ShowModal() { wxLocale locale; locale.Init(wxLANGUAGE_CHINESE_SIMPLIFIED); BEATS_ASSERT(m_pGridProperty != NULL); CListPropertyDescription* pListProperty = (CListPropertyDescription*)m_pGridProperty->GetClientData(); // When first time show an instance in the list, we have a chance to select a derived instance. CPtrPropertyDescription* pTemplateProperty = down_cast<CPtrPropertyDescription*>(pListProperty->GetTemplateProperty()); if (pListProperty->GetChildrenCount() == 0) { wxPtrButtonEditor::SelectDerivedInstanceInEditor(pTemplateProperty); } else { // If we already got some data in XML to indicate what the instance really is, let the pTemplateProperty to know. // So we know what cols should be add in InsertProperty CPtrPropertyDescription* pPtrChildProperty = down_cast<CPtrPropertyDescription*>(pListProperty->GetChild(0)); pTemplateProperty->SetDerivedGuid(pPtrChildProperty->GetDerivedGuid()); } BEATS_ASSERT(pTemplateProperty != NULL); InsertProperty(pTemplateProperty, false); size_t uChildrenCount = pListProperty->GetChildrenCount(); m_pGrid->AppendRows(uChildrenCount); for (size_t i = 0; i < uChildrenCount; ++i) { CPropertyDescriptionBase* pProperty = pListProperty->GetChild(i); std::vector<CPropertyDescriptionBase*> propertiesToAddInRow; BEATS_ASSERT(pProperty != NULL); if (pProperty->GetType() == eRPT_Ptr) { CPtrPropertyDescription* pPtrProperty = down_cast<CPtrPropertyDescription*>(pProperty); BEATS_ASSERT(pPtrProperty != NULL && pPtrProperty->GetInstanceComponent() != NULL); CComponentProxy* pProxy = pPtrProperty->GetInstanceComponent(); propertiesToAddInRow = *pProxy->GetPropertyPool(); } else { propertiesToAddInRow.push_back(pProperty); } for (size_t j = 0; j < propertiesToAddInRow.size(); ++j) { char szResult[10240]; propertiesToAddInRow[j]->GetValueAsChar(eVT_CurrentValue, szResult); if (propertiesToAddInRow[j]->GetType() == eRPT_Bool) { bool bValue = *((bool*)propertiesToAddInRow[j]->GetValue(eVT_CurrentValue)); szResult[0] = bValue ? '1' : 0; szResult[1] = 0; } else if (propertiesToAddInRow[j]->GetType() == eRPT_Enum) { CEnumPropertyDescription* pEnumProperty = down_cast<CEnumPropertyDescription*>(propertiesToAddInRow[j]); InitEnumCell(i, j, pEnumProperty); int nCurValue = *((int*)(pEnumProperty->GetValue(eVT_CurrentValue))); strcpy(szResult, pEnumProperty->QueryStringByValue(nCurValue).c_str()); } m_pGrid->SetCellValue(i, j, szResult); } } m_pGrid->AutoSize(); this->Fit(); this->Layout(); return super::ShowModal(); }
void CBatchEditWnd::OnApplyBtnClicked(wxCommandEvent& /*event*/) { wxString strPropertyName = m_pPropertyNameCtrl->GetValue(); if (strPropertyName.IsEmpty()) { wxMessageBox(_T("property name 不能为空!"), wxMessageBoxCaptionStr, wxOK | wxCENTRE, this); } else { int nRet = wxMessageBox(wxString::Format(_T("新的值为 %s, 确定吗?"), m_pNewValueCtrl->GetValue()), _T("即将修改变量值"), wxYES_NO, this); if (nRet == wxYES) { unsigned long uGuidRef = 0; m_pGuidTextCtrl->GetValue().ToULong(&uGuidRef, 16); std::set<CComponentProxy*> operatingComponentProxy; std::set<uint32_t> derivedClassSet; bool bApplyToDerivedClass = m_pApplyToDerivedCheckBox->GetValue(); if (bApplyToDerivedClass) { std::set<uint32_t> derivedClassGuid; CComponentProxyManager::GetInstance()->QueryDerivedClass(uGuidRef, derivedClassGuid, true); for (auto guid : derivedClassGuid) { BEATS_ASSERT(derivedClassSet.find(guid) == derivedClassSet.end()); derivedClassSet.insert(guid); } } if (m_pOperatingRange->GetSelection() == 0) { const std::map<uint32_t, CComponentProxy*>& curSceneComponentsMap = CComponentProxyManager::GetInstance()->GetComponentsInCurScene(); for (auto iter = curSceneComponentsMap.begin(); iter != curSceneComponentsMap.end(); ++iter) { uint32_t uGuid = iter->second->GetGuid(); if (uGuid == uGuidRef || (bApplyToDerivedClass && derivedClassSet.find(uGuid) != derivedClassSet.end())) { BEATS_ASSERT(operatingComponentProxy.find(iter->second) == operatingComponentProxy.end()); operatingComponentProxy.insert(iter->second); } } } else { const std::map<uint32_t, std::map<uint32_t, CComponentBase*>*>* pComponentInstanceMap = CComponentProxyManager::GetInstance()->GetComponentInstanceMap(); for (auto iter = pComponentInstanceMap->begin(); iter != pComponentInstanceMap->end(); ++iter) { uint32_t uGuid = iter->first; if (uGuid == uGuidRef || (bApplyToDerivedClass && derivedClassSet.find(uGuid) != derivedClassSet.end())) { for (auto subIter = iter->second->begin(); subIter != iter->second->end(); ++subIter) { CComponentProxy* pProxy = dynamic_cast<CComponentProxy*>(subIter->second); BEATS_ASSERT(pProxy != NULL); BEATS_ASSERT(operatingComponentProxy.find(pProxy) == operatingComponentProxy.end()); operatingComponentProxy.insert(pProxy); } } } } for (auto iter = operatingComponentProxy.begin(); iter != operatingComponentProxy.end(); ++iter) { CPropertyDescriptionBase* pProperty = (*iter)->GetProperty(strPropertyName); pProperty->GetValueByTChar(m_pNewValueCtrl->GetValue(), pProperty->GetValue(eVT_CurrentValue)); // Force update the host component, because we have set to the current value by GetValueByTChar. pProperty->SetValueWithType(pProperty->GetValue(eVT_CurrentValue), eVT_CurrentValue, true); } wxMessageBox(_T("修改完成!")); } } }
bool wxPtrButtonEditor::OnEvent( wxPropertyGrid* propGrid, wxPGProperty* property, wxWindow* ctrl, wxEvent& event ) const { if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) { wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary(); CWxwidgetsPropertyBase* pPropertyDescription = static_cast<CWxwidgetsPropertyBase*>(property->GetClientData()); CBDTWxFrame* pMainFrame = static_cast<CBDTWxApp*>(wxApp::GetInstance())->GetMainFrame(); const wxWindow* pButton = NULL; for (uint32_t i = 0; i < buttons->GetCount(); ++i) { if (event.GetId() == buttons->GetButtonId(i)) { pButton = buttons->GetButton(i); break; } } if (pButton != NULL) { if (pPropertyDescription->GetType() == eRPT_Ptr) { CPtrPropertyDescription* pPtrPropertyDescription = static_cast<CPtrPropertyDescription*>(pPropertyDescription); wxString valueStr = property->GetValueAsString(); bool bValueChanged = false; if (pButton->GetLabel().CmpNoCase(_T("+")) == 0) { uint32_t ptrGuid = pPtrPropertyDescription->GetPtrGuid(); std::vector<uint32_t> instanceClassGuid; CComponentProxyManager::GetInstance()->QueryDerivedClass(ptrGuid, instanceClassGuid, true); bValueChanged = instanceClassGuid.size() == 0; if (!bValueChanged) { instanceClassGuid.insert(instanceClassGuid.begin(), ptrGuid); wxPGChoices choice; for (auto i : instanceClassGuid) { CComponentBase* pBase = CComponentProxyManager::GetInstance()->GetComponentTemplate(i); if (pBase != NULL)//If it is NULL, it must be an abstract class. { choice.Add(pBase->GetClassStr(), pBase->GetGuid()); } BEATS_ASSERT(pBase != NULL || CComponentProxyManager::GetInstance()->GetAbstractComponentNameMap().find(i) != CComponentProxyManager::GetInstance()->GetAbstractComponentNameMap().end(), _T("We can't get a template component with guid %d while it can't be found in abstract class map!"), i); } wxString strSelectItem = ::wxGetSingleChoice(wxT("TypeChoice"), wxT("Caption"), choice.GetLabels(), NULL, wxDefaultCoord, wxDefaultCoord, false, wxCHOICE_WIDTH, wxCHOICE_HEIGHT); if ( !strSelectItem.empty() ) { int nSelectIndex = choice.Index(strSelectItem); uint32_t uDerivedGuid = choice.GetValue(nSelectIndex); pPtrPropertyDescription->SetDerivedGuid(uDerivedGuid); bValueChanged = true; } } if (bValueChanged) { bool bCreateInstance = pPtrPropertyDescription->CreateInstance(); BEATS_ASSERT(bCreateInstance); CComponentProxy* pCompBase = static_cast<CComponentProxy*>(pPtrPropertyDescription->GetInstanceComponent()); BEATS_ASSERT(pCompBase != NULL); BEATS_ASSERT(pMainFrame != NULL); TString* pStrValue = (TString*)pPtrPropertyDescription->GetValue(eVT_CurrentValue); property->SetValueFromString(pStrValue->c_str()); pMainFrame->InsertComponentsInPropertyGrid(pCompBase, property); buttons->GetButton(0)->SetLabel(_T("-")); valueStr.insert(0, _T("+")); } } else if (pButton->GetLabel().CmpNoCase(_T("-")) == 0) { property->DeleteChildren(); bool bDeleteInstance = pPtrPropertyDescription->DestroyInstance(true); // Destroy instance may cause the value changed, so we fetch it again. char szTmp[MAX_PATH]; pPtrPropertyDescription->GetValueAsChar(eVT_CurrentValue, szTmp); valueStr = szTmp; pPtrPropertyDescription->GetChildren().clear(); BEATS_ASSERT(bDeleteInstance); buttons->GetButton(0)->SetLabel(_T("+")); bValueChanged = true; } if (bValueChanged) { wxVariant newValue(valueStr); pPtrPropertyDescription->SetValue(newValue, false); property->SetValue(newValue); propGrid->Refresh(); } } if (pPropertyDescription->IsContainerProperty()) { if (pButton->GetLabel().CmpNoCase(_T("+")) == 0) { CPropertyDescriptionBase* pNewChild = pPropertyDescription->AddChild(NULL); if (pNewChild != NULL) { std::vector<CPropertyDescriptionBase*> value; value.push_back(pNewChild); pMainFrame->InsertInPropertyGrid(value, property); } } else if (pButton->GetLabel().CmpNoCase(_T("-")) == 0) { pPropertyDescription->DeleteAllChild(); property->DeleteChildren(); } char valueStr[256]; pPropertyDescription->GetValueAsChar(eVT_CurrentValue, valueStr); property->SetValue(valueStr); property->SetModifiedStatus(pPropertyDescription->GetChildrenCount() > 0); property->RecreateEditor(); } if (pButton->GetLabel().CmpNoCase(_T("x")) == 0) { BEATS_ASSERT(pPropertyDescription->GetParent() != NULL); CPropertyDescriptionBase* pParent = pPropertyDescription->GetParent(); pParent->DeleteChild(pPropertyDescription); // NOTICE: We have deleted this already! pPropertyDescription = NULL; property->SetClientData(NULL); char valueStr[256]; pParent->GetValueAsChar(eVT_CurrentValue, valueStr); property->GetParent()->SetValue(valueStr); //TODO: I can't refresh property here, because we are trying to delete property of which callback we are in. pMainFrame->RequestToUpdatePropertyGrid(); } return true; } } return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event); }