dynamically loop through tiers in picturebox control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    dynamically loop through tiers in picturebox control

    Ok so, I'm trying to make an .exe version of a World of Warcraft system. The Talent builder. I'm hoping that no one points and laughs too much... But anyways, this is the problem I'm having...

    Theres 11 tiers of my PictureBox[] Control, 44 total. The 1st tier is "Free" while each subsequent tier needs 5 points into the previous tier to make the next tier available.

    Right now I have the intentions of putting this code into a TextChanged() event handler on the total points holder (a Label). And this loop will check each time a point is put in, or taken out, and enable or disable a tier based on the amount of points that are in all of the 11 tiers combined.

    I'm having a really hard time figuring you how to make a dynamic loop to be able to do this with out manually code each tier opening up after X points were placed into it...

    I know the game is either loved or hated, but I'm learning C# based on this project. So I'm hoping that I can get some help with this loop without any criticism.

    Thanks...
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Hey, as a fellow WoW player I say to heck with the haters! :P Glad to see you're still working on this, actually.

    I'm not sure what you mean here though. Why do you need a loop? When you click a certain talent, couldn't you just do the checks there and enable/disable other talents based on that event? Some quick pseudo...

    Code:
    public void TalentClick(object sender, TalentClickEventArgs e)
    {
      Talent t = sender as Talent;
      if (t != null)
      {
        t.Spent.Increment(e.Increment);
    
        foreach (Talent tChild in t.ChildTalents)
        {
          tChild.Enabled = (t.Spent == t.MaximumPoints);
        }
      }
    }
    Would something like that work?

    Comment

    • Samishii23
      New Member
      • Sep 2009
      • 246

      #3
      Well basicly what little theory is actually coming to me is this.

      Theres 44 Talents in the tree. So every 4 talents is 1 tier.
      Current Tier = (Total Points / 5) + 1

      On Change:
      - Check Points
      - Cycle through current tier and next to see if next tier can be enabled or disabled, based current amount of points.
      - enable and disable as needed.

      I have the offical code for the website version. But honestly, not sure how to push that to exactly what I'm doing. lol

      This is Javascript btw, and i'm adding comments to the areas I understand...
      Code:
      function checkEnabled(treeNum) {
      	calcTreePts(); // Updates the counters for use...
      	
      	var tree = talentTrees[treeNum]; // gets the tree object
      	for(var talentNum = 0, len = tree.talents.length; talentNum < len; ++talentNum) { // cycle through each talent
      
      		var talent = tree.talents[talentNum]; // current talent object
      		var enabled = (talent.tier == 0 || tree.pts >= (talent.tier * talentVars.pointsPerTier)); // if first tier is true or current points is more or same as points needed for next tier
      
      		if(enabled && talent.pts == 0 && (talentVars.pts >= talentVars.maxPts || pageMode != "calc")) // if enabled and cur talent has 0 points and (im guessing current total points accross whole calc) is more then allowed total points
      			enabled = false;
      			
      		// (original comment) Dependent talents have special cases
      		if(enabled && !checkDependentTalent(talent))
      			enabled = false;
      
      		if(enabled) {
      			enableTalent(talent);
      			enableArrows(talent);
      
      		} else {
      			disableTalent(talent);
      			disableArrows(talent);
      		}
      	}
      }
      I'm sorry. This looks simple, but when I try to put the loop together in my head before in the editor, I go blank. I don't know why. =\

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        Ah, I misunderstood what you meant by dependency. I was thinking of just the arrows :)

        I don't really know web development much, but that loop looks like it updates the whole tree when a point is changed, is that correct?

        That loop does seem pretty straight forward... enable a talent if it's tier is less than the total number of points in the tree divided by the points per tier.

        Are you not sure how to convert this to C#?

        Comment

        • Samishii23
          New Member
          • Sep 2009
          • 246

          #5
          Kinda. The biggest problem is that I want to add checks for if theres only, say for example 10 points. Check up to 3 tiers. I believe thats where I'm starting to over think it and why I'm going blank. lol

          I mean pulling 44 loops when clicking on the talent quickly, would probably end up badly.

          Comment

          • GaryTexmo
            Recognized Expert Top Contributor
            • Jul 2009
            • 1501

            #6
            Well, yes and no... that's not terribly many as far as a computer is concerned, and if you're not doing a lot of work you're probably ok. As for stopping when you have no more talents, just put a break in there when the count is greater than the total number of spent talents.

            You don't have to constrain yourself to how they did it though... like I said, this looks like a full refresh. Could you simply update when you click on a specific talent? That's kinda what I was getting at in that pseudo code I posted above.

            * Talent was clicked
            * Update the talent itself
            * Enable/disable any talents above or below as necessary

            It could work if your talent array supported it...

            Code:
            List<Talent>[] talents = new List<Talent>[MAX_TIERS]();
            ?

            I'm not trying to tell you to rewrite your code or anything, just throwing out ideas :D

            Comment

            • Samishii23
              New Member
              • Sep 2009
              • 246

              #7
              Originally posted by GaryTexmo
              Well, yes and no... that's not terribly many as far as a computer is concerned, and if you're not doing a lot of work you're probably ok. As for stopping when you have no more talents, just put a break in there when the count is greater than the total number of spent talents.

              You don't have to constrain yourself to how they did it though... like I said, this looks like a full refresh. Could you simply update when you click on a specific talent? That's kinda what I was getting at in that pseudo code I posted above.

              * Talent was clicked
              * Update the talent itself
              * Enable/disable any talents above or below as necessary

              It could work if your talent array supported it...

              Code:
              List<Talent>[] talents = new List<Talent>[MAX_TIERS]();
              ?

              I'm not trying to tell you to rewrite your code or anything, just throwing out ideas :D
              Yea right now, I have the Individual talent counters working. Its enabling the next tier for the counting that is what I'm getting stuck on. I'm pushing some code on the side for it. I'll probably get it posted tomorrow. Have family things to tend to. :P

              Comment

              • Samishii23
                New Member
                • Sep 2009
                • 246

                #8
                This is what I came up with. It seems to work. But there is a noticable amount of lag cycling through the whole tree each click.

                Code:
                public void HandleChange_TreeCount(object X, EventArgs EX) {
                  ToolStripStatusLabel Obj = X as ToolStripStatusLabel;
                  
                  if (Obj == null)
                    return;
                
                  int id = s2i(Obj.Name.Substring(4, 1)), // Example Name "Tree1Counter"
                      CurPts = s2i(Obj.Text), // .Text property holds the total tree count
                      CurTier = (CurPts / 5) + 1, // This defines what Tier the current amount of points would suggest
                      TreeStart = (id - 1) * 44, // ID: 0 thru 2, want starting numbers like this: 0, 44, 88
                      TreeEnd = (TreeStart + 43);
                
                  if (CurTier == 1) // Do nothing if its the 1st tier
                    return;
                
                  for (int x = TreeStart; x < TreeEnd; x++) {
                    bool Enable = false;
                
                    // First Tier and Figures out next tier
                    if (TD.Tier[x] == 0 && CurPts >= (TD.Tier[x] * 5))
                      Enable = true;
                
                    if (Enable)
                      Talent_Enable(x);
                    else
                      Talent_Disable(x);
                    }
                  }
                Now I just need to think about say, stop the loop if maybe it's already enabled, or if just on the 2nd tier in terms of points, just cycle through to the next tier only cut out the extra cpu usage.
                Last edited by Samishii23; Jun 16 '10, 08:44 PM. Reason: Messed up Code Block

                Comment

                • Samishii23
                  New Member
                  • Sep 2009
                  • 246

                  #9
                  Oooook... Apparently I already implemented the Next tier thing without realizing it... Ugh. Sorry to have created a, now, useless thread... lol
                  The above code has been scrapped... heh

                  Comment

                  • GaryTexmo
                    Recognized Expert Top Contributor
                    • Jul 2009
                    • 1501

                    #10
                    lol :D

                    Glad you got it figured out!

                    Comment

                    • Samishii23
                      New Member
                      • Sep 2009
                      • 246

                      #11
                      Apparently I already covered all the points I needed to in my Add Point method, since it already covered all the Talents anyways, it was fine without me knowing it.

                      Now the only thing I have to do is, basicly do the same thing but now figure out not "Enabling" the next tier. Its the doing an image swap. Which I had already put into use, but it doesn't seem to work.

                      Woo. lol. Thanks for the support Gary

                      Comment

                      Working...