Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 172 additions & 2 deletions DarkEdif/Lib/Shared/DarkEdif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,31 +1301,86 @@ void DarkEdif::DLL::DLL_SetPropValue(mv * mV, EDITDATA * edPtr, unsigned int Pro
case 'INT ': // 4-byte signed int
{
Prop_SInt * prop2 = (Prop_SInt *)prop;
const json_value& propjson = CurLang["Properties"sv][PropID];

if (propjson["Minimum"sv].type != json_none)
{
prop2->Value = std::max((int)(json_int_t)propjson["Minimum"sv], prop2->Value);
}
if (propjson["Maximum"sv].type != json_none)
{
prop2->Value = std::min((int)(json_int_t)propjson["Maximum"sv], prop2->Value);
}
Props.Internal_PropChange(mV, edPtr, PropID, &prop2->Value, sizeof(int));
mvRefreshProp(mV, edPtr, PROPID_EXTITEM_CUSTOM_FIRST + PropID, TRUE);
break;
}
case 'DWRD': // 4-byte unsigned int
{
Prop_UInt * prop2 = (Prop_UInt *)prop;
const json_value& propjson = CurLang["Properties"sv][PropID];

if (propjson["Minimum"sv].type != json_none)
{
prop2->Value = std::max((uint32_t)(json_int_t)propjson["Minimum"sv], prop2->Value);
}
if (propjson["Maximum"sv].type != json_none)
{
prop2->Value = std::min((uint32_t)(json_int_t)propjson["Maximum"sv], prop2->Value);
}
Props.Internal_PropChange(mV, edPtr, PropID, &prop2->Value, sizeof(unsigned int));
mvRefreshProp(mV, edPtr, PROPID_EXTITEM_CUSTOM_FIRST + PropID, TRUE);
break;
}
case 'INT2': // 8-byte signed int
{
Prop_Int64 * prop2 = (Prop_Int64 *)prop;
const json_value& propjson = CurLang["Properties"sv][PropID];

if (propjson["Minimum"sv].type != json_none)
{
prop2->Value = std::max((json_int_t)propjson["Minimum"sv], prop2->Value);
}
if (propjson["Maximum"sv].type != json_none)
{
prop2->Value = std::min((json_int_t)propjson["Maximum"sv], prop2->Value);
}
Props.Internal_PropChange(mV, edPtr, PropID, &prop2->Value, sizeof(std::int64_t));
mvRefreshProp(mV, edPtr, PROPID_EXTITEM_CUSTOM_FIRST + PropID, TRUE);
break;
}
case 'DBLE': // 8-byte floating point var
{
Prop_Double * prop2 = (Prop_Double *)prop;
const json_value& propjson = CurLang["Properties"sv][PropID];

if (propjson["Minimum"sv].type != json_none)
{
prop2->Value = std::max((double)propjson["Minimum"sv], prop2->Value);
}
if (propjson["Maximum"sv].type != json_none)
{
prop2->Value = std::min((double)propjson["Maximum"sv], prop2->Value);
}
Props.Internal_PropChange(mV, edPtr, PropID, &prop2->Value, sizeof(double));
mvRefreshProp(mV, edPtr, PROPID_EXTITEM_CUSTOM_FIRST + PropID, TRUE);
break;
}
case 'FLOT': // 4-byte floating point var
{
Prop_Float * prop2 = (Prop_Float *)prop;
const json_value& propjson = CurLang["Properties"sv][PropID];

if (propjson["Minimum"sv].type != json_none)
{
prop2->Value = std::max((float)(double)propjson["Minimum"sv], prop2->Value);
}
if (propjson["Maximum"sv].type != json_none)
{
prop2->Value = std::min((float)(double)propjson["Maximum"sv], prop2->Value);
}
Props.Internal_PropChange(mV, edPtr, PropID, &prop2->Value, sizeof(float));
mvRefreshProp(mV, edPtr, PROPID_EXTITEM_CUSTOM_FIRST + PropID, TRUE);
break;
}
case 'SIZE': // Two ints depicting a size
Expand Down Expand Up @@ -4760,8 +4815,66 @@ void DarkEdif::DLL::GeneratePropDataFromJSON()
}
}

// Edit box for numbers (does not support min/max)
// Edit box for numbers (does not support min/max natively, but we implement that ourselves)
case PROPTYPE_EDIT_NUMBER:
{
const std::tstring& propName = DarkEdif::UTF8ToTString(Property["Title"sv]);
const json_type& propMinimumType = Property["Minimum"sv].type;
const json_type& propMaximumType = Property["Minimum"sv].type;
const json_type& propDefaultType = Property["DefaultState"sv].type;

if (propDefaultType != json_double && propDefaultType != json_integer)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" is either not specified or isn't a number."), propName.c_str());
}

