DoAllowedAreaSelectorsMC() public static method

public static DoAllowedAreaSelectorsMC ( Rect rect, bool>.Dictionary &areas, float lrMargin ) : void
rect UnityEngine.Rect
areas bool>.Dictionary
lrMargin float
return void
Ejemplo n.º 1
0
        public float DrawClearArea(Vector2 pos, float width)
        {
            var start   = pos;
            var rowRect = new Rect(
                pos.x,
                pos.y,
                width,
                ListEntryHeight);

            AreaAllowedGUI.DoAllowedAreaSelectorsMC(rowRect, ref _selected.ClearAreas);
            pos.y += ListEntryHeight;
            Utilities.DrawToggle(
                ref pos,
                width,
                "FMF.ClearWindCells".Translate(),
                "FMF.ClearWindCells.Tip".Translate(),
                ref _selected.ClearWindCells);

            return(pos.y - start.y);
        }
        public void DoContent(Rect rect)
        {
            // layout: settings | trees
            // draw background
            Widgets.DrawMenuSection(rect);

            // some variables
            float width         = rect.width;
            float height        = rect.height - _topAreaHeight - _button.y - Margin;
            var   cols          = 2;
            float colWidth      = width / cols - Margin;
            var   colRects      = new List <Rect>();
            var   colTitleRects = new List <Rect>();
            var   buttonRect    = new Rect(rect.width - _button.x, rect.height - _button.y, _button.x - Margin,
                                           _button.y - Margin);

            // set up rects
            for (var j = 0; j < cols; j++)
            {
                colRects.Add(new Rect(j * colWidth + j * Margin + Margin / 2, _topAreaHeight, colWidth, height));
                colTitleRects.Add(new Rect(j * colWidth + j * Margin + Margin * 2.5f, 0f, colWidth, _topAreaHeight));
            }

            // keep track of location
            Vector2 cur;

            // begin window
            GUI.BeginGroup(rect);

            // settings.
            Text.Anchor = TextAnchor.LowerLeft;
            Text.Font   = GameFont.Tiny;
            Widgets.Label(colTitleRects[0], "FMF.Options".Translate());
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperLeft;

            GUI.DrawTexture(colRects[0], Resources.SlightlyDarkBackground);
            GUI.BeginGroup(colRects[0]);
            cur = Vector2.zero;

            // trigger config (1)
            int currentCount    = _selected.Trigger.CurCount;
            int designatedCount = _selected.GetWoodInDesignations();
            int targetCount     = _selected.Trigger.Count;

            _selected.Trigger.DrawTriggerConfig(ref cur, colRects[0].width, EntryHeight, true,
                                                "FMF.TargetCount".Translate(currentCount, designatedCount, targetCount),
                                                "FMF.TargetCountTooltip".Translate(currentCount, designatedCount,
                                                                                   targetCount));

            // Clear wind cells (2)
            var clearWindCellsRect = new Rect(cur.x, cur.y, colWidth, EntryHeight);

            Utilities.DrawToggle(clearWindCellsRect, "FMF.ClearWindCells".Translate(),
                                 ref ManagerJob_Forestry.ClearWindCells);
            cur.y += EntryHeight;

            // clear additional areas(3)
            var clearAdditionalAreasLabelRect = new Rect(cur.x, cur.y, colWidth, EntryHeight);

            Widgets.DrawAltRect(clearAdditionalAreasLabelRect);
            Utilities.Label(clearAdditionalAreasLabelRect, "FMF.ClearAreas".Translate(), anchor: TextAnchor.MiddleLeft,
                            lrMargin: Margin);
            cur.y += EntryHeight;

            var clearAdditionalAreasSelectorRect = new Rect(cur.x, cur.y, colWidth, EntryHeight);

            Widgets.DrawAltRect(clearAdditionalAreasSelectorRect);
            AreaAllowedGUI.DoAllowedAreaSelectorsMC(clearAdditionalAreasSelectorRect, ref _selected.ClearAreas, Margin);
            cur.y += EntryHeight;

            // Allow saplings (4)
            var allowSaplingsRect = new Rect(cur.x, cur.y, colWidth, EntryHeight);

            Utilities.DrawToggle(allowSaplingsRect, "FMF.AllowSaplings".Translate(), ref _selected.AllowSaplings);
            cur.y += EntryHeight;

            // Logging area (5)
            var loggingAreaTitleRect = new Rect(cur.x, cur.y, colWidth, EntryHeight);

            Widgets.DrawAltRect(loggingAreaTitleRect);
            Utilities.Label(loggingAreaTitleRect, "FMF.LoggingArea".Translate(), anchor: TextAnchor.MiddleLeft,
                            lrMargin: Margin);
            cur.y += EntryHeight;

            var loggingAreaRect = new Rect(cur.x, cur.y, colWidth, EntryHeight);

            Widgets.DrawAltRect(loggingAreaRect);
            AreaAllowedGUI.DoAllowedAreaSelectors(loggingAreaRect, ref _selected.LoggingArea, manager, lrMargin: Margin);
            cur.y += EntryHeight;

            GUI.EndGroup();

            // treedefs.
            Text.Anchor = TextAnchor.LowerLeft;
            Text.Font   = GameFont.Tiny;
            Widgets.Label(colTitleRects[1], "FMF.Trees".Translate());
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperLeft;

            GUI.DrawTexture(colRects[1], Resources.SlightlyDarkBackground);
            GUI.BeginGroup(colRects[1]);
            cur = Vector2.zero;

            Rect outRect  = colRects[1].AtZero().ContractedBy(1f);
            var  viewRect = new Rect(0f, 0f, outRect.width, _selected.AllowedTrees.Count * EntryHeight);

            if (viewRect.height > outRect.height)
            {
                viewRect.width -= 16f;
            }

            // start scrolling view
            Widgets.BeginScrollView(outRect, ref _contentScrollPosition, viewRect);

            // list of keys in allowed trees list (all plans that yield wood in biome, static)
            var treeDefs = new List <ThingDef>(_selected.AllowedTrees.Keys);

            // toggle all
            var toggleAllRect = new Rect(cur.x, cur.y, colWidth, EntryHeight);

            Widgets.DrawAltRect(toggleAllRect);
            Utilities.DrawToggle(toggleAllRect, "<i>" + "FM.All".Translate() + "</i>",
                                 _selected.AllowedTrees.Values.All(v => v), delegate
            {
                foreach (
                    ThingDef def in treeDefs)
                {
                    _selected.AllowedTrees[def] =
                        true;
                }
            }, delegate
            {
                foreach (
                    ThingDef def in
                    treeDefs)
                {
                    _selected.AllowedTrees
                    [def] = false;
                }
            });

            cur.y += EntryHeight;

            // toggle for each tree
            var i = 1;

            foreach (ThingDef def in treeDefs)
            {
                var toggleRect = new Rect(cur.x, cur.y, colWidth, EntryHeight);

                // highlight alternate rows
                if (i++ % 2 == 0)
                {
                    Widgets.DrawAltRect(toggleRect);
                }

                // draw the toggle
                Utilities.DrawToggle(toggleRect, def.LabelCap, _selected.AllowedTrees[def],
                                     delegate
                                     { _selected.AllowedTrees[def] = !_selected.AllowedTrees[def]; });

                // update current position
                cur.y += EntryHeight;
            }

            // close scrolling view
            Widgets.EndScrollView();

            // close tree list
            GUI.EndGroup();

            // do the button
            if (!_selected.Managed)
            {
                if (Widgets.ButtonText(buttonRect, "FM.Manage".Translate()))
                {
                    // activate job, add it to the stack
                    _selected.Managed = true;
                    manager.JobStack.Add(_selected);

                    // refresh source list
                    Refresh();
                }
            }
            else
            {
                if (Widgets.ButtonText(buttonRect, "FM.Delete".Translate()))
                {
                    // inactivate job, remove from the stack.
                    manager.JobStack.Delete(_selected);

                    // remove content from UI
                    _selected = null;

                    // refresh source list
                    Refresh();
                }
            }

            // close window
            GUI.EndGroup();
        }