static TextNotificationsManager()
 {
     if (!ChromeMetrics.TryGet("SystemMessageLabel", out SystemMessageLabel))
     {
         SystemMessageLabel = "Battlefield Control";
     }
 }
Ejemplo n.º 2
0
 public TextRenderable(SpriteFont font, WPos pos, int zOffset, Color color, string text)
     : this(font, pos, zOffset, color,
            ChromeMetrics.Get <Color>("TextContrastColorDark"),
            ChromeMetrics.Get <Color>("TextContrastColorLight"),
            text)
 {
 }
Ejemplo n.º 3
0
        public ColorPickerLogic(Widget widget, ModData modData, World world, HSLColor initialColor, Action <HSLColor> onChange, WorldRenderer worldRenderer)
        {
            string actorType;

            if (!ChromeMetrics.TryGet("ColorPickerActorType", out actorType))
            {
                actorType = "mcv";
            }

            var preview = widget.GetOrNull <ActorPreviewWidget>("PREVIEW");
            var actor   = world.Map.Rules.Actors[actorType];

            var td = new TypeDictionary();

            td.Add(new OwnerInit(world.WorldActor.Owner));
            td.Add(new FactionInit(world.WorldActor.Owner.PlayerReference.Faction));
            foreach (var api in actor.TraitInfos <IActorPreviewInitInfo>())
            {
                foreach (var o in api.ActorPreviewInits(actor, ActorPreviewType.ColorPicker))
                {
                    td.Add(o);
                }
            }

            if (preview != null)
            {
                preview.SetPreview(actor, td);
            }

            var hueSlider    = widget.Get <SliderWidget>("HUE");
            var mixer        = widget.Get <ColorMixerWidget>("MIXER");
            var randomButton = widget.GetOrNull <ButtonWidget>("RANDOM_BUTTON");

            hueSlider.OnChange += _ => mixer.Set(hueSlider.Value);
            mixer.OnChange     += () => onChange(mixer.Color);

            if (randomButton != null)
            {
                randomButton.OnClick = () =>
                {
                    // Avoid colors with low sat or lum
                    var hue = (byte)Game.CosmeticRandom.Next(255);
                    var sat = (byte)Game.CosmeticRandom.Next(70, 255);
                    var lum = (byte)Game.CosmeticRandom.Next(70, 255);

                    mixer.Set(new HSLColor(hue, sat, lum));
                    hueSlider.Value = hue / 255f;
                }
            }
            ;

            // Set the initial state
            var validator = modData.Manifest.Get <ColorValidator>();

            mixer.SetPaletteRange(validator.HsvSaturationRange[0], validator.HsvSaturationRange[1], validator.HsvValueRange[0], validator.HsvValueRange[1]);
            mixer.Set(initialColor);

            hueSlider.Value = initialColor.H / 255f;
            onChange(mixer.Color);
        }
Ejemplo n.º 4
0
        public AddFactionSuffixLogic(Widget widget, World world)
        {
            string faction;

            if (!ChromeMetrics.TryGet("FactionSuffix-" + world.LocalPlayer.Faction.InternalName, out faction))
            {
                faction = world.LocalPlayer.Faction.InternalName;
            }
            var suffix = "-" + faction;

            if (widget is ButtonWidget)
            {
                ((ButtonWidget)widget).Background += suffix;
            }
            else if (widget is ImageWidget)
            {
                ((ImageWidget)widget).ImageCollection += suffix;
            }
            else if (widget is BackgroundWidget)
            {
                ((BackgroundWidget)widget).Background += suffix;
            }
            else if (widget is ProductionTabsWidget)
            {
                ((ProductionTabsWidget)widget).Button     += suffix;
                ((ProductionTabsWidget)widget).Background += suffix;
            }
            else
            {
                throw new InvalidOperationException("AddFactionSuffixLogic only supports ButtonWidget, ImageWidget, BackgroundWidget and ProductionTabsWidget");
            }
        }
        public GlobalChatLogic(Widget widget)
        {
            historyPanel     = widget.Get <ScrollPanelWidget>("HISTORY_PANEL");
            chatTemplate     = historyPanel.Get <ContainerWidget>("CHAT_TEMPLATE");
            nicknamePanel    = widget.Get <ScrollPanelWidget>("NICKNAME_PANEL");
            nicknameTemplate = nicknamePanel.Get("NICKNAME_TEMPLATE");

            var textColor = ChromeMetrics.Get <Color>("GlobalChatTextColor");
            var textLabel = chatTemplate.Get <LabelWidget>("TEXT");

            textLabel.GetColor = () => textColor;

            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;

            // IRC protocol limits messages to 510 characters + CRLF
            inputBox.MaxLength = 510;

            var nickName    = Game.GlobalChat.SanitizedName(Game.Settings.Player.Name);
            var nicknameBox = widget.Get <TextFieldWidget>("NICKNAME_TEXTFIELD");

            nicknameBox.Text         = 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.GlobalChat.Connect(nicknameBox.Text);

            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.Connect(nickName);
            }
        }
