more progress of adaption .

This commit is contained in:
Zero Fanker 2024-04-03 23:59:51 -04:00
parent ca20863dc1
commit d2070318ed
4 changed files with 112 additions and 202 deletions

View file

@ -71,9 +71,10 @@ BOOL CAITriggerAddDlg::OnInitDialog()
CListBox* lb=(CListBox*)GetDlgItem(IDC_AITRIGGERS);
int i;
for(i=0;i<ai.sections["AITriggerTypes"].values.size();i++)
{
lb->AddString(*ai.sections["AITriggerTypes"].GetValueName(i)+ (CString)" " +GetParam(*ai.sections["AITriggerTypes"].GetValue(i), 0));
for (i = 0; i < ai["AITriggerTypes"].Size(); i++) {
auto const& section = ai.GetSection("AITriggerTypes");
auto const& valuePair = section.Nth(i);
lb->AddString(valuePair.first + (CString)" " + GetParam(valuePair.second, 0));
}
return TRUE; // return TRUE unless you set the focus to a control

View file

@ -151,122 +151,26 @@ END_MESSAGE_MAP()
void ListObjects(CComboBox& cb)
{
CComboBox& m_UnitType=cb;
CIniFile& ini=Map->GetIniFile();
CComboBox& m_UnitType = cb;
CIniFile& ini = Map->GetIniFile();
int i;
auto addToUnitTypeByIni = [&m_UnitType](CIniFile& ini, const CString& sectionName) {
for (auto const& item : ini.GetSection(sectionName)) {
auto const& type = item.second;
auto const desc = type +
" (" + Map->GetUnitName(type) + ")";
m_UnitType.AddString(desc);
}
};
auto addToUnitType = [&ini, &addToUnitTypeByIni](const CString& sectionName) {
addToUnitTypeByIni(rules, sectionName);
addToUnitTypeByIni(ini, sectionName);
};
CString ss="InfantryTypes";
for(i=0;i<rules.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*rules.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
for(i=0;i<ini.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*ini.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
ss="VehicleTypes";
for(i=0;i<rules.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*rules.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
for(i=0;i<ini.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*ini.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
ss="AircraftTypes";
for(i=0;i<rules.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*rules.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
for(i=0;i<ini.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*ini.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
ss="BuildingTypes";
for(i=0;i<rules.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*rules.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
for(i=0;i<ini.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*ini.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
addToUnitType("InfantryTypes");
addToUnitType("VehicleTypes");
addToUnitType("AircraftTypes");
addToUnitType("BuildingTypes");
}
void CAITriggerTypes::UpdateDialog()
@ -347,9 +251,9 @@ void CAITriggerTypes::OnSelchangeAitriggertype()
m_Enabled=FALSE;
CIniFile& ini=Map->GetIniFile();
if(ini.sections["AITriggerTypesEnable"].values.find((LPCTSTR)aitrigger)!=ini.sections["AITriggerTypesEnable"].values.end())
if(stricmp(ini.sections["AITriggerTypesEnable"].values[(LPCTSTR)aitrigger], "yes")==NULL)
m_Enabled=TRUE;
if (ini.GetBool("AITriggerTypesEnable", aitrigger)) {
m_Enabled = TRUE;
}
AITrigInfo info;
info=ConvertToAITrigInfoFromHex((char*)(LPCSTR)aitt.data);
@ -541,34 +445,41 @@ void CAITriggerTypes::OnEnabled()
UpdateData();
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
if (sel < 0) {
return;
}
CString aitrigger;
m_AITriggerType.GetLBText(sel,aitrigger);
TruncSpace(aitrigger);
CIniFile& ini=Map->GetIniFile();
if(m_Enabled)
{
if(m_Enabled) {
// enable it
ini.sections["AITriggerTypesEnable"].values[(LPCTSTR)aitrigger]="yes";
ini.SetBool("AITriggerTypesEnable", aitrigger, true);
} else {
if (auto const pSec = ini.TryGetSection("AITriggerTypesEnable")) {
pSec->RemoveByKey(aitrigger);
}
}
else
ini.sections["AITriggerTypesEnable"].values.erase((LPCTSTR)aitrigger);
}
void CAITriggerTypes::SetAITriggerParam(const char *value, int param)
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
if (sel < 0) {
return;
}
CString aitrigger;
m_AITriggerType.GetLBText(sel,aitrigger);
TruncSpace(aitrigger);
CIniFile& ini=Map->GetIniFile();
ini.sections["AITriggerTypes"].values[aitrigger]=SetParam(ini.sections["AITriggerTypes"].values[aitrigger],param,value);
if (auto const pSec = ini.TryGetSection("AITriggerTypes")) {
pSec->SetString(aitrigger, SetParam(pSec->GetString(aitrigger), param, value));
}
}
void CAITriggerTypes::OnAdd()
@ -578,12 +489,9 @@ void CAITriggerTypes::OnAdd()
CString data="New AI Trigger,";
// now try to set a teamtype
if(ini.sections["TeamTypes"].values.size()>0)
{
data+=*ini.sections["TeamTypes"].GetValue(0);
}
else
{
if (ini["TeamTypes"].Size()>0) {
data+=*ini["TeamTypes"].Nth(0).second;
} else {
data+="<none>";
}
@ -599,18 +507,18 @@ void CAITriggerTypes::OnAdd()
data+="<none>,0000000000000000000000000000000000000000000000000000000000000000,50.000000,30.000000,50.000000,1,0,1,1,";
// a pool seems to need both teamtypes the same
if(ini.sections["TeamTypes"].values.size()>0)
{
data+="<none>";//*ini.sections["TeamTypes"].GetValue(0);
}
else
//if(ini.sections["TeamTypes"].values.size()>0)
//{
// data+="<none>";//*ini.sections["TeamTypes"].GetValue(0);
//}
//else
{
data+="<none>";
}
data+=",1,1,1";
ini.sections["AITriggerTypes"].values[ID]=data;
ini.SetString("AITriggerTypes", ID, data);
UpdateDialog();
@ -639,10 +547,10 @@ void CAITriggerTypes::OnDelete()
m_AITriggerType.GetLBText(sel,aitrigger);
TruncSpace(aitrigger);
CIniFile& ini=Map->GetIniFile();
CIniFile& ini = Map->GetIniFile();
ini.sections["AITriggerTypes"].values.erase(aitrigger);
ini.sections["AITriggerTypesEnable"].values.erase(aitrigger);
ini.RemoveValueByKey("AITriggerTypes", aitrigger);
ini.RemoveValueByKey("AITriggerTypesEnable", aitrigger);
UpdateDialog();
}

View file

@ -80,29 +80,27 @@ void CAiTriggerTypesEnable::UpdateDialog()
while(m_AITriggerType.DeleteString(0)!=CB_ERR);
CIniFile& ini=Map->GetIniFile();
CIniFile& ini = Map->GetIniFile();
int i;
for(i=0;i<ini.sections["AITriggerTypesEnable"].values.size();i++)
{
CString aitrigger=*ini.sections["AITriggerTypesEnable"].GetValueName(i);
CString str=aitrigger;
for(auto const[aitrigger, val] : ini["AITriggerTypesEnable"]) {
CString str = aitrigger;
str+=" (";
if(ai.sections["AITriggerTypes"].values.find(aitrigger)!=ai.sections["AITriggerTypes"].values.end())
{
// standard ai trigger
str+=GetParam(ai.sections["AITriggerTypes"].values[aitrigger],0);
str+=" -> ";
str+=*ini.sections["AITriggerTypesEnable"].GetValue(i);
}
if(ini.sections["AITriggerTypes"].values.find(aitrigger)!=ini.sections["AITriggerTypes"].values.end())
{
str+=GetParam(ini.sections["AITriggerTypes"].values[aitrigger],0);
str+=" -> ";
str+=*ini.sections["AITriggerTypesEnable"].GetValue(i);
// parse from map definition first
auto const& aiDef = ini.GetString("AITriggerTypes", aitrigger);
if (!aiDef.IsEmpty()) {
str += GetParam(aiDef, 0);
str += " -> ";
str += val;
} else {
// if not found, try retrieving from global AI ini
auto const& aiDef = ai.GetString("AITriggerTypes", aitrigger);
if (!aiDef.IsEmpty()) {
// standard ai trigger
str += GetParam(aiDef, 0);
str += " -> ";
str += val;
}
}
str+=")";
@ -122,9 +120,8 @@ void CAiTriggerTypesEnable::OnEnableall()
// enable all standard ai triggers
CIniFile& ini=Map->GetIniFile();
int i;
for(i=0;i<ai.sections["AITriggerTypes"].values.size();i++)
{
ini.sections["AITriggerTypesEnable"].values[*ai.sections["AITriggerTypes"].GetValueName(i)]="yes";
for (auto const& [id, def] : ai["AITriggerTypes"]) {
ini.SetBool("AITriggerTypesEnable", id, true);
}
UpdateDialog();
@ -140,31 +137,35 @@ void CAiTriggerTypesEnable::OnSelchangeAitriggertype()
void CAiTriggerTypesEnable::OnDelete()
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
if (sel < 0) {
return;
}
CString aitrigger;
m_AITriggerType.GetLBText(sel,aitrigger);
if(aitrigger.Find(" ")>=0) aitrigger.SetAt(aitrigger.Find(" "), 0);
if (aitrigger.Find(" ") >= 0) {
aitrigger.SetAt(aitrigger.Find(" "), 0);
}
CIniFile& ini=Map->GetIniFile();
ini.sections["AITriggerTypesEnable"].values.erase((LPCTSTR)aitrigger);
ini.RemoveValueByKey("AITriggerTypesEnable", aitrigger);
UpdateDialog();
}
void CAiTriggerTypesEnable::OnAdd()
{
//CString p=InputBox("Please enter the ID of the AITriggerType (for a list of all AITriggerType-IDs use the All-Section)","Enable AITriggerType");
//CString newTriggerId=InputBox("Please enter the ID of the AITriggerType (for a list of all AITriggerType-IDs use the All-Section)","Enable AITriggerType");
CAITriggerAddDlg dlg;
if(dlg.DoModal()==IDCANCEL) return;
CString p=dlg.m_AITrigger;
TruncSpace(p);
if(p.GetLength()==0) return;
CString newTriggerId = dlg.m_AITrigger;
TruncSpace(newTriggerId);
if (newTriggerId.GetLength() == 0) {
return;
}
CIniFile& ini=Map->GetIniFile();
ini.sections["AITriggerTypesEnable"].values[p]="yes";
ini.SetBool("AITriggerTypesEnable", newTriggerId, true);
UpdateDialog();
}

View file

@ -95,11 +95,10 @@ void CAll::UpdateDialog()
m_Value.SetWindowText("");
int i;
for(i=ini.sections.size()-1;i>=0;i--)
{
const CString* name=ini.GetSectionName(i);
if(!Map->IsMapSection(*name))
m_Sections.InsertString(0, *name);
for (auto const& [name, sec] : ini) {
if (!Map->IsMapSection(name)) {
m_Sections.InsertString(-1, name);
}
}
m_Sections.SetCurSel(1);
@ -119,10 +118,8 @@ void CAll::OnSelchangeSections()
int i;
m_Keys.SetRedraw(FALSE);
SetCursor(LoadCursor(0,IDC_WAIT));
for(i=0;i<ini.sections[cuSection].values.size();i++)
{
const CString* name=ini.sections[cuSection].GetValueName(i);
m_Keys.InsertString(-1, *name);
for(auto const&[key, val] : ini[cuSection]) {
m_Keys.InsertString(-1, key);
}
SetCursor(m_hArrowCursor);
@ -144,11 +141,11 @@ void CAll::OnChangeValue()
CString cuKey;
if(m_Keys.GetCurSel()>=0)m_Keys.GetText(m_Keys.GetCurSel(), cuKey) ;
if (m_Keys.GetCurSel() >= 0) {
m_Keys.GetText(m_Keys.GetCurSel(), cuKey);
}
ini.sections[cuSection].values[cuKey]=t;
ini.SetString(cuSection, cuKey, t);
}
@ -162,7 +159,7 @@ void CAll::OnSelchangeKeys()
CString cuKey;
m_Keys.GetText(m_Keys.GetCurSel(), cuKey) ;
m_Value.SetWindowText(ini.sections[cuSection].values[cuKey]);
m_Value.SetWindowText(ini.GetString(cuSection, cuKey));
}
void CAll::OnUpdateValue()
@ -172,11 +169,11 @@ void CAll::OnUpdateValue()
void CAll::OnAddsection()
{
CString name=InputBox("Please set the name of the new section (the section may already exist)", "Insert Section");
CString name = InputBox("Please set the name of the new section (the section may already exist)", "Insert Section");
CIniFile& ini=Map->GetIniFile();
CIniFile& ini = Map->GetIniFile();
CIniFileSection stub=ini.sections[(LPCTSTR)name];
ini.AddSection(name);
UpdateDialog();
}
@ -187,7 +184,7 @@ void CAll::OnDeletesection()
int cusection;
cusection=m_Sections.GetCurSel();
if(cusection==-1) {
if (cusection==-1) {
MessageBox("You cannot delete a section without choosing one.");
return;
}
@ -195,9 +192,11 @@ void CAll::OnDeletesection()
CString str;
m_Sections.GetLBText(cusection, str);
if(MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete section", MB_YESNO)==IDNO) return;
if (MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete section", MB_YESNO) == IDNO) {
return;
}
ini.sections.erase(str);
ini.DeleteSection(str);
UpdateDialog();
}
@ -220,9 +219,11 @@ void CAll::OnDeletekey()
m_Sections.GetLBText(cuSection, sec);
m_Keys.GetText(cukey, str);
if(MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete key", MB_YESNO)==IDNO) return;
if (MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete key", MB_YESNO) == IDNO) {
return;
}
ini.sections[sec].values.erase(str);
ini.RemoveValueByKey(sec, str);
UpdateDialog();
@ -246,15 +247,14 @@ void CAll::OnAddkey()
CString key, value;
key=InputBox("Please set the name and value for the current key here: (for example, setting a new key ""Strength"" with the value 200 can be written as ""Strength=200"". You don´t need to specify a value.)", "Create key");
if(key.Find("=")!=-1)
{
if (key.Find("=") != -1) {
// value specified
// MW BUGFIX
value=key.Right(key.GetLength()-key.Find("=")-1);
key=key.Left(key.Find("="));
}
ini.sections[sec].values[key]=value;
ini.SetString(sec, key, value);
UpdateDialog();
m_Sections.SetCurSel(cusection);