public CncInstallMusicLogic(Widget widget, Action onExit) { var installButton = widget.GetOrNull <ButtonWidget>("INSTALL_BUTTON"); if (installButton != null) { Action afterInstall = () => { try { var path = new string[] { Platform.SupportDir, "Content", WidgetUtils.ActiveModId() }.Aggregate(Path.Combine); FileSystem.Mount(Path.Combine(path, "scores.mix")); FileSystem.Mount(Path.Combine(path, "transit.mix")); Rules.Music.Do(m => m.Value.Reload()); var musicPlayerLogic = (MusicPlayerLogic)installButton.Parent.LogicObject; musicPlayerLogic.BuildMusicTable(); } catch (Exception e) { Log.Write("debug", "Mounting the new mixfile and rebuild of scores list failed:\n{0}", e); } }; installButton.OnClick = () => Ui.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs() { { "afterInstall", afterInstall }, { "filesToCopy", new[] { "SCORES.MIX" } }, { "filesToExtract", new[] { "transit.mix" } }, }); installButton.IsVisible = () => Rules.InstalledMusic.ToArray().Length < 3; // HACK around music being split between transit.mix and scores.mix } }
public AssetBrowserLogic(Widget widget, Action onExit, World world) { panel = widget; var sourceDropdown = panel.Get <DropDownButtonWidget>("SOURCE_SELECTOR"); sourceDropdown.OnMouseDown = _ => ShowSourceDropdown(sourceDropdown); sourceDropdown.GetText = () => { var name = AssetSource != null ? AssetSource.Name : "All Packages"; if (name.Length > 15) { name = "..." + name.Substring(name.Length - 15); } return(name); }; AssetSource = FileSystem.MountedFolders.First(); spriteImage = panel.Get <ShpImageWidget>("SPRITE"); filenameInput = panel.Get <TextFieldWidget>("FILENAME_INPUT"); filenameInput.Text = spriteImage.Image + ".shp"; filenameInput.OnEnterKey = () => LoadAsset(filenameInput.Text); frameSlider = panel.Get <SliderWidget>("FRAME_SLIDER"); frameSlider.MaximumValue = (float)spriteImage.FrameCount; frameSlider.Ticks = spriteImage.FrameCount + 1; frameSlider.OnChange += x => { spriteImage.Frame = (int)Math.Round(x); }; frameSlider.GetValue = () => spriteImage.Frame; panel.Get <LabelWidget>("FRAME_COUNT").GetText = () => "{0}/{1}".F(spriteImage.Frame, spriteImage.FrameCount); playButton = panel.Get <ButtonWidget>("BUTTON_PLAY"); playButton.OnClick = () => { spriteImage.LoopAnimation = true; playButton.Visible = false; pauseButton.Visible = true; }; pauseButton = panel.Get <ButtonWidget>("BUTTON_PAUSE"); pauseButton.OnClick = () => { spriteImage.LoopAnimation = false; playButton.Visible = true; pauseButton.Visible = false; }; panel.Get <ButtonWidget>("BUTTON_STOP").OnClick = () => { spriteImage.LoopAnimation = false; frameSlider.Value = 0; spriteImage.Frame = 0; playButton.Visible = true; pauseButton.Visible = false; }; panel.Get <ButtonWidget>("BUTTON_NEXT").OnClick = () => { spriteImage.RenderNextFrame(); }; panel.Get <ButtonWidget>("BUTTON_PREV").OnClick = () => { spriteImage.RenderPreviousFrame(); }; panel.Get <ButtonWidget>("LOAD_BUTTON").OnClick = () => { LoadAsset(filenameInput.Text); }; assetList = panel.Get <ScrollPanelWidget>("ASSET_LIST"); template = panel.Get <ScrollItemWidget>("ASSET_TEMPLATE"); PopulateAssetList(); var palette = (WidgetUtils.ActiveModId() == "d2k") ? "d2k.pal" : "egopal.pal"; panel.Get <ButtonWidget>("EXPORT_BUTTON").OnClick = () => { var ExtractGameFiles = new string[][] { new string[] { "--extract", WidgetUtils.ActiveModId(), palette, "--userdir" }, new string[] { "--extract", WidgetUtils.ActiveModId(), "{0}.shp".F(spriteImage.Image), "--userdir" }, }; var ExportToPng = new string[][] { new string[] { "--png", Platform.SupportDir + "{0}.shp".F(spriteImage.Image), Platform.SupportDir + palette }, }; var ImportFromPng = new string[][] { }; var args = new WidgetArgs() { { "ExtractGameFiles", ExtractGameFiles }, { "ExportToPng", ExportToPng }, { "ImportFromPng", ImportFromPng } }; Ui.OpenWindow("CONVERT_ASSETS_PANEL", args); }; panel.Get <ButtonWidget>("EXTRACT_BUTTON").OnClick = () => { var ExtractGameFilesList = new List <string[]>(); var ExportToPngList = new List <string[]>(); ExtractGameFilesList.Add(new string[] { "--extract", WidgetUtils.ActiveModId(), palette, "--userdir" }); foreach (var shp in AvailableShps) { ExtractGameFilesList.Add(new string[] { "--extract", WidgetUtils.ActiveModId(), shp, "--userdir" }); ExportToPngList.Add(new string[] { "--png", Platform.SupportDir + shp, Platform.SupportDir + palette }); Console.WriteLine(Platform.SupportDir + shp); } var ExtractGameFiles = ExtractGameFilesList.ToArray(); var ExportToPng = ExportToPngList.ToArray(); var ImportFromPng = new string[][] { }; var args = new WidgetArgs() { { "ExtractGameFiles", ExtractGameFiles }, { "ExportToPng", ExportToPng }, { "ImportFromPng", ImportFromPng } }; Ui.OpenWindow("CONVERT_ASSETS_PANEL", args); }; panel.Get <ButtonWidget>("IMPORT_BUTTON").OnClick = () => { var imageSizeInput = panel.Get <TextFieldWidget>("IMAGE_SIZE_INPUT"); var imageFilename = panel.Get <TextFieldWidget>("IMAGE_FILENAME_INPUT"); var ExtractGameFiles = new string[][] { }; var ExportToPng = new string[][] { }; var ImportFromPng = new string[][] { new string[] { "--shp", Platform.SupportDir + imageFilename.Text, imageSizeInput.Text }, }; var args = new WidgetArgs() { { "ExtractGameFiles", ExtractGameFiles }, { "ExportToPng", ExportToPng }, { "ImportFromPng", ImportFromPng } }; Ui.OpenWindow("CONVERT_ASSETS_PANEL", args); }; panel.Get <ButtonWidget>("CLOSE_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; }