private void MapList_MapSelected(object sender, MapSelectedEventArgs e) { activeMap = e.SelectedMap; SelectElement(null); foreach (var elem in elements) { this.Controls.Remove(elem); elem.Dispose(); } elements.Clear(); if (activeMap == null) { return; } foreach (var elem in activeMap.Elements) { var set = PluginInstance.PluginRequestCharSet(elem.CharSetId, null, null).FirstOrDefault(); if (set == null) { continue; } var newLemen = new MapElement(); newLemen.PixelScale = pixelScale; newLemen.Set = set.Clone(); newLemen.CellX = elem.CharX; newLemen.CellY = elem.CharY; newLemen.SetScale = elem.Scale; newLemen.Click += ElementOnDrag_Click; newLemen.Drag += ElementOnDrag_Drag; newLemen.ExtraByte = elem.ExtraData; this.Controls.Add(newLemen); newLemen.BringToFront(); PlaceElement(newLemen); elements.Add(newLemen); } }
private void BtnExportMapsToEditor_Click(object sender, EventArgs e) { StringBuilder sbDefines = new StringBuilder(); StringBuilder sbIndexes = new StringBuilder(); StringBuilder sbArray = new StringBuilder(); int index = 0; int mapNumber = 0; List <int> mapIndexes = new List <int>(); List <string> mapLines = new List <string>(); foreach (var map in mapList.Maps) { List <byte> tmpData = new List <byte>(); sbDefines.AppendLine(string.Format(defineTemplate, mapNumber, index)); mapIndexes.Add(index); foreach (var element in map.Elements) { var set = PluginInstance.PluginRequestCharSet(element.CharSetId, null, null)?.FirstOrDefault(); if (set == null) { continue; } var idxName = set.Name.Replace(" ", "").ToUpper() + "_INDEX"; if (idxName.StartsWith("DEFLECTOR")) { idxName = "DEFLECTOR_INDEX"; } int realIndex = Array.IndexOf(namedIndexes, idxName); if (realIndex == -1) { continue; } ushort toStore = (ushort)((((element.CharY + 1) & 31) << 10) | (((element.CharX + 1) & 31) << 5) | ((realIndex + 1) & 31)); tmpData.AddRange(BitConverter.GetBytes(toStore)); //Just for testing, need to retrieve extended info of the item switch (idxName) { case "DEFLECTOR_INDEX": byte extra = element.ExtraData; var objName = set.Name.Replace(" ", "").ToUpper(); switch (objName) { case "DEFLECTORA": extra = (byte)(extra | (1 << 4)); break; case "DEFLECTORB": extra = (byte)(extra | (2 << 4)); break; case "DEFLECTORC": extra = (byte)(extra | (3 << 4)); break; case "DEFLECTORD": extra = (byte)(extra | (4 << 4)); break; } tmpData.Add(extra); break; case "MOTHERSHIP_INDEX": case "HANGAR_INDEX": tmpData.Add(element.ExtraData); break; } } index += tmpData.Count + 1; mapNumber++; tmpData.Add(0); mapLines.Add(ByteArrayToHex(tmpData.ToArray())); } string arrayContent = string.Format(mapTemplate, index, string.Join(", _\r\n", mapLines) + " _"); string indexesContent = string.Format(indexesArrayTemplate, mapIndexes.Count, string.Join(", _\r\n", mapIndexes.Select(i => i.ToString())) + " _"); string finalContent = "'----DEFINES----\r\n" + sbDefines.ToString() + "\r\n\r\n'----INDEXES----\r\n" + indexesContent + "\r\n\r\n'----MAP_CONTENT----\r\n" + arrayContent; PluginInstance.PluginRequestEditorWindow("BattleGrid compiled map", finalContent); }