mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 20:15:35 -04:00
Simplify chat input sending
This commit is contained in:
parent
295e1a5ee0
commit
b365a3b796
@ -21,7 +21,7 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
int typingLogPos;
|
||||
string originalText;
|
||||
|
||||
public override int UsedLines {
|
||||
public override int UsedLines {
|
||||
get { return !game.ClassicMode && game.Server.SupportsPartialMessages ? 3 : 1; }
|
||||
}
|
||||
|
||||
@ -48,7 +48,12 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
|
||||
|
||||
public override void EnterInput() {
|
||||
SendChat();
|
||||
if (!Text.Empty) {
|
||||
// Don't want trailing spaces in output message
|
||||
string allText = new String(Text.value, 0, Text.TextLength);
|
||||
game.Chat.Send(allText);
|
||||
}
|
||||
|
||||
originalText = null;
|
||||
typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1.
|
||||
|
||||
@ -57,53 +62,6 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
base.EnterInput();
|
||||
}
|
||||
|
||||
|
||||
void SendChat() {
|
||||
if (Text.Empty) return;
|
||||
// Don't want trailing spaces in output message
|
||||
string allText = new String(Text.value, 0, Text.TextLength);
|
||||
game.Chat.InputLog.Add(allText);
|
||||
|
||||
if (game.Server.SupportsPartialMessages) {
|
||||
SendWithPartial(allText);
|
||||
} else {
|
||||
SendNormal();
|
||||
}
|
||||
}
|
||||
|
||||
void SendWithPartial(string allText) {
|
||||
// don't automatically word wrap the message.
|
||||
while (allText.Length > Utils.StringLength) {
|
||||
game.Chat.Send(allText.Substring(0, Utils.StringLength), true);
|
||||
allText = allText.Substring(Utils.StringLength);
|
||||
}
|
||||
game.Chat.Send(allText, false);
|
||||
}
|
||||
|
||||
void SendNormal() {
|
||||
int packetsCount = 0;
|
||||
for (int i = 0; i < lines.Length; i++) {
|
||||
if (lines[i] == null) break;
|
||||
packetsCount++;
|
||||
}
|
||||
|
||||
// split up into both partial and final packet.
|
||||
for (int i = 0; i < packetsCount - 1; i++)
|
||||
SendNormalText(i, true);
|
||||
SendNormalText(packetsCount - 1, false);
|
||||
}
|
||||
|
||||
void SendNormalText(int i, bool partial) {
|
||||
string text = lines[i];
|
||||
char lastCol = i == 0 ? 'f' : GetLastColour(0, i); // no previous colour on first line
|
||||
// TODO: this needs to be better, in case second/third line starts with a colour code
|
||||
|
||||
if (!IDrawer2D.IsWhiteCol(lastCol))
|
||||
text = "&" + lastCol + text;
|
||||
game.Chat.Send(text, partial);
|
||||
}
|
||||
|
||||
|
||||
#region Input handling
|
||||
|
||||
public override bool HandlesKeyPress(char key) {
|
||||
|
@ -30,15 +30,15 @@ namespace ClassicalSharp {
|
||||
/// <summary> List of chat messages sent by the user to the server. </summary>
|
||||
public List<string> InputLog = new List<string>();
|
||||
|
||||
public void Send(string text, bool partial) {
|
||||
text = text.TrimEnd(trimChars);
|
||||
public void Send(string text) {
|
||||
if (String.IsNullOrEmpty(text)) return;
|
||||
|
||||
InputLog.Add(text);
|
||||
if (game.CommandList.IsCommandPrefix(text)) {
|
||||
game.CommandList.Execute(text);
|
||||
return;
|
||||
} else {
|
||||
game.Server.SendChat(text);
|
||||
}
|
||||
game.Server.SendChat(text, partial);
|
||||
}
|
||||
|
||||
static char[] trimChars = new char[] { ' ', '\0' };
|
||||
@ -91,10 +91,10 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
static bool Allowed(char c) {
|
||||
return
|
||||
c == '{' || c == '}' ||
|
||||
c == '[' || c == ']' ||
|
||||
c == '(' || c == ')' ||
|
||||
return
|
||||
c == '{' || c == '}' ||
|
||||
c == '[' || c == ']' ||
|
||||
c == '(' || c == ')' ||
|
||||
(c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ namespace ClassicalSharp {
|
||||
if (!Hotkeys.IsHotkey(key, game.Input, out text, out more)) return;
|
||||
|
||||
if (!more) {
|
||||
game.Server.SendChat(text, false);
|
||||
game.Server.SendChat(text);
|
||||
} else if (game.Gui.activeScreen == null) {
|
||||
game.Gui.hudScreen.OpenTextInputBar(text);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace ClassicalSharp {
|
||||
/// <summary> Opens a connection to the given IP address and port, and prepares the initial state of the client. </summary>
|
||||
public abstract void Connect(IPAddress address, int port);
|
||||
|
||||
public abstract void SendChat(string text, bool partial);
|
||||
public abstract void SendChat(string text);
|
||||
|
||||
/// <summary> Informs the server of the client's current position and orientation. </summary>
|
||||
public abstract void SendPosition(Vector3 pos, float rotY, float headX);
|
||||
|
@ -10,9 +10,15 @@ namespace ClassicalSharp.Network {
|
||||
|
||||
internal bool addEntityHack = true;
|
||||
|
||||
public override void SendChat(string text, bool partial) {
|
||||
public override void SendChat(string text) {
|
||||
if (String.IsNullOrEmpty(text)) return;
|
||||
classic.WriteChat(text, partial);
|
||||
|
||||
while (text.Length > Utils.StringLength) {
|
||||
classic.WriteChat(text.Substring(0, Utils.StringLength), true);
|
||||
SendPacket();
|
||||
text = text.Substring(Utils.StringLength);
|
||||
}
|
||||
classic.WriteChat(text, false);
|
||||
SendPacket();
|
||||
}
|
||||
|
||||
@ -55,7 +61,7 @@ namespace ClassicalSharp.Network {
|
||||
game.LocalPlayer.fetchedSkin = false;
|
||||
|
||||
game.LocalPlayer.DisplayName = displayName;
|
||||
game.LocalPlayer.SkinName = skinName;
|
||||
game.LocalPlayer.SkinName = skinName;
|
||||
game.LocalPlayer.UpdateName();
|
||||
}
|
||||
|
||||
@ -71,7 +77,7 @@ namespace ClassicalSharp.Network {
|
||||
|
||||
internal void RemoveEntity(byte id) {
|
||||
Entity entity = game.Entities.List[id];
|
||||
if (entity == null) return;
|
||||
if (entity == null) return;
|
||||
if (id != EntityList.SelfID) game.Entities.RemoveEntity(id);
|
||||
|
||||
// See comment about some servers in HandleAddEntity
|
||||
|
@ -42,7 +42,7 @@ namespace ClassicalSharp.Network.Protocols {
|
||||
|
||||
internal void CheckSendWomID() {
|
||||
if (sendWomId && !sentWomId) {
|
||||
net.SendChat("/womid WoMClient-2.0.7", false);
|
||||
net.SendChat("/womid WoMClient-2.0.7");
|
||||
sentWomId = true;
|
||||
}
|
||||
}
|
||||
|
@ -40,10 +40,15 @@ namespace ClassicalSharp.Singleplayer {
|
||||
}
|
||||
|
||||
char lastCol = '\0';
|
||||
public override void SendChat(string text, bool partial) {
|
||||
if (!String.IsNullOrEmpty(text))
|
||||
AddChat(text);
|
||||
if (!partial) lastCol = '\0';
|
||||
public override void SendChat(string text) {
|
||||
if (String.IsNullOrEmpty(text)) return;
|
||||
lastCol = '\0';
|
||||
|
||||
while (text.Length > Utils.StringLength) {
|
||||
AddChat(text.Substring(0, Utils.StringLength));
|
||||
text = text.Substring(Utils.StringLength);
|
||||
}
|
||||
AddChat(text);
|
||||
}
|
||||
|
||||
void AddChat(string text) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user