Enum fixes

This commit is contained in:
parax0 2015-10-25 16:44:25 -06:00
parent 1dcfa63f3c
commit 8470923e45
3 changed files with 18 additions and 8 deletions

View File

@ -59,9 +59,10 @@ CPropertyStruct* CScriptLoader::LoadStructMP1(CInputStream& SCLY, CStructTemplat
break;
}
case eEnumProperty: {
CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pPropTmp);
long ID = SCLY.ReadLong();
long index = pTemp->EnumeratorIndex(ID);
CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pPropTmp);
u32 ID = SCLY.ReadLong();
u32 index = pEnumTemp->EnumeratorIndex(ID);
if (index == -1) Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + StringUtil::ToHexString(ID, true, true, 8));
pProp = new CEnumProperty(index);
break;
}
@ -274,9 +275,10 @@ void CScriptLoader::LoadStructMP2(CInputStream& SCLY, CPropertyStruct *pStruct,
case eEnumProperty: {
CEnumProperty *pEnumCast = static_cast<CEnumProperty*>(pProp);
CEnumTemplate *pTemp = static_cast<CEnumTemplate*>(pPropTemp);
long ID = SCLY.ReadLong();
long index = pTemp->EnumeratorIndex(ID);
CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pPropTemp);
u32 ID = SCLY.ReadLong();
u32 index = pEnumTemp->EnumeratorIndex(ID);
if (index == -1) Log::FileError(SCLY.GetSourceString(), SCLY.Tell() - 4, "Enum property \"" + pEnumTemp->Name() + "\" in struct \"" + pTemp->Name() + "\" has invalid enumerator value: " + StringUtil::ToHexString(ID, true, true, 8));
pEnumCast->Set(index);
break;
}

View File

@ -154,9 +154,16 @@ EVolumeShape CScriptTemplate::VolumeShape(CScriptObject *pObj)
break;
case eLongProperty:
case eEnumProperty:
v = (int) static_cast<CLongProperty*>(pProp)->Get();
break;
case eEnumProperty: {
CEnumProperty *pEnumCast = static_cast<CEnumProperty*>(pProp);
CEnumTemplate *pEnumTemp = static_cast<CEnumTemplate*>(pEnumCast->Template());
int index = static_cast<CEnumProperty*>(pProp)->Get();
v = pEnumTemp->EnumeratorID(index);
break;
}
}
// Test and check whether any of the conditions are true

View File

@ -148,7 +148,8 @@ void WPropertyEditor::CreateEditor()
pComboBox->addItem(QString::fromStdString(name));
}
pComboBox->setCurrentIndex(pEnumCast->Get());
u32 index = pEnumCast->Get();
if (index < pTemplate->NumEnumerators()) pComboBox->setCurrentIndex(index);
pComboBox->setFocusPolicy(Qt::StrongFocus);
pComboBox->setContextMenuPolicy(Qt::NoContextMenu);