Ejemplo n.º 6
0
        public SidebarWidget(IngameUiWidget ingameUi)
        {
            IngameUi = ingameUi;
            Id       = "KKND_SIDEBAR";

            Buttons = new Animation(IngameUi.World, "icon-" + IngameUi.World.LocalPlayer.Faction.InternalName);
            Font    = new Animation(IngameUi.World, "font");

            ChromeMetrics.TryGet("ButtonArea-" + IngameUi.World.LocalPlayer.Faction.InternalName, out ButtonArea);

            AddChild(new ProductionCategoryButtonWidget(this, 0, new[] { "infantry" }, "Infantry"));
            AddChild(new ProductionCategoryButtonWidget(this, 1, new[] { "vehicle", "beast" }, "Vehicles"));
            AddChild(new ProductionCategoryButtonWidget(this, 2, new[] { "building" }, "Buildings"));
            AddChild(new ProductionCategoryButtonWidget(this, 3, new[] { "tower" }, "Towers"));
            AddChild(new ProductionCategoryButtonWidget(this, 4, new[] { "wall" }, "Walls"));

            AddChild(bomber = new BomberButtonWidget(this));

            AddChild(sell     = new SellButtonWidget(this));
            AddChild(research = new ResearchButtonWidget(this));
            AddChild(repair   = new RepairButtonWidget(this));

            AddChild(radar   = new RadarButtonWidget(this));
            AddChild(options = new OptionsButtonWidget(this));

            Resize();
        }
Ejemplo n.º 7
0
        public SidebarWidget(IngameUiWidget ingameUi)
        {
            this.IngameUi = ingameUi;
            this.Id       = SidebarWidget.Identifier;

            this.Buttons = new(this.IngameUi.World, $"sidebar-{this.IngameUi.World.LocalPlayer.Faction.InternalName}");
            this.Font    = new(this.IngameUi.World, "font");

            ChromeMetrics.TryGet($"ButtonArea-{this.IngameUi.World.LocalPlayer.Faction.InternalName}", out this.ButtonArea);

            this.AddChild(new ProductionCategoryButtonWidget(this, 0, new[] { "infantry" }, "Infantry"));
            this.AddChild(new ProductionCategoryButtonWidget(this, 1, new[] { "vehicle", "beast" }, "Vehicles"));
            this.AddChild(new ProductionCategoryButtonWidget(this, 2, new[] { "building" }, "Buildings"));
            this.AddChild(new ProductionCategoryButtonWidget(this, 3, new[] { "tower" }, "Towers"));
            this.AddChild(new ProductionCategoryButtonWidget(this, 4, new[] { "wall" }, "Walls"));

            this.AddChild(this.bomber = new(this));

            this.AddChild(this.sell     = new(this));
            this.AddChild(this.research = new(this));
            this.AddChild(this.repair   = new(this));

            this.AddChild(this.radar   = new(this));
            this.AddChild(this.options = new(this));

            this.Resize();
        }
