Exemple #1
0
        void AddTabPage(HtmlPage page, bool create, int rewardNo)
        {
            this.tabPages.SuspendLayout();

            TabPage tab = null;
            TableLayoutPanel wholeTable = null;
            TableLayoutPanel buttonTable = null;
            TransparentRichTextBox textBox = null;

            if (create) {
                wholeTable = new TableLayoutPanel();
                buttonTable = new TableLayoutPanel();
                textBox = new TransparentRichTextBox();
                tabPages.TabPages.Add(page.HtmlPageId.ToString());
                tab = tabPages.TabPages[tabPages.TabPages.Count - 1];
                tab.BackColor = SystemColors.ControlDarkDark;
                tab.BackgroundImage = Properties.Resources.dialogBackground;
                tab.Controls.Add(wholeTable);
                tab.ForeColor = SystemColors.Info;
                tab.Location = new Point(4, 27);
                tab.Margin = new Padding(0);
                tab.Size = new Size(401, 449);
            } else {
                tab = tabPages.TabPages[0];
                wholeTable = tableLayoutPanel1;
                buttonTable = tableLayoutPanel2;
                textBox = transparentRichTextBox1;
            }

            tab.Text = page.HtmlPageId.ToString();
            tab.Tag = tab.ToolTipText = page.name;

            tab.SuspendLayout();
            wholeTable.SuspendLayout();
            buttonTable.SuspendLayout();
            textBox.SuspendLayout();
            this.SuspendLayout();

            if (create) {
                int scrollWidth = SystemInformation.VerticalScrollBarWidth;
                const int rewardsMaxHeight = 230;
                const int totalHeight = 401;

                wholeTable.BackColor = System.Drawing.Color.Transparent;
                wholeTable.ColumnCount = 1;
                wholeTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
                wholeTable.Controls.Add(buttonTable, 0, 1);
                wholeTable.Controls.Add(textBox, 0, 0);
                wholeTable.Location = new Point(31, 23);
                wholeTable.RowCount = 2;
                wholeTable.Size = new Size(339, totalHeight);

                bool isReward = page.name.StartsWith("select_quest_reward");
                RewardList rw = null;

                buttonTable.ColumnCount = 1;
                buttonTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
                buttonTable.Dock = DockStyle.Fill;

                int topHeight = 305;

                if (isReward) {
                    int repeat;
                    rw = new RewardList(_quest.GetReward(rewardNo, out repeat))
                    {
                        BackColor = Color.Transparent,
                        Width = 339 - 2 * scrollWidth,
                    };
                    int height = rw.RecommendedHeight;
                    if (height > rewardsMaxHeight)
                        height = rewardsMaxHeight;
                    rw.Height = height;

                    float topPerc = (float)(totalHeight - height) / totalHeight;
                    topHeight = (int)Math.Ceiling(totalHeight * topPerc);
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, topPerc * 100));
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100f * (1 - topPerc)));

                    buttonTable.Location = new Point(0, topHeight);
                    buttonTable.Margin = new Padding(scrollWidth, 0, 0, 0);
                    buttonTable.RowCount = 1;
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
                    buttonTable.Size = new Size(339 - 2 * scrollWidth, totalHeight - topHeight);
                    rw.RewardSelected += new RewardList.RewardSelectedEventHandler(OnRewardSelected);
                    buttonTable.Controls.Add(rw, 0, 0);
                } else {
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 76.05985F));
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 23.94015F));

                    buttonTable.Margin = new Padding(0);
                    buttonTable.Location = new Point(0, 305);
                    buttonTable.RowCount = 4;
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.Size = new Size(339, 96);
                }

                textBox.BorderStyle = BorderStyle.None;
                textBox.Dock = DockStyle.Fill;
                textBox.Font = new Font("Microsoft Sans Serif", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
                textBox.Location = new Point(0, 0);
                textBox.Margin = new Padding(0);
                textBox.ReadOnly = true;
                textBox.ScrollBars = RichTextBoxScrollBars.None;
                textBox.Size = new Size(339, topHeight);
            }

            buttonPanels.Add(buttonTable);

            StringBuilder text = new StringBuilder();
            if (page.Content != null) {
                if (page.Content.html != null && page.Content.html.body != null &&
                    page.Content.html.body.p != null) {
                    foreach (Paragraph para in page.Content.html.body.p) {
                        if (!String.IsNullOrEmpty(para.visible))
                            continue;
                        string line = para.Value;
                        if (!String.IsNullOrEmpty(line))
                            text.Append(Utility.GetParsedString(line, true));
                        text.Append('\n');
                    }
                }
                if (page.Selects != null) {
                    int i = 0;
                    foreach (SelectsAct action in page.Selects) {
                        if (String.IsNullOrEmpty(action.Value))
                            continue;
                        Button button = new Button();
                        button.BackColor = Color.DarkKhaki;
                        button.ForeColor = SystemColors.ControlText;
                        button.Text = action.Value.Trim('"', ' ', '“', '”');
                        button.Margin = new Padding(1, 1, 1, 1);
                        button.Dock = DockStyle.Fill;
                        ToolTip toolTip = new ToolTip();

                        string actionName = action.ActionName;
                        string emotionName = action.EmotionName;
                        string fixedPage = String.Empty;

                        // check if that page exists
                        HtmlPage matchedPage = _pages.Where(p => p.name == actionName)
                                                     .FirstOrDefault();
                        if (matchedPage == null) {
                            matchedPage = _pages.Where(p => p.name.StartsWith(actionName) &&
                                                            _pages.IndexOf(p) > _pages.IndexOf(page))
                                                .FirstOrDefault();
                            if (matchedPage == null && actionName == "ask_quest_accept") {
                                matchedPage = _pages.Where(p => p.name.StartsWith("quest_accept") &&
                                                            _pages.IndexOf(p) > _pages.IndexOf(page))
                                                    .FirstOrDefault();
                                fixedPage = String.Format("(wrong!!! Id = {0}, Name = ask_quest_accept)",
                                                          HtmlPage.Index["ask_quest_accept"]);
                            }
                        }

                        string tip = String.Empty;
                        if (matchedPage != null) {
                            // create click handler
                            button.Click += new EventHandler(delegate(object sender, EventArgs args)
                            {
                                var allPages = tabPages.TabPages.Cast<TabPage>();
                                var showPage = allPages.Where(t => ((string)t.Tag) == matchedPage.name &&
                                                                   !t.Equals(tab))
                                                       .FirstOrDefault();
                                if (showPage != null) {
                                    tabPages.SelectedTab = showPage;
                                }
                            });
                            tip = String.Format("Action Id = {0}, Page Id = {1}",
                                                action.Id, matchedPage.HtmlPageId);
                        } else {
                            tip = String.Format("Action Id = {0}, Name = {1}", action.Id, actionName);
                        }

                        if (!string.IsNullOrEmpty(fixedPage))
                            tip += fixedPage;

                        if (!String.IsNullOrEmpty(emotionName))
                            tip += String.Format(", Emotion = {0}", emotionName);

                        toolTip.SetToolTip(button, tip);

                        if (i > 3)
                            continue;
                        buttonTable.Controls.Add(button, 0, i++);
                    }
                }
            }

            textBox.Text = text.ToString();
            textBoxes.Add(textBox);

            tabPages.ResumeLayout(true);
            tab.ResumeLayout(true);
            wholeTable.ResumeLayout(true);
            buttonTable.ResumeLayout(true);
            textBox.ResumeLayout(true);
            this.ResumeLayout(false);
        }
