コード例 #1
0
        protected void DoSubRow(Rect rect, string key, HybridExtensionExposable extension, List <string> removeelements)
        {
            bool   isPawnKind = false;
            int    value      = (int)extension.hybridInfo.TryGetValue(key);
            string valuestr   = value.ToString();
            string label      = null;

            label = DefDatabase <ThingDef> .GetNamedSilentFail(key)?.label;

            if (label == null)
            {
                label = DefDatabase <PawnKindDef> .GetNamedSilentFail(key)?.label ?? "Undefined";

                isPawnKind = true;
            }
            Rect buttonRect = new Rect(rect.xMax - 90f, rect.y, 80f, rect.height);

            if (Widgets.ButtonText(buttonRect, "Delete"))
            {
                removeelements.Add(key);
            }
            buttonRect.x -= 80f;
            if (!isPawnKind)
            {
                if (Widgets.ButtonText(buttonRect, "PawnKind"))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    if (!VariousDefOf.AllKinds.NullOrEmpty())
                    {
                        foreach (PawnKindDef def in VariousDefOf.AllKinds)
                        {
                            if (def.race.defName == key)
                            {
                                if (extension.hybridInfo.ContainsKey(def.defName))
                                {
                                    continue;
                                }
                                else
                                {
                                    list.Add(new FloatMenuOption(def.label, delegate { extension.hybridInfo.Add(def.defName, 1.0f); }, Widgets.GetIconFor(def.race), Color.white));
                                }
                            }
                        }
                    }
                    if (!list.NullOrEmpty())
                    {
                        Find.WindowStack.Add(new FloatMenu(list));
                    }
                    else
                    {
                        SoundDefOf.ClickReject.PlayOneShotOnCamera();
                    }
                }
                buttonRect.x -= 80f;
            }
            else
            {
                Widgets.Label(buttonRect, "  PawnKind");
                buttonRect.x -= 80f;
            }
            label += ": " + key;
            Widgets.Label(rect, " - " + label);
            Widgets.TextFieldNumeric(buttonRect, ref value, ref valuestr, 0, 9999999);
            extension.hybridInfo.SetOrAdd(key, value);
            buttonRect.x -= 80f;
            Widgets.Label(buttonRect, String.Format("{0,0:P2}", value / totalWeight));
            Widgets.DrawHighlightIfMouseover(rect);
            TooltipHandler.TipRegion(rect, Translations.CustomHybrid_Tooltip(info.GetDef?.label ?? "Undefined", extension.GetDef?.label ?? "Undefined", label, String.Format("{0,0:0.########%}", value / totalWeight)));
        }
コード例 #2
0
        protected void DoMainContents(Rect inRect)
        {
            Rect labelRect  = new Rect(inRect.xMin, inRect.yMin, 300, 24);
            Rect buttonRect = new Rect(inRect.xMax - 120, 0, 100, 30);

            Widgets.Label(labelRect, Translations.CustomHybrid_Title(info.GetDef?.label ?? "Undefined"));
            Widgets.DrawLineHorizontal(inRect.x, labelRect.yMax, inRect.width);
            if (Widgets.ButtonText(buttonRect, "Add"))
            {
                if (!raceList.NullOrEmpty())
                {
                    Find.WindowStack.Add(new FloatMenu(raceList));
                }
            }
            if (!removeList.EnumerableNullOrEmpty())
            {
                buttonRect.x -= 100;
                if (Widgets.ButtonText(buttonRect, "Undo"))
                {
                    var element = removeList.Last();
                    info.hybridExtension.Add(element);
                    removeList.Remove(element);
                }

                foreach (HybridExtensionExposable element in removeList)
                {
                    info.hybridExtension.Remove(element);
                }
            }


            float additionalHeight = 0f;

            if (!info.hybridExtension.NullOrEmpty())
            {
                foreach (HybridExtensionExposable e in info.hybridExtension)
                {
                    additionalHeight += (e.hybridInfo?.Count() ?? 1) * rowH;
                }
            }


            Rect             outRect  = new Rect(inRect.x, inRect.y + 30f, inRect.width, inRect.height - 30f);
            Rect             mainRect = new Rect(inRect.x, inRect.y + 30f, inRect.width - 30f, rowH * (info.hybridExtension?.Count() ?? 1) + additionalHeight);
            Listing_Standard listmain = new Listing_Standard();

            Widgets.BeginScrollView(outRect, ref scroll, mainRect);
            listmain.Begin(mainRect);

            if (!info.hybridExtension.NullOrEmpty())
            {
                foreach (HybridExtensionExposable extension in info.hybridExtension)
                {
                    DoRow(listmain.GetRect(rowH + rowH * (extension.hybridInfo?.Count() ?? 1)), extension);
                }
            }



            Widgets.EndScrollView();
            listmain.End();
        }