Esempio n. 1
0
 protected TextFieldWidget(TextFieldWidget widget)
     : base(widget)
 {
     SetText(widget.Text);
     MaxLength = widget.MaxLength;
     Bold = widget.Bold;
     VisualHeight = widget.VisualHeight;
 }
Esempio n. 2
0
        public IngameChatLogic(Widget widget, OrderManager orderManager, World world)
        {
            World = world;
            var chatPanel = (ContainerWidget) widget;

            ChatOverlay = chatPanel.Get<ContainerWidget>("CHAT_OVERLAY");
            ChatOverlayDisplay = ChatOverlay.Get<ChatDisplayWidget>("CHAT_DISPLAY");
            ChatOverlay.Visible = false;

            ChatChrome = chatPanel.Get<ContainerWidget>("CHAT_CHROME");
            ChatChrome.Visible = true;

            var chatMode = ChatChrome.Get<ButtonWidget>("CHAT_MODE");
            chatMode.GetText = () => TeamChat ? "Team" : "All";
            chatMode.OnClick = () => TeamChat = !TeamChat;

            ChatText = ChatChrome.Get<TextFieldWidget>("CHAT_TEXTFIELD");
            ChatText.OnTabKey = () => { TeamChat = !TeamChat; return true; };
            ChatText.OnEnterKey = () =>
            {
                ChatText.Text = ChatText.Text.Trim();
                if (ChatText.Text != "")
                    orderManager.IssueOrder(Order.Chat(TeamChat, ChatText.Text));
                CloseChat();
                return true;
            };
            ChatText.OnEscKey = () => {CloseChat(); return true; };

            var chatClose = ChatChrome.Get<ButtonWidget>("CHAT_CLOSE");
            chatClose.OnClick += () => CloseChat();

            chatPanel.OnKeyPress = (e) =>
            {
                if (e.Event == KeyInputEvent.Up) return false;
                if (!IsOpen && (e.KeyName == "enter" || e.KeyName == "return") )
                {

                    var shift = e.Modifiers.HasModifier(Modifiers.Shift);
                    var toggle = Game.Settings.Game.TeamChatToggle ;
                    TeamChat = (!toggle && shift) || ( toggle &&  (TeamChat ^ shift) );
                    OpenChat();
                    return true;
                }

                return false;
            };

            ChatScrollPanel = ChatChrome.Get<ScrollPanelWidget>("CHAT_SCROLLPANEL");
            ChatTemplate = ChatScrollPanel.Get<ContainerWidget>("CHAT_TEMPLATE");

            Game.AddChatLine += AddChatLine;
            Game.BeforeGameStart += UnregisterEvents;

            CloseChat();
            ChatOverlayDisplay.AddLine(Color.White, null, "Use RETURN key to open chat window...");
        }
Esempio n. 3
0
 protected TextFieldWidget(TextFieldWidget widget)
     : base(widget)
 {
     Text              = widget.Text;
     MaxLength         = widget.MaxLength;
     Font              = widget.Font;
     TextColor         = widget.TextColor;
     TextColorDisabled = widget.TextColorDisabled;
     VisualHeight      = widget.VisualHeight;
 }
Esempio n. 4
0
 protected TextFieldWidget(TextFieldWidget widget)
     : base(widget)
 {
     Text = widget.Text;
     MaxLength = widget.MaxLength;
     Font = widget.Font;
     TextColor = widget.TextColor;
     DisabledColor = widget.DisabledColor;
     VisualHeight = widget.VisualHeight;
 }