Ejemplo n.º 8
0
        public MultiplayerLogic(Widget widget, Action onStart, Action onExit, string directConnectHost, int directConnectPort)
        {
            this.onStart = onStart;
            this.onExit  = onExit;

            incompatibleVersionColor       = ChromeMetrics.Get <Color>("IncompatibleVersionColor");
            incompatibleGameColor          = ChromeMetrics.Get <Color>("IncompatibleGameColor");
            incompatibleProtectedGameColor = ChromeMetrics.Get <Color>("IncompatibleProtectedGameColor");
            protectedGameColor             = ChromeMetrics.Get <Color>("ProtectedGameColor");
            waitingGameColor             = ChromeMetrics.Get <Color>("WaitingGameColor");
            incompatibleWaitingGameColor = ChromeMetrics.Get <Color>("IncompatibleWaitingGameColor");
            gameStartedColor             = ChromeMetrics.Get <Color>("GameStartedColor");
            incompatibleGameStartedColor = ChromeMetrics.Get <Color>("IncompatibleGameStartedColor");

            LoadBrowserPanel(widget);
            LoadDirectConnectPanel(widget);
            LoadCreateServerPanel(widget);

            // Filter and refresh buttons act on the browser panel,
            // but remain visible (disabled) on the other panels
            var refreshButton = widget.Get <ButtonWidget>("REFRESH_BUTTON");

            refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching || panel != PanelType.Browser;

            var filtersButton = widget.Get <DropDownButtonWidget>("FILTERS_DROPDOWNBUTTON");

            filtersButton.IsDisabled = () => searchStatus == SearchStatus.Fetching || panel != PanelType.Browser;

            var browserTab = widget.Get <ButtonWidget>("BROWSER_TAB");

            browserTab.IsHighlighted = () => panel == PanelType.Browser;
            browserTab.OnClick       = () => panel = PanelType.Browser;

            var directConnectTab = widget.Get <ButtonWidget>("DIRECTCONNECT_TAB");

            directConnectTab.IsHighlighted = () => panel == PanelType.DirectConnect;
            directConnectTab.OnClick       = () => panel = PanelType.DirectConnect;

            var createServerTab = widget.Get <ButtonWidget>("CREATE_TAB");

            createServerTab.IsHighlighted = () => panel == PanelType.CreateServer;
            createServerTab.OnClick       = () => panel = PanelType.CreateServer;

            widget.Get <ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
            Game.LoadWidget(null, "GLOBALCHAT_PANEL", widget.Get("GLOBALCHAT_ROOT"), new WidgetArgs());

            RefreshServerList();

            if (directConnectHost != null)
            {
                // The connection window must be opened at the end of the tick for the widget hierarchy to
                // work out, but we also want to prevent the server browser from flashing visible for one tick.
                widget.Visible = false;
                Game.RunAfterTick(() =>
                {
                    ConnectionLogic.Connect(directConnectHost, directConnectPort, "", OpenLobby, DoNothing);
                    widget.Visible = true;
                });
            }
        }
        public AddFactionSuffixLogic(Widget widget, World world)
        {
            string faction;

            if (!ChromeMetrics.TryGet("FactionSuffix-" + world.LocalPlayer.Faction.InternalName, out faction))
            {
                faction = world.LocalPlayer.Faction.InternalName;
            }
            var suffix = "-" + faction;

            var buttonWidget = widget as ButtonWidget;

            if (buttonWidget != null)
            {
                buttonWidget.Background += suffix;
            }
            else
            {
                var imageWidget = widget as ImageWidget;
                if (imageWidget != null)
                {
                    imageWidget.ImageCollection += suffix;
                }
                else
                {
                    throw new InvalidOperationException("AddFactionSuffixLogic only supports ButtonWidget and ImageWidget");
                }
            }
        }
Ejemplo n.º 10
0
 public UITextRenderable(SpriteFont font, WPos effectiveWorldPos, int2 screenPos, int zOffset, Color color, string text)
     : this(font, effectiveWorldPos, screenPos, zOffset, color,
            ChromeMetrics.Get <Color>("TextContrastColorDark"),
            ChromeMetrics.Get <Color>("TextContrastColorLight"),
            text)
 {
 }