if (propMaximumType != json_none && propMaximumType != json_double && propMaximumType != json_integer)
{
DarkEdif::MsgBox::Error(_T("Invalid Maximum prop for editbox float"), _T("JSON field \"Maximum\" for prop \"%s\" must be a number."), propName.c_str());
}
if (propMinimumType != json_none && propMinimumType != json_double && propMinimumType != json_integer)
{
DarkEdif::MsgBox::Error(_T("Invalid Minimum prop for editbox float"), _T("JSON field \"Minimum\" for prop \"%s\" must be a number."), propName.c_str());
}

if (propMinimumType != json_none && propMaximumType != json_none)
{
int defaultState = Property["DefaultState"sv];
int minimum = Property["Minimum"sv];
int maximum = Property["Maximum"sv];
if (minimum > maximum)
{
DarkEdif::MsgBox::Error(_T("Invalid Minimum prop for editbox float"), _T("JSON field \"Minimum\" for prop \"%s\" must not be greater than it's maximum.\nMinimum was %d, maximum was %d."), propName.c_str(), minimum, maximum);
}
if (defaultState < minimum)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" is lower than it's minimum value, %d.\nDefaultState was %d."), propName.c_str(), minimum, defaultState);
}
if (defaultState > maximum)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" is greater than it's maximum value, %d.\nDefaultState was %d."), propName.c_str(), maximum, defaultState);
}
}
else if (propMinimumType != json_none)
{
int defaultState = Property["DefaultState"sv];
int minimum = Property["Minimum"sv];
if (defaultState < minimum)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" must not be lower than it's minimum, %d.\nDefaultState was %d."), propName.c_str(), minimum, defaultState);
}
}
else if (propMaximumType != json_none)
{
int defaultState = Property["DefaultState"sv];
int maximum = Property["Maximum"sv];
if (defaultState > maximum)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" must not be greater than it's maximum, %d.\nDefaultState was %d."), propName.c_str(), maximum, defaultState);
}
}
SetAllProps(0, NULL);
}
case PROPTYPE_COLOR:
SetAllProps(0, NULL);

Expand Down Expand Up @@ -4958,9 +5071,66 @@ void DarkEdif::DLL::GeneratePropDataFromJSON()
case PROPTYPE_FONT:
SetAllProps(0, NULL);

// Edit box for floating point numbers (does not support min/max)
// Edit box for floating point numbers (does not natively support min/max, but we implement that ourselves)
case PROPTYPE_EDIT_FLOAT:
{
const std::tstring& propName = DarkEdif::UTF8ToTString(Property["Title"sv]);
const json_type& propMinimumType = Property["Minimum"sv].type;
const json_type& propMaximumType = Property["Minimum"sv].type;
const json_type& propDefaultType = Property["DefaultState"sv].type;

if (propDefaultType != json_double && propDefaultType != json_integer)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" is either not specified or isn't a number."), propName.c_str());
}

if (propMaximumType != json_none && propMaximumType != json_double && propMaximumType != json_integer)
{
DarkEdif::MsgBox::Error(_T("Invalid Maximum prop for editbox float"), _T("JSON field \"Maximum\" for prop \"%s\" must be a number."), propName.c_str());
}
if (propMinimumType != json_none && propMinimumType != json_double && propMinimumType != json_integer)
{
DarkEdif::MsgBox::Error(_T("Invalid Minimum prop for editbox float"), _T("JSON field \"Minimum\" for prop \"%s\" must be a number."), propName.c_str());
}

if (propMinimumType != json_none && propMaximumType != json_none)
{
double defaultState = Property["DefaultState"sv];
double minimum = Property["Minimum"sv];
double maximum = Property["Maximum"sv];
if (minimum > maximum)
{
DarkEdif::MsgBox::Error(_T("Invalid Minimum prop for editbox float"), _T("JSON field \"Minimum\" for prop \"%s\" must not be greater than it's maximum.\nMinimum was %f, maximum was %f."), propName.c_str(), minimum, maximum);
}
if (defaultState < minimum)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" is lower than it's minimum value, %f.\nDefaultState was %f."), propName.c_str(), minimum, defaultState);
}
if (defaultState > maximum)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" is greater than it's maximum value, %f.\nDefaultState was %f."), propName.c_str(), maximum, defaultState);
}
}
else if (propMinimumType != json_none)
{
double defaultState = Property["DefaultState"sv];
double minimum = Property["Minimum"sv];
if (defaultState < minimum)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" must not be lower than it's minimum, %f.\nDefaultState was %f."), propName.c_str(), minimum, defaultState);
}
}
else if (propMaximumType != json_none)
{
double defaultState = Property["DefaultState"sv];
double maximum = Property["Maximum"sv];
if (defaultState > maximum)
{
DarkEdif::MsgBox::Error(_T("Invalid DefaultState for editbox float"), _T("JSON field \"DefaultState\" for prop \"%s\" must not be greater than it's maximum, %f.\nDefaultState was %f."), propName.c_str(), maximum, defaultState);
}
}
SetAllProps(0, NULL);
}

// Image list
case PROPTYPE_IMAGELIST:
Expand Down