Esempio n. 5
0
        public GlobalChatLogic(Widget widget)
        {
            historyPanel = widget.Get<ScrollPanelWidget>("HISTORY_PANEL");
            historyTemplate = historyPanel.Get<LabelWidget>("HISTORY_TEMPLATE");
            nicknamePanel = widget.Get<ScrollPanelWidget>("NICKNAME_PANEL");
            nicknameTemplate = nicknamePanel.Get("NICKNAME_TEMPLATE");

            historyPanel.Bind(Game.GlobalChat.History, MakeHistoryWidget, HistoryWidgetEquals, true);
            nicknamePanel.Bind(Game.GlobalChat.Users, MakeUserWidget, UserWidgetEquals, false);

            inputBox = widget.Get<TextFieldWidget>("CHAT_TEXTFIELD");
            inputBox.IsDisabled = () => Game.GlobalChat.ConnectionStatus != ChatConnectionStatus.Joined;
            inputBox.OnEnterKey = EnterPressed;

            // Set a random default nick
            if (Game.Settings.Chat.Nickname == new ChatSettings().Nickname)
                Game.Settings.Chat.Nickname += Game.CosmeticRandom.Next(100, 999);

            var nicknameBox = widget.Get<TextFieldWidget>("NICKNAME_TEXTFIELD");
            nicknameBox.Text = Game.GlobalChat.SanitizedName(Game.Settings.Chat.Nickname);
            nicknameBox.OnTextEdited = () =>
            {
                nicknameBox.Text = Game.GlobalChat.SanitizedName(nicknameBox.Text);
            };

            var connectPanel = widget.Get("GLOBALCHAT_CONNECT_PANEL");
            connectPanel.IsVisible = () => Game.GlobalChat.ConnectionStatus == ChatConnectionStatus.Disconnected;

            var disconnectButton = widget.Get<ButtonWidget>("DISCONNECT_BUTTON");
            disconnectButton.OnClick = Game.GlobalChat.Disconnect;

            var connectAutomaticallyCheckBox = connectPanel.Get<CheckboxWidget>("CONNECT_AUTOMATICALLY_CHECKBOX");
            connectAutomaticallyCheckBox.IsChecked = () => Game.Settings.Chat.ConnectAutomatically;
            connectAutomaticallyCheckBox.OnClick = () => { Game.Settings.Chat.ConnectAutomatically ^= true; Game.Settings.Save(); };

            var connectButton = connectPanel.Get<ButtonWidget>("CONNECT_BUTTON");
            connectButton.IsDisabled = () => !Game.GlobalChat.IsValidNickname(nicknameBox.Text);
            connectButton.OnClick = () =>
            {
                Game.Settings.Chat.Nickname = nicknameBox.Text;
                Game.Settings.Save();
                Game.GlobalChat.Connect();
            };

            var mainPanel = widget.Get("GLOBALCHAT_MAIN_PANEL");
            mainPanel.IsVisible = () => Game.GlobalChat.ConnectionStatus != ChatConnectionStatus.Disconnected;

            mainPanel.Get<LabelWidget>("CHANNEL_TOPIC").GetText = () => Game.GlobalChat.Topic;

            if (Game.Settings.Chat.ConnectAutomatically && Game.GlobalChat.IsValidNickname(Game.Settings.Chat.Nickname))
                Game.GlobalChat.Connect();
        }
        public static void SetupNameWidget(OrderManager orderManager, Session.Client c, TextFieldWidget name)
        {
            name.Text = c.Name;
            name.OnEnterKey = () =>
            {
                name.Text = name.Text.Trim();
                if (name.Text.Length == 0)
                    name.Text = c.Name;

                name.LoseFocus();
                if (name.Text == c.Name)
                    return true;

                orderManager.IssueOrder(Order.Command("name " + name.Text));
                Game.Settings.Player.Name = name.Text;
                Game.Settings.Save();
                return true;
            };
            name.OnLoseFocus = () => name.OnEnterKey();
        }
Esempio n. 7
0
        public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Ruleset modRules)
        {
            this.modRules = modRules;

            chatTraits = world.WorldActor.TraitsImplementing<INotifyChat>().ToList();

            var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot);
            var disableTeamChat = world.LocalPlayer == null || world.LobbyInfo.IsSinglePlayer || !players.Any(p => p.IsAlliedWith(world.LocalPlayer));
            teamChat = !disableTeamChat;

            var chatPanel = (ContainerWidget)widget;
            chatOverlay = chatPanel.Get<ContainerWidget>("CHAT_OVERLAY");
            chatOverlayDisplay = chatOverlay.Get<ChatDisplayWidget>("CHAT_DISPLAY");
            chatOverlay.Visible = false;

            chatChrome = chatPanel.Get<ContainerWidget>("CHAT_CHROME");
            chatChrome.Visible = true;

            var chatMode = chatChrome.Get<ButtonWidget>("CHAT_MODE");
            chatMode.GetText = () => teamChat ? "Team" : "All";
            chatMode.OnClick = () => teamChat ^= true;
            chatMode.IsDisabled = () => disableTeamChat;

            chatText = chatChrome.Get<TextFieldWidget>("CHAT_TEXTFIELD");
            chatText.OnTabKey = () =>
            {
                if (!disableTeamChat)
                    teamChat ^= true;
                return true;
            };
            chatText.OnEnterKey = () =>
            {
                var team = teamChat && !disableTeamChat;
                if (chatText.Text != "")
                    orderManager.IssueOrder(Order.Chat(team, chatText.Text.Trim()));

                CloseChat();
                return true;
            };

            chatText.OnEscKey = () => { CloseChat(); return true; };

            var chatClose = chatChrome.Get<ButtonWidget>("CHAT_CLOSE");
            chatClose.OnClick += () => CloseChat();

            chatPanel.OnKeyPress = (e) =>
            {
                if (e.Event == KeyInputEvent.Up)
                    return false;

                if (!chatChrome.IsVisible() && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER))
                {
                    OpenChat();
                    return true;
                }

                return false;
            };

            chatScrollPanel = chatChrome.Get<ScrollPanelWidget>("CHAT_SCROLLPANEL");
            chatTemplate = chatScrollPanel.Get<ContainerWidget>("CHAT_TEMPLATE");
            chatScrollPanel.RemoveChildren();

            Game.AddChatLine += AddChatLine;
            Game.BeforeGameStart += UnregisterEvents;

            CloseChat();
        }
