Ejemplo n.º 1
0
        private void DrawAvailableUpgradeEntry(AssemblyLineUpgradeDef def, float currentScrollY)
        {
            Rect currentEntryRect = new Rect(margin, currentScrollY, upgradeEntrySize.x, upgradeEntrySize.y);

            Widgets.DrawMenuSection(currentEntryRect);
            Rect   innerRect = currentEntryRect.ContractedBy(4f);
            string s         = "MD2BuildingMaterials".Translate() + "\n";

            foreach (var item in def.RequiredMaterials)
            {
                s += item.amount.ToString() + " " + item.thing.LabelCap + "\n";
            }
            s += "InstallUpgradeTimeToComplete".Translate(TicksToTime.GetTime(def.workTicksAmount));
            TooltipHandler.TipRegion(innerRect, s);
            Vector2 butSize = new Vector2(60f, innerRect.height / 2);
            float   padding = 2f;

            try
            {
                GUI.BeginGroup(innerRect);

                Rect textBox = new Rect(0, 0, innerRect.width / 2, innerRect.height);
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(textBox, def.label);
                //Text.Anchor = TextAnchor.UpperLeft;

                Rect butRect = new Rect(innerRect.width - (butSize.x + padding), innerRect.height / 2 - (butSize.y / 2), butSize.x, butSize.y);
                if (Widgets.TextButton(butRect, "UpgradeInstall".Translate()))
                {
                    UpgradesInProgress.Add(new AssemblyLineUpgrade(def));
                }
            }
            finally
            {
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.EndGroup();
            }
        }