Ejemplo n.º 11
0
        public Player(World world, Session.Client client, PlayerReference pr)
        {
            string botType;

            World           = world;
            InternalName    = pr.Name;
            PlayerReference = pr;

            // Real player or host-created bot
            if (client != null)
            {
                ClientIndex    = client.Index;
                Color          = client.Color;
                PlayerName     = client.Name;
                botType        = client.Bot;
                Faction        = ChooseFaction(world, client.Faction, !pr.LockFaction);
                DisplayFaction = ChooseDisplayFaction(world, client.Faction);
            }
            else
            {
                // Map player
                ClientIndex    = 0;              // Owned by the host (TODO: fix this)
                Color          = pr.Color;
                PlayerName     = pr.Name;
                NonCombatant   = pr.NonCombatant;
                Playable       = pr.Playable;
                Spectating     = pr.Spectating;
                botType        = pr.Bot;
                Faction        = ChooseFaction(world, pr.Faction, false);
                DisplayFaction = ChooseDisplayFaction(world, pr.Faction);
            }

            PlayerActor = world.CreateActor("Player", new TypeDictionary {
                new OwnerInit(this)
            });
            Shroud = PlayerActor.Trait <Shroud>();

            fogVisibilities = PlayerActor.TraitsImplementing <IFogVisibilityModifier>().ToArray();

            // Enable the bot logic on the host
            IsBot = botType != null;
            if (IsBot && Game.IsHost)
            {
                var logic = PlayerActor.TraitsImplementing <IBot>().FirstOrDefault(b => b.Info.Name == botType);
                if (logic == null)
                {
                    Log.Write("debug", "Invalid bot type: {0}", botType);
                }
                else
                {
                    logic.Activate(this);
                }
            }

            stanceColors.Self     = ChromeMetrics.Get <Color>("PlayerStanceColorSelf");
            stanceColors.Allies   = ChromeMetrics.Get <Color>("PlayerStanceColorAllies");
            stanceColors.Enemies  = ChromeMetrics.Get <Color>("PlayerStanceColorEnemies");
            stanceColors.Neutrals = ChromeMetrics.Get <Color>("PlayerStanceColorNeutrals");
        }
Ejemplo n.º 12
0
 public CheckboxWidget(ModData modData)
     : base(modData)
 {
     GetCheckType      = () => CheckType;
     TextColor         = ChromeMetrics.Get <Color>("TextColor");
     TextColorDisabled = ChromeMetrics.Get <Color>("TextDisabledColor");
     GetColor          = () => TextColor;
     GetColorDisabled  = () => TextColorDisabled;
 }
Ejemplo n.º 13
0
 public MapPreviewWidget()
 {
     spawnClaimed       = ChromeProvider.GetImage("lobby-bits", "spawn-claimed");
     spawnUnclaimed     = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed");
     spawnFont          = WarGame.Renderer.Fonts[ChromeMetrics.Get <string>("SpawnFont")];
     spawnColor         = ChromeMetrics.Get <Color>("SpawnColor");
     spawnContrastColor = ChromeMetrics.Get <Color>("SpawnContrastColor");
     spawnLabelOffset   = ChromeMetrics.Get <Int2>("SpawnLabelOffset");
 }
Ejemplo n.º 14
0
 static TextNotificationsManager()
 {
     ChromeMetrics.TryGet("ChatMessageColor", out chatMessageColor);
     ChromeMetrics.TryGet("SystemMessageColor", out systemMessageColor);
     if (!ChromeMetrics.TryGet("SystemMessageLabel", out systemMessageLabel))
     {
         systemMessageLabel = "Battlefield Control";
     }
 }
Ejemplo n.º 15
0
        internal static void StartGame(string mapUID, WorldType type)
        {
            // Dispose of the old world before creating a new one.
            worldRenderer?.Dispose();

            Cursor.SetCursor(null);
            BeforeGameStart();

            Map map;

            using (new PerfTimer("PrepareMap"))
                map = ModData.PrepareMap(mapUID);

            using (new PerfTimer("NewWorld"))
            {
                OrderManager.World       = new World(ModData, map, OrderManager, type);
                OrderManager.FramesAhead = OrderManager.World.OrderLatency;
            }

            OrderManager.World.GameOver += FinishBenchmark;

            worldRenderer = new WorldRenderer(ModData, OrderManager.World);

            // Proactively collect memory during loading to reduce peak memory.
            GC.Collect();

            using (new PerfTimer("LoadComplete"))
                OrderManager.World.LoadComplete(worldRenderer);

            // Proactively collect memory during loading to reduce peak memory.
            GC.Collect();

            if (OrderManager.GameStarted)
            {
                return;
            }

            Ui.MouseFocusWidget    = null;
            Ui.KeyboardFocusWidget = null;

            OrderManager.LocalFrameNumber = 0;
            OrderManager.LastTickTime     = RunTime;
            OrderManager.StartGame();
            worldRenderer.RefreshPalette();
            Cursor.SetCursor(ChromeMetrics.Get <string>("DefaultCursor"));

            // Now loading is completed, now is the ideal time to run a GC and compact the LOH.
            // - All the temporary garbage created during loading can be collected.
            // - Live objects are likely to live for the length of the game or longer,
            //   thus promoting them into a higher generation is not an issue.
            // - We can remove any fragmentation in the LOH caused by temporary loading garbage.
            // - A loading screen is visible, so a delay won't matter to the user.
            //   Much better to clean up now then to drop frames during gameplay for GC pauses.
            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
            GC.Collect();
        }
