Terraria 1.3.5.3 Source Code

This commit is contained in:
MikeyIsBaeYT 2021-10-27 18:03:19 -04:00
commit 4b21dac4b6
503 changed files with 409032 additions and 0 deletions

View file

@ -0,0 +1,221 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.UI.States.UIAchievementsMenu
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using Terraria.Achievements;
using Terraria.GameContent.UI.Elements;
using Terraria.GameInput;
using Terraria.Graphics;
using Terraria.Localization;
using Terraria.UI;
using Terraria.UI.Gamepad;
namespace Terraria.GameContent.UI.States
{
public class UIAchievementsMenu : UIState
{
private UIList _achievementsList;
private List<UIAchievementListItem> _achievementElements = new List<UIAchievementListItem>();
private List<UIToggleImage> _categoryButtons = new List<UIToggleImage>();
private UIElement _backpanel;
private UIElement _outerContainer;
public void InitializePage()
{
this.RemoveAllChildren();
this._categoryButtons.Clear();
this._achievementElements.Clear();
this._achievementsList = (UIList) null;
bool largeForOtherLanguages = true;
int num = largeForOtherLanguages.ToInt() * 100;
UIElement element1 = new UIElement();
element1.Width.Set(0.0f, 0.8f);
element1.MaxWidth.Set(800f + (float) num, 0.0f);
element1.MinWidth.Set(600f + (float) num, 0.0f);
element1.Top.Set(220f, 0.0f);
element1.Height.Set(-220f, 1f);
element1.HAlign = 0.5f;
this._outerContainer = element1;
this.Append(element1);
UIPanel uiPanel = new UIPanel();
uiPanel.Width.Set(0.0f, 1f);
uiPanel.Height.Set(-110f, 1f);
uiPanel.BackgroundColor = new Color(33, 43, 79) * 0.8f;
uiPanel.PaddingTop = 0.0f;
element1.Append((UIElement) uiPanel);
this._achievementsList = new UIList();
this._achievementsList.Width.Set(-25f, 1f);
this._achievementsList.Height.Set(-50f, 1f);
this._achievementsList.Top.Set(50f, 0.0f);
this._achievementsList.ListPadding = 5f;
uiPanel.Append((UIElement) this._achievementsList);
UITextPanel<LocalizedText> uiTextPanel1 = new UITextPanel<LocalizedText>(Language.GetText("UI.Achievements"), large: true);
uiTextPanel1.HAlign = 0.5f;
uiTextPanel1.Top.Set(-33f, 0.0f);
uiTextPanel1.SetPadding(13f);
uiTextPanel1.BackgroundColor = new Color(73, 94, 171);
element1.Append((UIElement) uiTextPanel1);
UITextPanel<LocalizedText> uiTextPanel2 = new UITextPanel<LocalizedText>(Language.GetText("UI.Back"), 0.7f, true);
uiTextPanel2.Width.Set(-10f, 0.5f);
uiTextPanel2.Height.Set(50f, 0.0f);
uiTextPanel2.VAlign = 1f;
uiTextPanel2.HAlign = 0.5f;
uiTextPanel2.Top.Set(-45f, 0.0f);
uiTextPanel2.OnMouseOver += new UIElement.MouseEvent(this.FadedMouseOver);
uiTextPanel2.OnMouseOut += new UIElement.MouseEvent(this.FadedMouseOut);
uiTextPanel2.OnClick += new UIElement.MouseEvent(this.GoBackClick);
element1.Append((UIElement) uiTextPanel2);
this._backpanel = (UIElement) uiTextPanel2;
List<Achievement> achievementsList = Main.Achievements.CreateAchievementsList();
for (int index = 0; index < achievementsList.Count; ++index)
{
UIAchievementListItem achievementListItem = new UIAchievementListItem(achievementsList[index], largeForOtherLanguages);
this._achievementsList.Add((UIElement) achievementListItem);
this._achievementElements.Add(achievementListItem);
}
UIScrollbar scrollbar = new UIScrollbar();
scrollbar.SetView(100f, 1000f);
scrollbar.Height.Set(-50f, 1f);
scrollbar.Top.Set(50f, 0.0f);
scrollbar.HAlign = 1f;
uiPanel.Append((UIElement) scrollbar);
this._achievementsList.SetScrollbar(scrollbar);
UIElement element2 = new UIElement();
element2.Width.Set(0.0f, 1f);
element2.Height.Set(32f, 0.0f);
element2.Top.Set(10f, 0.0f);
Texture2D texture = TextureManager.Load("Images/UI/Achievement_Categories");
for (int index = 0; index < 4; ++index)
{
UIToggleImage uiToggleImage = new UIToggleImage(texture, 32, 32, new Point(34 * index, 0), new Point(34 * index, 34));
uiToggleImage.Left.Set((float) (index * 36 + 8), 0.0f);
uiToggleImage.SetState(true);
uiToggleImage.OnClick += new UIElement.MouseEvent(this.FilterList);
this._categoryButtons.Add(uiToggleImage);
element2.Append((UIElement) uiToggleImage);
}
uiPanel.Append(element2);
}
public override void Draw(SpriteBatch spriteBatch)
{
base.Draw(spriteBatch);
for (int index = 0; index < this._categoryButtons.Count; ++index)
{
if (this._categoryButtons[index].IsMouseHovering)
{
string textValue;
switch (index)
{
case -1:
textValue = Language.GetTextValue("Achievements.NoCategory");
break;
case 0:
textValue = Language.GetTextValue("Achievements.SlayerCategory");
break;
case 1:
textValue = Language.GetTextValue("Achievements.CollectorCategory");
break;
case 2:
textValue = Language.GetTextValue("Achievements.ExplorerCategory");
break;
case 3:
textValue = Language.GetTextValue("Achievements.ChallengerCategory");
break;
default:
textValue = Language.GetTextValue("Achievements.NoCategory");
break;
}
float x = Main.fontMouseText.MeasureString(textValue).X;
Vector2 vector2 = new Vector2((float) Main.mouseX, (float) Main.mouseY) + new Vector2(16f);
if ((double) vector2.Y > (double) (Main.screenHeight - 30))
vector2.Y = (float) (Main.screenHeight - 30);
if ((double) vector2.X > (double) Main.screenWidth - (double) x)
vector2.X = (float) (Main.screenWidth - 460);
Utils.DrawBorderStringFourWay(spriteBatch, Main.fontMouseText, textValue, vector2.X, vector2.Y, new Color((int) Main.mouseTextColor, (int) Main.mouseTextColor, (int) Main.mouseTextColor, (int) Main.mouseTextColor), Color.Black, Vector2.Zero);
break;
}
}
this.SetupGamepadPoints(spriteBatch);
}
public void GotoAchievement(Achievement achievement) => this._achievementsList.Goto((UIList.ElementSearchMethod) (element => element is UIAchievementListItem achievementListItem && achievementListItem.GetAchievement() == achievement));
private void GoBackClick(UIMouseEvent evt, UIElement listeningElement)
{
Main.menuMode = 0;
IngameFancyUI.Close();
}
private void FadedMouseOver(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(12);
((UIPanel) evt.Target).BackgroundColor = new Color(73, 94, 171);
}
private void FadedMouseOut(UIMouseEvent evt, UIElement listeningElement) => ((UIPanel) evt.Target).BackgroundColor = new Color(63, 82, 151) * 0.8f;
private void FilterList(UIMouseEvent evt, UIElement listeningElement)
{
this._achievementsList.Clear();
foreach (UIAchievementListItem achievementElement in this._achievementElements)
{
if (this._categoryButtons[(int) achievementElement.GetAchievement().Category].IsOn)
this._achievementsList.Add((UIElement) achievementElement);
}
this.Recalculate();
}
public override void OnActivate()
{
this.InitializePage();
if (Main.gameMenu)
{
this._outerContainer.Top.Set(220f, 0.0f);
this._outerContainer.Height.Set(-220f, 1f);
}
else
{
this._outerContainer.Top.Set(120f, 0.0f);
this._outerContainer.Height.Set(-120f, 1f);
}
this._achievementsList.UpdateOrder();
if (!PlayerInput.UsingGamepadUI)
return;
UILinkPointNavigator.ChangePoint(3002);
}
private void SetupGamepadPoints(SpriteBatch spriteBatch)
{
UILinkPointNavigator.Shortcuts.BackButtonCommand = 3;
int ID = 3000;
UILinkPointNavigator.SetPosition(ID, this._backpanel.GetInnerDimensions().ToRectangle().Center.ToVector2());
UILinkPointNavigator.SetPosition(ID + 1, this._outerContainer.GetInnerDimensions().ToRectangle().Center.ToVector2());
int key = ID;
UILinkPoint point1 = UILinkPointNavigator.Points[key];
point1.Unlink();
point1.Up = key + 1;
int num = key + 1;
UILinkPoint point2 = UILinkPointNavigator.Points[num];
point2.Unlink();
point2.Up = num + 1;
point2.Down = num - 1;
for (int index = 0; index < this._categoryButtons.Count; ++index)
{
++num;
UILinkPointNavigator.Shortcuts.FANCYUI_HIGHEST_INDEX = num;
UILinkPointNavigator.SetPosition(num, this._categoryButtons[index].GetInnerDimensions().ToRectangle().Center.ToVector2());
UILinkPoint point3 = UILinkPointNavigator.Points[num];
point3.Unlink();
point3.Left = index == 0 ? -3 : num - 1;
point3.Right = index == this._categoryButtons.Count - 1 ? -4 : num + 1;
point3.Down = ID;
}
}
}
}