Esempio n. 8
0
		public IrcLogic(Widget widget)
		{
			var historyPanel = widget.Get<ScrollPanelWidget>("HISTORY_PANEL");
			var historyTemplate = widget.Get<LabelWidget>("HISTORY_TEMPLATE");
			var nicknamePanel = widget.Get<ScrollPanelWidget>("NICKNAME_PANEL");
			var nicknameTemplate = widget.Get<LabelWidget>("NICKNAME_TEMPLATE");

			inputBox = widget.Get<TextFieldWidget>("INPUT_BOX");
			inputBox.OnEnterKey = EnterPressed;
			inputBox.OnTabKey = TabPressed;
			inputBox.IsDisabled = () => IrcClient.Instance.GetChannel(IrcClient.MainChannel) == null;

			nicknameBox = widget.Get<TextFieldWidget>("NICKNAME_BOX");
			nicknameBox.Text = ChooseNickname(Game.Settings.Irc.Nickname);

			connectBG = widget.Get("IRC_CONNECT_BG");
			ircContainer = widget.Get("IRC_CONTAINER");

			widget.Get<ButtonWidget>("DISCONNECT_BUTTON").OnClick = IrcClient.Instance.Disconnect;

			MaybeShowConnectPanel();

			historyPanel.Bind(IrcClient.Instance.History, item => MakeLabelWidget(historyTemplate, item), LabelItemEquals, true);

			var mainChannel = IrcClient.Instance.GetChannel(IrcClient.MainChannel);
			if (mainChannel != null)
				nicknamePanel.Bind(mainChannel.Users, item => MakeLabelWidget(nicknameTemplate, item), LabelItemEquals, false);

			IrcClient.Instance.OnSync += l =>
			{
				var channel = l.GetChannel();
				if (channel.Name.EqualsIC(IrcClient.MainChannel))
					nicknamePanel.Bind(channel.Users, item => MakeLabelWidget(nicknameTemplate, item), LabelItemEquals, false);
			};
			IrcClient.Instance.OnKick += l =>
			{
				if (l.KickeeNickname.EqualsIC(IrcClient.Instance.LocalUser.Nickname) && l.Target.EqualsIC(IrcClient.MainChannel))
					nicknamePanel.Unbind();
			};
			IrcClient.Instance.OnPart += l =>
			{
				if (l.PrefixIsSelf() && l.Target.EqualsIC(IrcClient.MainChannel))
					nicknamePanel.Unbind();
			};
			IrcClient.Instance.OnDisconnect += () =>
			{
				nicknamePanel.Unbind();
				MaybeShowConnectPanel();
			};

			commands.Add("me", args =>
			{
				IrcClient.Instance.Act(IrcClient.MainChannel, args);
				IrcClient.AddAction(IrcClient.Instance.LocalUser.Nickname, args);
			});
			commands.Add("slap", args =>
			{
				IrcClient.Instance.Act(IrcClient.MainChannel, "slaps {0} around a bit with a large trout".F(args));
				IrcClient.AddAction(IrcClient.Instance.LocalUser.Nickname, "slaps {0} around a bit with a large trout".F(args));
			});
			commands.Add("notice", args =>
			{
				var split = args.Split(new[] { ' ' }, 2);
				if (split.Length < 2)
				{
					IrcClient.AddHistory("/notice: Not enough arguments");
					return;
				}
				IrcClient.Instance.Notice(split[0], split[1]);
				IrcClient.AddSelfNotice(split[0], split[1]);
			});
			commands.Add("disconnect", args =>
			{
				Game.Settings.Irc.ConnectAutomatically = false;
				Game.Settings.Save();
				IrcClient.Instance.Disconnect();
			});
			commands.Add("quit", args =>
			{
				Game.Settings.Irc.ConnectAutomatically = false;
				Game.Settings.Save();
				if (IrcClient.Instance.IsConnected)
					IrcClient.Instance.Quit(args);
				else
					IrcClient.Instance.Disconnect();
			});
			commands.Add("nick", args => IrcClient.Instance.SetNickname(args));
			commands.Add("topic", args => IrcClient.Instance.GetTopic(IrcClient.MainChannel));
		}
