示例#1
0
        public static void SetupFactionWidget(Widget parent, Session.Slot s, Session.Client c,
                                              Dictionary <string, LobbyFaction> factions)
        {
            var factionName = parent.Get <LabelWidget>("FACTIONNAME");

            factionName.GetText = () => factions[c.Faction].Name;
            var factionFlag = parent.Get <ImageWidget>("FACTIONFLAG");

            factionFlag.GetImageName       = () => c.Faction;
            factionFlag.GetImageCollection = () => "flags";
        }
示例#2
0
        public static void ShowPlayerActionDropDown(DropDownButtonWidget dropdown, Session.Slot slot,
                                                    Session.Client c, OrderManager orderManager, Widget lobby, Action before, Action after)
        {
            Action <bool> okPressed = tempBan => { orderManager.IssueOrder(Order.Command("kick {0} {1}".F(c.Index, tempBan))); after(); };
            var           onClick   = new Action(() =>
            {
                before();

                Game.LoadWidget(null, "KICK_CLIENT_DIALOG", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs
                {
                    { "clientName", c.Name },
                    { "okPressed", okPressed },
                    { "cancelPressed", after }
                });
            });

            var options = new List <DropDownOption>
            {
                new DropDownOption
                {
                    Title   = "Kick",
                    OnClick = onClick
                },
            };

            if (orderManager.LobbyInfo.GlobalSettings.Dedicated)
            {
                options.Add(new DropDownOption
                {
                    Title   = "Transfer Admin",
                    OnClick = () => orderManager.IssueOrder(Order.Command("make_admin {0}".F(c.Index)))
                });
            }

            if (!c.IsObserver && orderManager.LobbyInfo.GlobalSettings.AllowSpectators)
            {
                options.Add(new DropDownOption
                {
                    Title   = "Move to Spectator",
                    OnClick = () => orderManager.IssueOrder(Order.Command("make_spectator {0}".F(c.Index)))
                });
            }

            Func <DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
            {
                var item        = ScrollItemWidget.Setup(itemTemplate, o.IsSelected, o.OnClick);
                var labelWidget = item.Get <LabelWidget>("LABEL");
                labelWidget.GetText = () => o.Title;
                return(item);
            };

            dropdown.ShowDropDown("PLAYERACTION_DROPDOWN_TEMPLATE", 167, options, setupItem);
        }
示例#3
0
        public static void SetupEditableReadyWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
        {
            var status = parent.Get <CheckboxWidget>("STATUS_CHECKBOX");

            status.IsChecked  = () => orderManager.LocalClient.IsReady || c.Bot != null;
            status.IsVisible  = () => true;
            status.IsDisabled = () => c.Bot != null || map.Status != MapStatus.Available || map.RuleStatus != MapRuleStatus.Cached;

            var state = orderManager.LocalClient.IsReady ? Session.ClientState.NotReady : Session.ClientState.Ready;

            status.OnClick = () => orderManager.IssueOrder(Order.Command("state {0}".F(state)));
        }
示例#4
0
        public static void SetupEditableFactionWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager,
                                                      Dictionary <string, LobbyFaction> factions)
        {
            var dropdown = parent.Get <DropDownButtonWidget>("FACTION");

            dropdown.IsDisabled  = () => s.LockFaction || orderManager.LocalClient.IsReady;
            dropdown.OnMouseDown = _ => ShowFactionDropDown(dropdown, c, orderManager, factions);
            var factionDescription = factions[c.Faction].Description;

            dropdown.GetTooltipText = () => factionDescription;
            SetupFactionWidget(dropdown, s, c, factions);
        }
示例#5
0
        public static void SetupNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, WorldRenderer worldRenderer)
        {
            var name = parent.Get <LabelWidget>("NAME");

            name.IsVisible = () => true;
            var font  = Game.Renderer.Fonts[name.Font];
            var label = WidgetUtils.TruncateText(c.Name, name.Bounds.Width, font);

            name.GetText = () => label;

            SetupProfileWidget(parent, c, orderManager, worldRenderer);
        }
