static void consoleInput_SubmitPressed() { Console.consoleOutput.AddRow("> " + Console.consoleInput.Text); string command = null; string[] args = null; if (Console.consoleInput.Text.IndexOf(" ") > 0) { command = Console.consoleInput.Text.Substring(0, Console.consoleInput.Text.IndexOf(" ")); args = Console.consoleInput.Text.Substring(Console.consoleInput.Text.IndexOf(" ") + 1, Console.consoleInput.Text.Length - (Console.consoleInput.Text.IndexOf(" ") + 1)).Split(' '); } else { command = Console.consoleInput.Text.Substring(0, Console.consoleInput.TextLength); } switch (command) { case "help": Console.consoleOutput.AddRow("Available Commands: help, clear, deltatime, drawdebug"); break; case "clear": Console.consoleOutput.RemoveAllRows(); break; case "deltatime": Console.consoleOutput.AddRow("Delta Time: " + Engine.deltaTime); break; case "drawdebug": if (Engine.drawDebug) { Engine.drawDebug = false; } else { Engine.drawDebug = true; } break; case "drawcollisions": if (Engine.drawCollisions) { Engine.drawCollisions = false; } else { Engine.drawCollisions = true; } break; case "kill": Engine.player.Kill(); break; case "killall": /*foreach (Entity e in Engine.map.entities.ToList()) { e.Kill(); }*/ break; case "giveitem": if(args.Length == 3) { TriggerGiveItem t = new TriggerGiveItem(Convert.ToInt16(args[2]), args[1]); //Actor target = (Actor)Engine.map.entities.Find(x => x.name == args[0]); // t.Run(target, false); } else { Console.consoleOutput.AddRow("Invalid arguments. Please use the form: giveitem <entity name> <item name> <item quantity>"); } break; default: Console.consoleOutput.AddRow("Unrecognised Command: \"" + Console.consoleInput.Text + "\""); break; } Console.consoleInput.Text = ""; }
public Map(string filename) { entities = new List<Entity>(); staticLights = new List<StaticLight>(); XElement root = XElement.Load(filename); if(root.Name == "map") { version = (string)root.Attribute("version"); orientation = (string)root.Attribute("orientation"); width = (int)root.Attribute("width"); height = (int)root.Attribute("height"); tileWidth = (int)root.Attribute("tilewidth"); tileHeight = (int)root.Attribute("tileheight"); List<XElement> mapProperties = root.Elements("properties").Descendants().ToList(); ambientColor.R = (byte)(int)mapProperties.Find(x => (string)x.Attribute("name") == "ambientColorR").Attribute("value"); ambientColor.G = (byte)(int)mapProperties.Find(x => (string)x.Attribute("name") == "ambientColorG").Attribute("value"); ambientColor.B = (byte)(int)mapProperties.Find(x => (string)x.Attribute("name") == "ambientColorB").Attribute("value"); ambientColor.A = (byte)(int)mapProperties.Find(x => (string)x.Attribute("name") == "ambientColorA").Attribute("value"); Log.WriteInfo("[Map] Loading map " + @filename + ", version " + version); IEnumerable<XElement> tilesets = root.Elements("tileset"); foreach(XElement e in tilesets) { tileSets.Add(new TileSet( (int)e.Attribute("firstgid"), (string)e.Attribute("name"), (int)e.Attribute("tilewidth"), (int)e.Attribute("tileheight") )); Log.WriteInfo("[Map] Tileset " + tileSets.Last().name + " found"); XElement img = e.Element("image"); tileSets.Last().SetImage( (string)img.Attribute("source"), (int)img.Attribute("width"), (int)img.Attribute("height") ); Log.WriteInfo("[Map] Tileset image is " + tileSets.Last().source); } IEnumerable<XElement> layerslist = root.Elements("layer"); foreach(XElement e in layerslist) { layers.Add(new Layer( (string)e.Attribute("name"), (int)e.Attribute("width"), (int)e.Attribute("height") )); IEnumerable<XElement> layerTiles = e.Elements("data").Elements("tile"); for (int y = 0; y < layers.Last().height; y++) { for (int x = 0; x < layers.Last().width; x++) { //TODO: create a missing tile texture and use the FirstOrDefault method to select it if an invalid tile is input layers.Last().tilesData[x, y] = (int)layerTiles.ElementAt(y*layers.Last().width+x).Attribute("gid"); } } } IEnumerable<XElement> objectGroups = root.Elements("objectgroup"); foreach(XElement e in objectGroups) { IEnumerable<XElement> objects = objectGroups.Elements("object"); foreach(XElement o in objects) { int oWidth = (int)o.Attribute("width"); int oHeight = (int)o.Attribute("height"); int oX = (int)o.Attribute("x"); int oY = (int)o.Attribute("y"); switch((string)o.Attribute("name")) { case "collisionrect": CollisionRect ent = new CollisionRect(oX, oY, oWidth, oHeight); entities.Add(ent); break; case "staticLight": List<XElement> properties = o.Elements("properties").Descendants().ToList(); byte r = (byte)(int)properties.Find(x => (string)x.Attribute("name") == "r").Attribute("value"); byte g = (byte)(int)properties.Find(x => (string)x.Attribute("name") == "g").Attribute("value"); byte b = (byte)(int)properties.Find(x => (string)x.Attribute("name") == "b").Attribute("value"); int startAngle = (int)properties.Find(x => (string)x.Attribute("name") == "startAngle").Attribute("value"); int endAngle = (int)properties.Find(x => (string)x.Attribute("name") == "endAngle").Attribute("value"); StaticLight light = new StaticLight( new Color(r, g, b), oWidth, startAngle, endAngle, new Vector2f(oX, oY) ); staticLights.Add(light); break; case "triggerGiveItem": string item, draw; int amount; List<XElement> _properties = o.Elements("properties").Descendants().ToList(); amount = (int)_properties.Find(x => (string)x.Attribute("name") == "amount").Attribute("value"); draw = (string)_properties.Find(x => (string)x.Attribute("name") == "draw").Attribute("value"); item = (string)_properties.Find(x => (string)x.Attribute("name") == "item").Attribute("value"); TriggerGiveItem trig3 = new TriggerGiveItem( oX, oY, oWidth, oHeight, amount, draw, item); entities.Add(trig3); break; } } } } else { Log.WriteError("[Map] Invalid map file: " + @filename + ", version " + version); } }
public void showItemModal(TriggerGiveItem sender) { Gwen.Control.WindowControl w = new Gwen.Control.WindowControl(_canvas, "Items", true); w.Width = 200; w.Height = 120; //w.DeleteOnClose = true; Gwen.Control.ImagePanel img = new Gwen.Control.ImagePanel(w); img.ImageName = "./assets/" + sender.item.iconName; img.SetPosition(5, 10); img.SetSize(32, 32); Gwen.Control.CheckBox check = new Gwen.Control.CheckBox(w); check.SetPosition(w.Width - 29, 32 / 2 + 3); check.IsChecked = true; Gwen.Control.Label itemName = new Gwen.Control.Label(w); itemName.Text = sender.item.name; itemName.SetPosition(48, 14); Gwen.Control.Label itemDescription = new Gwen.Control.Label(w); Gwen.Font descFont = defaultFont; descFont.Size = 9; itemDescription.Width = 200; itemDescription.Text = sender.item.description; itemDescription.Font = descFont; itemDescription.SetPosition(48, 25); Gwen.Control.Button takeAll = new Gwen.Control.Button(w); takeAll.SetText("Take All"); takeAll.TextColor = System.Drawing.Color.White; takeAll.TextColorOverride = System.Drawing.Color.FromArgb(236, 236, 255); takeAll.Width = 60; takeAll.X = 5; takeAll.Y = w.Height - takeAll.Height - 40; takeAll.Clicked += delegate { if (sender._amount > 0) { while(sender._amount > 0) { Engine.player.inventory.Add(sender.item); if (Engine.player.activeWeapon.name == null && sender.item.GetType().IsSubclassOf(typeof(Weapon))) { Engine.player.activeWeapon = (Panjin.Weapon)Engine.player.inventory[Engine.player.inventory.Count -1]; } sender._amount--; } w.SetPosition(-99, -99); w.Hide(); w.Close(); } else { w.SetPosition(-99, -99); w.Hide(); w.Close(); } }; Gwen.Control.Button takeSelected = new Gwen.Control.Button(w); takeSelected.SetText("Take Selected"); takeSelected.Width = 80; takeSelected.TextColor = System.Drawing.Color.White; takeSelected.TextColorOverride = System.Drawing.Color.FromArgb(236, 236, 255); takeSelected.X = w.Width - takeSelected.Width - 17; takeSelected.Y = w.Height - takeSelected.Height - 40; }