From d2070318edd4323ba2fd9cecf41e476c0277a48d Mon Sep 17 00:00:00 2001 From: Zero Fanker Date: Wed, 3 Apr 2024 23:59:51 -0400 Subject: [PATCH] more progress of adaption . --- MissionEditor/AITriggerAddDlg.cpp | 7 +- MissionEditor/AITriggerTypes.cpp | 190 +++++++------------------ MissionEditor/AiTriggerTypesEnable.cpp | 67 ++++----- MissionEditor/All.cpp | 50 +++---- 4 files changed, 112 insertions(+), 202 deletions(-) diff --git a/MissionEditor/AITriggerAddDlg.cpp b/MissionEditor/AITriggerAddDlg.cpp index 5f1b6e8..4535c0e 100644 --- a/MissionEditor/AITriggerAddDlg.cpp +++ b/MissionEditor/AITriggerAddDlg.cpp @@ -71,9 +71,10 @@ BOOL CAITriggerAddDlg::OnInitDialog() CListBox* lb=(CListBox*)GetDlgItem(IDC_AITRIGGERS); int i; - for(i=0;iAddString(*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 diff --git a/MissionEditor/AITriggerTypes.cpp b/MissionEditor/AITriggerTypes.cpp index 8e2b6fd..a5ebe09 100644 --- a/MissionEditor/AITriggerTypes.cpp +++ b/MissionEditor/AITriggerTypes.cpp @@ -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;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - - ss="VehicleTypes"; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - - ss="AircraftTypes"; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - - ss="BuildingTypes"; - for(i=0;iGetUnitName((char*)(LPCTSTR)type); - - s+=")"; - m_UnitType.AddString(s); - } - for(i=0;iGetUnitName((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+=""; } @@ -599,18 +507,18 @@ void CAITriggerTypes::OnAdd() data+=",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+="";//*ini.sections["TeamTypes"].GetValue(0); - } - else + //if(ini.sections["TeamTypes"].values.size()>0) + //{ + // data+="";//*ini.sections["TeamTypes"].GetValue(0); + //} + //else { data+=""; } 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(); } diff --git a/MissionEditor/AiTriggerTypesEnable.cpp b/MissionEditor/AiTriggerTypesEnable.cpp index f534b8b..de9b03e 100644 --- a/MissionEditor/AiTriggerTypesEnable.cpp +++ b/MissionEditor/AiTriggerTypesEnable.cpp @@ -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;iGetIniFile(); int i; - for(i=0;i=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(); } diff --git a/MissionEditor/All.cpp b/MissionEditor/All.cpp index a95ce2c..9a2f9c2 100644 --- a/MissionEditor/All.cpp +++ b/MissionEditor/All.cpp @@ -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=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);