示例#6
0
        public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
        {
            var slot = parent.Get <DropDownButtonWidget>("SLOT_OPTIONS");

            slot.IsVisible   = () => true;
            slot.IsDisabled  = () => orderManager.LocalClient.IsReady;
            slot.GetText     = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";
            slot.OnMouseDown = _ => ShowSlotDropDown(slot, s, c, orderManager, map);

            // Ensure Name selector (if present) is hidden
            HideChildWidget(parent, "NAME");
        }
示例#7
0
        public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr)
        {
            World           = world;
            InternalName    = pr.Name;
            PlayerReference = pr;
            string botType = null;

            // Real player or host-created bot
            if (client != null)
            {
                ClientIndex    = client.Index;
                Color          = client.Color;
                PlayerName     = client.Name;
                botType        = client.Bot;
                Country        = ChooseCountry(world, client.Race, !pr.LockRace);
                DisplayCountry = ChooseDisplayCountry(world, client.Race);
            }
            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;
                Country        = ChooseCountry(world, pr.Race, false);
                DisplayCountry = ChooseDisplayCountry(world, pr.Race);
            }

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

            // 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);
                }
            }
        }
示例#8
0
        public static void SetupEditableHandicapWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
        {
            var dropdown = parent.Get <DropDownButtonWidget>("HANDICAP_DROPDOWN");

            dropdown.IsVisible   = () => true;
            dropdown.IsDisabled  = () => s.LockTeam || orderManager.LocalClient.IsReady;
            dropdown.OnMouseDown = _ => ShowHandicapDropDown(dropdown, c, orderManager);

            var handicapLabel = new CachedTransform <int, string>(h => "{0}%".F(h));

            dropdown.GetText = () => handicapLabel.Update(c.Handicap);

            HideChildWidget(parent, "HANDICAP");
        }
示例#9
0
        public static void SetupEditableSpawnWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
        {
            var dropdown = parent.Get <DropDownButtonWidget>("SPAWN");

            dropdown.IsDisabled  = () => s.LockSpawn || orderManager.LocalClient.IsReady;
            dropdown.OnMouseDown = _ =>
            {
                var spawnPoints = Enumerable.Range(0, map.SpawnPoints.Length + 1).Except(
                    orderManager.LobbyInfo.Clients.Where(
                        client => client != c && client.SpawnPoint != 0).Select(client => client.SpawnPoint));
                ShowSpawnDropDown(dropdown, c, orderManager, spawnPoints);
            };
            dropdown.GetText = () => (c.SpawnPoint == 0) ? "-" : Convert.ToChar('A' - 1 + c.SpawnPoint).ToString();
        }
示例#10
0
        public static void SetupEditableGameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager,
                                                   Dictionary <string, LobbyFaction> factions)
        {
            var dropdown = parent.Get <DropDownButtonWidget>("GAME");

            dropdown.IsDisabled  = () => s.LockFaction || orderManager.LocalClient.IsReady;
            dropdown.OnMouseDown = _ => ShowGameDropDown(dropdown, c, orderManager, factions);

            /*var tooltip = SplitOnFirstToken(factions[c.Faction].Description);
             * dropdown.GetTooltipText = () => tooltip.First;
             * dropdown.GetTooltipDesc = () => tooltip.Second;*/

            SetupGameWidget(dropdown, s, c, factions);
        }
示例#11
0
        public static void SetupSlotWidget(Widget parent, Session.Slot s, Session.Client c)
        {
            var name = parent.Get <LabelWidget>("NAME");

            name.IsVisible = () => true;
            name.GetText   = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";

            // Ensure Slot selector (if present) is hidden
            var slot = parent.GetOrNull("SLOT_OPTIONS");

            if (slot != null)
            {
                slot.IsVisible = () => false;
            }
        }