View file

@ -0,0 +1,268 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.UI.States.UICharacterSelect
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.GameContent.UI.Elements;
using Terraria.GameInput;
using Terraria.IO;
using Terraria.Localization;
using Terraria.UI;
using Terraria.UI.Gamepad;
namespace Terraria.GameContent.UI.States
{
public class UICharacterSelect : UIState
{
private static string noteToEveryone = "This code is terrible and you will risk cancer reading it --Yoraiz0r";
private UIList _playerList;
private UITextPanel<LocalizedText> _backPanel;
private UITextPanel<LocalizedText> _newPanel;
private UIPanel _containerPanel;
private List<Tuple<string, bool>> favoritesCache = new List<Tuple<string, bool>>();
private bool skipDraw;
public override void OnInitialize()
{
UIElement element = new UIElement();
element.Width.Set(0.0f, 0.8f);
element.MaxWidth.Set(650f, 0.0f);
element.Top.Set(220f, 0.0f);
element.Height.Set(-220f, 1f);
element.HAlign = 0.5f;
UIPanel uiPanel = new UIPanel();
uiPanel.Width.Set(0.0f, 1f);
uiPanel.Height.Set(-110f, 1f);
uiPanel.BackgroundColor = new Color(33, 43, 79) * 0.8f;
this._containerPanel = uiPanel;
element.Append((UIElement) uiPanel);
this._playerList = new UIList();
this._playerList.Width.Set(-25f, 1f);
this._playerList.Height.Set(0.0f, 1f);
this._playerList.ListPadding = 5f;
uiPanel.Append((UIElement) this._playerList);
UIScrollbar scrollbar = new UIScrollbar();
scrollbar.SetView(100f, 1000f);
scrollbar.Height.Set(0.0f, 1f);
scrollbar.HAlign = 1f;
uiPanel.Append((UIElement) scrollbar);
this._playerList.SetScrollbar(scrollbar);
UITextPanel<LocalizedText> uiTextPanel1 = new UITextPanel<LocalizedText>(Language.GetText("UI.SelectPlayer"), 0.8f, true);
uiTextPanel1.HAlign = 0.5f;
uiTextPanel1.Top.Set(-35f, 0.0f);
uiTextPanel1.SetPadding(15f);
uiTextPanel1.BackgroundColor = new Color(73, 94, 171);
element.Append((UIElement) uiTextPanel1);
UITextPanel<LocalizedText> uiTextPanel2 = new UITextPanel<LocalizedText>(Language.GetText("UI.Back"), 0.7f, true);
uiTextPanel2.Width.Set(-10f, 0.5f);
uiTextPanel2.Height.Set(50f, 0.0f);
uiTextPanel2.VAlign = 1f;
uiTextPanel2.Top.Set(-45f, 0.0f);
uiTextPanel2.OnMouseOver += new UIElement.MouseEvent(this.FadedMouseOver);
uiTextPanel2.OnMouseOut += new UIElement.MouseEvent(this.FadedMouseOut);
uiTextPanel2.OnClick += new UIElement.MouseEvent(this.GoBackClick);
uiTextPanel2.SetSnapPoint("Back", 0);
element.Append((UIElement) uiTextPanel2);
this._backPanel = uiTextPanel2;
UITextPanel<LocalizedText> uiTextPanel3 = new UITextPanel<LocalizedText>(Language.GetText("UI.New"), 0.7f, true);
uiTextPanel3.CopyStyle((UIElement) uiTextPanel2);
uiTextPanel3.HAlign = 1f;
uiTextPanel3.OnMouseOver += new UIElement.MouseEvent(this.FadedMouseOver);
uiTextPanel3.OnMouseOut += new UIElement.MouseEvent(this.FadedMouseOut);
uiTextPanel3.OnClick += new UIElement.MouseEvent(this.NewCharacterClick);
element.Append((UIElement) uiTextPanel3);
uiTextPanel2.SetSnapPoint("New", 0);
this._newPanel = uiTextPanel3;
this.Append(element);
}
private void NewCharacterClick(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(10);
Player player = new Player();
player.inventory[0].SetDefaults(3507);
player.inventory[0].Prefix(-1);
player.inventory[1].SetDefaults(3509);
player.inventory[1].Prefix(-1);
player.inventory[2].SetDefaults(3506);
player.inventory[2].Prefix(-1);
Main.PendingPlayer = player;
Main.menuMode = 2;
}
private void GoBackClick(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(11);
Main.menuMode = 0;
}
private void FadedMouseOver(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(12);
((UIPanel) evt.Target).BackgroundColor = new Color(73, 94, 171);
}
private void FadedMouseOut(UIMouseEvent evt, UIElement listeningElement) => ((UIPanel) evt.Target).BackgroundColor = new Color(63, 82, 151) * 0.7f;
public override void OnActivate()
{
Main.ClearPendingPlayerSelectCallbacks();
Main.LoadPlayers();
this.UpdatePlayersList();
if (!PlayerInput.UsingGamepadUI)
return;
UILinkPointNavigator.ChangePoint(3000 + (this._playerList.Count == 0 ? 1 : 2));
}
private void UpdatePlayersList()
{
this._playerList.Clear();
List<PlayerFileData> playerFileDataList = new List<PlayerFileData>((IEnumerable<PlayerFileData>) Main.PlayerList);
playerFileDataList.Sort((Comparison<PlayerFileData>) ((x, y) =>
{
if (x.IsFavorite && !y.IsFavorite)
return -1;
if (!x.IsFavorite && y.IsFavorite)
return 1;
return x.Name.CompareTo(y.Name) != 0 ? x.Name.CompareTo(y.Name) : x.GetFileName().CompareTo(y.GetFileName());
}));
int num = 0;
foreach (PlayerFileData data in playerFileDataList)
this._playerList.Add((UIElement) new UICharacterListItem(data, num++));
}
public override void Draw(SpriteBatch spriteBatch)
{
if (this.skipDraw)
{
this.skipDraw = false;
}
else
{
if (this.UpdateFavoritesCache())
{
this.skipDraw = true;
Main.MenuUI.Draw(spriteBatch, new GameTime());
}
base.Draw(spriteBatch);
this.SetupGamepadPoints(spriteBatch);
}
}
private bool UpdateFavoritesCache()
{
List<PlayerFileData> playerFileDataList = new List<PlayerFileData>((IEnumerable<PlayerFileData>) Main.PlayerList);
playerFileDataList.Sort((Comparison<PlayerFileData>) ((x, y) =>
{
if (x.IsFavorite && !y.IsFavorite)
return -1;
if (!x.IsFavorite && y.IsFavorite)
return 1;
return x.Name.CompareTo(y.Name) != 0 ? x.Name.CompareTo(y.Name) : x.GetFileName().CompareTo(y.GetFileName());
}));
bool flag = false;
if (!flag && playerFileDataList.Count != this.favoritesCache.Count)
flag = true;
if (!flag)
{
for (int index = 0; index < this.favoritesCache.Count; ++index)
{
Tuple<string, bool> tuple = this.favoritesCache[index];
if (!(playerFileDataList[index].Name == tuple.Item1) || playerFileDataList[index].IsFavorite != tuple.Item2)
{
flag = true;
break;
}
}
}
if (flag)
{
this.favoritesCache.Clear();
foreach (PlayerFileData playerFileData in playerFileDataList)
this.favoritesCache.Add(Tuple.Create<string, bool>(playerFileData.Name, playerFileData.IsFavorite));
this.UpdatePlayersList();
}
return flag;
}
private void SetupGamepadPoints(SpriteBatch spriteBatch)
{
UILinkPointNavigator.Shortcuts.BackButtonCommand = 1;
int num1 = 3000;
UILinkPointNavigator.SetPosition(num1, this._backPanel.GetInnerDimensions().ToRectangle().Center.ToVector2());
UILinkPointNavigator.SetPosition(num1 + 1, this._newPanel.GetInnerDimensions().ToRectangle().Center.ToVector2());
int key1 = num1;
UILinkPoint point1 = UILinkPointNavigator.Points[key1];
point1.Unlink();
point1.Right = key1 + 1;
int key2 = num1 + 1;
UILinkPoint point2 = UILinkPointNavigator.Points[key2];
point2.Unlink();
point2.Left = key2 - 1;
Rectangle clippingRectangle = this._containerPanel.GetClippingRectangle(spriteBatch);
Vector2 minimum = clippingRectangle.TopLeft();
Vector2 maximum = clippingRectangle.BottomRight();
List<SnapPoint> snapPoints = this.GetSnapPoints();
for (int index = 0; index < snapPoints.Count; ++index)
{
if (!snapPoints[index].Position.Between(minimum, maximum))
{
snapPoints.Remove(snapPoints[index]);
--index;
}
}
SnapPoint[,] snapPointArray = new SnapPoint[this._playerList.Count, 4];
foreach (SnapPoint snapPoint in snapPoints.Where<SnapPoint>((Func<SnapPoint, bool>) (a => a.Name == "Play")))
snapPointArray[snapPoint.ID, 0] = snapPoint;
foreach (SnapPoint snapPoint in snapPoints.Where<SnapPoint>((Func<SnapPoint, bool>) (a => a.Name == "Favorite")))
snapPointArray[snapPoint.ID, 1] = snapPoint;
foreach (SnapPoint snapPoint in snapPoints.Where<SnapPoint>((Func<SnapPoint, bool>) (a => a.Name == "Cloud")))
snapPointArray[snapPoint.ID, 2] = snapPoint;
foreach (SnapPoint snapPoint in snapPoints.Where<SnapPoint>((Func<SnapPoint, bool>) (a => a.Name == "Delete")))
snapPointArray[snapPoint.ID, 3] = snapPoint;
int num2 = num1 + 2;
int[] numArray = new int[this._playerList.Count];
for (int index = 0; index < numArray.Length; ++index)
numArray[index] = -1;
for (int index1 = 0; index1 < 4; ++index1)
{
int key3 = -1;
for (int index2 = 0; index2 < snapPointArray.GetLength(0); ++index2)
{
if (snapPointArray[index2, index1] != null)
{
UILinkPoint point3 = UILinkPointNavigator.Points[num2];
point3.Unlink();
UILinkPointNavigator.SetPosition(num2, snapPointArray[index2, index1].Position);
if (key3 != -1)
{
point3.Up = key3;
UILinkPointNavigator.Points[key3].Down = num2;
}
if (numArray[index2] != -1)
{
point3.Left = numArray[index2];
UILinkPointNavigator.Points[numArray[index2]].Right = num2;
}
point3.Down = num1;
if (index1 == 0)
UILinkPointNavigator.Points[num1].Up = UILinkPointNavigator.Points[num1 + 1].Up = num2;
key3 = num2;
numArray[index2] = num2;
UILinkPointNavigator.Shortcuts.FANCYUI_HIGHEST_INDEX = num2;
++num2;
}
}
}
if (!PlayerInput.UsingGamepadUI || this._playerList.Count != 0 || UILinkPointNavigator.CurrentPoint <= 3001)
return;
UILinkPointNavigator.ChangePoint(3001);
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,19 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.UI.States.UISortableElement
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Terraria.UI;
namespace Terraria.GameContent.UI.States
{
public class UISortableElement : UIElement
{
public int OrderIndex;
public UISortableElement(int index) => this.OrderIndex = index;
public override int CompareTo(object obj) => obj is UISortableElement uiSortableElement ? this.OrderIndex.CompareTo(uiSortableElement.OrderIndex) : base.CompareTo(obj);
}
}

View file

@ -0,0 +1,789 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.UI.States.UIVirtualKeyboard
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria.GameContent.UI.Elements;
using Terraria.GameInput;
using Terraria.Graphics;
using Terraria.Localization;
using Terraria.UI;
using Terraria.UI.Gamepad;
namespace Terraria.GameContent.UI.States
{
public class UIVirtualKeyboard : UIState
{
private static UIVirtualKeyboard _currentInstance;
private static string _cancelCacheSign = "";
private static string _cancelCacheChest = "";
private const string DEFAULT_KEYS = "1234567890qwertyuiopasdfghjkl'zxcvbnm,.?";
private const string SHIFT_KEYS = "1234567890QWERTYUIOPASDFGHJKL'ZXCVBNM,.?";
private const string SYMBOL_KEYS = "1234567890!@#$%^&*()-_+=/\\{}[]<>;:\"`|~£¥";
private const float KEY_SPACING = 4f;
private const float KEY_WIDTH = 48f;
private const float KEY_HEIGHT = 37f;
private UITextPanel<object>[] _keyList = new UITextPanel<object>[50];
private UITextPanel<object> _shiftButton;
private UITextPanel<object> _symbolButton;
private UITextBox _textBox;
private UITextPanel<LocalizedText> _submitButton;
private UITextPanel<LocalizedText> _cancelButton;
private UIText _label;
private UITextPanel<object> _enterButton;
private UITextPanel<object> _spacebarButton;
private UITextPanel<object> _restoreButton;
private Texture2D _textureShift;
private Texture2D _textureBackspace;
private Color _internalBorderColor = new Color(89, 116, 213);
private Color _internalBorderColorSelected = Main.OurFavoriteColor;
private UITextPanel<LocalizedText> _submitButton2;
private UITextPanel<LocalizedText> _cancelButton2;
private UIElement outerLayer1;
private UIElement outerLayer2;
private bool _allowEmpty;
private UIVirtualKeyboard.KeyState _keyState;
private UIVirtualKeyboard.KeyboardSubmitEvent _submitAction;
private Action _cancelAction;
private int _lastOffsetDown;
public static int OffsetDown = 0;
private int _keyboardContext;
private bool _edittingSign;
private bool _edittingChest;
private float _textBoxHeight;
private float _labelHeight;
private bool _canSubmit;
public string Text
{
get => this._textBox.Text;
set
{
this._textBox.SetText(value);
this.ValidateText();
}
}
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 = TextureManager.Load("Images/UI/VK_Shift");
this._textureBackspace = TextureManager.Load("Images/UI/VK_Backspace");
this.Top.Pixels = (float) this._lastOffsetDown;
float num1 = (float) (-5000 * this._edittingSign.ToInt());
float maxValue = (float) byte.MaxValue;
float num2 = 0.0f;
float num3 = 516f;
UIElement element = new UIElement();
element.Width.Pixels = (float) ((double) num3 + 8.0 + 16.0);
element.Top.Precent = num2;
element.Top.Pixels = maxValue;
element.Height.Pixels = 266f;
element.HAlign = 0.5f;
element.SetPadding(0.0f);
this.outerLayer1 = element;
UIElement uiElement = new UIElement();
uiElement.Width.Pixels = (float) ((double) num3 + 8.0 + 16.0);
uiElement.Top.Precent = num2;
uiElement.Top.Pixels = maxValue;
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 num4 = -79f;
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 = num3;
this._textBox.Top.Pixels = (float) ((double) num4 + (double) maxValue - 10.0) + num1;
this._textBox.Top.Precent = num2;
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);
keyboardButton.OnClick += new UIElement.MouseEvent(this.TypeText);
mainPanel.Append((UIElement) keyboardButton);
}
}
this._shiftButton = this.CreateKeyboardButton((object) "", 0, 4, style: 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) =>
{
Main.PlaySound(12);
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, style: 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) =>
{
Main.PlaySound(12);
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 += (UIElement.MouseEvent) ((evt, listeningElement) => this.ValidateText());
this._submitButton.OnMouseOut += (UIElement.MouseEvent) ((evt, listeningElement) => this.ValidateText());
this._submitButton.OnClick += (UIElement.MouseEvent) ((evt, listeningElement) =>
{
string text = this.Text.Trim();
if (text.Length <= 0 && !this._edittingSign && !this._edittingChest && !this._allowEmpty)
return;
Main.PlaySound(10);
this._submitAction(text);
});
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) =>
{
Main.PlaySound(11);
this._cancelAction();
});
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.OnClick += (UIElement.MouseEvent) ((evt, listeningElement) =>
{
string text = this.Text.Trim();
if (text.Length <= 0 && !this._edittingSign && !this._edittingChest && !this._allowEmpty)
return;
Main.PlaySound(10);
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) =>
{
Main.PlaySound(11);
this._cancelAction();
});
this.outerLayer2.Append((UIElement) this._cancelButton2);
UITextPanel<object> keyboardButton1 = this.CreateKeyboardButton((object) "", 8, 4, 2);
keyboardButton1.OnClick += (UIElement.MouseEvent) ((evt, listeningElement) =>
{
Main.PlaySound(12);
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 = num3;
uiText.Top.Pixels = (float) ((double) num4 - 37.0 - 4.0) + maxValue + num1;
uiText.Top.Precent = num2;
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();
}
private void BuildSpaceBarArea(UIPanel mainPanel)
{
Action createTheseTwo = (Action) (() =>
{
bool flag = this.CanRestore();
int x = flag ? 4 : 5;
bool edittingSign = this._edittingSign;
int width = flag & edittingSign ? 2 : 3;
UITextPanel<object> keyboardButton1 = this.CreateKeyboardButton((object) Language.GetText("UI.SpaceButton"), 2, 4, this._edittingSign || this._edittingChest & flag ? width : 6);
keyboardButton1.OnClick += (UIElement.MouseEvent) ((evt, listeningElement) =>
{
Main.PlaySound(12);
this._textBox.Write(" ");
this.ValidateText();
});
mainPanel.Append((UIElement) keyboardButton1);
this._spacebarButton = keyboardButton1;
if (!edittingSign)
return;
UITextPanel<object> keyboardButton2 = this.CreateKeyboardButton((object) Language.GetText("UI.EnterButton"), x, 4, width);
keyboardButton2.OnClick += (UIElement.MouseEvent) ((evt, listeningElement) =>
{
Main.PlaySound(12);
this._textBox.Write("\n");
this.ValidateText();
});
mainPanel.Append((UIElement) keyboardButton2);
this._enterButton = keyboardButton2;
});
createTheseTwo();
if (!this.CanRestore())
return;
UITextPanel<object> restoreBar = this.CreateKeyboardButton((object) Language.GetText("UI.RestoreButton"), 6, 4, 2);
restoreBar.OnClick += (UIElement.MouseEvent) ((evt, listeningElement) =>
{
Main.PlaySound(12);
this.RestoreCancelledInput(this._keyboardContext);
this.ValidateText();
restoreBar.Remove();
this._enterButton.Remove();
this._spacebarButton.Remove();
createTheseTwo();
});
mainPanel.Append((UIElement) restoreBar);
this._restoreButton = restoreBar;
}
private bool CanRestore()
{
if (this._edittingSign)
return UIVirtualKeyboard._cancelCacheSign.Length > 0;
return this._edittingChest && UIVirtualKeyboard._cancelCacheChest.Length > 0;
}
private void TypeText(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(12);
int num = this.Text.Length == 0 ? 1 : 0;
this._textBox.Write(((UITextPanel<object>) listeningElement).Text);
this.ValidateText();
if (num == 0 || this.Text.Length <= 0 || this._keyState != UIVirtualKeyboard.KeyState.Shift)
return;
this.SetKeyState(UIVirtualKeyboard.KeyState.Default);
}
public void SetKeyState(UIVirtualKeyboard.KeyState keyState)
{
UITextPanel<object> uiTextPanel1 = (UITextPanel<object>) null;
switch (this._keyState)
{
case UIVirtualKeyboard.KeyState.Symbol:
uiTextPanel1 = this._symbolButton;
break;
case UIVirtualKeyboard.KeyState.Shift:
uiTextPanel1 = this._shiftButton;
break;
}
if (uiTextPanel1 != null)
{
if (uiTextPanel1.IsMouseHovering)
uiTextPanel1.BackgroundColor = new Color(73, 94, 171);
else
uiTextPanel1.BackgroundColor = new Color(63, 82, 151) * 0.7f;
}
string str = (string) null;
UITextPanel<object> uiTextPanel2 = (UITextPanel<object>) null;
switch (keyState)
{
case UIVirtualKeyboard.KeyState.Default:
str = "1234567890qwertyuiopasdfghjkl'zxcvbnm,.?";
break;
case UIVirtualKeyboard.KeyState.Symbol:
str = "1234567890!@#$%^&*()-_+=/\\{}[]<>;:\"`|~£¥";
uiTextPanel2 = this._symbolButton;
break;
case UIVirtualKeyboard.KeyState.Shift:
str = "1234567890QWERTYUIOPASDFGHJKL'ZXCVBNM,.?";
uiTextPanel2 = this._shiftButton;
break;
}
for (int index = 0; index < str.Length; ++index)
this._keyList[index].SetText((object) str[index].ToString());
this._keyState = keyState;
if (uiTextPanel2 == null)
return;
uiTextPanel2.BackgroundColor = new Color(93, 114, 191);
}
private void ValidateText()
{
if (this.Text.Trim().Length > 0 || this._edittingSign || this._edittingChest || this._allowEmpty)
{
this._canSubmit = true;
this._submitButton.TextColor = Color.White;
if (this._submitButton.IsMouseHovering)
this._submitButton.BackgroundColor = new Color(73, 94, 171);
else
this._submitButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
}
else
{
this._canSubmit = false;
this._submitButton.TextColor = Color.Gray;
if (this._submitButton.IsMouseHovering)
this._submitButton.BackgroundColor = new Color(180, 60, 60) * 0.85f;
else
this._submitButton.BackgroundColor = new Color(150, 40, 40) * 0.85f;
}
}
private void StyleKey<T>(UITextPanel<T> button, bool external = false)
{
button.PaddingLeft = 0.0f;
button.PaddingRight = 0.0f;
button.BackgroundColor = new Color(63, 82, 151) * 0.7f;
if (!external)
button.BorderColor = this._internalBorderColor * 0.7f;
button.OnMouseOver += (UIElement.MouseEvent) ((evt, listeningElement) =>
{
((UIPanel) listeningElement).BackgroundColor = new Color(73, 94, 171) * 0.85f;
if (external)
return;
((UIPanel) listeningElement).BorderColor = this._internalBorderColorSelected * 0.85f;
});
button.OnMouseOut += (UIElement.MouseEvent) ((evt, listeningElement) =>
{
((UIPanel) listeningElement).BackgroundColor = new Color(63, 82, 151) * 0.7f;
if (external)
return;
((UIPanel) listeningElement).BorderColor = this._internalBorderColor * 0.7f;
});
}
private UITextPanel<object> CreateKeyboardButton(
object text,
int x,
int y,
int width = 1,
bool style = true)
{
float num = 516f;
UITextPanel<object> button = new UITextPanel<object>(text, 0.4f, true);
button.Width.Pixels = (float) (48.0 * (double) width + 4.0 * (double) (width - 1));
button.Height.Pixels = 37f;
button.Left.Precent = 0.5f;
button.Left.Pixels = (float) (52.0 * (double) x - (double) num * 0.5);
button.Top.Pixels = 41f * (float) y;
if (style)
this.StyleKey<object>(button);
for (int index = 0; index < width; ++index)
this._keyList[y * 10 + x + index] = button;
return button;
}
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;
ref Vector2 local1 = ref position;
double num1 = (double) (Main.screenWidth / 2);
Rectangle rectangle = this._textBox.GetDimensions().ToRectangle();
double num2 = (double) (rectangle.Bottom + 32);
local1 = new Vector2((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();
}
byte num3 = (byte) (((int) byte.MaxValue + (int) Main.tileColor.R * 2) / 3);
Color color = new Color((int) num3, (int) num3, (int) num3, (int) byte.MaxValue);
this._textBox.TextColor = Color.Lerp(Color.White, color, 0.2f);
this._label.TextColor = Color.Lerp(Color.White, color, 0.2f);
ref Vector2 local2 = ref position;
double num4 = (double) (Main.screenWidth / 2);
rectangle = this._textBox.GetDimensions().ToRectangle();
double num5 = (double) (rectangle.Bottom + 32);
local2 = new Vector2((float) num4, (float) num5);
Main.instance.DrawWindowsIMEPanel(position, 0.5f);
}
}
private void UpdateOffsetDown()
{
int num1 = UIVirtualKeyboard.OffsetDown - this._lastOffsetDown;
int num2 = num1;
if (Math.Abs(num1) < 10)
num2 = num1;
this._lastOffsetDown += num2;
if (num2 == 0)
return;
this.Top.Pixels += (float) num2;
this.Recalculate();
}
public override void OnActivate()
{
if (!PlayerInput.UsingGamepadUI || this._restoreButton == null)
return;
UILinkPointNavigator.ChangePoint(3002);
}
public override void OnDeactivate()
{
base.OnDeactivate();
PlayerInput.WritingText = false;
UILinkPointNavigator.Shortcuts.FANCYUI_SPECIAL_INSTRUCTIONS = 0;
}
private void SetupGamepadPoints(SpriteBatch spriteBatch)
{
UILinkPointNavigator.Shortcuts.BackButtonCommand = 6;
UILinkPointNavigator.Shortcuts.FANCYUI_SPECIAL_INSTRUCTIONS = 1;
int num1 = 3002;
UILinkPointNavigator.SetPosition(3000, this._cancelButton.GetDimensions().Center());
UILinkPoint point1 = UILinkPointNavigator.Points[3000];
point1.Unlink();
point1.Right = 3001;
point1.Up = num1 + 40;
UILinkPointNavigator.SetPosition(3001, this._submitButton.GetDimensions().Center());
UILinkPoint point2 = UILinkPointNavigator.Points[3001];
point2.Unlink();
point2.Left = 3000;
point2.Up = num1 + 49;
for (int index1 = 0; index1 < 5; ++index1)
{
for (int index2 = 0; index2 < 10; ++index2)
{
int index3 = index1 * 10 + index2;
int num2 = num1 + index3;
if (this._keyList[index3] != null)
{
UILinkPointNavigator.SetPosition(num2, this._keyList[index3].GetDimensions().Center());
UILinkPoint point3 = UILinkPointNavigator.Points[num2];
point3.Unlink();
int num3 = index2 - 1;
while (num3 >= 0 && this._keyList[index1 * 10 + num3] == this._keyList[index3])
--num3;
point3.Left = num3 == -1 ? index1 * 10 + 9 + num1 : index1 * 10 + num3 + num1;
int index4 = index2 + 1;
while (index4 <= 9 && this._keyList[index1 * 10 + index4] == this._keyList[index3])
++index4;
point3.Right = index4 == 10 || this._keyList[index3] == this._keyList[index4] ? index1 * 10 + num1 : index1 * 10 + index4 + num1;
if (index1 != 0)
point3.Up = num2 - 10;
point3.Down = index1 == 4 ? (index2 < 5 ? 3000 : 3001) : num2 + 10;
}
}
}
}
public static void CycleSymbols()
{
if (UIVirtualKeyboard._currentInstance == null)
return;
switch (UIVirtualKeyboard._currentInstance._keyState)
{
case UIVirtualKeyboard.KeyState.Default:
UIVirtualKeyboard._currentInstance.SetKeyState(UIVirtualKeyboard.KeyState.Shift);
break;
case UIVirtualKeyboard.KeyState.Symbol:
UIVirtualKeyboard._currentInstance.SetKeyState(UIVirtualKeyboard.KeyState.Default);
break;
case UIVirtualKeyboard.KeyState.Shift:
UIVirtualKeyboard._currentInstance.SetKeyState(UIVirtualKeyboard.KeyState.Symbol);
break;
}
}
public static void BackSpace()
{
if (UIVirtualKeyboard._currentInstance == null)
return;
Main.PlaySound(12);
UIVirtualKeyboard._currentInstance._textBox.Backspace();
UIVirtualKeyboard._currentInstance.ValidateText();
}
public static bool CanSubmit => UIVirtualKeyboard._currentInstance != null && UIVirtualKeyboard._currentInstance._canSubmit;
public static void Submit()
{
if (UIVirtualKeyboard._currentInstance == null)
return;
string text = UIVirtualKeyboard._currentInstance.Text.Trim();
if (text.Length <= 0)
return;
Main.PlaySound(10);
UIVirtualKeyboard._currentInstance._submitAction(text);
}
public static void Cancel()
{
if (UIVirtualKeyboard._currentInstance == null)
return;
Main.PlaySound(11);
UIVirtualKeyboard._currentInstance._cancelAction();
}
public static void Write(string text)
{
if (UIVirtualKeyboard._currentInstance == null)
return;
Main.PlaySound(12);
int num = UIVirtualKeyboard._currentInstance.Text.Length == 0 ? 1 : 0;
UIVirtualKeyboard._currentInstance._textBox.Write(text);
UIVirtualKeyboard._currentInstance.ValidateText();
if (num == 0 || UIVirtualKeyboard._currentInstance.Text.Length <= 0 || UIVirtualKeyboard._currentInstance._keyState != UIVirtualKeyboard.KeyState.Shift)
return;
UIVirtualKeyboard._currentInstance.SetKeyState(UIVirtualKeyboard.KeyState.Default);
}
public static void CursorLeft()
{
if (UIVirtualKeyboard._currentInstance == null)
return;
Main.PlaySound(12);
UIVirtualKeyboard._currentInstance._textBox.CursorLeft();
}
public static void CursorRight()
{
if (UIVirtualKeyboard._currentInstance == null)
return;
Main.PlaySound(12);
UIVirtualKeyboard._currentInstance._textBox.CursorRight();
}
public static bool CanDisplay(int keyboardContext) => keyboardContext != 1 || Main.screenHeight > 700;
public static int KeyboardContext => UIVirtualKeyboard._currentInstance == null ? -1 : UIVirtualKeyboard._currentInstance._keyboardContext;
public static void CacheCancelledInput(int cacheMode)
{
if (cacheMode != 1)
return;
UIVirtualKeyboard._cancelCacheSign = Main.npcChatText;
}
private void RestoreCancelledInput(int cacheMode)
{
if (cacheMode != 1)
return;
Main.npcChatText = UIVirtualKeyboard._cancelCacheSign;
this.Text = Main.npcChatText;
UIVirtualKeyboard._cancelCacheSign = "";
}
private void CopyTextToSign()
{
if (!this._edittingSign)
return;
int sign = Main.player[Main.myPlayer].sign;
if (sign < 0 || Main.sign[sign] == null)
return;
Main.npcChatText = this.Text;
}
private void CopyTextToChest()
{
if (!this._edittingChest)
return;
Main.npcChatText = this.Text;
}
public delegate void KeyboardSubmitEvent(string text);
public enum KeyState
{
Default,
Symbol,
Shift,
}
}
}

