// Creates an empty table structure public static List <byte[]> TableStruct(string[] args, long cKey) { List <byte[]> result = new List <byte[]>(); if (!RVIDefinitions.Initialized) { RVIDefinitions.Initialize(); } RVIVector2 position = RVIVector2.Parse(args[0]); float width = float.Parse(args[1], CultureInfo.InvariantCulture); float height = float.Parse(args[2], CultureInfo.InvariantCulture); byte hCount = byte.Parse(args[3], CultureInfo.InvariantCulture); byte vCount = byte.Parse(args[4], CultureInfo.InvariantCulture); float currenyY = position.y; for (int v = 0; v < vCount; v++) { float currentX = position.x; for (int h = 0; h < hCount; h++) { result.Add(RVIPackets.Server_Rect.Create(new RVIVector2(currentX, currenyY), width, height, cKey)); currentX += width; } currenyY -= height; } return(result); }
// Creates a 2-point line private static byte[] Line(string[] args, long cKey, RVIVector2 offset, float scale) { RVIVector2 pointA = RVIVector2.Parse(args[0]); RVIVector2 pointB = RVIVector2.Parse(args[1]); pointA *= scale; pointB *= scale; pointA += offset; pointB += offset; return(RVIPackets.Server_Line.Create(pointA, pointB, cKey)); }
// Creates a 2D rectangle from a point, width and height private static byte[] Rect(string[] args, long cKey, RVIVector2 offset, float scale) { RVIVector2 position = RVIVector2.Parse(args[0]); float width = float.Parse(args[1], CultureInfo.InvariantCulture); float height = float.Parse(args[2], CultureInfo.InvariantCulture); position *= scale; width *= scale; height *= scale; position += offset; return(RVIPackets.Server_Rect.Create(position, width, height, cKey)); }
// Creates a borderless rectangle with text inside. The text size and lining are manually provided. public static List <byte[]> TextBoxSB(string[] args, long cKey) { List <byte[]> result = new List <byte[]>(); RVIVector2 pos = RVIVector2.Parse(args[0]); float w = float.Parse(args[1], CultureInfo.InvariantCulture); float h = float.Parse(args[2], CultureInfo.InvariantCulture); float charScale = float.Parse(args[3], CultureInfo.InvariantCulture); string text = args[4]; RVIVector2 arraypos = new RVIVector2(pos.x + (charScale / 2), pos.y + charScale / 2); result.AddRange(GetBytes(RVIInstructions.ArrayChar(arraypos, charScale, text), cKey)); return(result); }
// Draws an array of defined functions, separated by the '%' character. Inherits offseting and scaling private static List <byte[]> Array(string[] args, long cKey, RVIVector2 offset, float scale) { List <byte[]> result = new List <byte[]>(); // Initialize server definitions if necessary if (!RVIDefinitions.Initialized) { RVIDefinitions.Initialize(); } // Parse arguments RVIVector2 position = RVIVector2.Parse(args[0]); float elementScale = float.Parse(args[1], CultureInfo.InvariantCulture); string[] fNames = args[2].Split('%'); // Apply scale RVIVector2 finalOffset = position * scale; float finalScale = elementScale * scale; // Apply offset finalOffset += offset; foreach (string func in fNames) { string[] fLines = RVIDefinitions.Definitions[func.ToUpper()]; for (int i = 0; i < fLines.Length; i++) { // Ignore comment lines, empty lines and '-' lines if ((fLines[i][0] == '#') || (fLines[i][0] == '!') || (string.IsNullOrEmpty(fLines[i]))) { continue; } else { result.AddRange(Instruction2Packet.GetBytes(fLines[i], cKey, finalOffset.x, finalOffset.y, finalScale)); } } finalOffset += new RVIVector2(elementScale, 0); } return(result); }
// Creates a filled, borderless table. The text size and lining are manually provided. public static List <byte[]> TableArraySB(string[] args, long cKey) { List <byte[]> result = new List <byte[]>(); if (!RVIDefinitions.Initialized) { RVIDefinitions.Initialize(); } RVIVector2 pos = RVIVector2.Parse(args[0]); float width = float.Parse(args[1], CultureInfo.InvariantCulture); float height = float.Parse(args[2], CultureInfo.InvariantCulture); byte hCount = byte.Parse(args[3], CultureInfo.InvariantCulture); byte vCount = byte.Parse(args[4], CultureInfo.InvariantCulture); float charScale = float.Parse(args[5], CultureInfo.InvariantCulture); string[] contents = args[6].Split('·'); float currentY = pos.y - charScale / 2; for (int v = 0; v < vCount; v++) { float currentX = pos.x; for (int h = 0; h < hCount; h++) { int contentIndex = (v * hCount) + h; if (contentIndex > contents.Length - 1) { return(result); } string instruct = RVIInstructions.TextBoxSB(new RVIVector2(currentX, currentY), width, height, charScale, contents[contentIndex]); result.AddRange(GetBytes(instruct, cKey)); currentX += width; } currentY -= height; } return(result); }
// Calls a definition from the dictionary in RVIDefinitions. Inherits offseting and scaling private static List <byte[]> Func(string[] args, long cKey, RVIVector2 offset, float scale) { List <byte[]> result = new List <byte[]>(); // Initialize server definitions if necessary if (!RVIDefinitions.Initialized) { RVIDefinitions.Initialize(); } // Parse args string funcName = args[0]; RVIVector2 funcOffset = RVIVector2.Parse(args[1]); float funcScale = float.Parse(args[2], CultureInfo.InvariantCulture); // Apply scale RVIVector2 finalOffset = funcOffset * scale; float finalScale = funcScale * scale; // Apply offset finalOffset += offset; // Get function program lines string[] fLines = RVIDefinitions.Definitions[funcName.ToUpper()]; for (int i = 0; i < fLines.Length; i++) { // Ignore comment lines, empty lines and '-' lines if ((fLines[i][0] == '#') || (fLines[i][0] == '!') || (string.IsNullOrEmpty(fLines[i]))) { continue; } else { // Recursively call 'GetBytes' until all instructions are atomized result.AddRange(Instruction2Packet.GetBytes(fLines[i], cKey, finalOffset.x, finalOffset.y, finalScale)); } } return(result); }
// Creates a borderless rectangle with text inside.. The text font size and lines of the text are automatically adjusted to the textbox area. public static List <byte[]> TextBoxB(string[] args, long cKey) { List <byte[]> result = new List <byte[]>(); RVIVector2 pos = RVIVector2.Parse(args[0]); float w = float.Parse(args[1], CultureInfo.InvariantCulture); float h = float.Parse(args[2], CultureInfo.InvariantCulture); string text = args[3]; float charScale = 1; const int CharactersPerLineThreshold = 28; bool newLine = false; List <string> lines = new List <string>(); string currentLine = ""; int currentCounter = 0; for (int i = 0; i < text.Length; i++) { currentCounter++; if (currentCounter % CharactersPerLineThreshold == 0 && currentCounter != 0) { newLine = true; } if (text[i] == '·' && newLine) { lines.Add(currentLine); currentLine = ""; newLine = false; currentCounter = 0; } else { currentLine += text[i]; } } lines.Add(currentLine); charScale = w / ((lines.Max(o => o.Length)) + 1); text = ""; foreach (string line in lines) { text += line + "¬"; } if (charScale >= h / 1.5f) { charScale = h / 1.5f; } RVIVector2 arraypos = new RVIVector2(pos.x + (charScale / 2), pos.y + h - charScale * 2); if (lines.Count == 1) { arraypos.y = pos.y + h / 2 - charScale / 2; } result.AddRange(GetBytes(RVIInstructions.ArrayChar(arraypos, charScale, text), cKey)); return(result); }
// Draws an array of 1 character-size functions. Inherits offseting and scaling private static List <byte[]> ArrayChar(string[] args, long cKey, RVIVector2 offset, float scale) { List <byte[]> result = new List <byte[]>(); // Initialize server definitions if necessary if (!RVIDefinitions.Initialized) { RVIDefinitions.Initialize(); } // Parse arguments RVIVector2 position = RVIVector2.Parse(args[0]); float elementScale = float.Parse(args[1], CultureInfo.InvariantCulture); string chars = args[2]; string[] fNames = new string[chars.Length]; for (int i = 0; i < fNames.Length; i++) { fNames[i] = chars[i].ToString(); } // Apply scale RVIVector2 finalOffset = position * scale; float finalScale = elementScale * scale; // Apply offset finalOffset += offset; foreach (string func in fNames) { if (func == "\0") { continue; } if (func == "¬") { finalOffset.y -= elementScale * 1.4f; finalOffset.x = position.x * scale; continue; } string[] fLines = RVIDefinitions.Definitions[func.ToUpper()]; List <string> lns = fLines.ToList(); foreach (string line in lns) { line.Replace("\r", "").Replace(" ", "").Replace("\t", ""); } lns.RemoveAll(o => string.IsNullOrWhiteSpace(o)); fLines = lns.ToArray(); for (int i = 0; i < fLines.Length; i++) { // Ignore comment lines, empty lines and '-' lines if ((fLines[i][0] == '#') || (fLines[i][0] == '!') || (string.IsNullOrEmpty(fLines[i]))) { continue; } else { result.AddRange(Instruction2Packet.GetBytes(fLines[i], cKey, finalOffset.x, finalOffset.y, finalScale)); } } finalOffset += new RVIVector2(elementScale, 0); } return(result); }