Ejemplo n.º 16
0
        public void InitializeLoaders()
        {
            // all this manipulation of static crap here is nasty and breaks
            // horribly when you use ModData in unexpected ways.
            ChromeMetrics.Initialize(Manifest.ChromeMetrics);
            ChromeProvider.Initialize(Manifest.Chrome);
            VoxelLoader = new VoxelLoader();

            CursorProvider = new CursorProvider(this);
        }
Ejemplo n.º 17
0
        void InitHotkeyRemapDialog(Widget panel)
        {
            var label = new CachedTransform <HotkeyDefinition, string>(hd => hd.Description + ":");

            panel.Get <LabelWidget>("HOTKEY_LABEL").GetText = () => label.Update(selectedHotkeyDefinition);

            var duplicateNotice = panel.Get <LabelWidget>("DUPLICATE_NOTICE");

            duplicateNotice.TextColor = ChromeMetrics.Get <Color>("NoticeErrorColor");
            duplicateNotice.IsVisible = () => !isHotkeyValid;
            var duplicateNoticeText = new CachedTransform <HotkeyDefinition, string>(hd => hd != null ? duplicateNotice.Text.F(hd.Description) : duplicateNotice.Text);

            duplicateNotice.GetText = () => duplicateNoticeText.Update(duplicateHotkeyDefinition);

            var defaultNotice = panel.Get <LabelWidget>("DEFAULT_NOTICE");

            defaultNotice.TextColor = ChromeMetrics.Get <Color>("NoticeInfoColor");
            defaultNotice.IsVisible = () => isHotkeyValid && isHotkeyDefault;

            var originalNotice = panel.Get <LabelWidget>("ORIGINAL_NOTICE");

            originalNotice.TextColor = ChromeMetrics.Get <Color>("NoticeInfoColor");
            originalNotice.IsVisible = () => isHotkeyValid && !isHotkeyDefault;
            var originalNoticeText = new CachedTransform <HotkeyDefinition, string>(hd => originalNotice.Text.F(hd.Default.DisplayString()));

            originalNotice.GetText = () => originalNoticeText.Update(selectedHotkeyDefinition);

            var resetButton = panel.Get <ButtonWidget>("RESET_HOTKEY_BUTTON");

            resetButton.IsDisabled = () => isHotkeyDefault;
            resetButton.OnClick    = ResetHotkey;

            var clearButton = panel.Get <ButtonWidget>("CLEAR_HOTKEY_BUTTON");

            clearButton.IsDisabled = () => !hotkeyEntryWidget.Key.IsValid();
            clearButton.OnClick    = ClearHotkey;

            var overrideButton = panel.Get <ButtonWidget>("OVERRIDE_HOTKEY_BUTTON");

            overrideButton.IsDisabled = () => isHotkeyValid;
            overrideButton.IsVisible  = () => !isHotkeyValid;
            overrideButton.OnClick    = OverrideHotkey;

            hotkeyEntryWidget             = panel.Get <HotkeyEntryWidget>("HOTKEY_ENTRY");
            hotkeyEntryWidget.IsValid     = () => isHotkeyValid;
            hotkeyEntryWidget.OnLoseFocus = ValidateHotkey;
            hotkeyEntryWidget.OnEscKey    = () =>
            {
                hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue();
            };

            validHotkeyEntryWidth   = hotkeyEntryWidget.Bounds.Width;
            invalidHotkeyEntryWidth = validHotkeyEntryWidth - (clearButton.Bounds.X - overrideButton.Bounds.X);
        }
Ejemplo n.º 18
0
 public void InitializeLoaders()
 {
     // all this manipulation of static crap here is nasty and breaks
     // horribly when you use ModData in unexpected ways.
     ChromeMetrics.Initialize(Manifest.ChromeMetrics);
     ChromeProvider.Initialize(Manifest.Chrome);
     SheetBuilder = new SheetBuilder(SheetType.Indexed);
     SpriteLoader = new SpriteLoader(new string[] { ".shp" }, SheetBuilder);
     VoxelLoader  = new VoxelLoader();
     CursorProvider.Initialize(Manifest.Cursors);
 }
