Esempio n. 1
0
        public static void AddPlayerFlagAndName(ScrollItemWidget template, Player player)
        {
            var flag = template.Get<ImageWidget>("FLAG");
            flag.GetImageCollection = () => "flags";
            if (player.World.RenderPlayer != null && player.World.RenderPlayer.Stances[player] != Stance.Ally)
                flag.GetImageName = () => player.DisplayFaction.InternalName;
            else
                flag.GetImageName = () => player.Faction.InternalName;

            var client = player.World.LobbyInfo.ClientWithIndex(player.ClientIndex);
            var playerName = template.Get<LabelWidget>("PLAYER");
            var playerNameFont = Game.Renderer.Fonts[playerName.Font];
            var suffixLength = new CachedTransform<string, int>(s => playerNameFont.Measure(s).X);
            var name = new CachedTransform<Pair<string, int>, string>(c =>
                WidgetUtils.TruncateText(c.First, playerName.Bounds.Width - c.Second, playerNameFont));

            playerName.GetText = () =>
            {
                var suffix = player.WinState == WinState.Undefined ? "" : " (" + player.WinState + ")";
                if (client != null && client.State == Session.ClientState.Disconnected)
                    suffix = " (Gone)";

                var sl = suffixLength.Update(suffix);
                return name.Update(Pair.New(player.PlayerName, sl)) + suffix;
            };

            playerName.GetColor = () => player.Color.RGB;
        }
Esempio n. 2
0
        public static void AddPlayerFlagAndName(ScrollItemWidget template, Player player)
        {
            var flag = template.Get<ImageWidget>("FLAG");
            flag.GetImageName = () => player.Country.Race;
            flag.GetImageCollection = () => "flags";

            var playerName = template.Get<LabelWidget>("PLAYER");
            playerName.GetText = () => player.PlayerName + (player.WinState == WinState.Undefined ? "" : " (" + player.WinState + ")");
            playerName.GetColor = () => player.Color.RGB;
        }
Esempio n. 3
0
        public static void AddPlayerFlagAndName(ScrollItemWidget template, Player player)
        {
            var flag = template.Get<ImageWidget>("FLAG");
            flag.GetImageCollection = () => "flags";
            if (player.World.RenderPlayer != null && player.World.RenderPlayer.Stances[player] != Stance.Ally)
                flag.GetImageName = () => player.DisplayFaction.InternalName;
            else
                flag.GetImageName = () => player.Faction.InternalName;

            var playerName = template.Get<LabelWidget>("PLAYER");
            var client = player.World.LobbyInfo.ClientWithIndex(player.ClientIndex);
            playerName.GetText = () =>
            {
                if (client != null && client.State == Network.Session.ClientState.Disconnected)
                    return player.PlayerName + " (Gone)";
                return player.PlayerName + (player.WinState == WinState.Undefined ? "" : " (" + player.WinState + ")");
            };
            playerName.GetColor = () => player.Color.RGB;
        }
Esempio n. 4
0
        void SetupKeyBinding(ScrollItemWidget keyWidget, string description, Func<string> getValue, Action<string> setValue)
        {
            keyWidget.Get<LabelWidget>("FUNCTION").GetText = () => description;

            var textBox = keyWidget.Get<TextFieldWidget>("HOTKEY");

            textBox.Text = getValue();

            textBox.OnLoseFocus = () =>
            {
                textBox.Text.Trim();
                if (textBox.Text.Length == 0)
                    textBox.Text = getValue();
                else
                    setValue(textBox.Text);
            };

            textBox.OnEnterKey = () => { textBox.LoseFocus(); return true; };
        }