Ejemplo n.º 2
0
        public void OnGUI(float curY, Vector2 lineEntrySize, Vector2 interactButtonSize, Window page)
        {
            if (underConstruction)
            {
                //First we set the box that the current entry is in. We use the curY value to set its position in the list.
                Rect currentEntryRect = new Rect(0f, curY, lineEntrySize.x, lineEntrySize.y);

                //This widget draws the box for the entry.
                Widgets.DrawMenuSection(currentEntryRect);

                //We then get the innerRect of this entry box. This gives us a margin around the inside of the entry box, just to make it look nicer.
                Rect innerRect = currentEntryRect.ContractedBy(6f);

                //Start the group and display the information
                try
                {
                    GUI.BeginGroup(innerRect);

                    //This float is used for centering the buttons. The labels have the same height as the parent box, and the text inside them is aligned to the centre so this makes it easier for us to centre text.
                    float innerRectCentreY = (innerRect.yMax - innerRect.y) / 2;

                    //This sets up the rect for the line name label. It is indented 15f and is the same width and height as the parent box.
                    Rect lineLabelRect = new Rect(15f, 0f, innerRect.width, innerRect.height);
                    Text.Anchor = TextAnchor.MiddleLeft;
                    Text.Font   = GameFont.Small;
                    Widgets.Label(lineLabelRect, this.label);

                    //We reset the color just to make sure it is still on white.
                    GUI.color = Color.white;

                    //This draws label which shows either under construction: time remaining, or manager required.
                    Rect lineStatusRect = new Rect(400f, 0f, innerRect.width, innerRect.height);
                    Text.Font = GameFont.Tiny;
                    //we change the color of the text here
                    GUI.color = new Color(1f, 1f, 1f, 0.5f);
                    string str;
                    if (billOfMaterials.HasMats)
                    {
                        str = "AssemblyLineUnderConstruction".Translate(TicksToTime.GetTime((float)ConstructionTicks));
                    }
                    else
                    {
                        str = billOfMaterials.ReportString;
                    }
                    Widgets.Label(lineStatusRect, str);

                    //We change the color back to white
                    GUI.color   = Color.white;
                    Text.Anchor = TextAnchor.UpperLeft;
                    Text.Font   = GameFont.Small;

                    //This float is used to place the pause button. It takes the width of the parent box, takes away a margin of 12, then the width of the button and then the height. The height is used later for the delete button so this extra space is used.
                    float num = lineEntrySize.x - 12f - interactButtonSize.x - interactButtonSize.y;
                    //we use the centering float here to centre the buttons. Take away half the height of the button from the float to get the position where the button will be perfectly centered.
                    Rect butRect = new Rect(num, innerRectCentreY - (interactButtonSize.y / 2), interactButtonSize.x, interactButtonSize.y);
                    //Buttons return a bool if they are clicked, so placing them in an if statement will perform an action when they are clicked. (Remember that the DoWindowContents() function is called every frame, so this code is constantly being executed)
                    string butStr;
                    if (constructionPaused)
                    {
                        butStr = "MD2Resume".Translate();
                    }
                    else
                    {
                        butStr = "MD2Pause".Translate();
                    }
                    if (Widgets.TextButton(butRect, butStr))
                    {
                        if (constructionPaused)
                        {
                            constructionPaused = false;
                        }
                        else
                        {
                            constructionPaused = true;
                        }
                    }

                    Rect deleteButRect = new Rect(num + butRect.width + 5f, innerRectCentreY - (interactButtonSize.y / 2), interactButtonSize.y, interactButtonSize.y);
                    if (Widgets.ImageButton(deleteButRect, ContentFinder <Texture2D> .Get("UI/Buttons/Delete", true)))
                    {
                        string s;
                        if (!underConstruction)
                        {
                            s = "DeleteAssemblyLine".Translate();
                        }
                        else
                        {
                            s = "DeleteAssemblyLineUnderConstruction".Translate();
                        }
                        Find.WindowStack.Add(new Dialog_Confirm(s, delegate
                        {
                            MPmanager.manager.RemoveAssemblyLine(this);
                            ((Window_ManufacturingPlantMainUI)page).assemblyLines = MPmanager.manager.AssemblyLines;
                        }));
                    }
                    TooltipHandler.TipRegion(deleteButRect, "MD2Delete".Translate());
                }
                finally
                {
                    GUI.EndGroup();
                }
            }
            else
            {
                //First we set the box that the current entry is in. We use the curY value to set its position in the list.
                Rect currentEntryRect = new Rect(0f, curY, lineEntrySize.x, lineEntrySize.y);

                //This widget draws the box for the entry.
                Widgets.DrawMenuSection(currentEntryRect);

                //We then get the innerRect of this entry box. This gives us a margin around the inside of the entry box, just to make it look nicer.
                Rect innerRect = currentEntryRect.ContractedBy(6f);

                //We then begin the group for the entry. This tells the system that all the following widgets are grouped together.
                GUI.BeginGroup(innerRect);

                //This float is used for centering the buttons. The labels have the same height as the parent box, and the text inside them is aligned to the centre so this makes it easier for us to centre text.
                float innerRectCentreY = (innerRect.yMax - innerRect.y) / 2;

                //This sets up the rect for the line name label. It is indented 15f and is the same width and height as the parent box.
                Rect lineLabelRect = new Rect(15f, 0f, innerRect.width, innerRect.height);
                Text.Anchor = TextAnchor.MiddleLeft;
                Text.Font   = GameFont.Small;
                Widgets.Label(lineLabelRect, this.label);

                //We reset the color just to make sure it is still on white.
                GUI.color = Color.white;

                //This draws the manager info label. It is in the middle of the parent box.
                Rect lineInfoRect = new Rect(400f, 0f, innerRect.width, innerRect.height);
                Text.Font = GameFont.Tiny;
                //we change the color of the text here
                GUI.color = new Color(1f, 1f, 1f, 0.5f);
                string statusString;
                if (this.CurrentOrder != null && CurrentOrder.DesiresToWork)
                {
                    if (CurrentOrder.ShoppingList.HasAllMats)
                    {
                        statusString = "AssemblyLineStatusInProduction".Translate();
                    }
                    else
                    {
                        statusString = "AssemblyLineStatusRequiresMaterials".Translate();
                    }
                }
                else
                {
                    statusString = "MD2Idle".Translate();
                }
                Widgets.Label(lineInfoRect, statusString);

                //We change the color back to white
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperLeft;
                Text.Font   = GameFont.Small;
                //This float is used to place the select button. It takes the width of the parent box, takes away a margin of 12, then the width of the button and then the height. The height is used later for the delete button so this extra space is used.
                float num = lineEntrySize.x - 12f - interactButtonSize.x - interactButtonSize.y;
                //we use the centering float here to centre the buttons. Take away half the height of the button from the float to get the position where the button will be perfectly centered.
                Rect butRect = new Rect(num, innerRectCentreY - (interactButtonSize.y / 2), interactButtonSize.x, interactButtonSize.y);
                //Buttons return a bool if they are clicked, so placing them in an if statement will perform an action when they are clicked. (Remember that the DoWindowContents() function is called every frame, so this code is constantly being executed)
                if (Widgets.TextButton(butRect, "MD2Select".Translate()))
                {
                    Find.WindowStack.Add(new Window_LineManagementUI(this, page));
                }
                Rect deleteButRect = new Rect(num + butRect.width + 5f, innerRectCentreY - (interactButtonSize.y / 2), interactButtonSize.y, interactButtonSize.y);
                if (Widgets.ImageButton(deleteButRect, ContentFinder <Texture2D> .Get("UI/Buttons/Delete", true)))
                {
                    string s = "DeleteAssemblyLine".Translate();
                    Find.WindowStack.Add(new Dialog_Confirm(s, delegate
                    {
                        MPmanager.manager.RemoveAssemblyLine(this);
                        ((Window_ManufacturingPlantMainUI)page).assemblyLines = MPmanager.manager.AssemblyLines;
                    }));
                }
                TooltipHandler.TipRegion(deleteButRect, "MD2Delete".Translate());
                GUI.EndGroup();
            }
        }