Ejemplo n.º 19
0
        public void InitializeLoaders(IReadOnlyFileSystem fileSystem)
        {
            // all this manipulation of static crap here is nasty and breaks
            // horribly when you use ModData in unexpected ways.
            ChromeMetrics.Initialize(this);
            ChromeProvider.Initialize(this);

            Game.Sound.Initialize(SoundLoaders, fileSystem);

            CursorProvider = new CursorProvider(this);
        }
Ejemplo n.º 20
0
        public MapPreviewWidget()
        {
            tooltipContainer = Exts.Lazy(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer));

            spawnClaimed       = ChromeProvider.GetImage("lobby-bits", "spawn-claimed");
            spawnUnclaimed     = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed");
            spawnFont          = Game.Renderer.Fonts[ChromeMetrics.Get <string>("SpawnFont")];
            spawnColor         = ChromeMetrics.Get <Color>("SpawnColor");
            spawnContrastColor = ChromeMetrics.Get <Color>("SpawnContrastColor");
            spawnLabelOffset   = ChromeMetrics.Get <int2>("SpawnLabelOffset");
        }
Ejemplo n.º 21
0
        Widget MakeHistoryWidget(object o)
        {
            var message = (ChatMessage)o;
            var from    = message.Type == ChatMessageType.Notification ? "Battlefield Control" : message.Nick;
            var color   = message.Type == ChatMessageType.Notification ? ChromeMetrics.Get <Color>("GlobalChatNotificationColor")
                                : ChromeMetrics.Get <Color>("GlobalChatPlayerNameColor");
            var template = (ContainerWidget)chatTemplate.Clone();

            LobbyUtils.SetupChatLine(template, color, message.Time, from, message.Message);

            template.Id = message.UID;
            return(template);
        }
Ejemplo n.º 22
0
        public ColorPickerLogic(Widget widget, World world, HSLColor initialColor, Action <HSLColor> onChange, WorldRenderer worldRenderer)
        {
            string actorType;

            if (!ChromeMetrics.TryGet <string>("ColorPickerActorType", out actorType))
            {
                actorType = "mcv";
            }

            var preview = widget.GetOrNull <ActorPreviewWidget>("PREVIEW");
            var actor   = world.Map.Rules.Actors[actorType];

            var td = new TypeDictionary();

            td.Add(new HideBibPreviewInit());
            td.Add(new OwnerInit(world.WorldActor.Owner));
            td.Add(new RaceInit(world.WorldActor.Owner.PlayerReference.Faction));

            if (preview != null)
            {
                preview.SetPreview(actor, td);
            }

            var hueSlider    = widget.Get <SliderWidget>("HUE");
            var mixer        = widget.Get <ColorMixerWidget>("MIXER");
            var randomButton = widget.GetOrNull <ButtonWidget>("RANDOM_BUTTON");

            hueSlider.OnChange += _ => mixer.Set(hueSlider.Value);
            mixer.OnChange     += () => onChange(mixer.Color);

            if (randomButton != null)
            {
                randomButton.OnClick = () =>
                {
                    // Avoid colors with low sat or lum
                    var hue = (byte)Game.CosmeticRandom.Next(255);
                    var sat = (byte)Game.CosmeticRandom.Next(70, 255);
                    var lum = (byte)Game.CosmeticRandom.Next(70, 255);

                    mixer.Set(new HSLColor(hue, sat, lum));
                    hueSlider.Value = hue / 255f;
                }
            }
            ;

            // Set the initial state
            mixer.Set(initialColor);
            hueSlider.Value = initialColor.H / 255f;
            onChange(mixer.Color);
        }
Ejemplo n.º 23
0
        public AddFactionSuffixLogic(Widget widget, World world)
        {
            if (world.LocalPlayer == null)
            {
                return;
            }

            if (!ChromeMetrics.TryGet("FactionSuffix-" + world.LocalPlayer.Faction.InternalName, out string faction))
            {
                faction = world.LocalPlayer.Faction.InternalName;
            }
            var suffix = "-" + faction;

            if (widget is ButtonWidget bw)
            {
                bw.Background += suffix;
            }
            else if (widget is ImageWidget iw)
            {
                iw.ImageCollection += suffix;
            }
            else if (widget is BackgroundWidget bgw)
            {
                bgw.Background += suffix;
            }
            else if (widget is TextFieldWidget tfw)
            {
                tfw.Background += suffix;
            }
            else if (widget is ScrollPanelWidget spw)
            {
                spw.Button              += suffix;
                spw.Background          += suffix;
                spw.ScrollBarBackground += suffix;
                spw.Decorations         += suffix;
            }
            else if (widget is ProductionTabsWidget ptw)
            {
                ptw.Button     += suffix;
                ptw.Background += suffix;
            }
            else
            {
                throw new InvalidOperationException("AddFactionSuffixLogic only supports ButtonWidget, ImageWidget, BackgroundWidget, TextFieldWidget, ScrollPanelWidget and ProductionTabsWidget");
            }
        }