Exemple #2
0
        void AddTabPage(HtmlPage page, bool create, int rewardNo)
        {
            this.tabPages.SuspendLayout();

            TabPage                tab         = null;
            TableLayoutPanel       wholeTable  = null;
            TableLayoutPanel       buttonTable = null;
            TransparentRichTextBox textBox     = null;

            if (create)
            {
                wholeTable  = new TableLayoutPanel();
                buttonTable = new TableLayoutPanel();
                textBox     = new TransparentRichTextBox();
                tabPages.TabPages.Add(page.HtmlPageId.ToString());
                tab                 = tabPages.TabPages[tabPages.TabPages.Count - 1];
                tab.BackColor       = SystemColors.ControlDarkDark;
                tab.BackgroundImage = Properties.Resources.dialogBackground;
                tab.Controls.Add(wholeTable);
                tab.ForeColor = SystemColors.Info;
                tab.Location  = new Point(4, 27);
                tab.Margin    = new Padding(0);
                tab.Size      = new Size(401, 449);
            }
            else
            {
                tab         = tabPages.TabPages[0];
                wholeTable  = tableLayoutPanel1;
                buttonTable = tableLayoutPanel2;
                textBox     = transparentRichTextBox1;
            }

            tab.Text = page.HtmlPageId.ToString();
            tab.Tag  = tab.ToolTipText = page.name;

            tab.SuspendLayout();
            wholeTable.SuspendLayout();
            buttonTable.SuspendLayout();
            textBox.SuspendLayout();
            this.SuspendLayout();

            if (create)
            {
                int       scrollWidth      = SystemInformation.VerticalScrollBarWidth;
                const int rewardsMaxHeight = 230;
                const int totalHeight      = 401;

                wholeTable.BackColor   = System.Drawing.Color.Transparent;
                wholeTable.ColumnCount = 1;
                wholeTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
                wholeTable.Controls.Add(buttonTable, 0, 1);
                wholeTable.Controls.Add(textBox, 0, 0);
                wholeTable.Location = new Point(31, 23);
                wholeTable.RowCount = 2;
                wholeTable.Size     = new Size(339, totalHeight);

                bool       isReward = page.name.StartsWith("select_quest_reward");
                RewardList rw       = null;

                buttonTable.ColumnCount = 1;
                buttonTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
                buttonTable.Dock = DockStyle.Fill;

                int topHeight = 305;

                if (isReward)
                {
                    int repeat;
                    rw = new RewardList(_quest.GetReward(rewardNo, out repeat))
                    {
                        BackColor = Color.Transparent,
                        Width     = 339 - 2 * scrollWidth,
                    };
                    int height = rw.RecommendedHeight;
                    if (height > rewardsMaxHeight)
                    {
                        height = rewardsMaxHeight;
                    }
                    rw.Height = height;

                    float topPerc = (float)(totalHeight - height) / totalHeight;
                    topHeight = (int)Math.Ceiling(totalHeight * topPerc);
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, topPerc * 100));
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100f * (1 - topPerc)));

                    buttonTable.Location = new Point(0, topHeight);
                    buttonTable.Margin   = new Padding(scrollWidth, 0, 0, 0);
                    buttonTable.RowCount = 1;
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
                    buttonTable.Size   = new Size(339 - 2 * scrollWidth, totalHeight - topHeight);
                    rw.RewardSelected += new RewardList.RewardSelectedEventHandler(OnRewardSelected);
                    buttonTable.Controls.Add(rw, 0, 0);
                }
                else
                {
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 76.05985F));
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 23.94015F));

                    buttonTable.Margin   = new Padding(0);
                    buttonTable.Location = new Point(0, 305);
                    buttonTable.RowCount = 4;
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.Size = new Size(339, 96);
                }

                textBox.BorderStyle = BorderStyle.None;
                textBox.Dock        = DockStyle.Fill;
                textBox.Font        = new Font("Microsoft Sans Serif", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
                textBox.Location    = new Point(0, 0);
                textBox.Margin      = new Padding(0);
                textBox.ReadOnly    = true;
                textBox.ScrollBars  = RichTextBoxScrollBars.None;
                textBox.Size        = new Size(339, topHeight);
            }

            buttonPanels.Add(buttonTable);

            StringBuilder text = new StringBuilder();

            if (page.Content != null)
            {
                if (page.Content.html != null && page.Content.html.body != null &&
                    page.Content.html.body.p != null)
                {
                    foreach (Paragraph para in page.Content.html.body.p)
                    {
                        if (!String.IsNullOrEmpty(para.visible))
                        {
                            continue;
                        }
                        string line = para.Value;
                        if (!String.IsNullOrEmpty(line))
                        {
                            text.Append(Utility.GetParsedString(line, true));
                        }
                        text.Append('\n');
                    }
                }
                if (page.Selects != null)
                {
                    int i = 0;
                    foreach (SelectsAct action in page.Selects)
                    {
                        if (String.IsNullOrEmpty(action.Value))
                        {
                            continue;
                        }
                        Button button = new Button();
                        button.BackColor = Color.DarkKhaki;
                        button.ForeColor = SystemColors.ControlText;
                        button.Text      = action.Value.Trim('"', ' ', '“', '”');
                        button.Margin    = new Padding(1, 1, 1, 1);
                        button.Dock      = DockStyle.Fill;
                        ToolTip toolTip = new ToolTip();

                        string actionName  = action.ActionName;
                        string emotionName = action.EmotionName;
                        string fixedPage   = String.Empty;

                        // check if that page exists
                        HtmlPage matchedPage = _pages.Where(p => p.name == actionName)
                                               .FirstOrDefault();
                        if (matchedPage == null)
                        {
                            matchedPage = _pages.Where(p => p.name.StartsWith(actionName) &&
                                                       _pages.IndexOf(p) > _pages.IndexOf(page))
                                          .FirstOrDefault();
                            if (matchedPage == null && actionName == "ask_quest_accept")
                            {
                                matchedPage = _pages.Where(p => p.name.StartsWith("quest_accept") &&
                                                           _pages.IndexOf(p) > _pages.IndexOf(page))
                                              .FirstOrDefault();
                                fixedPage = String.Format("(wrong!!! Id = {0}, Name = ask_quest_accept)",
                                                          HtmlPage.Index["ask_quest_accept"]);
                            }
                        }

                        string tip = String.Empty;
                        if (matchedPage != null)
                        {
                            // create click handler
                            button.Click += new EventHandler(delegate(object sender, EventArgs args)
                            {
                                var allPages = tabPages.TabPages.Cast <TabPage>();
                                var showPage = allPages.Where(t => ((string)t.Tag) == matchedPage.name &&
                                                              !t.Equals(tab))
                                               .FirstOrDefault();
                                if (showPage != null)
                                {
                                    tabPages.SelectedTab = showPage;
                                }
                            });
                            tip = String.Format("Action Id = {0}, Page Id = {1}",
                                                action.Id, matchedPage.HtmlPageId);
                        }
                        else
                        {
                            tip = String.Format("Action Id = {0}, Name = {1}", action.Id, actionName);
                        }

                        if (!string.IsNullOrEmpty(fixedPage))
                        {
                            tip += fixedPage;
                        }

                        if (!String.IsNullOrEmpty(emotionName))
                        {
                            tip += String.Format(", Emotion = {0}", emotionName);
                        }

                        toolTip.SetToolTip(button, tip);

                        if (i > 3)
                        {
                            continue;
                        }
                        buttonTable.Controls.Add(button, 0, i++);
                    }
                }
            }

            textBox.Text = text.ToString();
            textBoxes.Add(textBox);

            tabPages.ResumeLayout(true);
            tab.ResumeLayout(true);
            wholeTable.ResumeLayout(true);
            buttonTable.ResumeLayout(true);
            textBox.ResumeLayout(true);
            this.ResumeLayout(false);
        }