示例#12
0
        public static void SetupPlayerActionWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager,
                                                   WorldRenderer worldRenderer, Widget lobby, Action before, Action after)
        {
            var slot = parent.Get <DropDownButtonWidget>("PLAYER_ACTION");

            slot.IsVisible   = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
            slot.IsDisabled  = () => orderManager.LocalClient.IsReady;
            slot.GetText     = () => c != null ? c.Name : string.Empty;
            slot.OnMouseDown = _ => ShowPlayerActionDropDown(slot, s, c, orderManager, lobby, before, after);

            SetupProfileWidget(slot, c, orderManager, worldRenderer);

            // Ensure Name selector (if present) is hidden
            HideChildWidget(parent, "NAME");
        }
示例#13
0
        public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, Ruleset rules)
        {
            var slot = parent.Get <DropDownButtonWidget>("SLOT_OPTIONS");

            slot.IsVisible   = () => true;
            slot.IsDisabled  = () => orderManager.LocalClient.IsReady;
            slot.GetText     = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";
            slot.OnMouseDown = _ => ShowSlotDropDown(rules, slot, s, c, orderManager);

            // Ensure Name selector (if present) is hidden
            var name = parent.GetOrNull("NAME");

            if (name != null)
            {
                name.IsVisible = () => false;
            }
        }
示例#14
0
        public static void SetupClientWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, bool visible)
        {
            parent.Get("ADMIN_INDICATOR").IsVisible = () => c.IsAdmin;
            var block = parent.Get("LATENCY");

            block.IsVisible = () => visible;

            if (visible)
            {
                block.Get <ColorBlockWidget>("LATENCY_COLOR").GetColor = () => LatencyColor(c.Latency);
            }

            var tooltip = parent.Get <ClientTooltipRegionWidget>("CLIENT_REGION");

            tooltip.IsVisible = () => visible;
            tooltip.Bind(orderManager, c.Index);
        }
示例#15
0
        public static void SetupEditableNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, WorldRenderer worldRenderer)
        {
            var name = parent.Get <TextFieldWidget>("NAME");

            name.IsVisible  = () => true;
            name.IsDisabled = () => orderManager.LocalClient.IsReady;

            name.Text = c.Name;
            var escPressed = false;

            name.OnLoseFocus = () =>
            {
                if (escPressed)
                {
                    escPressed = false;
                    return;
                }

                name.Text = name.Text.Trim();
                if (name.Text.Length == 0)
                {
                    name.Text = c.Name;
                }
                else if (name.Text != c.Name)
                {
                    name.Text = Settings.SanitizedPlayerName(name.Text);
                    orderManager.IssueOrder(Order.Command("name " + name.Text));
                    Game.Settings.Player.Name = name.Text;
                    Game.Settings.Save();
                }
            };

            name.OnEnterKey = () => { name.YieldKeyboardFocus(); return(true); };
            name.OnEscKey   = () =>
            {
                name.Text  = c.Name;
                escPressed = true;
                name.YieldKeyboardFocus();
                return(true);
            };

            SetupProfileWidget(name, c, orderManager, worldRenderer);

            HideChildWidget(parent, "SLOT_OPTIONS");
        }
示例#16
0
        public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c,
                                                   OrderManager orderManager, WorldRenderer worldRenderer, MapPreview map)
        {
            var slot = parent.Get <DropDownButtonWidget>("SLOT_OPTIONS");

            slot.IsVisible  = () => true;
            slot.IsDisabled = () => orderManager.LocalClient.IsReady;

            var truncated = new CachedTransform <string, string>(name =>
                                                                 WidgetUtils.TruncateText(name, slot.Bounds.Width - slot.Bounds.Height - slot.LeftMargin - slot.RightMargin,
                                                                                          Game.Renderer.Fonts[slot.Font]));

            slot.GetText     = () => truncated.Update(c != null ? c.Name : s.Closed ? "Closed" : "Open");
            slot.OnMouseDown = _ => ShowSlotDropDown(slot, s, c, orderManager, map);

            // Ensure Name selector (if present) is hidden
            HideChildWidget(parent, "NAME");
        }
