コード例 #1
0
        private void SetupControls(DailyAchievements.Dailies dailies)
        {
            if (reusable == null)
            {
                reusable = new Util.ReusableControls();
            }
            else
            {
                reusable.ReleaseAll();
            }

            var achievements = reusable.CreateOrAll <DailyAchievement>(dailies.Count,
                                                                       delegate
            {
                var control = new DailyAchievement()
                {
                    BackColor   = Color.White,
                    NameVisible = true,
                    NameFont    = fontName,
                    IconSize    = new Size(32, 32),
                    IconVisible = true,
                    Size        = new Size(panelContent.Width, 50),
                    Anchor      = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top,
                };

                control.MouseEnter += control_MouseEnter;
                control.MouseLeave += control_MouseLeave;

                return(control);
            });

            var bars = reusable.CreateOrAll <DailyCategoryBar>(dailies.Categories.Length + 1,
                                                               delegate
            {
                var bar = new DailyCategoryBar()
                {
                    Font      = fontBar,
                    BackColor = SystemColors.ControlLight,
                    Size      = new Size(panelContent.Width, 35),
                    Anchor    = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top,
                };

                bar.Collapsed += bar_Collapsed;
                bar.Expanded  += bar_Expanded;

                return(bar);
            });

            int x = 0,
                y = 0;

            //var primaryCategories = 3;
            //var lowLevel = new List<Control>(4);

            //int gi = 0,
            //    gii;

            byte id = 0;

            var groups   = this.groups = new DailyGroup[dailies.Categories.Length + 1];
            var lowlevel = new DailyGroup()
            {
                id        = 0,
                dailies   = new DailyAchievements.Daily[4],
                collapsed = Settings.HiddenDailyCategories[0].Value,
            };
            bool addedLow   = false;
            int  firstIndex = 0,
                 lastIndex  = groups.Length - 1;

            foreach (var c in dailies.Categories)
            {
                if (c.Name == "Fractals" && !addedLow)
                {
                    if (lowlevel.collapsed)
                    {
                        groups[lastIndex--] = lowlevel;
                    }
                    else
                    {
                        groups[firstIndex++] = lowlevel;
                    }
                    addedLow = true;
                }

                id++;

                var group = new DailyGroup()
                {
                    id        = id,
                    dailies   = new DailyAchievements.Daily[c.Dailies.Length],
                    collapsed = Settings.HiddenDailyCategories[id].Value,
                };

                foreach (var d in c.Dailies)
                {
                    if (d.MaxLevel < 80)
                    {
                        lowlevel.dailies[lowlevel.count++] = d;
                    }
                    else
                    {
                        group.dailies[group.count++] = d;
                    }
                }

                if (group.count > 0)
                {
                    var bar = group.bar = bars.GetNext();

                    bar.SetState(group.collapsed);
                    bar.Text = c.Name;
                }

                if (group.collapsed)
                {
                    groups[lastIndex--] = group;
                }
                else
                {
                    groups[firstIndex++] = group;
                }
            }

            if (lowlevel.count > 0)
            {
                var bar = lowlevel.bar = bars.GetNext();

                bar.Tag = lowlevel;
                bar.SetState(lowlevel.collapsed);
                bar.Text = "Pre level 80";
            }

            if (!addedLow)
            {
                groups[firstIndex++] = lowlevel;
            }

            if (firstIndex != groups.Length)
            {
                var count = groups.Length - firstIndex;
                if (count > 1)
                {
                    Array.Reverse(groups, firstIndex, count);
                }
            }

            firstIndex = 0;

            foreach (var group in groups)
            {
                group.index = firstIndex++;

                if (group.count > 0)
                {
                    var bar = group.bar;

                    bar.Tag      = group;
                    bar.Location = new Point(x, y);
                    bar.Visible  = true;

                    y += bar.Height + 1;

                    var visible = !group.collapsed;
                    group.controls = new DailyAchievement[group.count];

                    for (var i = 0; i < group.count; i++)
                    {
                        var control = group.controls[i] = achievements.GetNext();
                        var d       = group.dailies[i];

                        control.Daily     = d;
                        control.IconValue = d.Icon != null ? d.Icon : imageDefault;
                        control.Location  = new Point(x, y);
                        control.Visible   = visible;

                        if (visible)
                        {
                            y += control.Height + 1;
                        }
                    }

                    if (visible)
                    {
                        y--;
                    }
                }
            }

            while (bars.HasNext)
            {
                bars.GetNext().Visible = false;
            }

            while (achievements.HasNext)
            {
                achievements.GetNext().Visible = false;
            }

            panelContent.Height = y;
            scrollV.Maximum     = y - panelContainer.Height;

            if (bars.New != null)
            {
                panelContent.Controls.AddRange(bars.New);
            }
            if (achievements.New != null)
            {
                panelContent.Controls.AddRange(achievements.New);
            }
        }
