Esempio n. 1
0
        public UIVirtualKeyboard(
            string labelText,
            string startingText,
            UIVirtualKeyboard.KeyboardSubmitEvent submitAction,
            Action cancelAction,
            int inputMode   = 0,
            bool allowEmpty = false)
        {
            this._keyboardContext              = inputMode;
            this._allowEmpty                   = allowEmpty;
            UIVirtualKeyboard.OffsetDown       = 0;
            this._lastOffsetDown               = 0;
            this._edittingSign                 = this._keyboardContext == 1;
            this._edittingChest                = this._keyboardContext == 2;
            UIVirtualKeyboard._currentInstance = this;
            this._submitAction                 = submitAction;
            this._cancelAction                 = cancelAction;
            this._textureShift                 = (Asset <Texture2D>)Main.Assets.Request <Texture2D>("Images/UI/VK_Shift", (AssetRequestMode)1);
            this._textureBackspace             = (Asset <Texture2D>)Main.Assets.Request <Texture2D>("Images/UI/VK_Backspace", (AssetRequestMode)1);
            this.Top.Pixels = (float)this._lastOffsetDown;
            float     num1    = (float)(-5000 * this._edittingSign.ToInt());
            float     num2    = 270f;
            float     num3    = 0.0f;
            float     num4    = 516f;
            UIElement element = new UIElement();

            element.Width.Pixels  = (float)((double)num4 + 8.0 + 16.0);
            element.Top.Precent   = num3;
            element.Top.Pixels    = num2;
            element.Height.Pixels = 266f;
            element.HAlign        = 0.5f;
            element.SetPadding(0.0f);
            this.outerLayer1 = element;
            UIElement uiElement = new UIElement();

            uiElement.Width.Pixels  = (float)((double)num4 + 8.0 + 16.0);
            uiElement.Top.Precent   = num3;
            uiElement.Top.Pixels    = num2;
            uiElement.Height.Pixels = 266f;
            uiElement.HAlign        = 0.5f;
            uiElement.SetPadding(0.0f);
            this.outerLayer2 = uiElement;
            UIPanel mainPanel = new UIPanel();

            mainPanel.Width.Precent   = 1f;
            mainPanel.Height.Pixels   = 225f;
            mainPanel.BackgroundColor = new Color(23, 33, 69) * 0.7f;
            element.Append((UIElement)mainPanel);
            float num5 = -50f;

            this._textBox = new UITextBox("", 0.78f, true);
            this._textBox.BackgroundColor = Color.Transparent;
            this._textBox.BorderColor     = Color.Transparent;
            this._textBox.HAlign          = 0.5f;
            this._textBox.Width.Pixels    = num4;
            this._textBox.Top.Pixels      = (float)((double)num5 + (double)num2 - 10.0) + num1;
            this._textBox.Top.Precent     = num3;
            this._textBox.Height.Pixels   = 37f;
            this.Append((UIElement)this._textBox);
            for (int x = 0; x < 10; ++x)
            {
                for (int y = 0; y < 4; ++y)
                {
                    UITextPanel <object> keyboardButton = this.CreateKeyboardButton((object)"1234567890qwertyuiopasdfghjkl'zxcvbnm,.?"[y * 10 + x].ToString(), x, y, 1, true);
                    keyboardButton.OnClick += new UIElement.MouseEvent(this.TypeText);
                    mainPanel.Append((UIElement)keyboardButton);
                }
            }
            this._shiftButton                 = this.CreateKeyboardButton((object)"", 0, 4, 1, false);
            this._shiftButton.PaddingLeft     = 0.0f;
            this._shiftButton.PaddingRight    = 0.0f;
            this._shiftButton.PaddingBottom   = this._shiftButton.PaddingTop = 0.0f;
            this._shiftButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
            this._shiftButton.BorderColor     = this._internalBorderColor * 0.7f;
            this._shiftButton.OnMouseOver    += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                this._shiftButton.BorderColor = this._internalBorderColorSelected;
                if (this._keyState == UIVirtualKeyboard.KeyState.Shift)
                {
                    return;
                }
                this._shiftButton.BackgroundColor = new Color(73, 94, 171);
            });
            this._shiftButton.OnMouseOut += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                this._shiftButton.BorderColor = this._internalBorderColor * 0.7f;
                if (this._keyState == UIVirtualKeyboard.KeyState.Shift)
                {
                    return;
                }
                this._shiftButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
            });
            this._shiftButton.OnClick += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                SoundEngine.PlaySound(12, -1, -1, 1, 1f, 0.0f);
                this.SetKeyState(this._keyState == UIVirtualKeyboard.KeyState.Shift ? UIVirtualKeyboard.KeyState.Default : UIVirtualKeyboard.KeyState.Shift);
            });
            UIImage uiImage1 = new UIImage(this._textureShift);

            uiImage1.HAlign     = 0.5f;
            uiImage1.VAlign     = 0.5f;
            uiImage1.ImageScale = 0.85f;
            this._shiftButton.Append((UIElement)uiImage1);
            mainPanel.Append((UIElement)this._shiftButton);
            this._symbolButton                 = this.CreateKeyboardButton((object)"@%", 1, 4, 1, false);
            this._symbolButton.PaddingLeft     = 0.0f;
            this._symbolButton.PaddingRight    = 0.0f;
            this._symbolButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
            this._symbolButton.BorderColor     = this._internalBorderColor * 0.7f;
            this._symbolButton.OnMouseOver    += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                this._symbolButton.BorderColor = this._internalBorderColorSelected;
                if (this._keyState == UIVirtualKeyboard.KeyState.Symbol)
                {
                    return;
                }
                this._symbolButton.BackgroundColor = new Color(73, 94, 171);
            });
            this._symbolButton.OnMouseOut += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                this._symbolButton.BorderColor = this._internalBorderColor * 0.7f;
                if (this._keyState == UIVirtualKeyboard.KeyState.Symbol)
                {
                    return;
                }
                this._symbolButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
            });
            this._symbolButton.OnClick += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                SoundEngine.PlaySound(12, -1, -1, 1, 1f, 0.0f);
                this.SetKeyState(this._keyState == UIVirtualKeyboard.KeyState.Symbol ? UIVirtualKeyboard.KeyState.Default : UIVirtualKeyboard.KeyState.Symbol);
            });
            mainPanel.Append((UIElement)this._symbolButton);
            this.BuildSpaceBarArea(mainPanel);
            this._submitButton = new UITextPanel <LocalizedText>(this._edittingSign || this._edittingChest ? Language.GetText("UI.Save") : Language.GetText("UI.Submit"), 0.4f, true);
            this._submitButton.Height.Pixels = 37f;
            this._submitButton.Width.Precent = 0.4f;
            this._submitButton.HAlign        = 1f;
            this._submitButton.VAlign        = 1f;
            this._submitButton.PaddingLeft   = 0.0f;
            this._submitButton.PaddingRight  = 0.0f;
            this.ValidateText();
            this._submitButton.OnMouseOver += new UIElement.MouseEvent(this.FadedMouseOver);
            this._submitButton.OnMouseOut  += new UIElement.MouseEvent(this.FadedMouseOut);
            this._submitButton.OnMouseOver += (UIElement.MouseEvent)((evt, listeningElement) => this.ValidateText());
            this._submitButton.OnMouseOut  += (UIElement.MouseEvent)((evt, listeningElement) => this.ValidateText());
            this._submitButton.OnClick     += (UIElement.MouseEvent)((evt, listeningElement) => UIVirtualKeyboard.Submit());
            element.Append((UIElement)this._submitButton);
            this._cancelButton = new UITextPanel <LocalizedText>(Language.GetText("UI.Cancel"), 0.4f, true);
            this.StyleKey <LocalizedText>(this._cancelButton, true);
            this._cancelButton.Height.Pixels = 37f;
            this._cancelButton.Width.Precent = 0.4f;
            this._cancelButton.VAlign        = 1f;
            this._cancelButton.OnClick      += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                SoundEngine.PlaySound(11, -1, -1, 1, 1f, 0.0f);
                this._cancelAction();
            });
            this._cancelButton.OnMouseOver += new UIElement.MouseEvent(this.FadedMouseOver);
            this._cancelButton.OnMouseOut  += new UIElement.MouseEvent(this.FadedMouseOut);
            element.Append((UIElement)this._cancelButton);
            this._submitButton2               = new UITextPanel <LocalizedText>(this._edittingSign || this._edittingChest ? Language.GetText("UI.Save") : Language.GetText("UI.Submit"), 0.72f, true);
            this._submitButton2.TextColor     = Color.Silver;
            this._submitButton2.DrawPanel     = false;
            this._submitButton2.Height.Pixels = 60f;
            this._submitButton2.Width.Precent = 0.4f;
            this._submitButton2.HAlign        = 0.5f;
            this._submitButton2.VAlign        = 0.0f;
            this._submitButton2.OnMouseOver  += (UIElement.MouseEvent)((a, b) =>
            {
                ((UITextPanel <LocalizedText>)b).TextScale = 0.85f;
                ((UITextPanel <LocalizedText>)b).TextColor = Color.White;
            });
            this._submitButton2.OnMouseOut += (UIElement.MouseEvent)((a, b) =>
            {
                ((UITextPanel <LocalizedText>)b).TextScale = 0.72f;
                ((UITextPanel <LocalizedText>)b).TextColor = Color.Silver;
            });
            this._submitButton2.Top.Pixels   = 50f;
            this._submitButton2.PaddingLeft  = 0.0f;
            this._submitButton2.PaddingRight = 0.0f;
            this.ValidateText();
            this._submitButton2.OnMouseOver += (UIElement.MouseEvent)((evt, listeningElement) => this.ValidateText());
            this._submitButton2.OnMouseOut  += (UIElement.MouseEvent)((evt, listeningElement) => this.ValidateText());
            this._submitButton2.OnMouseOver += new UIElement.MouseEvent(this.FadedMouseOver);
            this._submitButton2.OnMouseOut  += new UIElement.MouseEvent(this.FadedMouseOut);
            this._submitButton2.OnClick     += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                string text = this.Text.Trim();
                if (text.Length <= 0 && !this._edittingSign && (!this._edittingChest && !this._allowEmpty))
                {
                    return;
                }
                SoundEngine.PlaySound(10, -1, -1, 1, 1f, 0.0f);
                this._submitAction(text);
            });
            this.outerLayer2.Append((UIElement)this._submitButton2);
            this._cancelButton2              = new UITextPanel <LocalizedText>(Language.GetText("UI.Cancel"), 0.72f, true);
            this._cancelButton2.TextColor    = Color.Silver;
            this._cancelButton2.DrawPanel    = false;
            this._cancelButton2.OnMouseOver += (UIElement.MouseEvent)((a, b) =>
            {
                ((UITextPanel <LocalizedText>)b).TextScale = 0.85f;
                ((UITextPanel <LocalizedText>)b).TextColor = Color.White;
            });
            this._cancelButton2.OnMouseOut += (UIElement.MouseEvent)((a, b) =>
            {
                ((UITextPanel <LocalizedText>)b).TextScale = 0.72f;
                ((UITextPanel <LocalizedText>)b).TextColor = Color.Silver;
            });
            this._cancelButton2.Height.Pixels = 60f;
            this._cancelButton2.Width.Precent = 0.4f;
            this._cancelButton2.Top.Pixels    = 114f;
            this._cancelButton2.VAlign        = 0.0f;
            this._cancelButton2.HAlign        = 0.5f;
            this._cancelButton2.OnClick      += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                SoundEngine.PlaySound(11, -1, -1, 1, 1f, 0.0f);
                this._cancelAction();
            });
            this.outerLayer2.Append((UIElement)this._cancelButton2);
            UITextPanel <object> keyboardButton1 = this.CreateKeyboardButton((object)"", 8, 4, 2, true);

            keyboardButton1.OnClick += (UIElement.MouseEvent)((evt, listeningElement) =>
            {
                SoundEngine.PlaySound(12, -1, -1, 1, 1f, 0.0f);
                this._textBox.Backspace();
                this.ValidateText();
            });
            keyboardButton1.PaddingLeft   = 0.0f;
            keyboardButton1.PaddingRight  = 0.0f;
            keyboardButton1.PaddingBottom = keyboardButton1.PaddingTop = 0.0f;
            UIImage uiImage2 = new UIImage(this._textureBackspace);

            uiImage2.HAlign     = 0.5f;
            uiImage2.VAlign     = 0.5f;
            uiImage2.ImageScale = 0.92f;
            keyboardButton1.Append((UIElement)uiImage2);
            mainPanel.Append((UIElement)keyboardButton1);
            UIText uiText = new UIText(labelText, 0.75f, true);

            uiText.HAlign        = 0.5f;
            uiText.Width.Pixels  = num4;
            uiText.Top.Pixels    = (float)((double)num5 - 37.0 - 4.0) + num2 + num1;
            uiText.Top.Precent   = num3;
            uiText.Height.Pixels = 37f;
            this.Append((UIElement)uiText);
            this._label = uiText;
            this.Append(element);
            this._textBox.SetTextMaxLength(this._edittingSign ? 99999 : 20);
            this.Text = startingText;
            if (this.Text.Length == 0)
            {
                this.SetKeyState(UIVirtualKeyboard.KeyState.Shift);
            }
            UIVirtualKeyboard.OffsetDown = 9999;
            this.UpdateOffsetDown();
        }
