Skip to content

Commit

Permalink
It's a console.
Browse files Browse the repository at this point in the history
Clientside stuff in DebugConsole.cs
Serverside stuff in ClientConsoleHost.cs
Client processes console commands and sends them to server if you tell it to.
Server processes same command , does stuff and answers client if you tell it to.
Sorry about the messy split.
  • Loading branch information
keelin committed Nov 14, 2013
1 parent a253efe commit d05d7fc
Show file tree
Hide file tree
Showing 20 changed files with 609 additions and 100 deletions.
2 changes: 1 addition & 1 deletion CGO/Component/Renderable/ParticleSystemComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace CGO
{
public class ParticleSystemComponent : Component, IRenderableComponent
public class ParticleSystemComponent : Component, IParticleSystemComponent, IRenderableComponent
{
#region Variables.
private Dictionary<string, ParticleSystem> _emitters = new Dictionary<string, ParticleSystem>(); // List of particle emitters.
Expand Down
1 change: 1 addition & 0 deletions ClientInterfaces/ClientInterfaces.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="GameStates\IGameStateManager.cs" />
<Compile Include="GOC\GetSVarsEventArgs.cs" />
<Compile Include="GOC\IEntityManagerContainer.cs" />
<Compile Include="GOC\IParticleSystemComponent.cs" />
<Compile Include="GOC\IPlayerAction.cs" />
<Compile Include="GOC\IRenderableComponent.cs" />
<Compile Include="GOC\ISpriteComponent.cs" />
Expand Down
1 change: 1 addition & 0 deletions ClientInterfaces/Configuration/IConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public interface IConfigurationManager
int GetRate();
int GetUpdateRate();
int GetCommandRate();
char GetConsoleKey();
float GetInterpolation();
}
}
15 changes: 15 additions & 0 deletions ClientInterfaces/GOC/IParticleSystemComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameObject;

namespace ClientInterfaces.GOC
{
public interface IParticleSystemComponent : IComponent
{
void AddParticleSystem(string name, bool active);
void RemoveParticleSystem(string name);
void SetParticleSystemActive(string name, bool active);
}
}
1 change: 1 addition & 0 deletions ClientServices/ClientServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<Compile Include="UserInterface\Components\Checkbox.cs" />
<Compile Include="UserInterface\Components\ContextMenu.cs" />
<Compile Include="UserInterface\Components\ArmorInfoLabel.cs" />
<Compile Include="UserInterface\Components\DebugConsole.cs" />
<Compile Include="UserInterface\Components\Showcase.cs" />
<Compile Include="UserInterface\Components\SimpleImage.cs" />
<Compile Include="UserInterface\Components\FloatingDeco.cs" />
Expand Down
1 change: 1 addition & 0 deletions ClientServices/Configuration/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public class Configuration
public int UpdateRate = 20; //Updates from the server per second
public int CommandRate = 30; //Commands to the server per second
public float Interpolation = 0.1f; //Number of seconds behind to render interpolation
public char ConsoleKey = '#';
}
}
5 changes: 5 additions & 0 deletions ClientServices/Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public string GetPlayerName()
return Configuration.PlayerName;
}

public char GetConsoleKey()
{
return Configuration.ConsoleKey;
}

