Esempio n. 1
0
        public static string doTerminalTextField(int myID, int x, int y, int width, int selectionHeight, int lines, string str, SpriteFont font)
        {
            string s = str;

            if (font == null)
            {
                font = GuiData.smallfont;
            }
            TextBox.BoxWasActivated = false;
            TextBox.UpWasPresed     = false;
            TextBox.DownWasPresed   = false;
            TextBox.TabWasPresed    = false;
            Rectangle tmpRect = GuiData.tmpRect;

            tmpRect.X      = x;
            tmpRect.Y      = y;
            tmpRect.Width  = width;
            tmpRect.Height = 0;
            if (tmpRect.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
            }
            else if (GuiData.hot == myID)
            {
                GuiData.hot = -1;
            }
            if (GuiData.mouseWasPressed())
            {
                if (GuiData.hot == myID)
                {
                    if (GuiData.active == myID)
                    {
                        int  num  = GuiData.mouse.X - x;
                        bool flag = false;
                        for (int length = 1; length <= str.Length; ++length)
                        {
                            if ((double)font.MeasureString(str.Substring(0, length)).X > (double)num)
                            {
                                TextBox.cursorPosition = length - 1;
                                break;
                            }
                            if (!flag)
                            {
                                TextBox.cursorPosition = str.Length;
                            }
                        }
                    }
                    else
                    {
                        GuiData.active         = myID;
                        TextBox.cursorPosition = str.Length;
                    }
                }
                else if (GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            int           active1             = GuiData.active;
            bool          flag1               = false;
            string        filteredStringInput = TextBox.getFilteredStringInput(s, GuiData.getKeyboadState(), GuiData.getLastKeyboadState());
            KeyboardState keyboardState       = GuiData.getKeyboadState();
            int           num1;

            if (keyboardState.IsKeyDown(Keys.Enter))
            {
                keyboardState = GuiData.getLastKeyboadState();
                num1          = keyboardState.IsKeyDown(Keys.Enter) ? 1 : 0;
            }
            else
            {
                num1 = 1;
            }
            if (num1 == 0)
            {
                TextBox.BoxWasActivated        = true;
                TextBox.cursorPosition         = 0;
                TextBox.textDrawOffsetPosition = 0;
            }
            tmpRect.Height = lines * TextBox.LINE_HEIGHT;
            ++TextBox.FramesSelected;
            tmpRect.X       = x;
            tmpRect.Y       = y;
            tmpRect.Width   = width;
            tmpRect.Height  = 10;
            tmpRect.X      += 2;
            tmpRect.Y      += 2;
            tmpRect.Width  -= 4;
            tmpRect.Height -= 4;
            float  num2       = (float)(((double)TextBox.LINE_HEIGHT - (double)font.MeasureString(filteredStringInput).Y) / 2.0);
            string str1       = filteredStringInput;
            int    num3       = 0;
            int    startIndex = 0;
            int    length1;

            for (string text = str1; (double)font.MeasureString(text).X > (double)(width - 5); text = str1.Substring(startIndex, length1))
            {
                ++num3;
                length1 = str1.Length - startIndex - (num3 - startIndex);
                if (length1 < 0)
                {
                    break;
                }
            }
            if (TextBox.cursorPosition < TextBox.textDrawOffsetPosition)
            {
                TextBox.textDrawOffsetPosition = Math.Max(0, TextBox.textDrawOffsetPosition - 1);
            }
            while (TextBox.cursorPosition > TextBox.textDrawOffsetPosition + (str1.Length - num3))
            {
                ++TextBox.textDrawOffsetPosition;
            }
            if (str1.Length <= num3 || TextBox.textDrawOffsetPosition < 0)
            {
                TextBox.textDrawOffsetPosition = TextBox.textDrawOffsetPosition > str1.Length - num3 ? 0 : str1.Length - num3;
            }
            else if (TextBox.textDrawOffsetPosition > num3)
            {
                num3 = TextBox.textDrawOffsetPosition;
            }
            if (num3 > str1.Length)
            {
                num3 = str1.Length - 1;
            }
            if (TextBox.textDrawOffsetPosition >= str1.Length)
            {
                TextBox.textDrawOffsetPosition = 0;
            }
            string text1 = str1.Substring(TextBox.textDrawOffsetPosition, str1.Length - num3);

            if (TextBox.MaskingText)
            {
                string str2 = "";
                for (int index = 0; index < filteredStringInput.Length; ++index)
                {
                    str2 += "*";
                }
                text1 = str2;
            }
            GuiData.spriteBatch.DrawString(font, text1, Utils.ClipVec2ForTextRendering(new Vector2((float)(x + 2), (float)y + num2)), Color.White);
            int active2 = GuiData.active;

            flag1 = false;
            if (filteredStringInput != "")
            {
                int length2 = Math.Min(TextBox.cursorPosition - TextBox.textDrawOffsetPosition, text1.Length);
                if (length2 <= 0)
                {
                    length2 = 1;
                }
                tmpRect.X = text1.Length != 0 ? (int)((double)x + (double)font.MeasureString(text1.Substring(0, length2)).X) + 3 : x;
            }
            else
            {
                tmpRect.X = x + 3;
            }
            tmpRect.Y      = y + 2;
            tmpRect.Width  = 1;
            tmpRect.Height = TextBox.LINE_HEIGHT - 4;
            if (LocaleActivator.ActiveLocaleIsCJK())
            {
                tmpRect.Y += 4;
            }
            GuiData.spriteBatch.Draw(Utils.white, tmpRect, TextBox.FramesSelected % 60 < 40 ? Color.White : Color.Gray);
            return(filteredStringInput);
        }
Esempio n. 2
0
        public static string doTextBox(int myID, int x, int y, int width, int lines, string str, SpriteFont font)
        {
            string str1 = str;

            if (font == null)
            {
                font = GuiData.smallfont;
            }
            TextBox.BoxWasActivated = false;
            Rectangle tmpRect = GuiData.tmpRect;

            tmpRect.X      = x;
            tmpRect.Y      = y;
            tmpRect.Width  = width;
            tmpRect.Height = lines * TextBox.LINE_HEIGHT;
            if (tmpRect.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
            }
            else if (GuiData.hot == myID)
            {
                GuiData.hot = -1;
            }
            if (GuiData.mouseWasPressed())
            {
                if (GuiData.hot == myID)
                {
                    if (GuiData.active == myID)
                    {
                        int  num  = GuiData.mouse.X - x;
                        bool flag = false;
                        for (int length = 1; length <= str.Length; ++length)
                        {
                            if ((double)font.MeasureString(str.Substring(0, length)).X > (double)num)
                            {
                                TextBox.cursorPosition = length - 1;
                                break;
                            }
                            if (!flag)
                            {
                                TextBox.cursorPosition = str.Length;
                            }
                        }
                    }
                    else
                    {
                        GuiData.active         = myID;
                        TextBox.cursorPosition = str.Length;
                    }
                }
                else if (GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            if (GuiData.active == myID)
            {
                GuiData.willBlockTextInput = true;
                str1 = TextBox.getStringInput(str1, GuiData.getKeyboadState(), GuiData.getLastKeyboadState());
                KeyboardState keyboardState = GuiData.getKeyboadState();
                int           num;
                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    keyboardState = GuiData.getLastKeyboadState();
                    num           = !keyboardState.IsKeyDown(Keys.Enter) ? 1 : 0;
                }
                else
                {
                    num = 1;
                }
                if (num == 0)
                {
                    TextBox.BoxWasActivated = true;
                    GuiData.active          = -1;
                }
            }
            ++TextBox.FramesSelected;
            tmpRect.X      = x;
            tmpRect.Y      = y;
            tmpRect.Width  = width;
            tmpRect.Height = lines * TextBox.LINE_HEIGHT;
            GuiData.spriteBatch.Draw(Utils.white, tmpRect, GuiData.active == myID ? GuiData.Default_Lit_Backing_Color : (GuiData.hot == myID ? GuiData.Default_Selected_Color : GuiData.Default_Dark_Background_Color));
            tmpRect.X      += 2;
            tmpRect.Y      += 2;
            tmpRect.Width  -= 4;
            tmpRect.Height -= 4;
            GuiData.spriteBatch.Draw(Utils.white, tmpRect, GuiData.Default_Light_Backing_Color);
            float num1 = (float)(((double)TextBox.LINE_HEIGHT - (double)font.MeasureString(str1).Y) / 2.0);

            GuiData.spriteBatch.DrawString(font, str1, new Vector2((float)(x + 2), (float)y + num1), Color.White);
            if (GuiData.active == myID)
            {
                tmpRect.X      = (int)((double)x + (double)font.MeasureString(str1.Substring(0, TextBox.cursorPosition)).X) + 3;
                tmpRect.Y      = y + 2;
                tmpRect.Width  = 1;
                tmpRect.Height = TextBox.LINE_HEIGHT - 4;
                GuiData.spriteBatch.Draw(Utils.white, tmpRect, TextBox.FramesSelected % 60 < 40 ? Color.White : Color.Gray);
            }
            return(str1);
        }
Esempio n. 3
0
 public static void OverrideFirstTimeInit(CommandSentEvent e)
 {
     if (Extension.Handler.ActiveInfo != null &&
         e[0] == "FirstTimeInitdswhupwnemfdsiuoewnmdsmffdjsklanfeebfjkalnbmsdakj")
     {
         var os    = e.OS;
         var num   = Settings.isConventionDemo ? 80 : 200;
         var num2  = Settings.isConventionDemo ? 150 : 300;
         var doTut = e[1] == "StartTutorial";
         if (doTut)
         {
             os.display.visible    = false;
             os.ram.visible        = false;
             os.netMap.visible     = false;
             os.terminal.visible   = true;
             os.mailicon.isEnabled = false;
             if (os.hubServerAlertsIcon != null)
             {
                 os.hubServerAlertsIcon.IsEnabled = false;
             }
         }
         if (Settings.debugCommandsEnabled && GuiData.getKeyboadState().IsKeyDown(Keys.LeftAlt))
         {
             num2 = (num = 1);
         }
         Programs.typeOut("Initializing .", os, 50);
         Programs.doDots(7, num + 100, os);
         Programs.typeOut("Loading modules.", os, 50);
         Programs.doDots(5, num, os);
         os.writeSingle("Complete");
         Utility.HaltThread(num2);
         Programs.typeOut("Loading nodes.", os, 50);
         Programs.doDots(5, num, os);
         os.writeSingle("Complete");
         Utility.HaltThread(num2);
         Programs.typeOut("Reticulating splines.", os, 50);
         Programs.doDots(5, num - 50, os);
         os.writeSingle("Complete");
         Utility.HaltThread(num2);
         if (os.crashModule.BootLoadErrors.Length > 0)
         {
             Programs.typeOut("\n------ " + LocaleTerms.Loc("BOOT ERRORS DETECTED") + " ------", os, 50);
             Utility.HaltThread(200);
             var array = os.crashModule.BootLoadErrors.Split(Utils.newlineDelim, StringSplitOptions.RemoveEmptyEntries);
             for (int i = 0; i < array.Length; i++)
             {
                 Programs.typeOut(array[i], os, 50);
                 Utility.HaltThread(100, true);
             }
             Programs.typeOut("---------------------------------\n", os, 50);
             Utility.HaltThread(200, true);
         }
         Programs.typeOut("\n--Initialization Complete--\n", os, 50);
         GuiData.getFilteredKeys();
         os.inputEnabled = true;
         Utility.HaltThread(num2 + 100);
         if (!doTut)
         {
             Programs.typeOut(LocaleTerms.Loc("For A Command List, type \"help\""), os, 50);
             Utility.HaltThread(num2 + 100);
         }
         os.write("");
         Utility.HaltThread(num2);
         os.write("");
         Utility.HaltThread(num2);
         os.write("");
         Utility.HaltThread(num2);
         os.write("\n");
         if (doTut)
         {
             os.write(LocaleTerms.Loc("Launching Tutorial..."));
             os.launchExecutable("Tutorial.exe", PortExploits.crackExeData[1], -1, null, null);
             Settings.initShowsTutorial = false;
             AdvancedTutorial advancedTutorial = null;
             for (int i = 0; i < os.exes.Count; i++)
             {
                 advancedTutorial = (os.exes[i] as AdvancedTutorial);
                 if (advancedTutorial != null)
                 {
                     break;
                 }
             }
             if (advancedTutorial != null)
             {
                 advancedTutorial.CanActivateFirstStep = false;
             }
             int num3 = 100;
             for (int i = 0; i < num3; i++)
             {
                 double num4 = (double)i / num3;
                 if (Utils.random.NextDouble() < num4)
                 {
                     os.ram.visible      = true;
                     os.netMap.visible   = false;
                     os.terminal.visible = false;
                 }
                 else
                 {
                     os.ram.visible      = false;
                     os.netMap.visible   = false;
                     os.terminal.visible = true;
                 }
                 Utility.HaltThread(16, true);
             }
             os.ram.visible      = true;
             os.netMap.visible   = false;
             os.terminal.visible = false;
             if (advancedTutorial != null)
             {
                 advancedTutorial.CanActivateFirstStep = true;
             }
         }
         else
         {
             os.runCommand("connect " + os.thisComputer.ip);
             if (doTut && !OS.WillLoadSave && !os.Flags.HasFlag("ExtensionFirstBootComplete"))
             {
                 ExtensionLoader.SendStartingEmailForActiveExtensionNextFrame(os);
                 float num5 = 2.2f;
                 var   num3 = (int)(60f * num5);
                 for (int i = 0; i < num3; i++)
                 {
                     double num4 = (double)i / num3;
                     os.ram.visible     = (Utils.random.NextDouble() < num4);
                     os.netMap.visible  = (Utils.random.NextDouble() < num4);
                     os.display.visible = (Utils.random.NextDouble() < num4);
                     Utility.HaltThread(16, true);
                 }
                 os.terminal.visible    = true;
                 os.display.visible     = true;
                 os.netMap.visible      = true;
                 os.ram.visible         = true;
                 os.terminal.visible    = true;
                 os.display.inputLocked = false;
                 os.netMap.inputLocked  = false;
                 os.ram.inputLocked     = false;
                 os.Flags.AddFlag("ExtensionFirstBootComplete");
             }
         }
         Utility.HaltThread(500, true);
         if (wasRecursed)
         {
             os.ram.visible         = true;
             os.ram.inputLocked     = false;
             os.display.visible     = true;
             os.display.inputLocked = false;
             os.netMap.visible      = true;
             os.netMap.inputLocked  = false;
         }
         else if (doTut)
         {
             os.ram.visible         = true;
             os.ram.inputLocked     = false;
             os.display.visible     = true;
             os.display.inputLocked = false;
             os.netMap.visible      = true;
             os.netMap.inputLocked  = false;
         }
         else if (!os.ram.visible)
         {
             wasRecursed = true;
             OverrideFirstTimeInit(e);
         }
     }
 }
Esempio n. 4
0
        private static void DrawLogin(DrawMainMenuEvent e)
        {
            RequestGoBack += (Action)(() => ChangeState(MenuState.MAIN_MENU));
            Rectangle  dest      = new Rectangle(bMenu.ScreenManager.GraphicsDevice.Viewport.Width / 4, bMenu.ScreenManager.GraphicsDevice.Viewport.Height / 4, bMenu.ScreenManager.GraphicsDevice.Viewport.Width / 2, bMenu.ScreenManager.GraphicsDevice.Viewport.Height / 4);
            SpriteFont smallfont = GuiData.smallfont;
            int        y1        = dest.Y + dest.Height + 12;
            int        y2        = y1 + 10;
            int        num1      = (int)((double)smallfont.MeasureString(currentPrompt).X + 4.0);
            int        num2      = dest.Y + dest.Height - 18;
            int        num3      = y2 - 60;
            float      num4      = GuiData.ActiveFontConfig.tinyFontCharHeight + 8f;
            Vector2    position  = new Vector2((float)dest.X, false ? (float)y2 : (float)(dest.Y + dest.Height - 20) - num4);

            GuiData.spriteBatch.Draw(Utils.white, new Rectangle(dest.X, y1, dest.Width / 2, 1), Utils.SlightlyDarkGray);
            GuiData.spriteBatch.DrawString(GuiData.UISmallfont, loginMessage, new Vector2(position.X, position.Y + 125), MainMenu.CancelColor);
            GuiData.spriteBatch.DrawString(smallfont, currentPrompt, new Vector2((float)dest.X, (float)num2), Color.White);

            if (IsReady)
            {
                if (!GuiData.getKeyboadState().IsKeyDown(Keys.Enter))
                {
                    CanReturnEnter = true;
                }
                if ((!HasOverlayScreen && (!IsLoginMode || Hacknet.Gui.Button.doButton(16392804, dest.X, y2, dest.Width / 3, 28, LocaleTerms.Loc("CONFIRM"), new Color?(Color.White))) || CanReturnEnter && Utils.keyPressed(GuiData.lastInput, Keys.Enter, new PlayerIndex?())) && !PreventAdvancing)
                {
                    if (IsLoginMode)
                    {
                        if (Answers.Count < 2)
                        {
                            ResetForLogin();
                        }
                        else
                        {
                            string username = Answers[Answers.Count - 2];
                            string password = Answers[Answers.Count - 1];
                            Hacknet.Gui.TextBox.MaskingText = false;
                            StartGame(username, password);
                        }
                    }
                    else
                    {
                        Hacknet.Gui.TextBox.MaskingText = false;
                        Console.Write("An Error has occured! Fixing now");
                        History.Clear();
                        currentPrompt = "";
                        ResetForLogin();
                        IsLoginMode = true;
                    }
                    PreventAdvancing = true;
                }
                y2 += 36;
            }
            else
            {
                Hacknet.Gui.TextBox.MaskingText = InPasswordMode;
                terminalString = Hacknet.Gui.TextBox.doTerminalTextField(16392802, dest.X + num1, num2 - 2, dest.Width, 20, 1, terminalString, GuiData.UISmallfont);
            }

            if (!HasOverlayScreen && Hacknet.Gui.TextBox.BoxWasActivated)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append(currentPrompt);
                stringBuilder.Append(" ");
                string str1 = terminalString;
                if (InPasswordMode)
                {
                    string str2 = "";
                    for (int index = 0; index < str1.Length; ++index)
                    {
                        str2 += "*";
                    }
                    str1 = str2;
                }
                stringBuilder.Append(str1);
                History.Add(stringBuilder.ToString());
                Advance(terminalString);
                terminalString = "";
                Hacknet.Gui.TextBox.cursorPosition  = 0;
                Hacknet.Gui.TextBox.BoxWasActivated = false;
            }
            if (!HasOverlayScreen && Hacknet.Gui.Button.doButton(16392806, dest.X, y2, dest.Width / 3, 22, LocaleTerms.Loc("CANCEL"), new Color?(CancelColor)) && RequestGoBack != null)
            {
                InPasswordMode = false;
                Hacknet.Gui.TextBox.MaskingText = false;
                RequestGoBack();
            }

            for (int index = History.Count - 1; index >= 0; --index)
            {
                GuiData.spriteBatch.DrawString(GuiData.UISmallfont, History[index], position, Color.White);
                position.Y -= num4 * (1f);
            }
        }
Esempio n. 5
0
        public void DoGui(float t)
        {
            int   num   = -1;
            Color color = this.userScreen.highlightColor;

            if (dragging != null)
            {
                if (GuiData.getKeyboadState().IsKeyUp(Microsoft.Xna.Framework.Input.Keys.LeftControl))
                {
                    dragging = null;
                }
                else
                {
                    dragging.position = MousePosToNMap(GuiData.getMousePos());
                }
            }

            lock (this.nodeList)
            {
                for (int i = 0; i < this.nodeList.Count; i++)
                {
                    color = this.userScreen.highlightColor;

                    Vector2 nodeDrawPos2 = this.GetNodeDrawPosDebug(this.nodeList[i].position);

                    if (userScreen.activeSession != null && userScreen.activeSession.ip == nodeList[i].ip)
                    {
                        color = Color.White;
                    }

                    if (Hacknet.Gui.Button.doButton(2000 + i, this.bounds.X + (int)nodeDrawPos2.X, this.bounds.Y + (int)nodeDrawPos2.Y, NetworkMap.NODE_SIZE, NetworkMap.NODE_SIZE, "", new Color?(color), this.nodeCircle))
                    {
                        if (this.dragging == null)
                        {
                            if (GuiData.getKeyboadState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl))
                            {
                                dragging = nodeList[i];
                            }
                            else
                            {
                                this.userScreen.Execute("connect " + this.nodeList[i].ip);
                            }
                        }
                    }
                    if (GuiData.hot == 2000 + i)
                    {
                        num = i;
                    }
                }
            }

            if (num != -1)
            {
                try
                {
                    int     i        = num;
                    int     num3     = i;
                    Vector2 vector   = this.GetNodeDrawPosDebug(this.nodeList[num3].position);
                    Vector2 ttpos    = new Vector2((float)(this.bounds.X + (int)vector.X + NetworkMap.NODE_SIZE), (float)(this.bounds.Y + (int)vector.Y));
                    string  text     = this.nodeList[num3].ip;//getTooltipString();
                    Vector2 textSize = GuiData.tinyfont.MeasureString(text);

                    userScreen.postFXDrawActions = (Action)System.Delegate.Combine(userScreen.postFXDrawActions, new Action(delegate
                    {
                        GuiData.spriteBatch.Draw(Utils.white, new Rectangle((int)ttpos.X, (int)ttpos.Y, (int)textSize.X, (int)textSize.Y), this.userScreen.netmapToolTipBackground);
                        Hacknet.Gui.TextItem.doFontLabel(ttpos, text, GuiData.tinyfont, new Color?(this.userScreen.netmapToolTipColor), 3.40282347E+38f, 3.40282347E+38f, false);
                    }));
                }
                catch (System.Exception ex)
                {
                    DebugLog.add(ex.ToString());
                }
            }
        }
Esempio n. 6
0
        public void Draw(SpriteBatch sb, Rectangle dest)
        {
            int       width      = 300;
            Rectangle rectangle1 = dest;
            Rectangle rectangle2 = new Rectangle(dest.X, dest.Y, dest.Width - width, dest.Height);

            if (!this.IsNewAccountMode)
            {
                dest = rectangle2;
            }
            SpriteFont smallfont = GuiData.smallfont;
            int        num1      = (int)((double)smallfont.MeasureString(this.currentPrompt).X + 4.0);
            int        num2      = this.DrawFromTop ? dest.Y : dest.Y + dest.Height - 18;

            GuiData.spriteBatch.DrawString(smallfont, this.currentPrompt, new Vector2((float)dest.X, (float)num2), Color.White);
            if (!this.IsReady)
            {
                TextBox.MaskingText = this.InPasswordMode;
                this.terminalString = TextBox.doTerminalTextField(16392802, dest.X + num1, num2 - 2, dest.Width, 20, 1, this.terminalString, GuiData.UISmallfont);
            }
            if (!this.IsNewAccountMode)
            {
                Vector2 pos = new Vector2((float)(rectangle1.X + rectangle2.Width), (float)rectangle1.Y);
                if (SaveFileManager.Accounts.Count > 0)
                {
                    TextItem.doFontLabel(pos, LocaleTerms.Loc("LOCAL ACCOUNTS") + " ::", GuiData.font, new Color?(Color.Gray), (float)width, 22f, false);
                    pos.Y += 22f;
                }
                if (!this.HasOverlayScreen)
                {
                    for (int index1 = 0; index1 < SaveFileManager.Accounts.Count; ++index1)
                    {
                        if (Button.doButton(2870300 + index1 + index1 * 12, (int)pos.X, (int)pos.Y, width, 18, SaveFileManager.Accounts[index1].Username, new Color?(Color.Black)))
                        {
                            this.Answers = new List <string>((IEnumerable <string>) new string[2]
                            {
                                SaveFileManager.Accounts[index1].Username,
                                SaveFileManager.Accounts[index1].Password
                            });
                            this.promptIndex        = 2;
                            TextBox.BoxWasActivated = true;
                            this.IsReady            = true;
                            break;
                        }
                        int index = index1;
                        if (Button.doButton(7070300 + index1 + index1 * 12, (int)pos.X + width + 4, (int)pos.Y, 21, 18, "X", new Color?(Color.DarkRed)))
                        {
                            MessageBoxScreen messageBoxScreen = new MessageBoxScreen(Utils.SuperSmartTwimForWidth(string.Format(LocaleTerms.Loc("Are you sure you wish to delete account {0}?"), (object)("\"" + SaveFileManager.Accounts[index1].Username + "\"")), 400, GuiData.font));
                            messageBoxScreen.OverrideAcceptedText = LocaleTerms.Loc("Delete Account");
                            messageBoxScreen.OverrideCancelText   = LocaleTerms.Loc("Cancel");
                            messageBoxScreen.AcceptedClicked     += (Action)(() =>
                            {
                                this.HasOverlayScreen = false;
                                SaveFileManager.DeleteUser(SaveFileManager.Accounts[index].Username);
                            });
                            messageBoxScreen.CancelClicked += (Action)(() => this.HasOverlayScreen = false);
                            Game1.getSingleton().sman.AddScreen((GameScreen)messageBoxScreen);
                            this.HasOverlayScreen = true;
                        }
                        pos.Y += 22f;
                    }
                }
            }
            if (!this.HasOverlayScreen && TextBox.BoxWasActivated)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append(this.currentPrompt);
                stringBuilder.Append(" ");
                string str1 = this.terminalString;
                if (this.InPasswordMode)
                {
                    string str2 = "";
                    for (int index = 0; index < str1.Length; ++index)
                    {
                        str2 += "*";
                    }
                    str1 = str2;
                }
                stringBuilder.Append(str1);
                this.History.Add(stringBuilder.ToString());
                this.Advance(this.terminalString);
                this.terminalString     = "";
                TextBox.cursorPosition  = 0;
                TextBox.BoxWasActivated = false;
            }
            int y1 = this.DrawFromTop ? dest.Y + 24 : dest.Y + dest.Height + 12;

            GuiData.spriteBatch.Draw(Utils.white, new Rectangle(dest.X, y1, dest.Width / 2, 1), Utils.SlightlyDarkGray);
            int y2   = y1 + 10;
            int num3 = y2 - 60;

            if (this.IsReady)
            {
                if (!GuiData.getKeyboadState().IsKeyDown(Keys.Enter))
                {
                    this.CanReturnEnter = true;
                }
                if ((!this.HasOverlayScreen && (!this.IsNewAccountMode || Button.doButton(16392804, dest.X, y2, dest.Width / 3, 28, LocaleTerms.Loc("CONFIRM"), new Color?(Color.White))) || this.CanReturnEnter && Utils.keyPressed(GuiData.lastInput, Keys.Enter, new PlayerIndex?())) && !this.PreventAdvancing)
                {
                    if (this.IsNewAccountMode)
                    {
                        if (this.Answers.Count < 3)
                        {
                            this.ResetForNewAccount();
                        }
                        else
                        {
                            string answer1 = this.Answers[0];
                            string answer2 = this.Answers[1];
                            TextBox.MaskingText = false;
                            if (this.StartNewGameForUsernameAndPass != null)
                            {
                                this.StartNewGameForUsernameAndPass(answer1, answer2);
                            }
                        }
                    }
                    else
                    {
                        TextBox.MaskingText = false;
                        if (this.LoadGameForUserFileAndUsername != null)
                        {
                            this.LoadGameForUserFileAndUsername(this.userPathCache, this.Answers[0]);
                        }
                        this.History.Clear();
                        this.currentPrompt = "";
                    }
                    this.PreventAdvancing = true;
                }
                y2 += 36;
            }
            if (!this.HasOverlayScreen && Button.doButton(16392806, dest.X, this.DrawFromTop ? num3 : y2, dest.Width / 3, 22, LocaleTerms.Loc("CANCEL"), new Color?(SavefileLoginScreen.CancelColor)) && this.RequestGoBack != null)
            {
                this.InPasswordMode = false;
                TextBox.MaskingText = false;
                this.RequestGoBack();
            }
            float   num4     = GuiData.ActiveFontConfig.tinyFontCharHeight + 8f;
            Vector2 position = new Vector2((float)dest.X, this.DrawFromTop ? (float)y2 : (float)(dest.Y + dest.Height - 20) - num4);

            for (int index = this.History.Count - 1; index >= 0; --index)
            {
                sb.DrawString(GuiData.UISmallfont, this.History[index], position, Color.White);
                position.Y -= num4 * (this.DrawFromTop ? -1f : 1f);
            }
        }