Esempio n. 2
0
 protected override void DrawSelf(SpriteBatch spriteBatch)
 {
     if (Main.gameMenu)
     {
         if (PlayerInput.UsingGamepad)
         {
             this.outerLayer2.Remove();
             if (!this.Elements.Contains(this.outerLayer1))
             {
                 this.Append(this.outerLayer1);
             }
             this.outerLayer1.Activate();
             this.outerLayer2.Deactivate();
             this.Recalculate();
             this.RecalculateChildren();
             if ((double)this._labelHeight != 0.0)
             {
                 this._textBox.Top.Pixels = this._textBoxHeight;
                 this._label.Top.Pixels   = this._labelHeight;
                 this._textBox.Recalculate();
                 this._label.Recalculate();
                 this._labelHeight = this._textBoxHeight = 0.0f;
                 UserInterface.ActiveInstance.ResetLasts();
             }
         }
         else
         {
             this.outerLayer1.Remove();
             if (!this.Elements.Contains(this.outerLayer2))
             {
                 this.Append(this.outerLayer2);
             }
             this.outerLayer2.Activate();
             this.outerLayer1.Deactivate();
             this.Recalculate();
             this.RecalculateChildren();
             if ((double)this._textBoxHeight == 0.0)
             {
                 this._textBoxHeight       = this._textBox.Top.Pixels;
                 this._labelHeight         = this._label.Top.Pixels;
                 this._textBox.Top.Pixels += 50f;
                 this._label.Top.Pixels   += 50f;
                 this._textBox.Recalculate();
                 this._label.Recalculate();
                 UserInterface.ActiveInstance.ResetLasts();
             }
         }
     }
     if (!Main.editSign && this._edittingSign)
     {
         IngameFancyUI.Close();
     }
     else if (!Main.editChest && this._edittingChest)
     {
         IngameFancyUI.Close();
     }
     else
     {
         base.DrawSelf(spriteBatch);
         this.UpdateOffsetDown();
         UIVirtualKeyboard.OffsetDown = 0;
         this.SetupGamepadPoints(spriteBatch);
         PlayerInput.WritingText = true;
         Main.instance.HandleIME();
         Vector2 position = new Vector2((float)(Main.screenWidth / 2), (float)(this._textBox.GetDimensions().ToRectangle().Bottom + 32));
         Main.instance.DrawWindowsIMEPanel(position, 0.5f);
         string inputText = Main.GetInputText(this.Text);
         if (this._edittingSign && Main.inputTextEnter)
         {
             inputText += (string)(object)'\n';
         }
         else
         {
             if (this._edittingChest && Main.inputTextEnter)
             {
                 ChestUI.RenameChestSubmit(Main.player[Main.myPlayer]);
                 IngameFancyUI.Close();
                 return;
             }
             if (Main.inputTextEnter && UIVirtualKeyboard.CanSubmit)
             {
                 UIVirtualKeyboard.Submit();
             }
             else if (Main.inputTextEscape)
             {
                 if (this._edittingSign)
                 {
                     Main.InputTextSignCancel();
                 }
                 if (this._edittingChest)
                 {
                     ChestUI.RenameChestCancel();
                 }
                 IngameFancyUI.Close();
                 return;
             }
         }
         if (IngameFancyUI.CanShowVirtualKeyboard(this._keyboardContext))
         {
             if (inputText != this.Text)
             {
                 this.Text = inputText;
             }
             if (this._edittingSign)
             {
                 this.CopyTextToSign();
             }
             if (this._edittingChest)
             {
                 this.CopyTextToChest();
             }
         }
         byte  num   = (byte)(((int)byte.MaxValue + (int)Main.tileColor.R * 2) / 3);
         Color color = new Color((int)num, (int)num, (int)num, (int)byte.MaxValue);
         this._textBox.TextColor = Color.Lerp(Color.White, color, 0.2f);
         this._label.TextColor   = Color.Lerp(Color.White, color, 0.2f);
         position = new Vector2((float)(Main.screenWidth / 2), (float)(this._textBox.GetDimensions().ToRectangle().Bottom + 32));
         Main.instance.DrawWindowsIMEPanel(position, 0.5f);
     }
 }
