public ModOptionsDialog() { InitializeComponent(); Mission = MainWindow.Instance.Mission; DataContext = Mission; OptionList.ItemsSource = Mission.ModOptions; }
// todo: refresh boxes when mod changes public MissionSettingsDialog() { InitializeComponent(); Mission = MainWindow.Instance.Mission; DataContext = Mission; WidgetsBox.BindCollection(Mission.DisabledWidgets); GadgetsBox.BindCollection(Mission.DisabledGadgets); }
public LuaTable GetLuaTable(Mission mission) { var map = new Dictionary<object, object> { {"areas", LuaTable.CreateArray(areas.Select(a => a.GetLuaMap(mission)))}, {"name", Name}, }; return new LuaTable(map); }
public LuaTable GetLuaMap(Mission mission) { var map = new Dictionary<object, object> { {"orderType", OrderType}, {"args", LuaTable.Empty}, }; return new LuaTable(map); }
public LuaTable GetLuaMap(Mission mission) { var map = new Dictionary<object, object> { {"orderType", OrderType}, {"target", Group} }; return new LuaTable(map); }
public LuaTable GetLuaMap(Mission mission) { var map = new Dictionary<object, object> { {"orderType", OrderType}, {"args", LuaTable.CreateArray(new [] { Mode })}, }; return new LuaTable(map); }
public override LuaTable GetLuaMap(Mission mission) { var map = new Dictionary<object, object> { {"category", "cylinder"}, {"x", mission.ToIngameX(X)}, {"y", mission.ToIngameY(Y)}, {"r", mission.ToIngameX(R)}, }; return new LuaTable(map); }
public override LuaTable GetLuaMap(Mission mission) { var map = new Dictionary<object, object> { {"category", "rectangle"}, {"x", mission.ToIngameX(X)}, {"y", mission.ToIngameY(Y)}, {"width", mission.ToIngameX(width)}, {"height", mission.ToIngameX(height)}, }; return new LuaTable(map); }
public LuaTable GetLuaMap(Mission mission) { var map = new Dictionary<object, object> { {"orderType", OrderType}, }; if (!String.IsNullOrEmpty(Group)) map.Add("target", Group); else { var args = LuaTable.CreateArray(new[] { mission.ToIngameX(X), 0, mission.ToIngameY(Y) }); map.Add("args", args); } return new LuaTable(map); }
public LuaTable GetLuaMap(Mission mission) { var map = new Dictionary<object, object> { { "unitDefName", UnitDef.Name }, { "x", Math.Floor(mission.ToIngameX(X)) }, { "y", Math.Floor(mission.ToIngameY(Y)) }, { "player", mission.Players.IndexOf(Player) }, { "groups", LuaTable.CreateSet(Groups) }, { "heading", Heading }, { "isGhost", isGhost}, }; return new LuaTable(map); }
public static void Publish(Mission mission, int? missionID) { var dialog = new PublishDialog { DataContext = mission, Owner = MainWindow.Instance}; dialog.OKButton.Click += delegate { var error = mission.VerifyCanPublish(); if (error == null) { SendMissionWithDialog(mission, dialog.PasswordBox.Password, missionID); dialog.Close(); } else MessageBox.Show(error); }; dialog.ShowDialog(); }
public static void SendMissionWithDialog(Mission mission, string password, int?missionId) { var loading = new LoadingDialog { Text = "Uploading Mission", Owner = MainWindow.Instance }; loading.Loaded += delegate { Utils.InvokeInNewThread(delegate { SendMission(mission, password, missionId); loading.Invoke(loading.Close); }); }; loading.ShowDialog(); }
public static void Publish(Mission mission, int?missionID) { var dialog = new PublishDialog { DataContext = mission, Owner = MainWindow.Instance }; dialog.OKButton.Click += delegate { var error = mission.VerifyCanPublish(); if (error == null) { SendMissionWithDialog(mission, dialog.PasswordBox.Password, missionID); dialog.Close(); } else { MessageBox.Show(error); } }; dialog.ShowDialog(); }
public static bool SendMission(Mission mission, string password, int?missionId) { try { var info = new ZkData.Mission() { Description = mission.Description, DescriptionStory = mission.DescriptionStory != String.Empty ? mission.DescriptionStory : null, Map = mission.Map.Name, Mod = mission.Mod.Name, Name = mission.Name, ScoringMethod = mission.ScoringMethod, Script = mission.GetScript(), ModRapidTag = mission.RapidTag, }; var slots = mission.GetSlots(); var image = File.ReadAllBytes(mission.ImagePath).ToImage(96, 96); var pngEncoder = new PngBitmapEncoder(); pngEncoder.Frames.Add(BitmapFrame.Create(image)); var imageStream = new MemoryStream(); pngEncoder.Save(imageStream); imageStream.Position = 0; info.Image = new Binary(imageStream.ToArray()); if (ApplicationDeployment.IsNetworkDeployed) { info.MissionEditorVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(); } using (var unitSync = new UnitSync(Settings.Default.SpringPath)) info.SpringVersion = unitSync.Version; if (missionId.HasValue) { info.MissionID = missionId.Value; } string tempPath = null; var missionFileName = "publish_mission_temp.sdz"; try { var paths = new SpringPaths(Settings.Default.SpringPath); using (var unitSync = new PlasmaShared.UnitSyncLib.UnitSync(paths)) { var modPath = Path.Combine(paths.WritableDirectory, "games"); tempPath = Path.Combine(modPath, missionFileName); } if (File.Exists(tempPath)) { File.Delete(tempPath); } mission.CreateArchive(tempPath); PlasmaShared.UnitSyncLib.Mod mod; using (var unitSync = new PlasmaShared.UnitSyncLib.UnitSync(paths)) { mod = unitSync.GetModFromArchive(mission.Mod.ArchiveName); if (mod == null) { throw new Exception("Mod metadata not extracted: mod not found"); } } info.Mutator = new Binary(File.ReadAllBytes(tempPath)); var client = MissionServiceClientFactory.MakeClient(); client.SendMission(info, slots, mission.Author, password, mod); MessageBox.Show("Mission successfully uploaded.\n\rIt is now accessible from the lobby.\r\nPlease make sure it works!"); return(true); } catch (Exception e) { if (Debugger.IsAttached) { throw; } MessageBox.Show(e.Message); return(false); } finally { try { if (tempPath != null && File.Exists(tempPath)) { File.Delete(tempPath); } } catch {} } } catch (FaultException <ExceptionDetail> e) { if (Debugger.IsAttached) { throw; } MessageBox.Show(e.Message); return(false); } catch (FaultException e) { if (Debugger.IsAttached) { throw; } MessageBox.Show(e.Message); return(false); } }
public static bool SendMission(Mission mission, string password, int? missionId) { try { var info = new ZkData.Mission() { Description = mission.Description, DescriptionStory = mission.DescriptionStory != String.Empty ? mission.DescriptionStory : null, Map = mission.Map.Name, Mod = mission.Mod.Name, Name = mission.Name, ScoringMethod = mission.ScoringMethod, Script = mission.GetScript(), ModRapidTag = mission.RapidTag, }; var slots = mission.GetSlots(); var image = File.ReadAllBytes(mission.ImagePath).ToImage(96, 96); var pngEncoder = new PngBitmapEncoder(); pngEncoder.Frames.Add(BitmapFrame.Create(image)); var imageStream = new MemoryStream(); pngEncoder.Save(imageStream); imageStream.Position = 0; info.Image = imageStream.ToArray(); if (ApplicationDeployment.IsNetworkDeployed) info.MissionEditorVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(); using (var unitSync = new UnitSync(Settings.Default.SpringPath)) info.SpringVersion = unitSync.Version; if (missionId.HasValue) info.MissionID = missionId.Value; string tempPath = null; var missionFileName = "publish_mission_temp.sdz"; try { var paths = new SpringPaths(Settings.Default.SpringPath); using (var unitSync = new ZkData.UnitSyncLib.UnitSync(paths)) { var modPath = Path.Combine(paths.WritableDirectory, "games"); tempPath = Path.Combine(modPath, missionFileName); } if (File.Exists(tempPath)) File.Delete(tempPath); mission.CreateArchive(tempPath); Mod mod; using (var unitSync = new ZkData.UnitSyncLib.UnitSync(paths)) { mod = (Mod)unitSync.GetResourceFromFileName(mission.Mod.ArchiveName); if (mod == null) throw new Exception("Mod metadata not extracted: mod not found"); } info.Mutator = File.ReadAllBytes(tempPath); var client = MissionServiceClientFactory.MakeClient(); client.SendMission(info, slots, mission.Author, password, mod); MessageBox.Show("Mission successfully uploaded.\n\rIt is now accessible from the lobby.\r\nPlease make sure it works!"); return true; } catch(Exception e) { if (Debugger.IsAttached) throw; MessageBox.Show(e.Message); return false; } finally { try { if (tempPath != null && File.Exists(tempPath)) File.Delete(tempPath); } catch {} } } catch(FaultException<ExceptionDetail> e) { if (Debugger.IsAttached) throw; MessageBox.Show(e.Message); return false; } catch(FaultException e) { if (Debugger.IsAttached) throw; MessageBox.Show(e.Message); return false; } }
public static void SendMissionWithDialog(Mission mission, string password, int? missionId) { var loading = new LoadingDialog { Text = "Uploading Mission", Owner = MainWindow.Instance }; loading.Loaded += delegate { Utils.InvokeInNewThread(delegate { SendMission(mission, password, missionId); loading.Invoke(loading.Close); }); }; loading.ShowDialog(); }
public abstract LuaTable GetLuaTable(Mission mission);
public abstract LuaTable GetLuaMap(Mission mission);
public ModOptionsDialog() { InitializeComponent(); Mission = MainWindow.Instance.Mission; DataContext = Mission; }
public LuaTable GetLuaMap(Mission mission) { var logicMaps = new List<LuaTable>(); foreach (var item in Logic) { var itemMap = new Dictionary<object, object> { {"logicType", item.GetType().Name}, {"args", item.GetLuaTable(mission)}, {"name", item.Name}, }; logicMaps.Add(new LuaTable(itemMap)); } var map = new Dictionary<object, object> { {"name", name}, {"logic", LuaTable.CreateArray(logicMaps)}, {"maxOccurrences", MaxOccurrences}, {"enabled", enabled}, {"probability", Probability}, }; return new LuaTable(map); }