View file

@ -0,0 +1,62 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.UI.States.UIWorldLoad
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria.GameContent.UI.Elements;
using Terraria.GameInput;
using Terraria.UI;
using Terraria.UI.Gamepad;
using Terraria.World.Generation;
namespace Terraria.GameContent.UI.States
{
public class UIWorldLoad : UIState
{
private UIGenProgressBar _progressBar = new UIGenProgressBar();
private UIHeader _progressMessage = new UIHeader();
private GenerationProgress _progress;
public UIWorldLoad(GenerationProgress progress)
{
this._progressBar.Top.Pixels = 370f;
this._progressBar.HAlign = 0.5f;
this._progressBar.VAlign = 0.0f;
this._progressBar.Recalculate();
this._progressMessage.CopyStyle((UIElement) this._progressBar);
this._progressMessage.Top.Pixels -= 70f;
this._progressMessage.Recalculate();
this._progress = progress;
this.Append((UIElement) this._progressBar);
this.Append((UIElement) this._progressMessage);
}
public override void OnActivate()
{
if (!PlayerInput.UsingGamepadUI)
return;
UILinkPointNavigator.Points[3000].Unlink();
UILinkPointNavigator.ChangePoint(3000);
}
protected override void DrawSelf(SpriteBatch spriteBatch)
{
this._progressBar.SetProgress(this._progress.TotalProgress, this._progress.Value);
this._progressMessage.Text = this._progress.Message;
this.UpdateGamepadSquiggle();
}
private void UpdateGamepadSquiggle()
{
Vector2 vector2 = new Vector2((float) Math.Cos((double) Main.GlobalTime * 6.28318548202515), (float) Math.Sin((double) Main.GlobalTime * 6.28318548202515 * 2.0)) * new Vector2(30f, 15f) + Vector2.UnitY * 20f;
UILinkPointNavigator.Points[3000].Unlink();
UILinkPointNavigator.SetPosition(3000, new Vector2((float) Main.screenWidth, (float) Main.screenHeight) / 2f + vector2);
}
public string GetStatusText() => string.Format("{0:0.0%} - " + this._progress.Message + " - {1:0.0%}", (object) this._progress.TotalProgress, (object) this._progress.Value);
}
}

