Page 1 of 1
Tree views and tag info
Posted: Sat Dec 15, 2007 11:10 pm
by Patrickh
I'm trying to get together a basic map file loader, and here's what I have so far:
reads headers and tags
loads them into a list box
opens ce or pc
However, I cant figure out how to put the tags into a tree view.
Im loading the tags by doing a loop where it reads one tag each time around, setting variables for the tag classes, meta offsets, name, etc., and i put the tags into the listbox by simply telling it to add the primary tagclass and name at the end of each loop.
Am i on the right track to putting them into a tree view?
Also, I'm not sure how to store the information from each tag. What I'm looking for is this: loading the tags into a tree view, then when you click on one, it displays some of the info i read earlier, like the classes, offsets, and such
I'm using vb, but you don't need to give me code, just the idea of what to do
here's what i have so far:
Any help is much appreciated!
Posted: Sun Dec 16, 2007 8:04 am
by grimdoomer
well if you add them to a treeview, you willl have that entire line the offset, tag class, and path. What you should dp is make it like tag classes then you exspand them and there are all the tags of that class.
Posted: Sun Dec 16, 2007 9:04 am
by Patrickh
grimdoomer wrote:well if you add them to a treeview, you willl have that entire line the offset, tag class, and path. What you should dp is make it like tag classes then you exspand them and there are all the tags of that class.
yes, but how? I have never used tree views before
Posted: Sun Dec 16, 2007 10:49 am
by Patrickssj6
Wait, you just cracked the magic of Halo maps...but you don't know how to populate a tree view? xD
No sorry, that's irony.
Posted: Sun Dec 16, 2007 12:58 pm
by Patrickh
Patrickssj6 wrote:Wait, you just cracked the magic of Halo maps...but you don't know how to populate a tree view? xD
No sorry, that's irony.
thats pretty much it >_>
so do you know how? you're good at vb, if i send you my source could you look at my method for loading the map and then determine a way to load it into a tree view?
Posted: Sun Dec 16, 2007 1:45 pm
by grimdoomer
ill help you but only on aim.
Posted: Sun Dec 16, 2007 1:54 pm
by Prey
grimdoomer wrote:ill help you but only on aim.
Halomods is not good enough?..
Anyway,
Treeviews are easy. Just loop through the main classes, make a node for each, loop through the tags, add the tag if it's of the same class, repeat..
Posted: Sun Dec 16, 2007 4:24 pm
by Patrickh
thanks for the link, prey. I was able to figure it out from there
Onward to my next problem: being able to click on a tag and retrieve it's attributes. would i create some sort of arraylist and then add to it as I loop through the tags? Once again, I'm a beginner programmer and could use some examples. Thanks for the help!
Posted: Sun Dec 16, 2007 4:38 pm
by grimdoomer
create a TreeView1_AfterSelect meathod then, you can get the tag path by doing Me.TreeView1.SelectedNodes.Text
Posted: Sun Dec 16, 2007 6:00 pm
by Patrickh
I know how to do that, but that can only return the tag's name. what I'm looking for is this:
when loading the tags, for each tag, I found some info, like the classes, meta offsets, etc. I want to be able to retrieve that info when I click on a tag... so I click on the warthog's tag and I can display it's meta offset in a textbox or something.
Posted: Sun Dec 16, 2007 6:51 pm
by grimdoomer
create a function and add this once you read it you will be able to make others,
Code: Select all
Public Function FindTagIndexByPath(ByVal TagPath As String) As Integer
Dim TagIndex As Integer = 0
'Loop through all the tags and if we find a matching path then we return then index of it
For i As Integer = 1 To ObjectCount Step 1
If H2Tag(i).TagPath = TagPath Then
TagIndex = i
Exit For
End If
Next
Return TagIndex
End Function
basicly if h2Tag.w/e = H2Tag.w/e Then you can read the info you want cus you now have that tag.
Posted: Sun Dec 16, 2007 7:18 pm
by Patrickh
the problem, though, is that the warthog's collision, model, physics, vehi, etc., all share the same name... that would definately lead to inaccuracies. That also seems like it would work really slowly.
Posted: Sun Dec 16, 2007 7:55 pm
by Altimit01
There's always the lazy way of using a hidden column (or if the language has a built in hidden value for a given item use that) with the array index of the data for the given tag. I find that to be the simplest solution even if it does feel like cheating.
Edit: found the hidden associator:
control.tag. If you can use that on a per listbox.item basis that'd be my recommendation.
P.S. why would you use a loop? It's faster to use objects like
dictionary or
hashtable isn't it?
Posted: Sun Dec 16, 2007 8:49 pm
by OwnZ joO
Altimit01 wrote:P.S. why would you use a loop? It's faster to use objects like
dictionary or
hashtable isn't it?
Those are faster I think, and easy to program with too, another solution that I used is a custom generic TreeNode<T> class that has an Item of type T, and I made the Type be Tag.
Posted: Sun Dec 16, 2007 11:27 pm
by Patrickh
thanks for the help everyone! I figured out a method. I created a hash table called MetaOffsetStorage. Then, While I'm looping through tags (only only ever loop once), for each tag, I create a key/value pair. I set the key to be the title of the branch i stuck that tag in plus "\" and then the name of the tag. Then I set the value to be Hex$(offset) (the number that HMT shows you when you do meta swaps). Then when you click on a tag, it returns it's path, which is the same as what i set the key to be, so I can easily retrieve it's corresponding value. Also, by adding the primary class to the beginning of the key, it prevent name duplicates like i mentioned earlier. It's probably a little unorthodox, but it works. Thanks for the help!
Removed double post.
Posted: Tue Dec 18, 2007 8:35 am
by Cryticfarm
Maybe you pressed post instead of edit?
Posted: Fri Dec 21, 2007 6:30 pm
by Patrickh
Quick question:
I have a node selected in a tree view. it's key is... key. I want to add that node and every other node within that parent to a combobox.
I tried:
ComboBox1.Items.Add(tv.SelectedNode.Parent.Nodes)
But it just prints "(Collection)"
Thanks in advance
Posted: Fri Dec 21, 2007 9:50 pm
by -DeToX-
Code: Select all
For i as integer = 0 to treeView1.SelectedNode.Parent.Nodes.Count - 1
ComboBox1.Items.Add(treeView1.SelectedNode.Parent.Nodes(i).Text
Next
Should take care of it for you.
Also you said some tags have different classes... Why not edit the above function to check classes aswell? Here I did it for you.
Code: Select all
Public Function FindTagIndexByPath(ByVal TagClass As String, ByVal TagPath As String) As Integer
Dim TagIndex As Integer = 0
'Loop through all the tags and if we find a matching path then we return then index of it
For i As Integer = 1 To ObjectCount Step 1
If H2Tag(i).TagPath = TagPath Then
If H2Tag(i).TagClass = TagClass Then
TagIndex = i
Exit For
End If
End If
Next
Return TagIndex
End Function
Posted: Sat Dec 22, 2007 3:12 am
by Prey
-DeToX- wrote:[...]
Should take care of it for you.
Missed out a bracket.. :Z
Code: Select all
For i as integer = 0 to treeView1.SelectedNode.Parent.Nodes.Count - 1
ComboBox1.Items.Add(treeView1.SelectedNode.Parent.Nodes(i).Text)
Next
-DeToX- wrote:Also you said some tags have different classes... Why not edit the above function to check classes aswell? Here I did it for you.
[...]
Meh I would swap the checks around, as comparing 4 chars against 4 chars first would be less memory intensive, opposed to comparing variable sized strings to each other that is. Also why the two if commands.. =x
And grimdoomer, initialising the TagIndex to 0 is a bad idea, because if no tag is found 0 is returned.. which is the first tag...
Here fixed it up:
Code: Select all
Public Function IndexOf(ByVal TagClass As String, ByVal TagPath As String) As Integer
For i As Integer = 1 To ObjectCount Step 1
If H2Tag(i).TagClass = TagClass And H2Tag(i).TagPath = TagPath Then
Return i
End If
Next
Return -1
End Function