Esempio n. 9
0
        public AssetBrowserLogic(Widget widget, Action onExit, World world)
        {
            this.world = world;

            panel = widget;
            assetSource = GlobalFileSystem.MountedFolders.First();

            var ticker = panel.GetOrNull<LogicTickerWidget>("ANIMATION_TICKER");
            if (ticker != null)
            {
                ticker.OnTick = () =>
                {
                    if (animateFrames)
                        SelectNextFrame();
                };
            }

            var sourceDropdown = panel.GetOrNull<DropDownButtonWidget>("SOURCE_SELECTOR");
            if (sourceDropdown != null)
            {
                sourceDropdown.OnMouseDown = _ => ShowSourceDropdown(sourceDropdown);
                sourceDropdown.GetText = () =>
                {
                    var name = assetSource != null ? Platform.UnresolvePath(assetSource.Name) : "All Packages";
                    if (name.Length > 15)
                        name = "..." + name.Substring(name.Length - 15);

                    return name;
                };
            }

            var spriteWidget = panel.GetOrNull<SpriteWidget>("SPRITE");
            if (spriteWidget != null)
            {
                spriteWidget.GetSprite = () => currentSprites != null ? currentSprites[currentFrame] : null;
                currentPalette = spriteWidget.Palette;
                spriteWidget.GetPalette = () => currentPalette;
                spriteWidget.IsVisible = () => !isVideoLoaded;
            }

            var playerWidget = panel.GetOrNull<VqaPlayerWidget>("PLAYER");
            if (playerWidget != null)
                playerWidget.IsVisible = () => isVideoLoaded;

            var paletteDropDown = panel.GetOrNull<DropDownButtonWidget>("PALETTE_SELECTOR");
            if (paletteDropDown != null)
            {
                paletteDropDown.OnMouseDown = _ => ShowPaletteDropdown(paletteDropDown, world);
                paletteDropDown.GetText = () => currentPalette;
            }

            var colorPreview = panel.GetOrNull<ColorPreviewManagerWidget>("COLOR_MANAGER");
            if (colorPreview != null)
                colorPreview.Color = Game.Settings.Player.Color;

            var colorDropdown = panel.GetOrNull<DropDownButtonWidget>("COLOR");
            if (colorDropdown != null)
            {
                colorDropdown.IsDisabled = () => currentPalette != colorPreview.PaletteName;
                colorDropdown.OnMouseDown = _ => ShowColorDropDown(colorDropdown, colorPreview, world);
                panel.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => Game.Settings.Player.Color.RGB;
            }

            filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");
            filenameInput.OnTextEdited = () => ApplyFilter(filenameInput.Text);

            var frameContainer = panel.GetOrNull("FRAME_SELECTOR");
            if (frameContainer != null)
                frameContainer.IsVisible = () => (currentSprites != null && currentSprites.Length > 1) || (player != null && player.Video != null && player.Video.Frames > 1);

            frameSlider = panel.Get<SliderWidget>("FRAME_SLIDER");
            if (frameSlider != null)
            {
                frameSlider.OnChange += x =>
                {
                    if (!isVideoLoaded)
                        currentFrame = (int)Math.Round(x);
                };

                frameSlider.GetValue = () => isVideoLoaded ? player.Video.CurrentFrame : currentFrame;
                frameSlider.IsDisabled = () => isVideoLoaded;
            }

            var frameText = panel.GetOrNull<LabelWidget>("FRAME_COUNT");
            if (frameText != null)
            {
                frameText.GetText = () =>
                    isVideoLoaded ?
                    "{0} / {1}".F(player.Video.CurrentFrame + 1, player.Video.Frames) :
                    "{0} / {1}".F(currentFrame + 1, currentSprites.Length);
            }

            var playButton = panel.GetOrNull<ButtonWidget>("BUTTON_PLAY");
            if (playButton != null)
            {
                playButton.OnClick = () =>
                {
                    if (isVideoLoaded)
                        player.Play();
                    else
                        animateFrames = true;
                };

                playButton.IsVisible = () => isVideoLoaded ? player.Paused : !animateFrames;
            }

            var pauseButton = panel.GetOrNull<ButtonWidget>("BUTTON_PAUSE");
            if (pauseButton != null)
            {
                pauseButton.OnClick = () =>
                {
                    if (isVideoLoaded)
                        player.Pause();
                    else
                        animateFrames = false;
                };

                pauseButton.IsVisible = () => isVideoLoaded ? !player.Paused : animateFrames;
            }

            var stopButton = panel.GetOrNull<ButtonWidget>("BUTTON_STOP");
            if (stopButton != null)
            {
                stopButton.OnClick = () =>
                {
                    if (isVideoLoaded)
                        player.Stop();
                    else
                    {
                        frameSlider.Value = 0;
                        currentFrame = 0;
                        animateFrames = false;
                    }
                };
            }

            var nextButton = panel.GetOrNull<ButtonWidget>("BUTTON_NEXT");
            if (nextButton != null)
            {
                nextButton.OnClick = () =>
                {
                    if (!isVideoLoaded)
                        nextButton.OnClick = SelectNextFrame;
                };

                nextButton.IsVisible = () => !isVideoLoaded;
            }

            var prevButton = panel.GetOrNull<ButtonWidget>("BUTTON_PREV");
            if (prevButton != null)
            {
                prevButton.OnClick = () =>
                {
                    if (!isVideoLoaded)
                        SelectPreviousFrame();
                };

                prevButton.IsVisible = () => !isVideoLoaded;
            }

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

            var closeButton = panel.GetOrNull<ButtonWidget>("CLOSE_BUTTON");
            if (closeButton != null)
                closeButton.OnClick = () =>
                {
                    if (isVideoLoaded)
                        player.Stop();
                    Ui.CloseWindow();
                    onExit();
                };
        }
