public MainWindow() { InitializeComponent(); fetchWorlds(); XmlDocument xml = new XmlDocument(); string xmlData = string.Empty; using (Stream stream = this.GetType().Assembly.GetManifestResourceStream("Terrafirma.tiles.xml")) { xml.Load(stream); } tileInfos = new TileInfos(xml.GetElementsByTagName("tile")); XmlNodeList wallList = xml.GetElementsByTagName("wall"); wallInfo = new WallInfo[wallList.Count + 1]; for (int i = 0; i < wallList.Count; i++) { int id = Convert.ToInt32(wallList[i].Attributes["num"].Value); wallInfo[id].name = wallList[i].Attributes["name"].Value; wallInfo[id].color = parseColor(wallList[i].Attributes["color"].Value); if (wallList[i].Attributes["blend"] != null) wallInfo[id].blend = Convert.ToInt16(wallList[i].Attributes["blend"].Value); else wallInfo[id].blend = (Int16)id; } XmlNodeList globalList = xml.GetElementsByTagName("global"); for (int i = 0; i < globalList.Count; i++) { string kind = globalList[i].Attributes["id"].Value; UInt32 color = parseColor(globalList[i].Attributes["color"].Value); switch (kind) { case "sky": skyColor = color; break; case "earth": earthColor = color; break; case "rock": rockColor = color; break; case "hell": hellColor = color; break; case "water": waterColor = color; break; case "lava": lavaColor = color; break; case "honey": honeyColor = color; break; } } XmlNodeList prefixList = xml.GetElementsByTagName("prefix"); prefixes = new string[prefixList.Count + 1]; for (int i = 0; i < prefixList.Count; i++) { int id = Convert.ToInt32(prefixList[i].Attributes["num"].Value); prefixes[id] = prefixList[i].Attributes["name"].Value; } XmlNodeList itemList = xml.GetElementsByTagName("item"); //find min/max Int32 minItemId = 0, maxItemId = 0; for (int i = 0; i < itemList.Count; i++) { Int32 id = Convert.ToInt32(itemList[i].Attributes["num"].Value); if (id < minItemId) minItemId = id; if (id > maxItemId) maxItemId = id; } itemNames2 = new string[(-minItemId) + 1]; itemNames = new string[maxItemId + 1]; for (int i = 0; i < itemList.Count; i++) { int id = Convert.ToInt32(itemList[i].Attributes["num"].Value); if (id < 0) itemNames2[-id] = itemList[i].Attributes["name"].Value; else itemNames[id] = itemList[i].Attributes["name"].Value; } render = new Render(tileInfos, wallInfo, skyColor, earthColor, rockColor, hellColor, waterColor, lavaColor, honeyColor); //this resize timer is used so we don't get killed on the resize resizeTimer = new DispatcherTimer( TimeSpan.FromMilliseconds(20), DispatcherPriority.Normal, delegate { resizeTimer.IsEnabled = false; curWidth = newWidth; curHeight = newHeight; mapbits = new WriteableBitmap(curWidth, curHeight, 96.0, 96.0, PixelFormats.Bgr32, null); Map.Source = mapbits; bits = new byte[curWidth * curHeight * 4]; Map.Width = curWidth; Map.Height = curHeight; if (loaded) RenderMap(); else { var rect = new Int32Rect(0, 0, curWidth, curHeight); for (int i = 0; i < curWidth * curHeight * 4; i++) bits[i] = 0xff; mapbits.WritePixels(rect, bits, curWidth * 4, 0); } }, Dispatcher) { IsEnabled = false }; curWidth = 496; curHeight = 400; newWidth = 496; newHeight = 400; mapbits = new WriteableBitmap(curWidth, curHeight, 96.0, 96.0, PixelFormats.Bgr32, null); Map.Source = mapbits; bits = new byte[curWidth * curHeight * 4]; curX = curY = 0; curScale = 1.0; tiles = new Tile[Widest, Highest]; //setup quick hilight menu ArrayList quickItems = new ArrayList(); foreach (TileInfo info in tileInfos.Items()) { info.isHilighting = false; quickItems.Add(new HTile(info.name, info)); addVariants(quickItems, info); } quickItems.Sort(); QuickHilite.ItemsSource = quickItems; }
public MainWindow() { InitializeComponent(); fetchWorlds(); XmlDocument xml = new XmlDocument(); string xmlData = string.Empty; using (Stream stream = this.GetType().Assembly.GetManifestResourceStream("Terrafirma.tiles.xml")) { xml.Load(stream); } tileInfos = new TileInfos(xml.GetElementsByTagName("tile")); XmlNodeList wallList = xml.GetElementsByTagName("wall"); wallInfo = new WallInfo[wallList.Count + 1]; for (int i = 0; i < wallList.Count; i++) { int id = Convert.ToInt32(wallList[i].Attributes["num"].Value); wallInfo[id].name = wallList[i].Attributes["name"].Value; wallInfo[id].color = parseColor(wallList[i].Attributes["color"].Value); } XmlNodeList globalList = xml.GetElementsByTagName("global"); for (int i = 0; i < globalList.Count; i++) { string kind = globalList[i].Attributes["id"].Value; UInt32 color = parseColor(globalList[i].Attributes["color"].Value); switch (kind) { case "sky": skyColor = color; break; case "earth": earthColor = color; break; case "rock": rockColor = color; break; case "hell": hellColor = color; break; case "water": waterColor = color; break; case "lava": lavaColor = color; break; } } render = new Render(tileInfos, wallInfo, skyColor, earthColor, rockColor, hellColor, waterColor, lavaColor); //this resize timer is used so we don't get killed on the resize resizeTimer = new DispatcherTimer( TimeSpan.FromMilliseconds(20), DispatcherPriority.Normal, delegate { resizeTimer.IsEnabled = false; curWidth = newWidth; curHeight = newHeight; mapbits = new WriteableBitmap(curWidth, curHeight, 96.0, 96.0, PixelFormats.Bgr32, null); Map.Source = mapbits; bits = new byte[curWidth * curHeight * 4]; Map.Width = curWidth; Map.Height = curHeight; if (loaded) RenderMap(); else { var rect = new Int32Rect(0, 0, curWidth, curHeight); for (int i = 0; i < curWidth * curHeight * 4; i++) bits[i] = 0xff; mapbits.WritePixels(rect, bits, curWidth * 4, 0); } }, Dispatcher) { IsEnabled = false }; curWidth = 496; curHeight = 400; newWidth = 496; newHeight = 400; mapbits = new WriteableBitmap(curWidth, curHeight, 96.0, 96.0, PixelFormats.Bgr32, null); Map.Source = mapbits; bits = new byte[curWidth * curHeight * 4]; curX = curY = 0; curScale = 1.0; tiles = new Tile[Widest, Highest]; }