Esempio n. 3
0
 protected override void DrawSelf(SpriteBatch spriteBatch)
 {
     if (Main.gameMenu)
     {
         if (PlayerInput.UsingGamepad)
         {
             this.outerLayer2.Remove();
             if (!this.Elements.Contains(this.outerLayer1))
             {
                 this.Append(this.outerLayer1);
             }
             this.outerLayer1.Activate();
             this.outerLayer2.Deactivate();
             this.Recalculate();
             this.RecalculateChildren();
             if ((double)this._labelHeight != 0.0)
             {
                 this._textBox.Top.Pixels = this._textBoxHeight;
                 this._label.Top.Pixels   = this._labelHeight;
                 this._textBox.Recalculate();
                 this._label.Recalculate();
                 this._labelHeight = this._textBoxHeight = 0.0f;
                 UserInterface.ActiveInstance.ResetLasts();
             }
         }
         else
         {
             this.outerLayer1.Remove();
             if (!this.Elements.Contains(this.outerLayer2))
             {
                 this.Append(this.outerLayer2);
             }
             this.outerLayer2.Activate();
             this.outerLayer1.Deactivate();
             this.Recalculate();
             this.RecalculateChildren();
             if ((double)this._textBoxHeight == 0.0)
             {
                 this._textBoxHeight       = this._textBox.Top.Pixels;
                 this._labelHeight         = this._label.Top.Pixels;
                 this._textBox.Top.Pixels += 50f;
                 this._label.Top.Pixels   += 50f;
                 this._textBox.Recalculate();
                 this._label.Recalculate();
                 UserInterface.ActiveInstance.ResetLasts();
             }
         }
     }
     if (!Main.editSign && this._edittingSign)
     {
         IngameFancyUI.Close();
     }
     else if (!Main.editChest && this._edittingChest)
     {
         IngameFancyUI.Close();
     }
     else
     {
         base.DrawSelf(spriteBatch);
         this.UpdateOffsetDown();
         UIVirtualKeyboard.OffsetDown = 0;
         this.SetupGamepadPoints(spriteBatch);
         PlayerInput.WritingText = true;
         Main.instance.HandleIME();
         Vector2 position;
         // ISSUE: explicit reference operation
         // ISSUE: variable of a reference type
         Vector2&  local1    = @position;
         double    num1      = (double)(Main.screenWidth / 2);
         Rectangle rectangle = this._textBox.GetDimensions().ToRectangle();
         // ISSUE: explicit reference operation
         double num2 = (double)(((Rectangle)@rectangle).get_Bottom() + 32);
         ((Vector2)local1).\u002Ector((float)num1, (float)num2);
         Main.instance.DrawWindowsIMEPanel(position, 0.5f);
         string inputText = Main.GetInputText(this.Text);
         if (this._edittingSign && Main.inputTextEnter)
         {
             inputText += "\n";
         }
         else
         {
             if (this._edittingChest && Main.inputTextEnter)
             {
                 ChestUI.RenameChestSubmit(Main.player[Main.myPlayer]);
                 IngameFancyUI.Close();
                 return;
             }
             if (Main.inputTextEnter && UIVirtualKeyboard.CanSubmit)
             {
                 UIVirtualKeyboard.Submit();
             }
             else if (Main.inputTextEscape)
             {
                 if (this._edittingSign)
                 {
                     Main.InputTextSignCancel();
                 }
                 if (this._edittingChest)
                 {
                     ChestUI.RenameChestCancel();
                 }
                 IngameFancyUI.Close();
                 return;
             }
         }
         if (IngameFancyUI.CanShowVirtualKeyboard(this._keyboardContext))
         {
             if (inputText != this.Text)
             {
                 this.Text = inputText;
             }
             if (this._edittingSign)
             {
                 this.CopyTextToSign();
             }
             if (this._edittingChest)
             {
                 this.CopyTextToChest();
             }
         }
         // ISSUE: explicit reference operation
         byte  num3 = (byte)(((int)byte.MaxValue + (int)((Color)@Main.tileColor).get_R() * 2) / 3);
         Color color;
         // ISSUE: explicit reference operation
         ((Color)@color).\u002Ector((int)num3, (int)num3, (int)num3, (int)byte.MaxValue);
         this._textBox.TextColor = Color.Lerp(Color.get_White(), color, 0.2f);
         this._label.TextColor   = Color.Lerp(Color.get_White(), color, 0.2f);
         // ISSUE: explicit reference operation
         // ISSUE: variable of a reference type
         Vector2& local2 = @position;
         double   num4   = (double)(Main.screenWidth / 2);
         rectangle = this._textBox.GetDimensions().ToRectangle();
         // ISSUE: explicit reference operation
         double num5 = (double)(((Rectangle)@rectangle).get_Bottom() + 32);
         ((Vector2)local2).\u002Ector((float)num4, (float)num5);
         Main.instance.DrawWindowsIMEPanel(position, 0.5f);
     }
 }