コード例 #2
0
ファイル: formNotes.cs プロジェクト: cjschneider2/Gw2Launcher
        private void SetupControls()
        {
            var notes = account.Notes;
            var count = 0;

            if (notes != null && notes.Count > 0)
            {
                if (reusable == null)
                {
                    reusable = new Util.ReusableControls();
                }
                else
                {
                    reusable.ReleaseAll();
                }

                var controls = reusable.CreateOrAll <NoteMessage>(notes.Count,
                                                                  delegate
                {
                    var c = new NoteMessage()
                    {
                        Width  = panelContent.Width,
                        Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
                    };

                    c.DeleteClick += message_DeleteClick;
                    c.EditClick   += message_EditClick;

                    return(c);
                });

                var now = DateTime.UtcNow;

                var x = 0;
                var y = 0;

                var expired = selectedTab == buttonExpired;
                Settings.Notes.Note[] _notes;

                lock (notes)
                {
                    var index = notes.IndexOf(now);

                    if (expired)
                    {
                        _notes = new Settings.Notes.Note[index];
                    }
                    else
                    {
                        _notes = new Settings.Notes.Note[notes.Count - index];
                    }

                    ExpiredCount = index;
                    MessageCount = notes.Count - index;

                    if (_notes.Length > 0)
                    {
                        notes.CopyTo(expired ? 0 : index, _notes, 0, _notes.Length);
                    }
                }

                for (var i = 0; i < _notes.Length; i++)
                {
                    Settings.Notes.Note n;
                    if (expired)
                    {
                        n = _notes[_notes.Length - i - 1];
                    }
                    else
                    {
                        n = _notes[i];
                    }

                    var c = controls.GetNext();

                    c.Location = new Point(x, y);
                    c.Tag      = n;
                    c.Expires  = n.Expires;

                    string message;
                    strings.TryGetValue(n.SID, out message);
                    c.Message = message;

                    c.Visible = true;

                    y += c.Height + 1;

                    count++;
                }

                if (y > 0)
                {
                    y--;
                }

                panelContent.Height = y;

                while (controls.HasNext)
                {
                    controls.GetNext().Visible = false;
                }
                if (controls.New != null)
                {
                    panelContent.Controls.AddRange(controls.New);
                }
            }
            else
            {
                ExpiredCount = 0;
                MessageCount = 0;
            }

            if (count > 0)
            {
                panelContent.Visible = true;
                labelMessage.Visible = false;

                scrollV.Maximum = panelContent.Height - panelContainer.Height;
            }
            else
            {
                panelContent.Visible     = false;
                labelMessage.Text        = "No messages";
                labelMessage.MaximumSize = new Size(panelContainer.Width * 3 / 4, panelContainer.Height);
                labelMessage.Location    = new Point(panelContainer.Width / 2 - labelMessage.Width / 2, panelContainer.Height / 2 - labelMessage.Height / 2);
                labelMessage.Visible     = true;
            }
        }