View file

@ -0,0 +1,259 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.UI.States.UIWorldSelect
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.GameContent.UI.Elements;
using Terraria.GameInput;
using Terraria.IO;
using Terraria.Localization;
using Terraria.UI;
using Terraria.UI.Gamepad;
namespace Terraria.GameContent.UI.States
{
public class UIWorldSelect : UIState
{
private UIList _worldList;
private UITextPanel<LocalizedText> _backPanel;
private UITextPanel<LocalizedText> _newPanel;
private UIPanel _containerPanel;
private List<Tuple<string, bool>> favoritesCache = new List<Tuple<string, bool>>();
private bool skipDraw;
public override void OnInitialize()
{
UIElement element = new UIElement();
element.Width.Set(0.0f, 0.8f);
element.MaxWidth.Set(650f, 0.0f);
element.Top.Set(220f, 0.0f);
element.Height.Set(-220f, 1f);
element.HAlign = 0.5f;
UIPanel uiPanel = new UIPanel();
uiPanel.Width.Set(0.0f, 1f);
uiPanel.Height.Set(-110f, 1f);
uiPanel.BackgroundColor = new Color(33, 43, 79) * 0.8f;
element.Append((UIElement) uiPanel);
this._containerPanel = uiPanel;
this._worldList = new UIList();
this._worldList.Width.Set(-25f, 1f);
this._worldList.Height.Set(0.0f, 1f);
this._worldList.ListPadding = 5f;
uiPanel.Append((UIElement) this._worldList);
UIScrollbar scrollbar = new UIScrollbar();
scrollbar.SetView(100f, 1000f);
scrollbar.Height.Set(0.0f, 1f);
scrollbar.HAlign = 1f;
uiPanel.Append((UIElement) scrollbar);
this._worldList.SetScrollbar(scrollbar);
UITextPanel<LocalizedText> uiTextPanel1 = new UITextPanel<LocalizedText>(Language.GetText("UI.SelectWorld"), 0.8f, true);
uiTextPanel1.HAlign = 0.5f;
uiTextPanel1.Top.Set(-35f, 0.0f);
uiTextPanel1.SetPadding(15f);
uiTextPanel1.BackgroundColor = new Color(73, 94, 171);
element.Append((UIElement) uiTextPanel1);
UITextPanel<LocalizedText> uiTextPanel2 = new UITextPanel<LocalizedText>(Language.GetText("UI.Back"), 0.7f, true);
uiTextPanel2.Width.Set(-10f, 0.5f);
uiTextPanel2.Height.Set(50f, 0.0f);
uiTextPanel2.VAlign = 1f;
uiTextPanel2.Top.Set(-45f, 0.0f);
uiTextPanel2.OnMouseOver += new UIElement.MouseEvent(this.FadedMouseOver);
uiTextPanel2.OnMouseOut += new UIElement.MouseEvent(this.FadedMouseOut);
uiTextPanel2.OnClick += new UIElement.MouseEvent(this.GoBackClick);
element.Append((UIElement) uiTextPanel2);
this._backPanel = uiTextPanel2;
UITextPanel<LocalizedText> uiTextPanel3 = new UITextPanel<LocalizedText>(Language.GetText("UI.New"), 0.7f, true);
uiTextPanel3.CopyStyle((UIElement) uiTextPanel2);
uiTextPanel3.HAlign = 1f;
uiTextPanel3.OnMouseOver += new UIElement.MouseEvent(this.FadedMouseOver);
uiTextPanel3.OnMouseOut += new UIElement.MouseEvent(this.FadedMouseOut);
uiTextPanel3.OnClick += new UIElement.MouseEvent(this.NewWorldClick);
element.Append((UIElement) uiTextPanel3);
this._newPanel = uiTextPanel3;
this.Append(element);
}
private void NewWorldClick(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(10);
Main.menuMode = 16;
Main.newWorldName = Lang.gen[57].Value + " " + (object) (Main.WorldList.Count + 1);
}
private void GoBackClick(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(11);
Main.menuMode = Main.menuMultiplayer ? 12 : 1;
}
private void FadedMouseOver(UIMouseEvent evt, UIElement listeningElement)
{
Main.PlaySound(12);
((UIPanel) evt.Target).BackgroundColor = new Color(73, 94, 171);
}
private void FadedMouseOut(UIMouseEvent evt, UIElement listeningElement) => ((UIPanel) evt.Target).BackgroundColor = new Color(63, 82, 151) * 0.7f;
public override void OnActivate()
{
Main.LoadWorlds();
this.UpdateWorldsList();
if (!PlayerInput.UsingGamepadUI)
return;
UILinkPointNavigator.ChangePoint(3000 + (this._worldList.Count == 0 ? 1 : 2));
}
private void UpdateWorldsList()
{
this._worldList.Clear();
List<WorldFileData> worldFileDataList = new List<WorldFileData>((IEnumerable<WorldFileData>) Main.WorldList);
worldFileDataList.Sort((Comparison<WorldFileData>) ((x, y) =>
{
if (x.IsFavorite && !y.IsFavorite)
return -1;
if (!x.IsFavorite && y.IsFavorite)
return 1;
return x.Name.CompareTo(y.Name) != 0 ? x.Name.CompareTo(y.Name) : x.GetFileName().CompareTo(y.GetFileName());
}));
int num = 0;
foreach (WorldFileData data in worldFileDataList)
this._worldList.Add((UIElement) new UIWorldListItem(data, num++));
}
public override void Draw(SpriteBatch spriteBatch)
{
if (this.skipDraw)
{
this.skipDraw = false;
}
else
{
if (this.UpdateFavoritesCache())
{
this.skipDraw = true;
Main.MenuUI.Draw(spriteBatch, new GameTime());
}
base.Draw(spriteBatch);
this.SetupGamepadPoints(spriteBatch);
}
}
private bool UpdateFavoritesCache()
{
List<WorldFileData> worldFileDataList = new List<WorldFileData>((IEnumerable<WorldFileData>) Main.WorldList);
worldFileDataList.Sort((Comparison<WorldFileData>) ((x, y) =>
{
if (x.IsFavorite && !y.IsFavorite)
return -1;
if (!x.IsFavorite && y.IsFavorite)
return 1;
return x.Name.CompareTo(y.Name) != 0 ? x.Name.CompareTo(y.Name) : x.GetFileName().CompareTo(y.GetFileName());
}));
bool flag = false;
if (!flag && worldFileDataList.Count != this.favoritesCache.Count)
flag = true;
if (!flag)
{
for (int index = 0; index < this.favoritesCache.Count; ++index)
{
Tuple<string, bool> tuple = this.favoritesCache[index];
if (!(worldFileDataList[index].Name == tuple.Item1) || worldFileDataList[index].IsFavorite != tuple.Item2)
{
flag = true;
break;
}
}
}
if (flag)
{
this.favoritesCache.Clear();
foreach (WorldFileData worldFileData in worldFileDataList)
this.favoritesCache.Add(Tuple.Create<string, bool>(worldFileData.Name, worldFileData.IsFavorite));
this.UpdateWorldsList();
}
return flag;
}
private void SetupGamepadPoints(SpriteBatch spriteBatch)
{
UILinkPointNavigator.Shortcuts.BackButtonCommand = 2;
int num1 = 3000;
UILinkPointNavigator.SetPosition(num1, this._backPanel.GetInnerDimensions().ToRectangle().Center.ToVector2());
UILinkPointNavigator.SetPosition(num1 + 1, this._newPanel.GetInnerDimensions().ToRectangle().Center.ToVector2());
int key1 = num1;
UILinkPoint point1 = UILinkPointNavigator.Points[key1];
point1.Unlink();
point1.Right = key1 + 1;
int key2 = num1 + 1;
UILinkPoint point2 = UILinkPointNavigator.Points[key2];
point2.Unlink();
point2.Left = key2 - 1;
Rectangle clippingRectangle = this._containerPanel.GetClippingRectangle(spriteBatch);
Vector2 minimum = clippingRectangle.TopLeft();
Vector2 maximum = clippingRectangle.BottomRight();
List<SnapPoint> snapPoints = this.GetSnapPoints();
for (int index = 0; index < snapPoints.Count; ++index)
{
if (!snapPoints[index].Position.Between(minimum, maximum))
{
snapPoints.Remove(snapPoints[index]);
--index;
}
}
SnapPoint[,] snapPointArray = new SnapPoint[this._worldList.Count, 5];
foreach (SnapPoint snapPoint in snapPoints.Where<SnapPoint>((Func<SnapPoint, bool>) (a => a.Name == "Play")))
snapPointArray[snapPoint.ID, 0] = snapPoint;
foreach (SnapPoint snapPoint in snapPoints.Where<SnapPoint>((Func<SnapPoint, bool>) (a => a.Name == "Favorite")))
snapPointArray[snapPoint.ID, 1] = snapPoint;
foreach (SnapPoint snapPoint in snapPoints.Where<SnapPoint>((Func<SnapPoint, bool>) (a => a.Name == "Cloud")))
snapPointArray[snapPoint.ID, 2] = snapPoint;
foreach (SnapPoint snapPoint in snapPoints.Where<SnapPoint>((Func<SnapPoint, bool>) (a => a.Name == "Seed")))
snapPointArray[snapPoint.ID, 3] = snapPoint;
foreach (SnapPoint snapPoint in snapPoints.Where<SnapPoint>((Func<SnapPoint, bool>) (a => a.Name == "Delete")))
snapPointArray[snapPoint.ID, 4] = snapPoint;
int num2 = num1 + 2;
int[] numArray = new int[this._worldList.Count];
for (int index = 0; index < numArray.Length; ++index)
numArray[index] = -1;
for (int index1 = 0; index1 < 5; ++index1)
{
int key3 = -1;
for (int index2 = 0; index2 < snapPointArray.GetLength(0); ++index2)
{
if (snapPointArray[index2, index1] != null)
{
UILinkPoint point3 = UILinkPointNavigator.Points[num2];
point3.Unlink();
UILinkPointNavigator.SetPosition(num2, snapPointArray[index2, index1].Position);
if (key3 != -1)
{
point3.Up = key3;
UILinkPointNavigator.Points[key3].Down = num2;
}
if (numArray[index2] != -1)
{
point3.Left = numArray[index2];
UILinkPointNavigator.Points[numArray[index2]].Right = num2;
}
point3.Down = num1;
if (index1 == 0)
UILinkPointNavigator.Points[num1].Up = UILinkPointNavigator.Points[num1 + 1].Up = num2;
key3 = num2;
numArray[index2] = num2;
UILinkPointNavigator.Shortcuts.FANCYUI_HIGHEST_INDEX = num2;
++num2;
}
}
}
if (!PlayerInput.UsingGamepadUI || this._worldList.Count != 0 || UILinkPointNavigator.CurrentPoint <= 3001)
return;
UILinkPointNavigator.ChangePoint(3001);
}
}
}