Пример #1
0
        public override void DoWindowContents(Rect maxBounds)
        {
            var  global      = new Rect(maxBounds.x, maxBounds.y, maxBounds.width, maxBounds.height - 50);
            Rect titleArea   = new Rect(global.x, global.y, global.width, TopHeight);
            Rect searchArea  = new Rect(global.x, global.y + TopHeight + 5, SideWidth, SearchHeight);
            Rect pagesArea   = new Rect(global.x, global.y + TopHeight + 10 + SearchHeight, SideWidth, global.height - 10 - TopHeight - SearchHeight);
            Rect contentArea = new Rect(global.x + SideWidth + 5, global.y + TopHeight + 5, global.width - SideWidth - 5, global.height - TopHeight - 5);

            Widgets.DrawBoxSolid(pagesArea, Color.white * 0.4f);
            Widgets.DrawBox(pagesArea);
            Widgets.DrawBox(titleArea);
            Widgets.DrawBox(contentArea);

            // Title
            Text.Font = GameFont.Medium;
            var titleSize = Text.CalcSize(Wiki.WikiTitle);

            Widgets.Label(new Rect(titleArea.x + (titleArea.width - titleSize.x) * 0.5f, titleArea.y + (titleArea.height - titleSize.y) * 0.5f, titleSize.x, titleSize.y), Wiki.WikiTitle);

            // Search box.
            SearchText = Widgets.TextField(searchArea, SearchText);

            // Draw all pages list.
            Widgets.BeginScrollView(pagesArea, ref scroll, new Rect(pagesArea.x, pagesArea.y, pagesArea.width, lastHeight));
            lastHeight = 0;

            // Normalize search string.
            string searchString = SearchText?.Trim().ToLowerInvariant();
            bool   isSearching  = !string.IsNullOrEmpty(searchString);

            int hiddenCount = 0;

            foreach (var page in Wiki.Pages)
            {
                if (page == null)
                {
                    continue;
                }

                if (isSearching)
                {
                    string pageName = page.Title.Trim().ToLowerInvariant();
                    if (!pageName.Contains(searchString))
                    {
                        continue;
                    }
                }

                if (page.IsSpoiler)
                {
                    hiddenCount++;
                    continue;
                }

                if (page.Icon != null)
                {
                    Widgets.DrawTextureFitted(new Rect(pagesArea.x + 4, pagesArea.y + 4 + lastHeight + 5, 24, 24), page.Icon, 1f);
                }
                bool clicked = Widgets.ButtonText(new Rect(pagesArea.x + 28, pagesArea.y + 4 + lastHeight, pagesArea.width - 28 - 4, 40), page.Title);
                if (clicked)
                {
                    CurrentPage = page;
                }

                lastHeight += 32 + 5;
            }

            if (hiddenCount > 0)
            {
                string text = $"<color=#FF6D71><i>{"Wiki.HiddenWarning".Translate(hiddenCount)}</i></color>";
                Widgets.Label(new Rect(pagesArea.x + 4, pagesArea.y + 4 + lastHeight, pagesArea.width - 4, 50), text);
                lastHeight += 42 + 5;
            }

            Widgets.EndScrollView();

            // Current page.
            CurrentPage?.Draw(contentArea);

            // Spoiler mode toggle.
            bool   spoilerMode = ModWiki.NoSpoilerMode;
            string txt         = "Wiki.HideSpoilerMode".Translate();
            float  width       = Text.CalcSize(txt).x + 24;

            Widgets.CheckboxLabeled(new Rect(maxBounds.x + 5, maxBounds.yMax - 32, width, 32), txt, ref spoilerMode);
            ModWiki.NoSpoilerMode = spoilerMode;
        }
Пример #2
0
        public static WikiPage CreateFromThingDef(ModWiki wiki, ThingDef thing)
        {
            if (thing == null)
            {
                return(null);
            }

            WikiPage p = new WikiPage(wiki);

            try
            {
                p.Title            = thing.LabelCap;
                p.ShortDescription = thing.DescriptionDetailed;
                p.Icon             = thing.uiIcon;
            }
            catch (Exception e)
            {
                throw new Exception("Exception setting page basics.", e);
            }

            try
            {
                // Cost.
                if (thing.costList != null)
                {
                    var cost = new SectionWikiElement();
                    cost.Name = "Wiki.Cost".Translate();

                    foreach (var costThing in thing.costList)
                    {
                        cost.Elements.Add(new WikiElement()
                        {
                            DefForIconAndLabel = costThing.thingDef, Text = costThing.count <= 1 ? "" : $"x{costThing.count}"
                        });
                    }

                    int outputCount = thing.recipeMaker?.productCount ?? 1;

                    cost.Elements.Add(WikiElement.Create("Wiki.OutputCount".Translate(outputCount)));

                    if (cost.Elements.Count > 0)
                    {
                        p.Elements.Add(cost);
                    }

                    var creates = new SectionWikiElement();
                    creates.Name = "Wiki.Creates".Translate();

                    // Show recipes added by this production thing.
                    foreach (var rec in thing.AllRecipes)
                    {
                        creates.Elements.Add(WikiElement.Create($" • {rec.LabelCap}"));
                    }

                    if (creates.Elements.Count > 0)
                    {
                        p.Elements.Add(creates);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Exception generating thing cost list.", e);
            }

            try
            {
                // Crafting (where is it crafted)
                if (thing.recipeMaker?.recipeUsers != null)
                {
                    var crafting = new SectionWikiElement();
                    crafting.Name = "Wiki.CraftedAt".Translate();

                    foreach (var user in thing.recipeMaker.recipeUsers)
                    {
                        crafting.Elements.Add(new WikiElement()
                        {
                            DefForIconAndLabel = user
                        });
                    }

                    if (crafting.Elements.Count > 0)
                    {
                        p.Elements.Add(crafting);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Exception generating thing crafting location list.", e);
            }

            try
            {
                // Research prerequisite.
                var research = new SectionWikiElement();
                research.Name = "Wiki.ResearchToUnlock".Translate();
                if (thing.researchPrerequisites != null && thing.researchPrerequisites.Count > 0) // Generally buildings.
                {
                    foreach (var r in thing.researchPrerequisites)
                    {
                        research.Elements.Add(new WikiElement()
                        {
                            Text = $" • {r.LabelCap}"
                        });
                    }
                }
                if (thing.recipeMaker?.researchPrerequisites != null) // Generally craftable items.
                {
                    foreach (var r in thing.recipeMaker.researchPrerequisites)
                    {
                        research.Elements.Add(new WikiElement()
                        {
                            Text = $" • {r.LabelCap}"
                        });
                    }
                }
                if (thing.recipeMaker?.researchPrerequisite != null) // Generally craftable items.
                {
                    var r = thing.recipeMaker.researchPrerequisite;
                    research.Elements.Add(new WikiElement()
                    {
                        Text = $" • {r.LabelCap}"
                    });
                }

                if (research.Elements.Count > 0)
                {
                    p.Elements.Add(research);
                }

                if (DebugMode)
                {
                    if (thing.weaponTags != null)
                    {
                        foreach (var tag in thing.weaponTags)
                        {
                            p.Elements.Add(new WikiElement()
                            {
                                Text = $"WeaponTag: {tag}"
                            });
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Exception generating thing research requirements.", e);
            }

            p.Def = thing;

            return(p);
        }