This commit is contained in:
Sofia 2017-05-11 22:01:38 +03:00
commit 5f3c56cf42
5 changed files with 78 additions and 24 deletions

View File

@ -41,21 +41,17 @@ namespace Cyber.Console {
public int RowLength = 80; public int RowLength = 80;
/// <summary> /// <summary>
/// The linecount threshold when the <see cref="TextField"/> is cleaned /// How many lines are included in the <see cref="TextField"/> when
/// up so it has <see cref="LineCountSavedFromCleanup"/> lines left. /// the total amount of lines exceeds this.
/// </summary> /// </summary>
public int MaxLinesUntilCleanup = 48; public int LinesRendered = 15;
/// <summary>
/// See <see cref="MaxLinesUntilCleanup"/>.
/// </summary>
public int LineCountSavedFromCleanup = 24;
private Dictionary<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>(); private Dictionary<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>();
private List<string> Lines = new List<string>(); private List<string> Lines = new List<string>();
private List<string> Commands = new List<string>(); private List<string> Commands = new List<string>();
private int LastCommandIndex = 0; private int LastCommandIndex = 0;
private string LastUnexecutedCommand = ""; private string LastUnexecutedCommand = "";
private int ScrollOffset = 1;
/// <summary> /// <summary>
/// Creates a new <see cref="DebugConsole"/>, and sets the <see cref="Term"/>'s singleton. /// Creates a new <see cref="DebugConsole"/>, and sets the <see cref="Term"/>'s singleton.
@ -128,7 +124,6 @@ namespace Cyber.Console {
/// </remarks> /// </remarks>
/// <param name="text">Text.</param> /// <param name="text">Text.</param>
public void Print(string text) { public void Print(string text) {
// Wrap lines and log them to Lines // Wrap lines and log them to Lines
int Index = 0; int Index = 0;
int EscapeIndex = 0; int EscapeIndex = 0;
@ -143,16 +138,19 @@ namespace Cyber.Console {
TextField.text += Line + "\n"; TextField.text += Line + "\n";
EscapeIndex++; EscapeIndex++;
} while (Index < text.Length && EscapeIndex < 10); } while (Index < text.Length && EscapeIndex < 10);
if (Lines.Count > MaxLinesUntilCleanup) { UpdateTextField();
// The print history is too long, clear up until there are only }
// a small amount left (so the user doesn't notice the cleanup)
string NewLog = ""; private void UpdateTextField() {
Lines.RemoveRange(0, Lines.Count - LineCountSavedFromCleanup); string NewLog = "";
foreach (string Line in Lines) { int LineAmt = Mathf.Min(LinesRendered, Lines.Count);
NewLog += Line + "\n"; for (int i = 0; i < LineAmt; i++) {
int Index = Lines.Count - (i + ScrollOffset);
if (Index >= 0 && Index < Lines.Count) {
NewLog += Lines[i] + "\n";
} }
TextField.text = NewLog;
} }
TextField.text = NewLog;
} }
private void Start() { private void Start() {
@ -229,6 +227,14 @@ namespace Cyber.Console {
InputField.text = LastUnexecutedCommand; InputField.text = LastUnexecutedCommand;
} }
} }
if (Input.GetAxis("Mouse ScrollWheel") > 0 && ScrollOffset + 1 <= Lines.Count) {
ScrollOffset++;
UpdateTextField();
}
if (Input.GetAxis("Mouse ScrollWheel") < 0 && ScrollOffset - 1 > 1) {
ScrollOffset--;
UpdateTextField();
}
// Slide up/down animation // Slide up/down animation
RectTransform Rect = Panel.GetComponent<RectTransform>(); RectTransform Rect = Panel.GetComponent<RectTransform>();

View File

@ -4,9 +4,21 @@ using Cyber.Console;
using Cyber.Util; using Cyber.Util;
namespace Cyber.Entities.SyncBases { namespace Cyber.Entities.SyncBases {
/// <summary>
/// Runs functions.
/// </summary>
/// \todo Implement programs in an editor-friendly way
public class Computer : Interactable { public class Computer : Interactable {
/// <summary>The "left key" key code.</summary>
public const string KeyCodeLeft = "KeyLeft"; public const string KeyCodeLeft = "KeyLeft";
/// <summary>The "right key" key code.</summary>
public const string KeyCodeRight = "KeyRight"; public const string KeyCodeRight = "KeyRight";
/// <summary>
/// The delegate which defines the function that will be run when the
/// computer is interacted with (directly or through keys).
/// </summary>
public delegate void RunProgram(Computer host, string key); public delegate void RunProgram(Computer host, string key);
/// <summary> /// <summary>
@ -32,6 +44,12 @@ namespace Cyber.Entities.SyncBases {
/// </summary> /// </summary>
public RunProgram Program; public RunProgram Program;
/// <summary>
/// Runs the <see cref="Program"/> with some input, determined by the
/// Trigger.
/// </summary>
/// <param name="Trigger">Determines the keycode given to the
/// <see cref="Program"/>.</param>
public override void Interact(SyncBase Trigger) { public override void Interact(SyncBase Trigger) {
if (Trigger == KeyLeft) { if (Trigger == KeyLeft) {
Screen.SetTextProperties(new TextTextureProperties("\n Pressed left!")); Screen.SetTextProperties(new TextTextureProperties("\n Pressed left!"));
@ -42,16 +60,36 @@ namespace Cyber.Entities.SyncBases {
} }
} }
/// <summary>
/// No serialization needed (yet).
/// </summary>
/// <param name="reader"></param>
public override void Deserialize(NetworkReader reader) { public override void Deserialize(NetworkReader reader) {
} }
/// <summary>
/// No serialization needed (yet).
/// </summary>
/// <param name="writer"></param>
public override void Serialize(NetworkWriter writer) { public override void Serialize(NetworkWriter writer) {
} }
/// <summary>
/// Computers could have lots of data, and therefore should be hashed
/// to optimize bandwidth usage. No hurry in updating them though, so
/// an update per 10 ticks is enough.
/// </summary>
/// <returns>The sync handletype.</returns>
public override SyncHandletype GetSyncHandletype() { public override SyncHandletype GetSyncHandletype() {
return new SyncHandletype(true, 10); return new SyncHandletype(true, 10);
} }
/// <summary>
/// Computers should share state between different clients, so sync and
/// send interactions to the network.
/// </summary>
/// <returns>The Interaction information.</returns>
public override InteractableSyncdata GetInteractableSyncdata() { public override InteractableSyncdata GetInteractableSyncdata() {
return new InteractableSyncdata(true, true); return new InteractableSyncdata(true, true);
} }

View File

@ -142,7 +142,7 @@ namespace Cyber.Networking.Serverside {
SendToAll(PktType.TextMessage, new TextMessagePkt("Server: " + args[0])); SendToAll(PktType.TextMessage, new TextMessagePkt("Server: " + args[0]));
}); });
gameObject.AddComponent<Syncer>(); Syncer = gameObject.AddComponent<Syncer>();
ServerSyncHandler = new ServerSyncHandler(Players); ServerSyncHandler = new ServerSyncHandler(Players);

View File

@ -63,10 +63,20 @@ namespace Cyber.Util {
/// <param name="forceRender">Whether the texture should be rendered /// <param name="forceRender">Whether the texture should be rendered
/// again even if it's cached.</param> /// again even if it's cached.</param>
public static Texture2D GetText(TextTextureProperties text, bool forceRender = false) { public static Texture2D GetText(TextTextureProperties text, bool forceRender = false) {
if (forceRender || !Cache.ContainsKey(text.Text)) { string Hash = CreateHash(text);
Cache[text.Text] = Singleton.RenderText(text); if (forceRender || !Cache.ContainsKey(Hash)) {
Cache[Hash] = Singleton.RenderText(text);
Term.Println("Created a new texture for:");
Term.Println(Hash);
Term.Println("====");
} }
return Cache[text.Text]; return Cache[Hash];
}
private static string CreateHash(TextTextureProperties text) {
return text.Text + "," + text.Width + "," + text.Height + "," +
text.FontSize + "," + text.Background.r + "," +
text.Background.g + "," + text.Background.b;
} }
} }
} }

View File

@ -37,9 +37,9 @@ Version 0.3.0 - Mortician
Version 0.2.0 - Juniper Version 0.2.0 - Juniper
----------------------- -----------------------
- [ ] Basic interactions and an environment for testing. - [x] Basic interactions and an environment for testing.
- [ ] A room with a door, a button and a screen. - [x] A room with a door, a button and a screen.
- [ ] Both players should be able to open the door and press the button, and see a reaction in the world (door opening, screen flashing). - [x] Both players should be able to open the door and press the button, and see a reaction in the world (door opening, screen flashing).
Version 0.1.0 - Gigantic Version 0.1.0 - Gigantic
------------------------ ------------------------