Ejemplo n.º 3
0
        private void DrawUpgradeInProgressEntry(AssemblyLineUpgrade upgrade, float currentScrollY)
        {
            Rect currentEntryRect = new Rect(margin, currentScrollY, upgradeEntrySize.x, upgradeEntrySize.y);

            Widgets.DrawMenuSection(currentEntryRect);
            Rect    innerRect = currentEntryRect.ContractedBy(4f);
            Vector2 butSize   = new Vector2(60f, innerRect.height / 2);

            Widgets.FillableBar(currentEntryRect, upgrade.PercentageComplete, FillableBarTex, null, false);

            try
            {
                GUI.BeginGroup(innerRect);

                Text.Anchor = TextAnchor.MiddleLeft;
                float width     = Text.CalcSize(upgrade.Def.LabelCap).x;
                Rect  labelRect = new Rect(0f, 0f, width, innerRect.height);
                Widgets.Label(labelRect, upgrade.Def.LabelCap);

                string s;
                if (upgrade.BillOfMaterials.HasMats)
                {
                    s = "MD2Progress".Translate((upgrade.PercentageComplete * 100).ToString("0.0\\%"));
                    TooltipHandler.TipRegion(innerRect, "UpgradeInstallTimeRemaining".Translate(TicksToTime.GetTime(upgrade.TicksRemaining)));
                }
                else
                {
                    s = upgrade.BillOfMaterials.ReportString;
                }
                Text.Anchor = TextAnchor.MiddleLeft;
                Rect progressRect = new Rect(innerRect.width / 2 - (Text.CalcSize(s).x), innerRect.yMin, innerRect.width, innerRect.height);
                Widgets.Label(progressRect, s);
            }
            finally
            {
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.EndGroup();
            }
        }