Esempio n. 7
0
        public static string doTextBox(int myID, int x, int y, int width, int lines, string str, SpriteFont font)
        {
            var str1 = str;

            if (font == null)
            {
                font = GuiData.smallfont;
            }
            BoxWasActivated = false;
            var destinationRectangle = GuiData.tmpRect;

            destinationRectangle.X      = x;
            destinationRectangle.Y      = y;
            destinationRectangle.Width  = width;
            destinationRectangle.Height = lines * LINE_HEIGHT;
            if (destinationRectangle.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
            }
            else if (GuiData.hot == myID)
            {
                GuiData.hot = -1;
            }
            if (GuiData.mouseWasPressed())
            {
                if (GuiData.hot == myID)
                {
                    if (GuiData.active == myID)
                    {
                        var num  = GuiData.mouse.X - x;
                        var flag = false;
                        for (var length = 1; length <= str.Length; ++length)
                        {
                            if (font.MeasureString(str.Substring(0, length)).X > (double)num)
                            {
                                cursorPosition = length - 1;
                                break;
                            }
                            if (!flag)
                            {
                                cursorPosition = str.Length;
                            }
                        }
                    }
                    else
                    {
                        GuiData.active = myID;
                        cursorPosition = str.Length;
                    }
                }
                else if (GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            if (GuiData.active == myID)
            {
                GuiData.willBlockTextInput = true;
                str1 = getStringInput(str1, GuiData.getKeyboadState(), GuiData.getLastKeyboadState());
                if (GuiData.getKeyboadState().IsKeyDown(Keys.Enter) &&
                    GuiData.getLastKeyboadState().IsKeyDown(Keys.Enter))
                {
                    BoxWasActivated = true;
                    GuiData.active  = -1;
                }
            }
            ++FramesSelected;
            destinationRectangle.X      = x;
            destinationRectangle.Y      = y;
            destinationRectangle.Width  = width;
            destinationRectangle.Height = lines * LINE_HEIGHT;
            GuiData.spriteBatch.Draw(Utils.white, destinationRectangle,
                                     GuiData.active == myID
                    ? GuiData.Default_Lit_Backing_Color
                    : (GuiData.hot == myID ? GuiData.Default_Selected_Color : GuiData.Default_Dark_Background_Color));
            destinationRectangle.X      += 2;
            destinationRectangle.Y      += 2;
            destinationRectangle.Width  -= 4;
            destinationRectangle.Height -= 4;
            GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, GuiData.Default_Light_Backing_Color);
            var num1 = (float)((LINE_HEIGHT - (double)font.MeasureString(str1).Y) / 2.0);

            GuiData.spriteBatch.DrawString(font, str1, new Vector2(x + 2, y + num1), Color.White);
            if (GuiData.active == myID)
            {
                destinationRectangle.X = (int)(x + (double)font.MeasureString(str1.Substring(0, cursorPosition)).X) +
                                         3;
                destinationRectangle.Y      = y + 2;
                destinationRectangle.Width  = 1;
                destinationRectangle.Height = LINE_HEIGHT - 4;
                GuiData.spriteBatch.Draw(Utils.white, destinationRectangle,
                                         FramesSelected % 60 < 40 ? Color.White : Color.Gray);
            }
            return(str1);
        }
Esempio n. 8
0
        public static string doTerminalTextField(int myID, int x, int y, int width, int selectionHeight, int lines,
                                                 string str, SpriteFont font)
        {
            var s = str;

            if (font == null)
            {
                font = GuiData.smallfont;
            }
            BoxWasActivated = false;
            UpWasPresed     = false;
            DownWasPresed   = false;
            TabWasPresed    = false;
            var destinationRectangle = GuiData.tmpRect;

            destinationRectangle.X      = x;
            destinationRectangle.Y      = y;
            destinationRectangle.Width  = width;
            destinationRectangle.Height = 0;
            if (destinationRectangle.Contains(GuiData.getMousePoint()))
            {
                GuiData.hot = myID;
            }
            else if (GuiData.hot == myID)
            {
                GuiData.hot = -1;
            }
            if (GuiData.mouseWasPressed())
            {
                if (GuiData.hot == myID)
                {
                    if (GuiData.active == myID)
                    {
                        var num  = GuiData.mouse.X - x;
                        var flag = false;
                        for (var length = 1; length <= str.Length; ++length)
                        {
                            if (font.MeasureString(str.Substring(0, length)).X > (double)num)
                            {
                                cursorPosition = length - 1;
                                break;
                            }
                            if (!flag)
                            {
                                cursorPosition = str.Length;
                            }
                        }
                    }
                    else
                    {
                        GuiData.active = myID;
                        cursorPosition = str.Length;
                    }
                }
                else if (GuiData.active == myID)
                {
                    GuiData.active = -1;
                }
            }
            var num1 = GuiData.active;
            var filteredStringInput = getFilteredStringInput(s, GuiData.getKeyboadState(), GuiData.getLastKeyboadState());

            if (GuiData.getKeyboadState().IsKeyDown(Keys.Enter) && !GuiData.getLastKeyboadState().IsKeyDown(Keys.Enter))
            {
                BoxWasActivated        = true;
                cursorPosition         = 0;
                textDrawOffsetPosition = 0;
            }
            destinationRectangle.Height = lines * LINE_HEIGHT;
            ++FramesSelected;
            destinationRectangle.X       = x;
            destinationRectangle.Y       = y;
            destinationRectangle.Width   = width;
            destinationRectangle.Height  = 10;
            destinationRectangle.X      += 2;
            destinationRectangle.Y      += 2;
            destinationRectangle.Width  -= 4;
            destinationRectangle.Height -= 4;
            var num2       = (float)((LINE_HEIGHT - (double)font.MeasureString(filteredStringInput).Y) / 2.0);
            var str1       = filteredStringInput;
            var num3       = 0;
            var startIndex = 0;
            int length1;

            for (var text = str1;
                 font.MeasureString(text).X > (double)(width - 5);
                 text = str1.Substring(startIndex, length1))
            {
                ++num3;
                length1 = str1.Length - startIndex - (num3 - startIndex);
            }
            if (cursorPosition < textDrawOffsetPosition)
            {
                textDrawOffsetPosition = Math.Max(0, textDrawOffsetPosition - 1);
            }
            while (cursorPosition > textDrawOffsetPosition + (str1.Length - num3))
            {
                ++textDrawOffsetPosition;
            }
            if (str1.Length <= num3 || textDrawOffsetPosition < 0)
            {
                textDrawOffsetPosition = textDrawOffsetPosition > str1.Length - num3 ? 0 : str1.Length - num3;
            }
            else if (textDrawOffsetPosition > num3)
            {
                num3 = textDrawOffsetPosition;
            }
            var text1 = str1.Substring(textDrawOffsetPosition, str1.Length - num3);

            if (MaskingText)
            {
                var str2 = "";
                for (var index = 0; index < filteredStringInput.Length; ++index)
                {
                    str2 += "*";
                }
                text1 = str2;
            }
            GuiData.spriteBatch.DrawString(font, text1, new Vector2(x + 2, y + num2), Color.White);
            var num4 = GuiData.active;

            if (filteredStringInput != "")
            {
                var length2 = Math.Min(cursorPosition - textDrawOffsetPosition, text1.Length);
                destinationRectangle.X = (int)(x + (double)font.MeasureString(text1.Substring(0, length2)).X) + 3;
            }
            else
            {
                destinationRectangle.X = x + 3;
            }
            destinationRectangle.Y      = y + 2;
            destinationRectangle.Width  = 1;
            destinationRectangle.Height = LINE_HEIGHT - 4;
            GuiData.spriteBatch.Draw(Utils.white, destinationRectangle,
                                     FramesSelected % 60 < 40 ? Color.White : Color.Gray);
            return(filteredStringInput);
        }
Esempio n. 9
0
        public void Draw(SpriteBatch sb, Rectangle dest)
        {
            var width      = 300;
            var rectangle1 = dest;
            var rectangle2 = new Rectangle(dest.X, dest.Y, dest.Width - width, dest.Height);

            if (!IsNewAccountMode)
            {
                dest = rectangle2;
            }
            var spriteFont = GuiData.smallfont;
            var num1       = (int)(spriteFont.MeasureString(currentPrompt).X + 4.0);

            GuiData.spriteBatch.DrawString(spriteFont, currentPrompt, new Vector2(dest.X, dest.Y + dest.Height - 16),
                                           Color.White);
            if (!IsReady)
            {
                TextBox.MaskingText = InPasswordMode;
                terminalString      = TextBox.doTerminalTextField(16392802, dest.X + num1, dest.Y + dest.Height - 18,
                                                                  dest.Width, 20, 1, terminalString, GuiData.UISmallfont);
            }
            if (!IsNewAccountMode)
            {
                var pos = new Vector2(rectangle1.X + rectangle2.Width, rectangle1.Y);
                if (SaveFileManager.Accounts.Count > 0)
                {
                    TextItem.doFontLabel(pos, "LOCAL ACCOUNTS ::", GuiData.font, Color.Gray, width, 22f);
                    pos.Y += 22f;
                }
                for (var index = 0; index < SaveFileManager.Accounts.Count; ++index)
                {
                    if (Button.doButton(2870300 + index + index * 12, (int)pos.X, (int)pos.Y, width, 18,
                                        SaveFileManager.Accounts[index].Username, Color.Black))
                    {
                        Answers = new List <string>(new string[2]
                        {
                            SaveFileManager.Accounts[index].Username,
                            SaveFileManager.Accounts[index].Password
                        });
                        promptIndex             = 2;
                        TextBox.BoxWasActivated = true;
                        IsReady = true;
                        break;
                    }
                    pos.Y += 22f;
                }
            }
            if (TextBox.BoxWasActivated)
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.Append(currentPrompt);
                stringBuilder.Append(" ");
                var str1 = terminalString;
                if (InPasswordMode)
                {
                    var str2 = "";
                    for (var index = 0; index < str1.Length; ++index)
                    {
                        str2 += "*";
                    }
                    str1 = str2;
                }
                stringBuilder.Append(str1);
                History.Add(stringBuilder.ToString());
                Advance(terminalString);
                terminalString          = "";
                TextBox.cursorPosition  = 0;
                TextBox.BoxWasActivated = false;
            }
            var y1 = dest.Y + dest.Height + 12;

            GuiData.spriteBatch.Draw(Utils.white, new Rectangle(dest.X, y1, dest.Width / 2, 1), Utils.SlightlyDarkGray);
            var y2 = y1 + 8;

            if (IsReady)
            {
                if (!GuiData.getKeyboadState().IsKeyDown(Keys.Enter))
                {
                    CanReturnEnter = true;
                }
                if ((!IsNewAccountMode ||
                     Button.doButton(16392804, dest.X, y2, dest.Width / 3, 28, "CONFIRM", Color.White) ||
                     CanReturnEnter && Utils.keyPressed(GuiData.lastInput, Keys.Enter, new PlayerIndex?())) &&
                    !PreventAdvancing)
                {
                    if (IsNewAccountMode)
                    {
                        if (Answers.Count < 3)
                        {
                            ResetForNewAccount();
                        }
                        else
                        {
                            var str1 = Answers[0];
                            var str2 = Answers[1];
                            TextBox.MaskingText = false;
                            if (StartNewGameForUsernameAndPass != null)
                            {
                                StartNewGameForUsernameAndPass(str1, str2);
                            }
                        }
                    }
                    else
                    {
                        TextBox.MaskingText = false;
                        if (LoadGameForUserFileAndUsername != null)
                        {
                            LoadGameForUserFileAndUsername(userPathCache, Answers[0]);
                        }
                    }
                    PreventAdvancing = true;
                }
                y2 += 36;
            }
            if (Button.doButton(16392806, dest.X, y2, dest.Width / 3, 22, "CANCEL", CancelColor) && RequestGoBack != null)
            {
                TextBox.MaskingText = false;
                RequestGoBack();
            }
            var num2     = GuiData.ActiveFontConfig.tinyFontCharHeight + 8f;
            var position = new Vector2(dest.X, dest.Y + dest.Height - 20 - num2);

            for (var index = History.Count - 1; index >= 0; --index)
            {
                sb.DrawString(GuiData.UISmallfont, History[index], position, Color.White);
                position.Y -= num2;
            }
        }