Esempio n. 10
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(); };
        }
Esempio n. 11
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. 12
0
        public IngameChatLogic(Widget widget, OrderManager orderManager, World world, ModData modData)
        {
            this.orderManager = orderManager;
            this.modRules = modData.DefaultRules;

            chatTraits = world.WorldActor.TraitsImplementing<INotifyChat>().ToArray();

            var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot);
            disableTeamChat = world.IsReplay || world.LobbyInfo.IsSinglePlayer || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer)));
            teamChat = !disableTeamChat;

            tabCompletion.Commands = chatTraits.OfType<ChatCommands>().SelectMany(x => x.Commands.Keys).ToList();
            tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList();

            var chatPanel = (ContainerWidget)widget;
            chatOverlay = chatPanel.Get<ContainerWidget>("CHAT_OVERLAY");
            chatOverlayDisplay = chatOverlay.Get<ChatDisplayWidget>("CHAT_DISPLAY");
            chatOverlay.Visible = false;

            chatChrome = chatPanel.Get<ContainerWidget>("CHAT_CHROME");
            chatChrome.Visible = true;

            var chatMode = chatChrome.Get<ButtonWidget>("CHAT_MODE");
            chatMode.GetText = () => teamChat ? "Team" : "All";
            chatMode.OnClick = () => teamChat ^= true;
            chatMode.IsDisabled = () => disableTeamChat;

            chatText = chatChrome.Get<TextFieldWidget>("CHAT_TEXTFIELD");
            chatText.OnEnterKey = () =>
            {
                var team = teamChat && !disableTeamChat;
                if (chatText.Text != "")
                {
                    if (!chatText.Text.StartsWith("/"))
                        orderManager.IssueOrder(Order.Chat(team, chatText.Text.Trim()));
                    else if (chatTraits != null)
                    {
                        var text = chatText.Text.Trim();
                        foreach (var trait in chatTraits)
                            trait.OnChat(orderManager.LocalClient.Name, text);
                    }
                }

                chatText.Text = "";
                CloseChat();
                return true;
            };

            chatText.OnTabKey = () =>
            {
                var previousText = chatText.Text;
                chatText.Text = tabCompletion.Complete(chatText.Text);
                chatText.CursorPosition = chatText.Text.Length;

                if (chatText.Text == previousText)
                    return SwitchTeamChat();
                else
                    return true;
            };

            chatText.OnEscKey = () => { CloseChat(); return true; };

            var chatClose = chatChrome.Get<ButtonWidget>("CHAT_CLOSE");
            chatClose.OnClick += CloseChat;

            chatPanel.OnKeyPress = e =>
            {
                if (e.Event == KeyInputEvent.Up)
                    return false;

                if (!chatChrome.IsVisible() && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER))
                {
                    OpenChat();
                    return true;
                }

                return false;
            };

            chatScrollPanel = chatChrome.Get<ScrollPanelWidget>("CHAT_SCROLLPANEL");
            chatTemplate = chatScrollPanel.Get<ContainerWidget>("CHAT_TEMPLATE");
            chatScrollPanel.RemoveChildren();
            chatScrollPanel.ScrollToBottom();

            foreach (var chatLine in orderManager.ChatCache)
                AddChatLine(chatLine.Color, chatLine.Name, chatLine.Text, true);

            orderManager.AddChatLine += AddChatLineWrapper;
            Game.BeforeGameStart += UnregisterEvents;

            CloseChat();
            chatText.IsDisabled = () => world.IsReplay;

            var keyListener = chatChrome.Get<LogicKeyListenerWidget>("KEY_LISTENER");
            keyListener.OnKeyPress = e =>
            {
                if (e.Event == KeyInputEvent.Up || !chatText.IsDisabled())
                    return false;

                if ((e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER || e.Key == Keycode.ESCAPE) && e.Modifiers == Modifiers.None)
                {
                    CloseChat();
                    return true;
                }

                return false;
            };
        }