Ejemplo n.º 24
0
        public SupportPowerTimerWidget(World world)
        {
            powers = world.ActorsWithTrait <SupportPowerManager>()
                     .Where(p => !p.Actor.IsDead && !p.Actor.Owner.NonCombatant)
                     .SelectMany(s => s.Trait.Powers.Values)
                     .Where(p => p.Instances.Any() && p.Info.DisplayTimerStances != Stance.None && !p.Disabled);

            // Timers in replays should be synced to the effective game time, not the playback time.
            timestep = world.Timestep;
            if (world.IsReplay)
            {
                timestep = world.WorldActor.Trait <MapOptions>().GameSpeed.Timestep;
            }

            bgDark  = ChromeMetrics.Get <Color>("TextContrastColorDark");
            bgLight = ChromeMetrics.Get <Color>("TextContrastColorLight");
        }
Ejemplo n.º 25
0
        public IngameTransientNotificationsLogic(Widget widget, OrderManager orderManager, ModData modData, Dictionary <string, MiniYaml> logicArgs)
        {
            this.orderManager = orderManager;
            modRules          = modData.DefaultRules;

            displayWidget = widget.Get <TextNotificationsDisplayWidget>("TRANSIENTS_DISPLAY");

            orderManager.AddTextNotification += AddNotificationWrapper;

            if (logicArgs.TryGetValue("TransientLineSound", out var yaml))
            {
                transientLineSound = yaml.Value;
            }
            else
            {
                ChromeMetrics.TryGet("TransientLineSound", out transientLineSound);
            }
        }
Ejemplo n.º 26
0
        Widget MakeHistoryWidget(object o)
        {
            var message = (ChatMessage)o;
            var widget  = (LabelWidget)historyTemplate.Clone();
            var font    = Game.Renderer.Fonts[widget.Font];

            var color = message.Type == ChatMessageType.Notification ?
                        ChromeMetrics.Get <Color>("GlobalChatNotificationColor") :
                        ChromeMetrics.Get <Color>("GlobalChatTextColor");

            var display = WidgetUtils.WrapText(message.ToString(), widget.Bounds.Width, font);

            widget.Bounds.Height = font.Measure(display).Y;
            widget.GetText       = () => display;
            widget.GetColor      = () => color;
            widget.Id            = message.UID;
            return(widget);
        }
Ejemplo n.º 27
0
        protected MapPreviewWidget(MapPreviewWidget other)
            : base(other)
        {
            Preview = other.Preview;

            IgnoreMouseInput = other.IgnoreMouseInput;
            ShowSpawnPoints  = other.ShowSpawnPoints;
            TooltipTemplate  = other.TooltipTemplate;
            TooltipContainer = other.TooltipContainer;
            SpawnOccupants   = other.SpawnOccupants;


            spawnClaimed       = ChromeProvider.GetImage("lobby-bits", "spawn-claimed");
            spawnUnclaimed     = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed");
            spawnFont          = WarGame.Renderer.Fonts[ChromeMetrics.Get <string>("SpawnFont")];
            spawnColor         = ChromeMetrics.Get <Color>("SpawnColor");
            spawnContrastColor = ChromeMetrics.Get <Color>("SpawnContrastColor");
            spawnLabelOffset   = ChromeMetrics.Get <Int2>("SpawnLabelOffset");
        }
        void BindHotkeyPref(HotkeyDefinition hd, Widget template, Widget parent)
        {
            var key = template.Clone() as Widget;

            key.Id        = hd.Name;
            key.IsVisible = () => true;

            key.Get <LabelWidget>("FUNCTION").GetText = () => hd.Description + ":";

            var remapButton = key.Get <ButtonWidget>("HOTKEY");

            WidgetUtils.TruncateButtonToTooltip(remapButton, modData.Hotkeys[hd.Name].GetValue().DisplayString());

            remapButton.IsHighlighted = () => selectedHotkeyDefinition == hd;

            var hotkeyValidColor   = ChromeMetrics.Get <Color>("HotkeyColor");
            var hotkeyInvalidColor = ChromeMetrics.Get <Color>("HotkeyColorInvalid");

            remapButton.GetColor = () =>
            {
                return(modData.Hotkeys.GetFirstDuplicate(hd.Name, modData.Hotkeys[hd.Name].GetValue(), hd) != null ?
                       hotkeyInvalidColor :
                       hotkeyValidColor);
            };

            if (selectedHotkeyDefinition == hd)
            {
                selectedHotkeyButton  = remapButton;
                hotkeyEntryWidget.Key = modData.Hotkeys[hd.Name].GetValue();
                ValidateHotkey();
            }

            remapButton.OnClick = () =>
            {
                selectedHotkeyDefinition = hd;
                selectedHotkeyButton     = remapButton;
                hotkeyEntryWidget.Key    = modData.Hotkeys[hd.Name].GetValue();
                ValidateHotkey();
                hotkeyEntryWidget.TakeKeyboardFocus();
            };

            parent.AddChild(key);
        }
