add rear diff ratio to setup menu and fix params with no units

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6896 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 1520154143244388831772a5be35dda53714a2c7
Former-commit-id: 86ad8192c31f2d33252cf859de2c08775c5572dd
This commit is contained in:
iobyte 2020-04-08 16:09:10 +00:00
parent ed4858d31f
commit b5a6ce554d
2 changed files with 35 additions and 13 deletions

View file

@ -78,6 +78,7 @@ void CarSetupMenu::onReset(void *pMenu)
pCarSetupMenu->rearWing.value = pCarSetupMenu->rearWing.defaultValue;
pCarSetupMenu->rearDiffSlip.value = pCarSetupMenu->rearDiffSlip.defaultValue;
pCarSetupMenu->rearDiffCoastSlip.value = pCarSetupMenu->rearDiffCoastSlip.defaultValue;
pCarSetupMenu->rearDiffRatio.value = pCarSetupMenu->rearDiffRatio.defaultValue;
pCarSetupMenu->updateControls();
}
@ -87,7 +88,7 @@ void CarSetupMenu::updateControl(const attnum &att)
if (att.exists)
{
std::ostringstream ossValue;
ossValue << std::fixed << std::setprecision(1) << att.value;
ossValue << std::fixed << std::setprecision(att.precision) << att.value;
GfuiEditboxSetString(getMenuHandle(), att.editId, ossValue.str().c_str());
if (att.minValue == att.maxValue)
@ -111,11 +112,13 @@ void CarSetupMenu::updateControls()
updateControl(rearWing);
updateControl(rearDiffSlip);
updateControl(rearDiffCoastSlip);
updateControl(rearDiffRatio);
}
void CarSetupMenu::loadSetting(const char *label, const char *edit, const char *defaultLabel,
void *hparmCar, void *hparmCarSetup, attnum &att,
const char *section, const char *param, const char *labelStr, const char *units)
const char *section, const char *param, const char *labelStr,
const char *units, int precision)
{
att.labelId = getDynamicControlId(label);
att.editId = getDynamicControlId(edit);
@ -123,10 +126,14 @@ void CarSetupMenu::loadSetting(const char *label, const char *edit, const char *
att.section = section;
att.param = param;
att.units = units;
att.precision = precision;
// Set label text.
std::ostringstream ossLabel;
ossLabel << labelStr << " (" << units << ")";
ossLabel << labelStr;
if (!att.units.empty())
ossLabel << " (" << att.units << ")";
ossLabel << ":";
GfuiLabelSetText(getMenuHandle(),
att.labelId,
ossLabel.str().c_str());
@ -144,12 +151,12 @@ void CarSetupMenu::loadSetting(const char *label, const char *edit, const char *
// Check for missing min and max.
if (att.minValue == att.maxValue)
{
ossLabel << std::fixed << std::setprecision(1)
ossLabel << std::fixed << std::setprecision(att.precision)
<< "Default: " << att.defaultValue;
}
else
{
ossLabel << std::fixed << std::setprecision(1)
ossLabel << std::fixed << std::setprecision(att.precision)
<< "Min: " << att.minValue
<< " Default: " << att.defaultValue
<< " Max: " << att.maxValue;
@ -207,21 +214,29 @@ void CarSetupMenu::loadSettings()
GfLogInfo("Opened car setup file: %s\n", ossCarSetupFileName.str().c_str());
loadSetting("BrakeBiasLabel", "BrakeBiasEdit", "BrakeBiasDefaultLabel",
hparmCar, hparmCarSetup, brakeRepartition, SECT_BRKSYST, PRM_BRKREP, "Brake Bias", "%");
hparmCar, hparmCarSetup, brakeRepartition, SECT_BRKSYST, PRM_BRKREP,
"Brake Bias", "%", 1);
loadSetting("FrontARBLabel", "FrontARBEdit", "FrontARBDefaultLabel",
hparmCar, hparmCarSetup, frontARB, SECT_FRNTARB, PRM_SPR, "Front Anti-Roll Bar", "kN/m");
hparmCar, hparmCarSetup, frontARB, SECT_FRNTARB, PRM_SPR,
"Front Anti-Roll Bar", "kN/m", 1);
loadSetting("RearARBLabel", "RearARBEdit", "RearARBDefaultLabel",
hparmCar, hparmCarSetup, rearARB, SECT_REARARB, PRM_SPR, "Rear Anti-Roll Bar", "kN/m");
hparmCar, hparmCarSetup, rearARB, SECT_REARARB, PRM_SPR,
"Rear Anti-Roll Bar", "kN/m", 1);
loadSetting("FrontWingLabel", "FrontWingEdit", "FrontWingDefaultLabel",
hparmCar, hparmCarSetup, frontWing, SECT_FRNTWING, PRM_WINGANGLE, "Front Wing Angle", "deg");
hparmCar, hparmCarSetup, frontWing, SECT_FRNTWING, PRM_WINGANGLE,
"Front Wing Angle", "deg", 1);
loadSetting("RearWingLabel", "RearWingEdit", "RearWingDefaultLabel",
hparmCar, hparmCarSetup, rearWing, SECT_REARWING, PRM_WINGANGLE, "Rear Wing Angle", "deg");
hparmCar, hparmCarSetup, rearWing, SECT_REARWING, PRM_WINGANGLE,
"Rear Wing Angle", "deg", 1);
loadSetting("RearDiffSlipLabel", "RearDiffSlipEdit", "RearDiffSlipDefaultLabel",
hparmCar, hparmCarSetup, rearDiffSlip, SECT_REARDIFFERENTIAL, PRM_MAX_SLIP_BIAS,
"Rear Diff Max Slip Bias", "%");
"Rear Diff Max Slip Bias", "%", 1);
loadSetting("RearDiffCoastSlipLabel", "RearDiffCoastSlipEdit", "RearDiffCoastSlipDefaultLabel",
hparmCar, hparmCarSetup, rearDiffCoastSlip, SECT_REARDIFFERENTIAL, PRM_COAST_MAX_SLIP_BIAS,
"Rear Diff Coast Max Slip Bias", "%");
"Rear Diff Coast Max Slip Bias", "%", 1);
loadSetting("RearDiffRatioLabel", "RearDiffRatioEdit", "RearDiffRatioDefaultLabel",
hparmCar, hparmCarSetup, rearDiffRatio, SECT_REARDIFFERENTIAL, PRM_RATIO,
"Rear Diff Ratio", "", 3);
// Close the XML file of the car.
GfParmReleaseHandle(hparmCar);
@ -286,6 +301,7 @@ void CarSetupMenu::storeSettings()
storeSetting(hparmCarSetup, rearWing);
storeSetting(hparmCarSetup, rearDiffSlip);
storeSetting(hparmCarSetup, rearDiffCoastSlip);
storeSetting(hparmCarSetup, rearDiffRatio);
// Write the XML file of the car setup.
GfParmWriteFile(NULL, hparmCarSetup, strCarId.c_str());
@ -343,6 +359,10 @@ bool CarSetupMenu::initialize(void *pMenu, const GfRace *pRace, const GfDriver *
createEditControl("RearDiffCoastSlipEdit", this, NULL, NULL);
createLabelControl("RearDiffCoastSlipDefaultLabel");
createLabelControl("RearDiffRatioLabel");
createEditControl("RearDiffRatioEdit", this, NULL, NULL);
createLabelControl("RearDiffRatioDefaultLabel");
createButtonControl("ApplyButton", this, onAccept);
createButtonControl("CancelButton", this, onCancel);
createButtonControl("ResetButton", this, onReset);

View file

@ -72,6 +72,7 @@ protected:
std::string section;
std::string param;
std::string units;
int precision;
attnum() :
labelId(0), editId(0), defaultLabelId(0), exists(false),
@ -84,7 +85,7 @@ protected:
void loadSetting(const char *label, const char *edit, const char *defaultLabel,
void *hparmCar, void *hparmCarSetup, attnum &att,
const char *section, const char *param, const char *labelStr,
const char *units);
const char *units, int precision);
void storeSetting(void *hparmCarSetup, attnum &att);
attnum brakeRepartition;
@ -94,6 +95,7 @@ protected:
attnum rearWing;
attnum rearDiffSlip;
attnum rearDiffCoastSlip;
attnum rearDiffRatio;
};
#endif /* _CARSETUPMENU_H_ */