Esempio n. 1
0
        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.Replace(Platform.SupportDir, "^") : "All Packages";

                if (name.Length > 15)
                {
                    name = "..." + name.Substring(name.Length - 15);
                }

                return(name);
            };

            assetSource = FileSystem.MountedFolders.First();

            spriteWidget = panel.Get <ShpImageWidget>("SPRITE");

            currentPalette = world.WorldActor.TraitsImplementing <PaletteFromFile>().First(p => p.Name == spriteWidget.Palette);

            var paletteDropDown = panel.Get <DropDownButtonWidget>("PALETTE_SELECTOR");

            paletteDropDown.OnMouseDown = _ => ShowPaletteDropdown(paletteDropDown, world);
            paletteDropDown.GetText     = () => currentPalette.Name;

            var colorPreview = panel.Get <ColorPreviewManagerWidget>("COLOR_MANAGER");

            colorPreview.Color = Game.Settings.Player.Color;

            var color = panel.Get <DropDownButtonWidget>("COLOR");

            color.IsDisabled  = () => currentPalette.Name != colorPreview.Palette;
            color.OnMouseDown = _ => ShowColorDropDown(color, colorPreview, world);
            var block = panel.Get <ColorBlockWidget>("COLORBLOCK");

            block.GetColor = () => Game.Settings.Player.Color.RGB;

            filenameInput            = panel.Get <TextFieldWidget>("FILENAME_INPUT");
            filenameInput.OnEnterKey = () => LoadAsset(filenameInput.Text);

            frameSlider = panel.Get <SliderWidget>("FRAME_SLIDER");
            frameSlider.MaximumValue = (float)spriteWidget.FrameCount;
            frameSlider.Ticks        = spriteWidget.FrameCount + 1;
            frameSlider.IsVisible    = () => spriteWidget.FrameCount > 0;
            frameSlider.OnChange    += x => { spriteWidget.Frame = (int)Math.Round(x); };
            frameSlider.GetValue     = () => spriteWidget.Frame;

            panel.Get <LabelWidget>("FRAME_COUNT").GetText = () => "{0} / {1}".F(spriteWidget.Frame + 1, spriteWidget.FrameCount + 1);

            playButton         = panel.Get <ButtonWidget>("BUTTON_PLAY");
            playButton.OnClick = () =>
            {
                spriteWidget.LoopAnimation = true;
                playButton.Visible         = false;
                pauseButton.Visible        = true;
            };
            pauseButton         = panel.Get <ButtonWidget>("BUTTON_PAUSE");
            pauseButton.OnClick = () =>
            {
                spriteWidget.LoopAnimation = false;
                playButton.Visible         = true;
                pauseButton.Visible        = false;
            };

            panel.Get <ButtonWidget>("BUTTON_STOP").OnClick = () =>
            {
                spriteWidget.LoopAnimation = false;
                frameSlider.Value          = 0;
                spriteWidget.Frame         = 0;
                playButton.Visible         = true;
                pauseButton.Visible        = false;
            };

            panel.Get <ButtonWidget>("BUTTON_NEXT").OnClick = () => { spriteWidget.RenderNextFrame(); };
            panel.Get <ButtonWidget>("BUTTON_PREV").OnClick = () => { spriteWidget.RenderPreviousFrame(); };

            panel.Get <ButtonWidget>("LOAD_BUTTON").OnClick = () =>
            {
                LoadAsset(filenameInput.Text);
            };

            assetList = panel.Get <ScrollPanelWidget>("ASSET_LIST");
            template  = panel.Get <ScrollItemWidget>("ASSET_TEMPLATE");
            PopulateAssetList();

            panel.Get <ButtonWidget>("CLOSE_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
        }
Esempio n. 2
0
        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(); };
        }