Ejemplo n.º 4
0
        public override void DoWindowContents(Rect inRect)
        {
            base.DoWindowContents(inRect);

            //First we draw the header
            Text.Font   = GameFont.Medium;
            Text.Anchor = TextAnchor.UpperCenter;
            Widgets.Label(new Rect(0f, 0f, 300f, 300f), "ManufacturingPlant".Translate());
            Text.Anchor = TextAnchor.UpperLeft;

            //This float is used to set the padding at the bottom of the window.
            float bottomPaddingHeight = 50f;

            //The mainRect is the rectangle which contains the listbox
            Rect mainRect = new Rect(0f, bottomPaddingHeight, inRect.width, inRect.height - bottomPaddingHeight - 50f);

            //We initialise the entry and button sizes according to the main rect, which is sized depending on the window size. This lets the window be resized easily without (hoepfully) creating too many problems.
            this.lineEntrySize      = new Vector2(mainRect.width - 16f, 100f);
            this.interactButtonSize = new Vector2(100f, this.lineEntrySize.y / 2 - 14f);

            //We begin the group to tell the system that the following elements are grouped together.
            GUI.BeginGroup(mainRect);

            //This float is the height of the entry with a small margin added to it.
            float entryHeightWithMargin = this.lineEntrySize.y + 8f;

            //This float is the height of the entire list with all included entries and margins. This is used for the rect which houses all the entries, even though we wont see all of them at once.
            float height = (float)assemblyLines.Count * entryHeightWithMargin;

            //This rect is used inside the scroll view, and is moved up and down to show the entries.
            Rect viewRect = new Rect(0f, 0f, mainRect.width - 16f, height);

            //This is the rect on the screen to be used for the ScrollView
            Rect outRect = new Rect(mainRect.AtZero());

            //This function starts the scrolling view, and uses the scrollPosition variable to record where in the scrollview we are looking
            Widgets.BeginScrollView(outRect, ref this.scrollPosition, viewRect);

            //This float is the current y position in the scrollview, we use this for drawing each entry under each other.
            float currentY = 0f;

            //We first check to see if there are any entries. If no, then give a small message
            if (assemblyLines.Count == 0)
            {
                Rect rect2 = new Rect(0f, currentY, this.lineEntrySize.x, this.lineEntrySize.y);
                Text.Font = GameFont.Small;
                Widgets.Label(rect2, "NoAssemblyLines".Translate());
            }

            //If there are entries, then we draw the entry for each element in the list, calling our Draw...() function.
            else
            {
                foreach (AssemblyLine line in assemblyLines)
                {
                    line.OnGUI(currentY, this.lineEntrySize, this.interactButtonSize, this);
                    //Increment the current y position for the next entry to be drawn
                    currentY += entryHeightWithMargin;
                }
            }
            //Must remember to end the view once it has been drawn.
            Widgets.EndScrollView();
            //Likewise, remember to end the group
            GUI.EndGroup();

            //This draws the button in the bottom right corner of the window. It uses the same size as the Close button
            Rect lineManagerButRect = new Rect(inRect.width - this.lineManagerButtonSize.x, inRect.height - this.lineManagerButtonSize.y, this.lineManagerButtonSize.x, this.lineManagerButtonSize.y);

            if (Widgets.TextButton(lineManagerButRect, "ConstructNewAssemblyLine".Translate()))
            {
                if (MPmanager.manager.CanAddAssemblyLine)
                {
                    string costString = "";
                    if (Game.GodMode && AssemblyLine.Settings.instaBuild)
                    {
                        costString = "Nothing".Translate();
                    }
                    else
                    {
                        foreach (var item in AssemblyLine.Settings.BuildingCost)
                        {
                            costString += string.Format("{1} {0}\n", item.thing.label, item.amount);
                        }
                    }
                    Find.WindowStack.Add(new Dialog_Confirm("BuildNewAssemblyLineDialog".Translate(costString, TicksToTime.GetTime((float)AssemblyLine.ConstructionTicksRequired)), delegate
                    {
                        MPmanager.manager.AddNewAssemblyLine((Game.GodMode && AssemblyLine.Settings.instaBuild));
                    }));
                }
                else
                {
                    Dialog_Message m = new Dialog_Message("MaximumAssemblyLines".Translate());
                    Find.WindowStack.Add(m);
                    SoundDefOf.ClickReject.PlayOneShot(SoundInfo.OnCamera());
                }
            }
        }