示例#17
0
        public static void SetupKickWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, Widget lobby, Action before, Action after)
        {
            var button = parent.Get <ButtonWidget>("KICK");

            button.IsVisible  = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
            button.IsDisabled = () => orderManager.LocalClient.IsReady;
            Action <bool> okPressed = tempBan => { orderManager.IssueOrder(Order.Command("kick {0} {1}".F(c.Index, tempBan))); after(); };

            button.OnClick = () =>
            {
                before();

                Game.LoadWidget(null, "KICK_CLIENT_DIALOG", lobby, new WidgetArgs
                {
                    { "clientName", c.Name },
                    { "okPressed", okPressed },
                    { "cancelPressed", after }
                });
            };
        }
示例#18
0
        public static void SetupPlayerActionWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager,
                                                   WorldRenderer worldRenderer, Widget lobby, Action before, Action after)
        {
            var slot = parent.Get <DropDownButtonWidget>("PLAYER_ACTION");

            slot.IsVisible  = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
            slot.IsDisabled = () => orderManager.LocalClient.IsReady;

            var truncated = new CachedTransform <string, string>(name =>
                                                                 WidgetUtils.TruncateText(name, slot.Bounds.Width - slot.Bounds.Height - slot.LeftMargin - slot.RightMargin,
                                                                                          Game.Renderer.Fonts[slot.Font]));

            slot.GetText     = () => truncated.Update(c != null ? c.Name : string.Empty);
            slot.OnMouseDown = _ => ShowPlayerActionDropDown(slot, s, c, orderManager, lobby, before, after);

            SetupProfileWidget(slot, c, orderManager, worldRenderer);

            // Ensure Name selector (if present) is hidden
            HideChildWidget(parent, "NAME");
        }
示例#19
0
        public static void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot,
                                            Session.Client client, OrderManager orderManager, MapPreview map)
        {
            var options = new Dictionary <string, IEnumerable <SlotDropDownOption> >
            {
                {
                    "Slot", new List <SlotDropDownOption>
                    {
                        new SlotDropDownOption("Open", "slot_open " + slot.PlayerReference, () => (!slot.Closed && client == null)),
                        new SlotDropDownOption("Closed", "slot_close " + slot.PlayerReference, () => slot.Closed)
                    }
                }
            };

            var bots = new List <SlotDropDownOption>();

            if (slot.AllowBots)
            {
                foreach (var b in map.Rules.Actors["player"].TraitInfos <IBotInfo>())
                {
                    var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
                    bots.Add(new SlotDropDownOption(b.Name,
                                                    "slot_bot {0} {1} {2}".F(slot.PlayerReference, botController.Index, b.Type),
                                                    () => client != null && client.Bot == b.Type));
                }
            }

            options.Add(bots.Any() ? "Bots" : "Bots Disabled", bots);

            Func <SlotDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
            {
                var item = ScrollItemWidget.Setup(itemTemplate,
                                                  o.Selected,
                                                  () => orderManager.IssueOrder(Order.Command(o.Order)));
                item.Get <LabelWidget>("LABEL").GetText = () => o.Title;
                return(item);
            };

            dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 180, options, setupItem);
        }
示例#20
0
 public static void SetupTeamWidget(Widget parent, Session.Slot s, Session.Client c)
 {
     parent.Get <LabelWidget>("TEAM").GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
 }
示例#21
0
 public static void SetupReadyWidget(Widget parent, Session.Slot s, Session.Client c)
 {
     parent.Get <ImageWidget>("STATUS_IMAGE").IsVisible = () => c.IsReady || c.Bot != null;
 }
示例#22
0
        public static void SetupColorWidget(Widget parent, Session.Slot s, Session.Client c)
        {
            var color = parent.Get <ColorBlockWidget>("COLORBLOCK");

            color.GetColor = () => c.Color;
        }
示例#23
0
        public static void SetupNameWidget(Widget parent, Session.Slot s, Session.Client c)
        {
            var name = parent.Get <LabelWidget>("NAME");

            name.GetText = () => c.Name;
        }
示例#24
0
 public static void SetupSpawnWidget(Widget parent, Session.Slot s, Session.Client c)
 {
     parent.Get <LabelWidget>("SPAWN").GetText = () => (c.SpawnPoint == 0) ? "-" : Convert.ToChar('A' - 1 + c.SpawnPoint).ToString();
 }