diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index 3b23b0230..2e4e18f01 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -247,7 +247,7 @@ namespace ClassicalSharp.Gui.Screens { bottomRight.SetText(2 - (int)(type - MessageType.BottomRight1), e.Text); } else if (type == MessageType.Announcement) { announcement.SetText(e.Text); - } else if (type >= MessageType.ClientStatus1 && type <= MessageType.ClientStatus6) { + } else if (type >= MessageType.ClientStatus1 && type <= MessageType.ClientStatus3) { clientStatus.SetText((int)(type - MessageType.ClientStatus1), e.Text); UpdateChatYOffset(true); } diff --git a/ClassicalSharp/2D/Widgets/Chat/ChatInputWidget.cs b/ClassicalSharp/2D/Widgets/Chat/ChatInputWidget.cs index e74783c87..de7d1d84d 100644 --- a/ClassicalSharp/2D/Widgets/Chat/ChatInputWidget.cs +++ b/ClassicalSharp/2D/Widgets/Chat/ChatInputWidget.cs @@ -11,7 +11,7 @@ using Android.Graphics; namespace ClassicalSharp.Gui.Widgets { public sealed class ChatInputWidget : InputWidget { - public ChatInputWidget(Game game, Font font) : base(game, font) { + public ChatInputWidget(Game game, Font font) : base(game, font, "> ", 3) { typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1. ShowCaret = true; Padding = 5; @@ -20,28 +20,9 @@ namespace ClassicalSharp.Gui.Widgets { static FastColour backColour = new FastColour(0, 0, 0, 127); int typingLogPos; string originalText; - bool shownWarning; - public override int MaxLines { get { return game.ClassicMode ? 1 : 3; } } - public override string Prefix { get { return "> "; } } - public override int MaxCharsPerLine { - get { - bool allChars = game.ClassicMode || game.Server.SupportsPartialMessages; - return allChars ? 64 : 62; // need 2 chars for colour in multilined chat, when server doesn't support partial messages - } - } - - public override void Init() { - base.Init(); - bool supports = game.Server.SupportsPartialMessages; - - if (Text.Length > MaxCharsPerLine && !shownWarning && !supports) { - game.Chat.Add("&eNote: On this server, each line will be sent separately.", MessageType.ClientStatus6); - shownWarning = true; - } else if (Text.Length <= MaxCharsPerLine && shownWarning) { - game.Chat.Add(null, MessageType.ClientStatus6); - shownWarning = false; - } + public override int UsedLines { + get { return !game.ClassicMode && game.Server.SupportsPartialMessages ? 3 : 1; } } public override void Render(double delta) { @@ -71,9 +52,8 @@ namespace ClassicalSharp.Gui.Widgets { originalText = null; typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1. - game.Chat.Add(null, MessageType.ClientStatus4); - game.Chat.Add(null, MessageType.ClientStatus5); - game.Chat.Add(null, MessageType.ClientStatus6); + game.Chat.Add(null, MessageType.ClientStatus2); + game.Chat.Add(null, MessageType.ClientStatus3); base.EnterInput(); } @@ -167,7 +147,7 @@ namespace ClassicalSharp.Gui.Widgets { void DownKey(bool controlDown) { if (controlDown) { - if (caret == -1 || caret >= (lines.Length - 1) * MaxCharsPerLine) return; + if (caret == -1 || caret >= (UsedLines - 1) * MaxCharsPerLine) return; caret += MaxCharsPerLine; UpdateCaret(); return; @@ -200,7 +180,7 @@ namespace ClassicalSharp.Gui.Widgets { string part = new String(value, start, pos + 1 - start); List matches = new List(); - game.Chat.Add(null, MessageType.ClientStatus5); + game.Chat.Add(null, MessageType.ClientStatus3); TabListEntry[] entries = game.TabList.Entries; for (int i = 0; i < EntityList.MaxCount; i++) { @@ -232,7 +212,7 @@ namespace ClassicalSharp.Gui.Widgets { sb.Append(ref index, match); sb.Append(ref index, ' '); } - game.Chat.Add(sb.ToString(), MessageType.ClientStatus5); + game.Chat.Add(sb.ToString(), MessageType.ClientStatus3); } } diff --git a/ClassicalSharp/2D/Widgets/InputWidget.cs b/ClassicalSharp/2D/Widgets/InputWidget.cs index 6c711aef1..428e3a29d 100644 --- a/ClassicalSharp/2D/Widgets/InputWidget.cs +++ b/ClassicalSharp/2D/Widgets/InputWidget.cs @@ -9,16 +9,17 @@ using Android.Graphics; namespace ClassicalSharp.Gui.Widgets { public abstract class InputWidget : Widget { - public InputWidget(Game game, Font font) : base(game) { - Text = new WrappableStringBuffer(Utils.StringLength * MaxLines); - lines = new string[MaxLines]; - lineSizes = new Size[MaxLines]; + public InputWidget(Game game, Font font, string prefix, int maxLines) : base(game) { + Text = new WrappableStringBuffer(Utils.StringLength * maxLines); + lines = new string[maxLines]; + lineSizes = new Size[maxLines]; + this.font = font; + Prefix = prefix; DrawTextArgs args = new DrawTextArgs("_", font, true); caretTex = game.Drawer2D.MakeTextTexture(ref args, 0, 0); caretTex.Width = (ushort)((caretTex.Width * 3) / 4); caretWidth = caretTex.Width; caretHeight = caretTex.Height; - this.font = font; if (Prefix == null) return; args = new DrawTextArgs(Prefix, font, true); @@ -45,13 +46,13 @@ namespace ClassicalSharp.Gui.Widgets { public WrappableStringBuffer Text; /// The maximum number of lines that may be entered. - public abstract int MaxLines { get; } + public abstract int UsedLines { get; } /// The maximum number of characters that can fit on one line. - public abstract int MaxCharsPerLine { get; } + public int MaxCharsPerLine = Utils.StringLength; /// The prefix string that is always shown before the input text. Can be null. - public abstract string Prefix { get; } + public string Prefix; /// The horizontal offset (in pixels) from the start of the box background /// to the beginning of the input texture. @@ -67,7 +68,7 @@ namespace ClassicalSharp.Gui.Widgets { protected double caretAccumulator; public override void Init() { - if (lines.Length > 1) { + if (UsedLines > 1) { Text.WordWrap(game.Drawer2D, lines, MaxCharsPerLine); } else { lines[0] = Text.ToString(); @@ -105,7 +106,7 @@ namespace ClassicalSharp.Gui.Widgets { lineSizes[0].Width = prefixWidth; DrawTextArgs args = new DrawTextArgs(null, font, true); - for (int y = 0; y < MaxLines; y++) { + for (int y = 0; y < UsedLines; y++) { args.Text = lines[y]; lineSizes[y] += game.Drawer2D.MeasureSize(ref args); } @@ -114,7 +115,8 @@ namespace ClassicalSharp.Gui.Widgets { /// Calculates the location and size of the caret character public void UpdateCaret() { - if (caret >= Text.Length) caret = -1; + int maxChars = UsedLines * MaxCharsPerLine; + if (caret >= maxChars) caret = -1; Text.GetCoords(caret, lines, out caretX, out caretY); DrawTextArgs args = new DrawTextArgs(null, font, false); IDrawer2D drawer = game.Drawer2D; @@ -160,7 +162,7 @@ namespace ClassicalSharp.Gui.Widgets { /// Also updates the dimensions of the widget. public virtual void RemakeTexture() { int totalHeight = 0, maxWidth = 0; - for (int i = 0; i < MaxLines; i++) { + for (int i = 0; i < UsedLines; i++) { totalHeight += lineSizes[i].Height; maxWidth = Math.Max(maxWidth, lineSizes[i].Width); } @@ -249,8 +251,8 @@ namespace ClassicalSharp.Gui.Widgets { bool TryAppendChar(char c) { - int totalChars = MaxCharsPerLine * lines.Length; - if (Text.Length == totalChars) return false; + int maxChars = UsedLines * MaxCharsPerLine; + if (Text.Length >= maxChars) return false; if (!AllowedChar(c)) return false; AppendChar(c); @@ -409,15 +411,15 @@ namespace ClassicalSharp.Gui.Widgets { static char[] trimChars = {'\r', '\n', '\v', '\f', ' ', '\t', '\0'}; bool OtherKey(Key key) { - int totalChars = MaxCharsPerLine * lines.Length; - if (key == Key.V && Text.Length < totalChars) { + int maxChars = UsedLines * MaxCharsPerLine; + if (key == Key.V && Text.Length < maxChars) { string text = null; try { text = game.window.ClipboardText.Trim(trimChars); } catch (Exception ex) { ErrorHandler.LogError("Paste from clipboard", ex); const string warning = "&cError while trying to paste from clipboard."; - game.Chat.Add(warning, MessageType.ClientStatus4); + game.Chat.Add(warning, MessageType.ClientStatus2); return true; } @@ -431,7 +433,7 @@ namespace ClassicalSharp.Gui.Widgets { } catch (Exception ex) { ErrorHandler.LogError("Copy to clipboard", ex); const string warning = "&cError while trying to copy to clipboard."; - game.Chat.Add(warning, MessageType.ClientStatus4); + game.Chat.Add(warning, MessageType.ClientStatus2); } return true; } diff --git a/ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs b/ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs index 71ba8825c..deecd1321 100644 --- a/ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs +++ b/ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs @@ -9,7 +9,7 @@ using Android.Graphics; namespace ClassicalSharp.Gui.Widgets { public sealed class MenuInputWidget : InputWidget { - public MenuInputWidget(Game game, Font font) : base(game, font) { } + public MenuInputWidget(Game game, Font font) : base(game, font, null, 1) { } public static MenuInputWidget Create(Game game, int width, int height, string text, Font font, MenuInputValidator validator) { @@ -28,9 +28,7 @@ namespace ClassicalSharp.Gui.Widgets { public int MinWidth, MinHeight; public MenuInputValidator Validator; - public override int MaxLines { get { return 1; } } - public override string Prefix { get { return null; } } - public override int MaxCharsPerLine { get { return Utils.StringLength; } } + public override int UsedLines { get { return 1; } } public override void Render(double delta) { gfx.Texturing = false; @@ -85,7 +83,7 @@ namespace ClassicalSharp.Gui.Widgets { protected override bool AllowedChar(char c) { if (c == '&' || !Utils.IsValidInputChar(c, true)) return false; if (!Validator.IsValidChar(c)) return false; - if (Text.Length == MaxCharsPerLine) return false; + if (Text.Length == UsedLines * MaxCharsPerLine) return false; // See if the new string is in valid format AppendChar(c); diff --git a/ClassicalSharp/Game/ChatLog.cs b/ClassicalSharp/Game/ChatLog.cs index 1beb7f26f..3c7d995a9 100644 --- a/ClassicalSharp/Game/ChatLog.cs +++ b/ClassicalSharp/Game/ChatLog.cs @@ -11,7 +11,7 @@ namespace ClassicalSharp { public ChatLine Status1, Status2, Status3, BottomRight1, BottomRight2, BottomRight3, Announcement; - public ChatLine[] ClientStatus = new ChatLine[6]; + public ChatLine[] ClientStatus = new ChatLine[3]; Game game; public void Init(Game game) { @@ -63,7 +63,7 @@ namespace ClassicalSharp { BottomRight3 = text; } else if (type == MessageType.Announcement) { Announcement = text; - } else if (type >= MessageType.ClientStatus1 && type <= MessageType.ClientStatus6) { + } else if (type >= MessageType.ClientStatus1 && type <= MessageType.ClientStatus3) { ClientStatus[(int)(type - MessageType.ClientStatus1)] = text; } game.Events.RaiseChatReceived(text, type); diff --git a/ClassicalSharp/Network/Enums.cs b/ClassicalSharp/Network/Enums.cs index 93cdacff0..88735595f 100644 --- a/ClassicalSharp/Network/Enums.cs +++ b/ClassicalSharp/Network/Enums.cs @@ -66,12 +66,9 @@ namespace ClassicalSharp { Announcement = 100, // client defined message ids - ClientStatus1 = 256, - ClientStatus2 = 257, - ClientStatus3 = 258, // cuboid messages - ClientStatus4 = 259, // clipboard invalid characters - ClientStatus5 = 260, // tab list matching names - ClientStatus6 = 261, // no LongerMessages warning + ClientStatus1 = 256, // cuboid messages + ClientStatus2 = 257, // clipboard invalid characters + ClientStatus3 = 258, // tab list matching names } public enum BlockFace { XMax, XMin, YMax, YMin, ZMax, ZMin, } diff --git a/ClassicalSharp/Network/IServerConnection.cs b/ClassicalSharp/Network/IServerConnection.cs index 1d4637ed5..1732f35f2 100644 --- a/ClassicalSharp/Network/IServerConnection.cs +++ b/ClassicalSharp/Network/IServerConnection.cs @@ -19,7 +19,7 @@ namespace ClassicalSharp { /// Represents a connection to either a multiplayer server, or an internal single player server. public abstract class IServerConnection { - public abstract bool IsSinglePlayer { get; } + public bool IsSinglePlayer; /// Opens a connection to the given IP address and port, and prepares the initial state of the client. public abstract void Connect(IPAddress address, int port); diff --git a/ClassicalSharp/Network/NetworkProcessor.cs b/ClassicalSharp/Network/NetworkProcessor.cs index ebba8ab0a..6d5184d88 100644 --- a/ClassicalSharp/Network/NetworkProcessor.cs +++ b/ClassicalSharp/Network/NetworkProcessor.cs @@ -24,10 +24,9 @@ namespace ClassicalSharp.Network { public NetworkProcessor(Game window) { game = window; cpeData = new CPESupport(); game.Components.Add(cpeData); + IsSinglePlayer = false; } - public override bool IsSinglePlayer { get { return false; } } - Socket socket; DateTime lastPacket; byte lastOpcode; diff --git a/ClassicalSharp/Singleplayer/Server.cs b/ClassicalSharp/Singleplayer/Server.cs index 66ebc44f2..92da1fc2c 100644 --- a/ClassicalSharp/Singleplayer/Server.cs +++ b/ClassicalSharp/Singleplayer/Server.cs @@ -20,10 +20,9 @@ namespace ClassicalSharp.Singleplayer { physics = new PhysicsBase(game); SupportsFullCP437 = !game.ClassicMode; SupportsPartialMessages = true; + IsSinglePlayer = true; } - public override bool IsSinglePlayer { get { return true; } } - public override void Connect(IPAddress address, int port) { game.Chat.SetLogName("Singleplayer"); game.UseCPEBlocks = game.UseCPE; diff --git a/src/Client/Widgets.c b/src/Client/Widgets.c index 9b478df8e..57f40c9af 100644 --- a/src/Client/Widgets.c +++ b/src/Client/Widgets.c @@ -370,7 +370,7 @@ void HotbarWidget_Reposition(Widget* elem) { Real32 scale = Game_GetHotbarScale(); widget->BarHeight = (Real32)Math_Floor(22.0f * scale); - elem->Width = (Int32)(182 * scale); + elem->Width = (Int32)(182 * scale); elem->Height = (Int32)widget->BarHeight; widget->SelBlockSize = (Real32)Math_Ceil(24.0f * scale); diff --git a/src/Client/Widgets.h b/src/Client/Widgets.h index 5046ccc58..e77c031fc 100644 --- a/src/Client/Widgets.h +++ b/src/Client/Widgets.h @@ -118,14 +118,13 @@ void SpecialInputWidget_UpdateCols(SpecialInputWidget* widget); void SpecialInputWidget_SetActive(SpecialInputWidget* widget, bool active); -#define INPUTWIDGET_MAX_LINES 4 +#define INPUTWIDGET_MAX_LINES 3 struct InputWidget_; /* Remakes the raw texture containing all the chat lines. Also updates the dimensions of the widget. */ typedef struct InputWidget_ { Widget Base; FontDesc Font; - Int32 MaxLines; - Int32 MaxCharsPerLine; + Int32 (*GetMaxLines)(GuiElement* elem); Int32 Padding; void (*RemakeTexture)(GuiElement* elem); /* Remakes the raw texture containing all the chat lines. Also updates dimensions. */ void (*OnPressedEnter)(GuiElement* elem); /* Invoked when the user presses enter. */ @@ -147,7 +146,7 @@ typedef struct InputWidget_ { Real64 CaretAccumulator; } InputWidget; -void InputWidget_Create(InputWidget* widget, FontDesc* font); +void InputWidget_Create(InputWidget* widget, FontDesc* font, STRING_REF String* prefix); /* Calculates the sizes of each line in the text buffer. */ void InputWidget_CalculateLineSizes(InputWidget* widget); /* Calculates the location and size of the caret character. */