예제 #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(); };
        }
예제 #2
0
        bool ShowPaletteDropdown(DropDownButtonWidget dropdown, World world)
        {
            Func<PaletteFromFile, ScrollItemWidget, ScrollItemWidget> setupItem = (palette, itemTemplate) =>
            {
                var item = ScrollItemWidget.Setup(itemTemplate,
                    () => currentPalette.Name == palette.Name,
                    () => { currentPalette = palette; spriteWidget.Palette = currentPalette.Name; });
                item.Get<LabelWidget>("LABEL").GetText = () => palette.Name;
                return item;
            };

            var palettes = world.WorldActor.TraitsImplementing<PaletteFromFile>();
            dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, palettes, setupItem);
            return true;
        }