public bool GetVsync()
{
return Configuration.VSync;
Expand Down
254 changes: 254 additions & 0 deletions ClientServices/UserInterface/Components/DebugConsole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using ClientInterfaces.Configuration;
using ClientInterfaces.GOC;
using ClientInterfaces.Map;
using ClientInterfaces.Network;
using ClientInterfaces.Player;
using ClientInterfaces.Resource;
using ClientInterfaces.UserInterface;
using GameObject;
using GorgonLibrary;
using GorgonLibrary.Graphics;
using GorgonLibrary.InputDevices;
using Lidgren.Network;
using SS13.IoC;
using SS13_Shared;
using SS13_Shared.GO;
using SS13_Shared.Utility;

namespace ClientServices.UserInterface.Components
{
public class DebugConsole : ScrollableContainer
{
private Textbox input;
private List<Label> lines = new List<Label>();
private int last_y = 0;

public DebugConsole(string uniqueName, Size size, IResourceManager resourceManager) : base(uniqueName, size, resourceManager)
{
input = new Textbox(size.Width, resourceManager);
input.ClearFocusOnSubmit = false;
input.drawColor = Color.FromArgb(100, Color.Gray);
input.textColor = Color.FloralWhite;
input.OnSubmit += new Textbox.TextSubmitHandler(input_OnSubmit);
this.BackgroundColor = Color.FromArgb(100, Color.Gray);
this.DrawBackground = true;
this.DrawBorder = true;
Update(0);
}

void input_OnSubmit(string text, Textbox sender)
{
AddLine(text, Color.FloralWhite);
ProcessCommand(text);
}

public void AddLine(string text, Color color)
{
Label newLabel = new Label(text, "MICROGBE", this._resourceManager);
newLabel.Position = new Point(5, last_y);
newLabel.TextColor = color;
newLabel.Update(0);
last_y = newLabel.ClientArea.Bottom;
components.Add(newLabel);
}

public override void Update(float frameTime)
{
base.Update(frameTime);
if (input != null)
{
input.Position = new Point(ClientArea.Left, ClientArea.Bottom);
input.Update(frameTime);
}
}

public override void ToggleVisible()
{
var netMgr = IoCManager.Resolve<INetworkManager>();
base.ToggleVisible();
if (IsVisible())
{
IoCManager.Resolve<IUserInterfaceManager>().SetFocus(input);
netMgr.MessageArrived += new EventHandler<IncomingNetworkMessageArgs>(netMgr_MessageArrived);
}
else
{
netMgr.MessageArrived -= new EventHandler<IncomingNetworkMessageArgs>(netMgr_MessageArrived);
}
}

void netMgr_MessageArrived(object sender, IncomingNetworkMessageArgs e)
{
//Make sure we reset the position - we might recieve this message after the gamestates.
if (e.Message.Position > 0) e.Message.Position = 0;
if (e.Message.MessageType == NetIncomingMessageType.Data && (NetMessage)e.Message.PeekByte() == NetMessage.ConsoleCommandReply)
{
e.Message.ReadByte();
AddLine("Server: " + e.Message.ReadString(), Color.RoyalBlue);
}
//Again, make sure we reset the position - we might get it before the gamestate and then that would break.
e.Message.Position = 0;
}

public override void Render()
{
base.Render();
if (input != null) input.Render();
}

public override void Dispose()
{
base.Dispose();
input.Dispose();
}

public override bool MouseDown(MouseInputEventArgs e)
{
if (!base.MouseDown(e))
if (input.MouseDown(e))
{
IoCManager.Resolve<IUserInterfaceManager>().SetFocus(input);
return true;
}
return false;
}

public override bool MouseUp(MouseInputEventArgs e)
{
if (!base.MouseUp(e))
return input.MouseUp(e);
else return false;
}

public override void MouseMove(MouseInputEventArgs e)
{
base.MouseMove(e);
input.MouseMove(e);
}

public override bool MouseWheelMove(MouseInputEventArgs e)
{
if (!base.MouseWheelMove(e))
return input.MouseWheelMove(e);
else return false;
}

public override bool KeyDown(KeyboardInputEventArgs e)
{
if (!base.KeyDown(e))
return input.KeyDown(e);
else return false;
}

/// <summary>
/// Processes commands (chat messages starting with /)
/// </summary>
/// <param name="text">input text</param>
private void ProcessCommand(string text)
{
//Commands are processed locally and then sent to the server to be processed there again.
var args = new List<string>();

CommandParsing.ParseArguments(text, args);

string command = args[0];

//Entity player;
//var entMgr = IoCManager.Resolve<IEntityManager>();
//var plrMgr = IoCManager.Resolve<IPlayerManager>();
//player = plrMgr.ControlledEntity;
//IoCManager.Resolve<INetworkManager>().

switch (command)
{
case "addparticles": //This is only clientside.
if (args.Count >= 3)
{
Entity target = null;
if (args[1].ToLowerInvariant() == "player")
{
var plrMgr = IoCManager.Resolve<IPlayerManager>();
if (plrMgr != null)
if (plrMgr.ControlledEntity != null) target = plrMgr.ControlledEntity;
}
else
{
var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
if (entMgr != null)
{
int entUid = int.Parse(args[1]);
target = entMgr.EntityManager.GetEntity(entUid);
}
}

if (target != null)
{
if (!target.HasComponent(ComponentFamily.Particles))
{
var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
var compo = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent");
target.AddComponent(ComponentFamily.Particles, compo);
}
else
{
var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
var compo = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent");
target.AddComponent(ComponentFamily.Particles, compo);
}
}
}
SendServerConsoleCommand(text); //Forward to server.
break;
case "removeparticles":
if (args.Count >= 3)
{
Entity target = null;
if (args[1].ToLowerInvariant() == "player")
{
var plrMgr = IoCManager.Resolve<IPlayerManager>();
if (plrMgr != null)
if (plrMgr.ControlledEntity != null) target = plrMgr.ControlledEntity;
}
else
{
var entMgr = IoCManager.Resolve<IEntityManager>();
if (entMgr != null)
{
int entUid = int.Parse(args[1]);
target = entMgr.GetEntity(entUid);
}
}

if (target != null)
{
if (target.HasComponent(ComponentFamily.Particles))
{
IParticleSystemComponent compo = (IParticleSystemComponent)target.GetComponent(ComponentFamily.Particles);
compo.RemoveParticleSystem(args[2]);
}
}
}
SendServerConsoleCommand(text); //Forward to server.
break;
default:
SendServerConsoleCommand(text); //Forward to server.
break;
}
}

private void SendServerConsoleCommand(string text)
{
var netMgr = IoCManager.Resolve<INetworkManager>();
if (netMgr != null && netMgr.IsConnected)
{
NetOutgoingMessage outMsg = netMgr.CreateMessage();
outMsg.Write((byte) NetMessage.ConsoleCommand);
outMsg.Write(text);
netMgr.SendMessage(outMsg, NetDeliveryMethod.ReliableUnordered);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace ClientServices.UserInterface.Components
{
internal class ScrollableContainer : GuiComponent
public class ScrollableContainer : GuiComponent
//This is a note: Spooge wants support for mouseover-scrolling of scrollable containers inside other scrollable containers.
{
protected readonly IResourceManager _resourceManager;
Expand Down
18 changes: 18 additions & 0 deletions ClientServices/UserInterface/Components/Textbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ internal class Textbox : GuiComponent
private Sprite _textboxMain;
private Sprite _textboxRight;

public Color drawColor = Color.White;
public Color textColor = Color.Black;

private float blinkCount;

public Textbox(int width, IResourceManager resourceManager)
Expand Down Expand Up @@ -90,6 +93,13 @@ public override void Update(float frameTime)

public override void Render()
{
if (drawColor != Color.White)
{
_textboxLeft.Color = drawColor;
_textboxMain.Color = drawColor;
_textboxRight.Color = drawColor;
}

_textboxLeft.Draw(_clientAreaLeft);
_textboxMain.Draw(_clientAreaMain);
_textboxRight.Draw(_clientAreaRight);
Expand All @@ -99,6 +109,14 @@ public override void Render()
Label.Position.Y + (Label.Height/2f) - (_caretHeight/2f),
_caretWidth, _caretHeight, Color.WhiteSmoke);

if (drawColor != Color.White)
{
_textboxLeft.Color = Color.White;
_textboxMain.Color = Color.White;
_textboxRight.Color = Color.White;
}

Label.Color = textColor;
Label.Text = _displayText;
Label.Draw();
}
Expand Down
Loading

0 comments on commit d05d7fc

Please sign in to comment.