Esempio n. 13
0
        public AssetBrowserLogic(Widget widget, Action onExit, ModData modData, World world, Dictionary<string, MiniYaml> logicArgs)
        {
            this.world = world;
            this.modData = modData;
            panel = widget;

            var ticker = panel.GetOrNull<LogicTickerWidget>("ANIMATION_TICKER");
            if (ticker != null)
            {
                ticker.OnTick = () =>
                {
                    if (animateFrames)
                        SelectNextFrame();
                };
            }

            var sourceDropdown = panel.GetOrNull<DropDownButtonWidget>("SOURCE_SELECTOR");
            if (sourceDropdown != null)
            {
                sourceDropdown.OnMouseDown = _ => ShowSourceDropdown(sourceDropdown);
                sourceDropdown.GetText = () =>
                {
                    var name = assetSource != null ? Platform.UnresolvePath(assetSource.Name) : "All Packages";
                    if (name.Length > 15)
                        name = "..." + name.Substring(name.Length - 15);

                    return name;
                };
            }

            var spriteWidget = panel.GetOrNull<SpriteWidget>("SPRITE");
            if (spriteWidget != null)
            {
                spriteWidget.GetSprite = () => currentSprites != null ? currentSprites[currentFrame] : null;
                currentPalette = spriteWidget.Palette;
                spriteWidget.GetPalette = () => currentPalette;
                spriteWidget.IsVisible = () => !isVideoLoaded;
            }

            var playerWidget = panel.GetOrNull<VqaPlayerWidget>("PLAYER");
            if (playerWidget != null)
                playerWidget.IsVisible = () => isVideoLoaded;

            var paletteDropDown = panel.GetOrNull<DropDownButtonWidget>("PALETTE_SELECTOR");
            if (paletteDropDown != null)
            {
                paletteDropDown.OnMouseDown = _ => ShowPaletteDropdown(paletteDropDown, world);
                paletteDropDown.GetText = () => currentPalette;
            }

            var colorPreview = panel.GetOrNull<ColorPreviewManagerWidget>("COLOR_MANAGER");
            if (colorPreview != null)
                colorPreview.Color = Game.Settings.Player.Color;

            var colorDropdown = panel.GetOrNull<DropDownButtonWidget>("COLOR");
            if (colorDropdown != null)
            {
                colorDropdown.IsDisabled = () => currentPalette != colorPreview.PaletteName;
                colorDropdown.OnMouseDown = _ => ColorPickerLogic.ShowColorDropDown(colorDropdown, colorPreview, world);
                panel.Get<ColorBlockWidget>("COLORBLOCK").GetColor = () => Game.Settings.Player.Color.RGB;
            }

            filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");
            filenameInput.OnTextEdited = () => ApplyFilter(filenameInput.Text);
            filenameInput.OnEscKey = filenameInput.YieldKeyboardFocus;

            var frameContainer = panel.GetOrNull("FRAME_SELECTOR");
            if (frameContainer != null)
                frameContainer.IsVisible = () => (currentSprites != null && currentSprites.Length > 1) ||
                    (isVideoLoaded && player != null && player.Video != null && player.Video.Frames > 1);

            frameSlider = panel.Get<SliderWidget>("FRAME_SLIDER");
            if (frameSlider != null)
            {
                frameSlider.OnChange += x =>
                {
                    if (!isVideoLoaded)
                        currentFrame = (int)Math.Round(x);
                };

                frameSlider.GetValue = () => isVideoLoaded ? player.Video.CurrentFrame : currentFrame;
                frameSlider.IsDisabled = () => isVideoLoaded;
            }

            var frameText = panel.GetOrNull<LabelWidget>("FRAME_COUNT");
            if (frameText != null)
            {
                frameText.GetText = () =>
                    isVideoLoaded ?
                    "{0} / {1}".F(player.Video.CurrentFrame + 1, player.Video.Frames) :
                    "{0} / {1}".F(currentFrame, currentSprites.Length - 1);
            }

            var playButton = panel.GetOrNull<ButtonWidget>("BUTTON_PLAY");
            if (playButton != null)
            {
                playButton.Key = new Hotkey(Keycode.SPACE, Modifiers.None);
                playButton.OnClick = () =>
                {
                    if (isVideoLoaded)
                        player.Play();
                    else
                        animateFrames = true;
                };

                playButton.IsVisible = () => isVideoLoaded ? player.Paused : !animateFrames;
            }

            var pauseButton = panel.GetOrNull<ButtonWidget>("BUTTON_PAUSE");
            if (pauseButton != null)
            {
                pauseButton.Key = new Hotkey(Keycode.SPACE, Modifiers.None);
                pauseButton.OnClick = () =>
                {
                    if (isVideoLoaded)
                        player.Pause();
                    else
                        animateFrames = false;
                };

                pauseButton.IsVisible = () => isVideoLoaded ? !player.Paused : animateFrames;
            }

            var stopButton = panel.GetOrNull<ButtonWidget>("BUTTON_STOP");
            if (stopButton != null)
            {
                stopButton.Key = new Hotkey(Keycode.RETURN, Modifiers.None);
                stopButton.OnClick = () =>
                {
                    if (isVideoLoaded)
                        player.Stop();
                    else
                    {
                        frameSlider.Value = 0;
                        currentFrame = 0;
                        animateFrames = false;
                    }
                };
            }

            var nextButton = panel.GetOrNull<ButtonWidget>("BUTTON_NEXT");
            if (nextButton != null)
            {
                nextButton.Key = new Hotkey(Keycode.RIGHT, Modifiers.None);
                nextButton.OnClick = () =>
                {
                    if (!isVideoLoaded)
                        nextButton.OnClick = SelectNextFrame;
                };

                nextButton.IsVisible = () => !isVideoLoaded;
            }

            var prevButton = panel.GetOrNull<ButtonWidget>("BUTTON_PREV");
            if (prevButton != null)
            {
                prevButton.Key = new Hotkey(Keycode.LEFT, Modifiers.None);
                prevButton.OnClick = () =>
                {
                    if (!isVideoLoaded)
                        SelectPreviousFrame();
                };

                prevButton.IsVisible = () => !isVideoLoaded;
            }

            if (logicArgs.ContainsKey("SupportedFormats"))
                allowedExtensions = FieldLoader.GetValue<string[]>("SupportedFormats", logicArgs["SupportedFormats"].Value);
            else
                allowedExtensions = new string[0];

            acceptablePackages = modData.ModFiles.MountedPackages.Where(p =>
                p.Contents.Any(c => allowedExtensions.Contains(Path.GetExtension(c).ToLowerInvariant())));

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

            var closeButton = panel.GetOrNull<ButtonWidget>("CLOSE_BUTTON");
            if (closeButton != null)
                closeButton.OnClick = () =>
                {
                    if (isVideoLoaded)
                        player.Stop();
                    Ui.CloseWindow();
                    onExit();
                };
        }