3 using Microsoft.Xna.Framework;
11 private readonly
struct ClientEventData : IEventData
13 public readonly
string Text;
15 public ClientEventData(
string text)
21 private GUIListBox historyBox;
22 private GUITextBlock fillerBlock;
23 private GUITextBox inputBox;
24 private bool shouldSelectInputBox;
26 partial
void InitProjSpecific(XElement element)
28 float marginMultiplier = element.GetAttributeFloat(
"marginmultiplier", 1.0f);
30 var layoutGroup =
new GUILayoutGroup(
new RectTransform(
GuiFrame.
Rect.Size - GUIStyle.ItemFrameMargin.Multiply(marginMultiplier),
GuiFrame.
RectTransform,
Anchor.Center) { AbsoluteOffset = GUIStyle.ItemFrameOffset.Multiply(marginMultiplier) })
32 ChildAnchor =
Anchor.TopCenter,
33 RelativeSpacing = 0.02f,
37 historyBox =
new GUIListBox(
new RectTransform(
new Vector2(1, .9f), layoutGroup.RectTransform), style:
null)
46 new GUIFrame(
new RectTransform(
new Vector2(0.9f, 0.01f), layoutGroup.RectTransform), style:
"HorizontalLine");
48 inputBox =
new GUITextBox(
new RectTransform(
new Vector2(1, .1f), layoutGroup.RectTransform), textColor:
TextColor)
50 MaxTextLength = MaxMessageLength,
52 OnEnterPressed = (GUITextBox textBox,
string text) =>
54 if (GameMain.NetworkMember ==
null)
60 item.CreateClientEvent(
this,
new ClientEventData(text));
62 textBox.Text =
string.Empty;
68 layoutGroup.Recalculate();
81 private void SendOutput(
string input)
83 if (input.Length > MaxMessageLength)
85 input = input.Substring(0, MaxMessageLength);
89 ShowOnDisplay(input, addToHistory:
true,
TextColor, isWelcomeMessage:
false);
93 partial
void ShowOnDisplay(
string input,
bool addToHistory, Color color,
bool isWelcomeMessage)
97 messageHistory.Add(
new TerminalMessage(input, color, isWelcomeMessage));
98 while (messageHistory.Count > MaxMessages)
100 messageHistory.RemoveAt(0);
102 while (historyBox.Content.CountChildren > MaxMessages)
104 historyBox.RemoveChild(historyBox.Content.Children.First());
108 GUITextBlock newBlock =
new GUITextBlock(
109 new RectTransform(
new Vector2(1, 0), historyBox.Content.RectTransform, anchor:
Anchor.TopCenter),
111 textColor: color, wrap:
true, font:
UseMonospaceFont ? GUIStyle.MonospacedFont : GUIStyle.Font)
116 if (fillerBlock !=
null)
118 float y = fillerBlock.RectTransform.RelativeSize.Y - newBlock.RectTransform.RelativeSize.Y;
121 fillerBlock.RectTransform.RelativeSize =
new Vector2(1, y);
125 historyBox.RemoveChild(fillerBlock);
130 historyBox.RecalculateChildren();
131 historyBox.UpdateScrollBarSize();
134 historyBox.ScrollBar.BarScrollValue = 1;
140 shouldSelectInputBox =
true;
141 return base.Select(character);
149 base.AddToGUIUpdateList(order: order);
150 if (shouldSelectInputBox && !
Readonly)
153 shouldSelectInputBox =
false;
159 if (TryExtractEventData(extraData, out ClientEventData eventData))
RectTransform RectTransform
void SendSignal(string signal, string connectionName)
void ClientEventRead(IReadMessage msg, float sendingTime)
void ClientEventWrite(IWriteMessage msg, NetEntityEvent.IData extraData=null)
override bool Select(Character character)
override void AddToGUIUpdateList(int order=0)
Interface for entities that the clients can send events to the server
Interface for entities that the server can send events to the clients
void WriteString(string val)