I'm attempting to add some items to a tree list and it's ****ing complicated and frustrating, so I would be extremely grateful for some assistance!
I am attempting to write a new Script Editor utility for the game Operation Flashpoint, and I am using the treeview control to hold the Weapons and Ammunition names in the following format:
EQUIPMENT
--Weapons & Ammunition
..--{Weapon Name}
....--{Ammo Name}
....--{Additional Ammo Name}
Each weapon type will always have at least one Ammo subnode but some may have two. (I hope BI don't add weapons that can use 3 types of ammo, cos then I'm really buggered!)
So far, I have got the weapon and ammo names stored in three arrays and have successfully loaded the Weapon names into the tree list. How the heck do I now load the ammo names in there too? I've been working on it for hours and I'm getting nowhere!!!
The problem that I have is trying to work out in the program which item index I am supposed to be using.
Anyway, here's the code I've got so far:
---
// Create the Tree List
with trvList.Items do
begin
clear;
// Add Root Nodes
add(nil, 'MISSION');
add(nil, 'COMMANDS');
add(nil, 'EQUIPMENT');
// Equipment:
TN := trvList.Items[2];
addchild(TN, 'Weapons & Ammo');
addchild(TN, 'Other');
// Read the Equipment list from the file EQUIPLIST.TXT and add
// to the tree:
TN := trvList.Items[4];
AssignFile(F, 'equiplist.txt');
Reset(F);
while not Eof(F) do
begin
Readln(F, Equip);
addchild(TN, Equip);
end;
CloseFile(F);
// Read the Weapons and Ammunition List from the file WEAPONLIST.TXT.
// Add the Weapons to the treelist and store the weapon name and
// associated ammo to arrays.
TN := trvList.Items[3];
WeapCount := 0;
AmmoCount := 0;
AssignFile(F, 'weaponlist.txt');
Reset(F);
while not eof(F) do
begin
Readln(F, TxtLn);
Weapon := Copy(TxtLn, 1, Pos(',', TxtLn) - 1);
WeapList[WeapCount] := Weapon;
addchild(TN, Weapon);
Ammo := Copy(TxtLn, Pos(',', TxtLn) + 1, Length(TxtLn) - Pos(',', TxtLn));
if Pos('|', Ammo) > 0 then
begin
Ammo2 := Copy(Ammo, Pos('|', Ammo) + 1, Length(Ammo) - Pos('|', Ammo));
Ammo := Copy(Ammo, 1, Pos('|', Ammo) - 1);
AmmoList[WeapCount] := Ammo;
Ammo2List[WeapCount] := Ammo2;
end
else
begin
AmmoList[WeapCount] := Ammo;
Ammo2List[WeapCount] := '';
end;
WeapCount := WeapCount + 1;
end;
CloseFile(F);
[NB - HERE'S WHERE IT STARTS TO GO HORRIBLY WRONG, BUT THIS IS AS CLOSE AS I CAN GET SO FAR!!!]
// Now add the ammunitions to the list.
Ind := 4;
WeapCount := 0;
for I := 1 to 10 do
begin
TN2 := trvList.Items[Ind];
if (Ammo2List[WeapCount] > '') then
begin
addchild(TN2, AmmoList[WeapCount]);
addchild(TN2, Ammo2List[WeapCount]);
AmmoCount := 2;
end
else
begin
addchild(TN2, AmmoList[WeapCount]);
AmmoCount := 1;
end;
WeapCount := WeapCount + 1;
Ind := Ind + WeapCount + AmmoCount;
end;
---
While I await your responses, I am going for a lie down. My head hurts.
Thanks
Gareth
I am attempting to write a new Script Editor utility for the game Operation Flashpoint, and I am using the treeview control to hold the Weapons and Ammunition names in the following format:
EQUIPMENT
--Weapons & Ammunition
..--{Weapon Name}
....--{Ammo Name}
....--{Additional Ammo Name}
Each weapon type will always have at least one Ammo subnode but some may have two. (I hope BI don't add weapons that can use 3 types of ammo, cos then I'm really buggered!)
So far, I have got the weapon and ammo names stored in three arrays and have successfully loaded the Weapon names into the tree list. How the heck do I now load the ammo names in there too? I've been working on it for hours and I'm getting nowhere!!!
The problem that I have is trying to work out in the program which item index I am supposed to be using.
Anyway, here's the code I've got so far:
---
// Create the Tree List
with trvList.Items do
begin
clear;
// Add Root Nodes
add(nil, 'MISSION');
add(nil, 'COMMANDS');
add(nil, 'EQUIPMENT');
// Equipment:
TN := trvList.Items[2];
addchild(TN, 'Weapons & Ammo');
addchild(TN, 'Other');
// Read the Equipment list from the file EQUIPLIST.TXT and add
// to the tree:
TN := trvList.Items[4];
AssignFile(F, 'equiplist.txt');
Reset(F);
while not Eof(F) do
begin
Readln(F, Equip);
addchild(TN, Equip);
end;
CloseFile(F);
// Read the Weapons and Ammunition List from the file WEAPONLIST.TXT.
// Add the Weapons to the treelist and store the weapon name and
// associated ammo to arrays.
TN := trvList.Items[3];
WeapCount := 0;
AmmoCount := 0;
AssignFile(F, 'weaponlist.txt');
Reset(F);
while not eof(F) do
begin
Readln(F, TxtLn);
Weapon := Copy(TxtLn, 1, Pos(',', TxtLn) - 1);
WeapList[WeapCount] := Weapon;
addchild(TN, Weapon);
Ammo := Copy(TxtLn, Pos(',', TxtLn) + 1, Length(TxtLn) - Pos(',', TxtLn));
if Pos('|', Ammo) > 0 then
begin
Ammo2 := Copy(Ammo, Pos('|', Ammo) + 1, Length(Ammo) - Pos('|', Ammo));
Ammo := Copy(Ammo, 1, Pos('|', Ammo) - 1);
AmmoList[WeapCount] := Ammo;
Ammo2List[WeapCount] := Ammo2;
end
else
begin
AmmoList[WeapCount] := Ammo;
Ammo2List[WeapCount] := '';
end;
WeapCount := WeapCount + 1;
end;
CloseFile(F);
[NB - HERE'S WHERE IT STARTS TO GO HORRIBLY WRONG, BUT THIS IS AS CLOSE AS I CAN GET SO FAR!!!]
// Now add the ammunitions to the list.
Ind := 4;
WeapCount := 0;
for I := 1 to 10 do
begin
TN2 := trvList.Items[Ind];
if (Ammo2List[WeapCount] > '') then
begin
addchild(TN2, AmmoList[WeapCount]);
addchild(TN2, Ammo2List[WeapCount]);
AmmoCount := 2;
end
else
begin
addchild(TN2, AmmoList[WeapCount]);
AmmoCount := 1;
end;
WeapCount := WeapCount + 1;
Ind := Ind + WeapCount + AmmoCount;
end;
---
While I await your responses, I am going for a lie down. My head hurts.
Thanks
Gareth