Foreach (line.contains("id") in reader.readline())

recently i started to make a user-interface manager based on .nui file(s),

they look like this :

begin genwnd
id = addinformation_creature;
spr = ui_frame.spr;
rect = 0,0,220,319;
style = KSTYLE_NOCLOSE | KSTYLE_NOMINIMIZE | KSTYLE_NORESIZE | KSTYLE_NOTITLE | KSTYLE_NOSTATUSBAR | KSTYLE_NOTOPFRAME | KSTYLE_MOVE_BY_CUSTOM | KSTYLE_VERTICAL_REPEAT ;
end

begin static
id = addcreature_subtitle01;
spr = ui_frame.spr;
ani = background_infocommon_subtitle2;
pos = 17,0;
flag = KFLAG_NO_GET_MESSAGE ;
end

now doing my reader, i have occured a problem (due to static) i coded everything dynamicly in a treeview so far, and i've been succesfull adding them under the right node.

however ; static occurs about 60 to 70 time(s) if not more, with the id,spr,ani,pos,flag below it as 'childs'.

i've been unable to add them under each dynamicly created 'id'(head-node) i tried various ways.

the code i use is plain and simple, how ever it needs a few tweaks i just cant seem to figure it out.

#region Begin Static
case "begin static":
/// <summary= begin static> here we read the window <see static>
/// <param= end> read till end of the file where <end> is the variable to stop at.
/// <param= id> read <id> for the name in <treeview>.
/// <param= pos> read <rect> for the sizes in <treeview> (X,Y).
/// <param= ani> read <ani> for the animation script in <treeview>.
#region reading...
while ((line = reader.ReadLine()) != "end")
{
int a = 0;
if (line.Contains("id = "))
{
string str = line;
int startIndex = str.IndexOf("id = ") + "id = ".Length;
int endIndex = str.IndexOf(";");
Form1.Instance.treeView1.Nodes[0].Nodes.Add("Picture: " + str.Substring(startIndex, endIndex - startIndex).ToString());
a = a + 1;
}

if (line.Contains("ani = "))
{
string str1 = line;
int startIndex1 = str1.IndexOf("ani = ") + "ani = ".Length;
int endIndex1 = str1.IndexOf(";");
Form1.Instance.treeView1.Nodes[0].Nodes[1].Nodes.Add("Animation: " + str1.Substring(startIndex1, endIndex1 - startIndex1).ToString());

}


if (line.Contains("pos = "))
{
string str2 = line;
int startIndex2 = str2.IndexOf("pos = ") + "pos = ".Length;
int endIndex2 = str2.IndexOf(";");
Form1.Instance.treeView1.Nodes[0].Nodes[1].Nodes.Add("Position");
//Form1.Instance.treeView1.Nodes[i].Nodes.Add("Position: " + str.Substring(startIndex, endIndex - startIndex).ToString());

}


if (line.Contains("flag = "))
{
string str3 = line;
int startIndex3 = str3.IndexOf("flag = ") + "flag = ".Length;
int endIndex3 = str3.IndexOf(";");
Form1.Instance.treeView1.Nodes[0].Nodes[1].Nodes.Add("Flags: " + str3.Substring(startIndex3, endIndex3 - startIndex3).ToString());
}
 }
 break;

as you see, it placed the node's perfectly, but all childs are inside node 1 but the childs have to be repeated, eg(spr,ani,pos,flag as childs) for each node.

enter image description here

Jon Skeet
people
quotationmark

It's not really clear what you mean, but I suspect you just want to keep a reference to the "current node" - which you change when you get a new ID. So:

TreeNode node = null;

while ((line = reader.ReadLine()) != "end")
{
    if (line.Contains("id"))
    {
         ...
         // Note how you don't need to call ToString() on the result of Substring
         node = Form1.Instance.treeView1.Noodes[0].Nodes.Add("Picture: " + 
             str.Substring(startIndex, endIndex - startIndex));
    }
    else if (line.Contains("ani = "))
    {
        ...
        node.Add(...);
    }
}

This will fail if you get a line before the id line, admittedly... but presumably the id is always the first line within a section.

people

See more on this question at Stackoverflow