Ejemplo n.º 29
0
        public WorldInteractionControllerWidget(World world, WorldRenderer worldRenderer)
        {
            World = world;
            this.worldRenderer = worldRenderer;
            if (!ChromeMetrics.TryGet("AltSelectionColor", out altSelectionColor))
            {
                altSelectionColor = Color.White;
            }

            if (!ChromeMetrics.TryGet("CtrlSelectionColor", out ctrlSelectionColor))
            {
                ctrlSelectionColor = Color.White;
            }

            if (!ChromeMetrics.TryGet("NormalSelectionColor", out normalSelectionColor))
            {
                normalSelectionColor = Color.White;
            }
        }
Ejemplo n.º 30
0
        public HotkeyDialogLogic(Widget widget, Action onSave, HotkeyDefinition hotkeyDefinition, HotkeyManager hotkeyManager)
        {
            panel           = widget;
            this.onSave     = onSave;
            definition      = hotkeyDefinition;
            manager         = hotkeyManager;
            currentHotkey   = manager[definition.Name].GetValue();
            hotkeyEntry     = panel.Get <HotkeyEntryWidget>("HOTKEY_ENTRY");
            resetButton     = panel.Get <ButtonWidget>("RESET_BUTTON");
            clearButton     = panel.Get <ButtonWidget>("CLEAR_BUTTON");
            cancelButton    = panel.Get <ButtonWidget>("CANCEL_BUTTON");
            duplicateNotice = panel.Get <LabelWidget>("DUPLICATE_NOTICE");
            defaultNotice   = panel.Get <LabelWidget>("DEFAULT_NOTICE");
            originalNotice  = panel.Get <LabelWidget>("ORIGINAL_NOTICE");

            panel.Get <LabelWidget>("HOTKEY_LABEL").GetText = () => hotkeyDefinition.Description + ":";

            duplicateNotice.TextColor = ChromeMetrics.Get <Color>("NoticeErrorColor");
            duplicateNotice.GetText   = () =>
            {
                return((duplicateHotkey != null) ? duplicateNotice.Text.F(duplicateHotkey.Description) : duplicateNotice.Text);
            };
            defaultNotice.TextColor  = ChromeMetrics.Get <Color>("NoticeInfoColor");
            originalNotice.TextColor = ChromeMetrics.Get <Color>("NoticeInfoColor");
            originalNotice.Text      = originalNotice.Text.F(hotkeyDefinition.Default.DisplayString());

            resetButton.OnClick  = Reset;
            clearButton.OnClick  = Clear;
            cancelButton.OnClick = Cancel;

            hotkeyEntry.Key         = currentHotkey;
            hotkeyEntry.IsValid     = () => isValid;
            hotkeyEntry.OnTakeFocus = OnHotkeyEntryTakeFocus;
            hotkeyEntry.OnLoseFocus = OnHotkeyEntryLoseFocus;
            hotkeyEntry.OnEscape    = Cancel;
            hotkeyEntry.OnReturn    = Cancel;
            hotkeyEntry.TakeKeyboardFocus();

            Validate();
            isFirstValidation = false;
        }