本文整理汇总了C#中OpenRA.Widgets.ScrollPanelWidget.Get方法的典型用法代码示例。如果您正苦于以下问题:C# ScrollPanelWidget.Get方法的具体用法?C# ScrollPanelWidget.Get怎么用?C# ScrollPanelWidget.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenRA.Widgets.ScrollPanelWidget
的用法示例。
在下文中一共展示了ScrollPanelWidget.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TileSelectorLogic
public TileSelectorLogic(Widget widget, WorldRenderer worldRenderer, Ruleset modRules)
{
var tileset = modRules.TileSets[worldRenderer.World.Map.Tileset];
editor = widget.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
panel = widget.Get<ScrollPanelWidget>("TILETEMPLATE_LIST");
itemTemplate = panel.Get<ScrollItemWidget>("TILEPREVIEW_TEMPLATE");
panel.Layout = new GridLayout(panel);
var tileCategorySelector = widget.Get<DropDownButtonWidget>("TILE_CATEGORY");
var categories = tileset.EditorTemplateOrder;
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template,
() => tileCategorySelector.Text == option,
() => { tileCategorySelector.Text = option; IntializeTilePreview(widget, worldRenderer, tileset, option); });
item.Get<LabelWidget>("LABEL").GetText = () => option;
return item;
};
tileCategorySelector.OnClick = () =>
tileCategorySelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, categories, setupItem);
tileCategorySelector.Text = categories.First();
IntializeTilePreview(widget, worldRenderer, tileset, categories.First());
}
示例2: ModContentLogic
public ModContentLogic(Widget widget, Manifest mod, ModContent content, Action onCancel)
{
this.content = content;
var panel = widget.Get("CONTENT_PANEL");
var modFileSystem = new FileSystem.FileSystem(Game.Mods);
modFileSystem.LoadFromManifest(mod);
var sourceYaml = MiniYaml.Load(modFileSystem, content.Sources, null);
foreach (var s in sourceYaml)
sources.Add(s.Key, new ModContent.ModSource(s.Value));
var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null);
foreach (var d in downloadYaml)
downloads.Add(d.Key, new ModContent.ModDownload(d.Value));
modFileSystem.UnmountAll();
scrollPanel = panel.Get<ScrollPanelWidget>("PACKAGES");
template = scrollPanel.Get<ContainerWidget>("PACKAGE_TEMPLATE");
var headerTemplate = panel.Get<LabelWidget>("HEADER_TEMPLATE");
var headerLines = !string.IsNullOrEmpty(content.HeaderMessage) ? content.HeaderMessage.Replace("\\n", "\n").Split('\n') : new string[0];
var headerHeight = 0;
foreach (var l in headerLines)
{
var line = (LabelWidget)headerTemplate.Clone();
line.GetText = () => l;
line.Bounds.Y += headerHeight;
panel.AddChild(line);
headerHeight += headerTemplate.Bounds.Height;
}
panel.Bounds.Height += headerHeight;
panel.Bounds.Y -= headerHeight / 2;
scrollPanel.Bounds.Y += headerHeight;
var discButton = panel.Get<ButtonWidget>("CHECK_DISC_BUTTON");
discButton.Bounds.Y += headerHeight;
discButton.IsVisible = () => discAvailable;
discButton.OnClick = () => Ui.OpenWindow("DISC_INSTALL_PANEL", new WidgetArgs
{
{ "afterInstall", () => { } },
{ "sources", sources },
{ "content", content }
});
var backButton = panel.Get<ButtonWidget>("BACK_BUTTON");
backButton.Bounds.Y += headerHeight;
backButton.OnClick = () => { Ui.CloseWindow(); onCancel(); };
PopulateContentList();
Game.RunAfterTick(Ui.ResetTooltips);
}
示例3: MapChooserLogic
internal MapChooserLogic(Widget widget, string initialMap, Action onExit, Action<Map> onSelect)
{
map = Game.modData.AvailableMaps[WidgetUtils.ChooseInitialMap(initialMap)];
widget.Get<ButtonWidget>("BUTTON_OK").OnClick = () => { Ui.CloseWindow(); onSelect(map); };
widget.Get<ButtonWidget>("BUTTON_CANCEL").OnClick = () => { Ui.CloseWindow(); onExit(); };
scrollpanel = widget.Get<ScrollPanelWidget>("MAP_LIST");
scrollpanel.ScrollVelocity = 40f;
scrollpanel.Layout = new GridLayout(scrollpanel);
itemTemplate = scrollpanel.Get<ScrollItemWidget>("MAP_TEMPLATE");
var gameModeDropdown = widget.GetOrNull<DropDownButtonWidget>("GAMEMODE_FILTER");
if (gameModeDropdown != null)
{
var selectableMaps = Game.modData.AvailableMaps.Where(m => m.Value.Selectable).ToList();
var gameModes = selectableMaps
.GroupBy(m => m.Value.Type)
.Select(g => Pair.New(g.Key, g.Count())).ToList();
// 'all game types' extra item
gameModes.Insert(0, Pair.New(null as string, selectableMaps.Count()));
Func<Pair<string, int>, string> showItem =
x => "{0} ({1})".F(x.First ?? "All Game Types", x.Second);
Func<Pair<string, int>, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, template) =>
{
var item = ScrollItemWidget.Setup(template,
() => gameMode == ii.First,
() => { gameMode = ii.First; EnumerateMaps(onSelect); });
item.Get<LabelWidget>("LABEL").GetText = () => showItem(ii);
return item;
};
gameModeDropdown.OnClick = () =>
gameModeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, gameModes, setupItem);
gameModeDropdown.GetText = () => showItem(gameModes.First(m => m.First == gameMode));
}
var randomMapButton = widget.GetOrNull<ButtonWidget>("RANDOMMAP_BUTTON");
if (randomMapButton != null)
{
randomMapButton.OnClick = () =>
{
var kv = visibleMaps.Random(Game.CosmeticRandom);
map = kv.Value;
scrollpanel.ScrollToItem(kv.Key);
};
randomMapButton.IsDisabled = () => visibleMaps == null || visibleMaps.Count == 0;
}
EnumerateMaps(onSelect);
}
示例4: LayerSelectorLogic
public LayerSelectorLogic(Widget widget, WorldRenderer worldRenderer)
{
this.worldRenderer = worldRenderer;
editor = widget.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
layerTemplateList = widget.Get<ScrollPanelWidget>("LAYERTEMPLATE_LIST");
layerTemplateList.Layout = new GridLayout(layerTemplateList);
layerPreviewTemplate = layerTemplateList.Get<ScrollItemWidget>("LAYERPREVIEW_TEMPLATE");
IntializeLayerPreview(widget);
}
示例5: MusicPlayerLogic
public MusicPlayerLogic(Widget widget, Ruleset modRules, Action onExit)
{
this.modRules = modRules;
var panel = widget.Get("MUSIC_PANEL");
musicList = panel.Get<ScrollPanelWidget>("MUSIC_LIST");
itemTemplate = musicList.Get<ScrollItemWidget>("MUSIC_TEMPLATE");
BuildMusicTable();
Func<bool> noMusic = () => !installed;
panel.Get("NO_MUSIC_LABEL").IsVisible = noMusic;
var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY");
playButton.OnClick = Play;
playButton.IsDisabled = noMusic;
playButton.IsVisible = () => !Sound.MusicPlaying;
var pauseButton = panel.Get<ButtonWidget>("BUTTON_PAUSE");
pauseButton.OnClick = Sound.PauseMusic;
pauseButton.IsDisabled = noMusic;
pauseButton.IsVisible = () => Sound.MusicPlaying;
var stopButton = panel.Get<ButtonWidget>("BUTTON_STOP");
stopButton.OnClick = Sound.StopMusic;
stopButton.IsDisabled = noMusic;
var nextButton = panel.Get<ButtonWidget>("BUTTON_NEXT");
nextButton.OnClick = () => { currentSong = GetNextSong(); Play(); };
nextButton.IsDisabled = noMusic;
var prevButton = panel.Get<ButtonWidget>("BUTTON_PREV");
prevButton.OnClick = () => { currentSong = GetPrevSong(); Play(); };
prevButton.IsDisabled = noMusic;
var shuffleCheckbox = panel.Get<CheckboxWidget>("SHUFFLE");
shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle;
shuffleCheckbox.OnClick = () => Game.Settings.Sound.Shuffle ^= true;
var repeatCheckbox = panel.Get<CheckboxWidget>("REPEAT");
repeatCheckbox.IsChecked = () => Game.Settings.Sound.Repeat;
repeatCheckbox.OnClick = () => Game.Settings.Sound.Repeat ^= true;
panel.Get<LabelWidget>("TIME_LABEL").GetText = () => (currentSong == null) ? "" :
"{0:D2}:{1:D2} / {2:D2}:{3:D2}".F((int)Sound.MusicSeekPosition / 60, (int)Sound.MusicSeekPosition % 60,
currentSong.Length / 60, currentSong.Length % 60);
var musicSlider = panel.Get<SliderWidget>("MUSIC_SLIDER");
musicSlider.OnChange += x => Sound.MusicVolume = x;
musicSlider.Value = Sound.MusicVolume;
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); };
}
示例6: GlobalChatLogic
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();
}
示例7: ActorSelectorLogic
public ActorSelectorLogic(Widget widget, World world, WorldRenderer worldRenderer)
{
mapRules = world.Map.Rules;
this.world = world;
this.worldRenderer = worldRenderer;
editor = widget.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
ownersDropDown = widget.Get<DropDownButtonWidget>("OWNERS_DROPDOWN");
panel = widget.Get<ScrollPanelWidget>("ACTORTEMPLATE_LIST");
itemTemplate = panel.Get<ScrollItemWidget>("ACTORPREVIEW_TEMPLATE");
panel.Layout = new GridLayout(panel);
var editorLayer = world.WorldActor.Trait<EditorActorLayer>();
selectedOwner = editorLayer.Players.Players.Values.First();
Func<PlayerReference, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () =>
{
selectedOwner = option;
ownersDropDown.Text = selectedOwner.Name;
ownersDropDown.TextColor = selectedOwner.Color.RGB;
IntializeActorPreviews();
});
item.Get<LabelWidget>("LABEL").GetText = () => option.Name;
item.GetColor = () => option.Color.RGB;
return item;
};
ownersDropDown.OnClick = () =>
{
var owners = editorLayer.Players.Players.Values.OrderBy(p => p.Name);
ownersDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, setupItem);
};
ownersDropDown.Text = selectedOwner.Name;
ownersDropDown.TextColor = selectedOwner.Color.RGB;
IntializeActorPreviews();
}
示例8: LobbyLogic
internal LobbyLogic(Widget widget, World world, OrderManager orderManager,
Action onExit, Action onStart, bool addBots)
{
var lobby = widget;
this.orderManager = orderManager;
this.OnGameStart = () => { CloseWindow(); onStart(); };
this.onExit = onExit;
Game.LobbyInfoChanged += UpdateCurrentMap;
Game.LobbyInfoChanged += UpdatePlayerList;
Game.BeforeGameStart += OnGameStart;
Game.AddChatLine += AddChatLine;
Game.ConnectionStateChanged += ConnectionStateChanged;
var name = lobby.GetOrNull<LabelWidget>("SERVER_NAME");
if (name != null)
name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName;
UpdateCurrentMap();
Players = lobby.Get<ScrollPanelWidget>("PLAYERS");
EditablePlayerTemplate = Players.Get("TEMPLATE_EDITABLE_PLAYER");
NonEditablePlayerTemplate = Players.Get("TEMPLATE_NONEDITABLE_PLAYER");
EmptySlotTemplate = Players.Get("TEMPLATE_EMPTY");
EditableSpectatorTemplate = Players.Get("TEMPLATE_EDITABLE_SPECTATOR");
NonEditableSpectatorTemplate = Players.Get("TEMPLATE_NONEDITABLE_SPECTATOR");
NewSpectatorTemplate = Players.Get("TEMPLATE_NEW_SPECTATOR");
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Color = Game.Settings.Player.Color;
var mapPreview = lobby.Get<MapPreviewWidget>("MAP_PREVIEW");
mapPreview.IsVisible = () => Map != null;
mapPreview.Map = () => Map;
mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint( orderManager, mapPreview, Map, mi );
mapPreview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager, Map);
var mapTitle = lobby.GetOrNull<LabelWidget>("MAP_TITLE");
if (mapTitle != null)
{
mapTitle.IsVisible = () => Map != null;
mapTitle.GetText = () => Map.Title;
}
var mapType = lobby.GetOrNull<LabelWidget>("MAP_TYPE");
if (mapType != null)
{
mapType.IsVisible = () => Map != null;
mapType.GetText = () => Map.Type;
}
var mapAuthor = lobby.GetOrNull<LabelWidget>("MAP_AUTHOR");
if (mapAuthor != null)
{
mapAuthor.IsVisible = () => Map != null;
mapAuthor.GetText = () => "Created by {0}".F(Map.Author);
}
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
.Where(c => c.Selectable)
.ToDictionary(a => a.Race, a => a.Name);
CountryNames.Add("random", "Any");
var gameStarting = false;
var mapButton = lobby.Get<ButtonWidget>("CHANGEMAP_BUTTON");
mapButton.OnClick = () =>
{
var onSelect = new Action<Map>(m =>
{
orderManager.IssueOrder(Order.Command("map " + m.Uid));
Game.Settings.Server.Map = m.Uid;
Game.Settings.Save();
});
Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
{
{ "initialMap", Map.Uid },
{ "onExit", () => {} },
{ "onSelect", onSelect }
});
};
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
var assignTeams = lobby.GetOrNull<DropDownButtonWidget>("ASSIGNTEAMS_DROPDOWNBUTTON");
if (assignTeams != null)
{
assignTeams.IsVisible = () => Game.IsHost;
assignTeams.IsDisabled = () => gameStarting || orderManager.LobbyInfo.Clients.Count(c => c.Slot != null) < 2
|| orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
assignTeams.OnMouseDown = _ =>
{
var options = Enumerable.Range(2, orderManager.LobbyInfo.Clients.Count(c => c.Slot != null).Clamp(2, 8) - 1).Select(d => new DropDownOption
{
Title = "{0} Teams".F(d),
IsSelected = () => false,
OnClick = () => orderManager.IssueOrder(Order.Command("assignteams {0}".F(d.ToString())))
});
Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
//.........这里部分代码省略.........
示例9: IngameChatLogic
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...");
}
示例10: LobbyLogic
internal LobbyLogic(Widget widget, WorldRenderer worldRenderer, OrderManager orderManager,
Action onExit, Action onStart, bool skirmishMode, Ruleset modRules)
{
lobby = widget;
this.orderManager = orderManager;
this.onStart = onStart;
this.onExit = onExit;
this.skirmishMode = skirmishMode;
this.modRules = modRules;
shellmapWorld = worldRenderer.World;
orderManager.AddChatLine += AddChatLine;
Game.LobbyInfoChanged += UpdateCurrentMap;
Game.LobbyInfoChanged += UpdatePlayerList;
Game.BeforeGameStart += OnGameStart;
Game.ConnectionStateChanged += ConnectionStateChanged;
var name = lobby.GetOrNull<LabelWidget>("SERVER_NAME");
if (name != null)
name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName;
Ui.LoadWidget("LOBBY_MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs
{
{ "orderManager", orderManager },
{ "lobby", this }
});
UpdateCurrentMap();
players = Ui.LoadWidget<ScrollPanelWidget>("LOBBY_PLAYER_BIN", lobby.Get("PLAYER_BIN_ROOT"), new WidgetArgs());
players.IsVisible = () => panel == PanelType.Players;
var playerBinHeaders = lobby.GetOrNull<ContainerWidget>("LABEL_CONTAINER");
if (playerBinHeaders != null)
playerBinHeaders.IsVisible = () => panel == PanelType.Players;
editablePlayerTemplate = players.Get("TEMPLATE_EDITABLE_PLAYER");
nonEditablePlayerTemplate = players.Get("TEMPLATE_NONEDITABLE_PLAYER");
emptySlotTemplate = players.Get("TEMPLATE_EMPTY");
editableSpectatorTemplate = players.Get("TEMPLATE_EDITABLE_SPECTATOR");
nonEditableSpectatorTemplate = players.Get("TEMPLATE_NONEDITABLE_SPECTATOR");
newSpectatorTemplate = players.Get("TEMPLATE_NEW_SPECTATOR");
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Color = Game.Settings.Player.Color;
foreach (var f in modRules.Actors["world"].Traits.WithInterface<FactionInfo>())
factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description });
var gameStarting = false;
Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting ||
panel == PanelType.Kick || panel == PanelType.ForceStart ||
orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
var mapButton = lobby.GetOrNull<ButtonWidget>("CHANGEMAP_BUTTON");
if (mapButton != null)
{
mapButton.IsDisabled = () => gameStarting || panel == PanelType.Kick || panel == PanelType.ForceStart ||
orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
mapButton.OnClick = () =>
{
var onSelect = new Action<string>(uid =>
{
// Don't select the same map again
if (uid == Map.Uid)
return;
orderManager.IssueOrder(Order.Command("map " + uid));
Game.Settings.Server.Map = uid;
Game.Settings.Save();
});
Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
{
{ "initialMap", Map.Uid },
{ "initialTab", MapClassification.System },
{ "onExit", DoNothing },
{ "onSelect", Game.IsHost ? onSelect : null },
{ "filter", MapVisibility.Lobby },
});
};
}
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
if (slotsButton != null)
{
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
Map.RuleStatus != MapRuleStatus.Cached || !orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots || !s.LockTeam);
var botNames = modRules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name);
slotsButton.OnMouseDown = _ =>
{
var options = new Dictionary<string, IEnumerable<DropDownOption>>();
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
if (orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots))
{
var botOptions = new List<DropDownOption>()
{
new DropDownOption()
{
Title = "Add",
//.........这里部分代码省略.........
示例11: LobbyLogic
internal LobbyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, OrderManager orderManager,
Action onExit, Action onStart, bool skirmishMode)
{
Map = MapCache.UnknownMap;
lobby = widget;
this.modData = modData;
this.orderManager = orderManager;
this.onStart = onStart;
this.onExit = onExit;
this.skirmishMode = skirmishMode;
// TODO: This needs to be reworked to support per-map tech levels, bots, etc.
this.modRules = modData.DefaultRules;
shellmapWorld = worldRenderer.World;
orderManager.AddChatLine += AddChatLine;
Game.LobbyInfoChanged += UpdateCurrentMap;
Game.LobbyInfoChanged += UpdatePlayerList;
Game.BeforeGameStart += OnGameStart;
Game.ConnectionStateChanged += ConnectionStateChanged;
var name = lobby.GetOrNull<LabelWidget>("SERVER_NAME");
if (name != null)
name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName;
Ui.LoadWidget("LOBBY_MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs
{
{ "orderManager", orderManager },
{ "lobby", this }
});
UpdateCurrentMap();
var playerBin = Ui.LoadWidget("LOBBY_PLAYER_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs());
playerBin.IsVisible = () => panel == PanelType.Players;
players = playerBin.Get<ScrollPanelWidget>("LOBBY_PLAYERS");
editablePlayerTemplate = players.Get("TEMPLATE_EDITABLE_PLAYER");
nonEditablePlayerTemplate = players.Get("TEMPLATE_NONEDITABLE_PLAYER");
emptySlotTemplate = players.Get("TEMPLATE_EMPTY");
editableSpectatorTemplate = players.Get("TEMPLATE_EDITABLE_SPECTATOR");
nonEditableSpectatorTemplate = players.Get("TEMPLATE_NONEDITABLE_SPECTATOR");
newSpectatorTemplate = players.Get("TEMPLATE_NEW_SPECTATOR");
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
colorPreview.Color = Game.Settings.Player.Color;
foreach (var f in modRules.Actors["world"].TraitInfos<FactionInfo>())
factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description });
var gameStarting = false;
Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting ||
panel == PanelType.Kick || panel == PanelType.ForceStart ||
!Map.RulesLoaded || Map.InvalidCustomRules ||
orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
var mapButton = lobby.GetOrNull<ButtonWidget>("CHANGEMAP_BUTTON");
if (mapButton != null)
{
mapButton.IsDisabled = () => gameStarting || panel == PanelType.Kick || panel == PanelType.ForceStart ||
orderManager.LocalClient == null || orderManager.LocalClient.IsReady;
mapButton.OnClick = () =>
{
var onSelect = new Action<string>(uid =>
{
// Don't select the same map again
if (uid == Map.Uid)
return;
orderManager.IssueOrder(Order.Command("map " + uid));
Game.Settings.Server.Map = uid;
Game.Settings.Save();
});
Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
{
{ "initialMap", Map.Uid },
{ "initialTab", MapClassification.System },
{ "onExit", DoNothing },
{ "onSelect", Game.IsHost ? onSelect : null },
{ "filter", MapVisibility.Lobby },
});
};
}
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
if (slotsButton != null)
{
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
(orderManager.LobbyInfo.Slots.Values.All(s => !s.AllowBots) &&
orderManager.LobbyInfo.Slots.Count(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null) == 0);
slotsButton.OnMouseDown = _ =>
{
var botNames = Map.Rules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name);
var options = new Dictionary<string, IEnumerable<DropDownOption>>();
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
if (orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots))
{
var botOptions = new List<DropDownOption>()
//.........这里部分代码省略.........
示例12: LobbyLogic
internal LobbyLogic(Widget widget, World world, OrderManager orderManager,
Action onExit, Action onStart, bool addBots)
{
var lobby = widget;
this.orderManager = orderManager;
this.OnGameStart = () => { CloseWindow(); onStart(); };
this.onExit = onExit;
Game.LobbyInfoChanged += UpdateCurrentMap;
Game.LobbyInfoChanged += UpdatePlayerList;
Game.BeforeGameStart += OnGameStart;
Game.AddChatLine += AddChatLine;
Game.ConnectionStateChanged += ConnectionStateChanged;
UpdateCurrentMap();
PlayerPalettePreview = world.WorldActor.Trait<ColorPickerPaletteModifier>();
PlayerPalettePreview.Ramp = Game.Settings.Player.ColorRamp;
Players = lobby.Get<ScrollPanelWidget>("PLAYERS");
EditablePlayerTemplate = Players.Get("TEMPLATE_EDITABLE_PLAYER");
NonEditablePlayerTemplate = Players.Get("TEMPLATE_NONEDITABLE_PLAYER");
EmptySlotTemplate = Players.Get("TEMPLATE_EMPTY");
EditableSpectatorTemplate = Players.Get("TEMPLATE_EDITABLE_SPECTATOR");
NonEditableSpectatorTemplate = Players.Get("TEMPLATE_NONEDITABLE_SPECTATOR");
NewSpectatorTemplate = Players.Get("TEMPLATE_NEW_SPECTATOR");
var mapPreview = lobby.Get<MapPreviewWidget>("MAP_PREVIEW");
mapPreview.IsVisible = () => Map != null;
mapPreview.Map = () => Map;
mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint( orderManager, mapPreview, Map, mi );
mapPreview.SpawnColors = () => LobbyUtils.GetSpawnColors( orderManager, Map );
var mapTitle = lobby.GetOrNull<LabelWidget>("MAP_TITLE");
if (mapTitle != null)
{
mapTitle.IsVisible = () => Map != null;
mapTitle.GetText = () => Map.Title;
}
CountryNames = Rules.Info["world"].Traits.WithInterface<CountryInfo>()
.Where(c => c.Selectable)
.ToDictionary(a => a.Race, a => a.Name);
CountryNames.Add("random", "Any");
var mapButton = lobby.Get<ButtonWidget>("CHANGEMAP_BUTTON");
mapButton.OnClick = () =>
{
var onSelect = new Action<Map>(m =>
{
orderManager.IssueOrder(Order.Command("map " + m.Uid));
Game.Settings.Server.Map = m.Uid;
Game.Settings.Save();
});
Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
{
{ "initialMap", Map.Uid },
{ "onExit", () => {} },
{ "onSelect", onSelect }
});
};
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");
disconnectButton.OnClick = () => { CloseWindow(); onExit(); };
var gameStarting = false;
var allowCheats = lobby.Get<CheckboxWidget>("ALLOWCHEATS_CHECKBOX");
allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats;
allowCheats.IsDisabled = () => !Game.IsHost || gameStarting || orderManager.LocalClient == null
|| orderManager.LocalClient.IsReady;
allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command(
"allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats)));
var startGameButton = lobby.Get<ButtonWidget>("START_GAME_BUTTON");
startGameButton.IsVisible = () => Game.IsHost;
startGameButton.IsDisabled = () => gameStarting;
startGameButton.OnClick = () =>
{
gameStarting = true;
orderManager.IssueOrder(Order.Command("startgame"));
};
bool teamChat = false;
var chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE");
var chatTextField = lobby.Get<TextFieldWidget>("CHAT_TEXTFIELD");
chatTextField.OnEnterKey = () =>
{
if (chatTextField.Text.Length == 0)
return true;
orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text));
chatTextField.Text = "";
return true;
};
chatTextField.OnTabKey = () =>
{
teamChat ^= true;
//.........这里部分代码省略.........
示例13: MainMenuLogic
public MainMenuLogic(Widget widget, World world)
{
rootMenu = widget;
rootMenu.Get<LabelWidget>("VERSION_LABEL").Text = Game.ModData.Manifest.Mod.Version;
// Menu buttons
var mainMenu = widget.Get("MAIN_MENU");
mainMenu.IsVisible = () => menuType == MenuType.Main;
mainMenu.Get<ButtonWidget>("SINGLEPLAYER_BUTTON").OnClick = () => menuType = MenuType.Singleplayer;
mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("SERVERBROWSER_PANEL", new WidgetArgs
{
{ "onStart", RemoveShellmapUI },
{ "onExit", () => menuType = MenuType.Main },
{ "directConnectHost", null },
{ "directConnectPort", 0 },
});
};
mainMenu.Get<ButtonWidget>("MODS_BUTTON").OnClick = () =>
{
Game.Settings.Game.PreviousMod = Game.ModData.Manifest.Mod.Id;
Game.InitializeMod("modchooser", null);
};
mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Main }
});
};
mainMenu.Get<ButtonWidget>("EXTRAS_BUTTON").OnClick = () => menuType = MenuType.Extras;
mainMenu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
// Singleplayer menu
var singleplayerMenu = widget.Get("SINGLEPLAYER_MENU");
singleplayerMenu.IsVisible = () => menuType == MenuType.Singleplayer;
var missionsButton = singleplayerMenu.Get<ButtonWidget>("MISSIONS_BUTTON");
missionsButton.OnClick = () =>
{
menuType = MenuType.None;
Game.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Singleplayer },
{ "onStart", RemoveShellmapUI }
});
};
var hasCampaign = Game.ModData.Manifest.Missions.Any();
var hasMissions = Game.ModData.MapCache
.Any(p => p.Status == MapStatus.Available && p.Map.Visibility.HasFlag(MapVisibility.MissionSelector));
missionsButton.Disabled = !hasCampaign && !hasMissions;
singleplayerMenu.Get<ButtonWidget>("SKIRMISH_BUTTON").OnClick = StartSkirmishGame;
singleplayerMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main;
// Extras menu
var extrasMenu = widget.Get("EXTRAS_MENU");
extrasMenu.IsVisible = () => menuType == MenuType.Extras;
extrasMenu.Get<ButtonWidget>("REPLAYS_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Extras },
{ "onStart", RemoveShellmapUI }
});
};
extrasMenu.Get<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Extras },
{ "world", world }
});
};
extrasMenu.Get<ButtonWidget>("MAP_EDITOR_BUTTON").OnClick = () => menuType = MenuType.MapEditor;
var assetBrowserButton = extrasMenu.GetOrNull<ButtonWidget>("ASSETBROWSER_BUTTON");
if (assetBrowserButton != null)
assetBrowserButton.OnClick = () =>
{
menuType = MenuType.None;
Game.OpenWindow("ASSETBROWSER_PANEL", new WidgetArgs
{
//.........这里部分代码省略.........
示例14: ObserverStatsLogic
public ObserverStatsLogic(World world, WorldRenderer worldRenderer, Widget widget, Action onExit)
{
this.world = world;
this.worldRenderer = worldRenderer;
players = world.Players.Where(p => !p.NonCombatant);
basicStatsHeaders = widget.Get<ContainerWidget>("BASIC_STATS_HEADERS");
economyStatsHeaders = widget.Get<ContainerWidget>("ECONOMY_STATS_HEADERS");
productionStatsHeaders = widget.Get<ContainerWidget>("PRODUCTION_STATS_HEADERS");
combatStatsHeaders = widget.Get<ContainerWidget>("COMBAT_STATS_HEADERS");
earnedThisMinuteGraphHeaders = widget.Get<ContainerWidget>("EARNED_THIS_MIN_GRAPH_HEADERS");
playerStatsPanel = widget.Get<ScrollPanelWidget>("PLAYER_STATS_PANEL");
playerStatsPanel.Layout = new GridLayout(playerStatsPanel);
basicPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("BASIC_PLAYER_TEMPLATE");
economyPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("ECONOMY_PLAYER_TEMPLATE");
productionPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("PRODUCTION_PLAYER_TEMPLATE");
combatPlayerTemplate = playerStatsPanel.Get<ScrollItemWidget>("COMBAT_PLAYER_TEMPLATE");
earnedThisMinuteGraphTemplate = playerStatsPanel.Get<ContainerWidget>("EARNED_THIS_MIN_GRAPH_TEMPLATE");
teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
statsDropDown = widget.Get<DropDownButtonWidget>("STATS_DROPDOWN");
statsDropDown.GetText = () => "Basic";
statsDropDown.OnMouseDown = _ =>
{
var options = new List<StatsDropDownOption>
{
new StatsDropDownOption
{
Title = "Basic",
IsSelected = () => basicStatsHeaders.Visible,
OnClick = () =>
{
ClearStats();
statsDropDown.GetText = () => "Basic";
DisplayStats(BasicStats);
}
},
new StatsDropDownOption
{
Title = "Economy",
IsSelected = () => economyStatsHeaders.Visible,
OnClick = () =>
{
ClearStats();
statsDropDown.GetText = () => "Economy";
DisplayStats(EconomyStats);
}
},
new StatsDropDownOption
{
Title = "Production",
IsSelected = () => productionStatsHeaders.Visible,
OnClick = () =>
{
ClearStats();
statsDropDown.GetText = () => "Production";
DisplayStats(ProductionStats);
}
},
new StatsDropDownOption
{
Title = "Combat",
IsSelected = () => combatStatsHeaders.Visible,
OnClick = () =>
{
ClearStats();
statsDropDown.GetText = () => "Combat";
DisplayStats(CombatStats);
}
},
new StatsDropDownOption
{
Title = "Earnings (graph)",
IsSelected = () => earnedThisMinuteGraphHeaders.Visible,
OnClick = () =>
{
ClearStats();
statsDropDown.GetText = () => "Earnings (graph)";
EarnedThisMinuteGraph();
}
}
};
Func<StatsDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
return item;
};
statsDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
};
ClearStats();
DisplayStats(BasicStats);
var close = widget.GetOrNull<ButtonWidget>("CLOSE");
if (close != null)
close.OnClick = () =>
//.........这里部分代码省略.........
示例15: MusicPlayerLogic
public MusicPlayerLogic(Widget widget, ModData modData, World world, Action onExit)
{
var panel = widget;
musicList = panel.Get<ScrollPanelWidget>("MUSIC_LIST");
itemTemplate = musicList.Get<ScrollItemWidget>("MUSIC_TEMPLATE");
musicPlaylist = world.WorldActor.Trait<MusicPlaylist>();
BuildMusicTable();
Func<bool> noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null;
panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable;
if (musicPlaylist.IsMusicAvailable)
{
panel.Get<LabelWidget>("MUTE_LABEL").GetText = () =>
{
if (Game.Settings.Sound.Mute)
return "Audio has been muted in settings.";
return "";
};
}
var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY");
playButton.OnClick = Play;
playButton.IsDisabled = noMusic;
playButton.IsVisible = () => !Game.Sound.MusicPlaying;
var pauseButton = panel.Get<ButtonWidget>("BUTTON_PAUSE");
pauseButton.OnClick = Game.Sound.PauseMusic;
pauseButton.IsDisabled = noMusic;
pauseButton.IsVisible = () => Game.Sound.MusicPlaying;
var stopButton = panel.Get<ButtonWidget>("BUTTON_STOP");
stopButton.OnClick = () => { musicPlaylist.Stop(); };
stopButton.IsDisabled = noMusic;
var nextButton = panel.Get<ButtonWidget>("BUTTON_NEXT");
nextButton.OnClick = () => { currentSong = musicPlaylist.GetNextSong(); Play(); };
nextButton.IsDisabled = noMusic;
var prevButton = panel.Get<ButtonWidget>("BUTTON_PREV");
prevButton.OnClick = () => { currentSong = musicPlaylist.GetPrevSong(); Play(); };
prevButton.IsDisabled = noMusic;
var shuffleCheckbox = panel.Get<CheckboxWidget>("SHUFFLE");
shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle;
shuffleCheckbox.OnClick = () => Game.Settings.Sound.Shuffle ^= true;
shuffleCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground;
var repeatCheckbox = panel.Get<CheckboxWidget>("REPEAT");
repeatCheckbox.IsChecked = () => Game.Settings.Sound.Repeat;
repeatCheckbox.OnClick = () => Game.Settings.Sound.Repeat ^= true;
repeatCheckbox.IsDisabled = () => musicPlaylist.CurrentSongIsBackground;
panel.Get<LabelWidget>("TIME_LABEL").GetText = () =>
{
if (currentSong == null || musicPlaylist.CurrentSongIsBackground)
return "";
var minutes = (int)Game.Sound.MusicSeekPosition / 60;
var seconds = (int)Game.Sound.MusicSeekPosition % 60;
var totalMinutes = currentSong.Length / 60;
var totalSeconds = currentSong.Length % 60;
return "{0:D2}:{1:D2} / {2:D2}:{3:D2}".F(minutes, seconds, totalMinutes, totalSeconds);
};
var musicTitle = panel.GetOrNull<LabelWidget>("TITLE_LABEL");
if (musicTitle != null)
musicTitle.GetText = () => currentSong != null ? currentSong.Title : "No song playing";
var musicSlider = panel.Get<SliderWidget>("MUSIC_SLIDER");
musicSlider.OnChange += x => Game.Sound.MusicVolume = x;
musicSlider.Value = Game.Sound.MusicVolume;
var songWatcher = widget.GetOrNull<LogicTickerWidget>("SONG_WATCHER");
if (songWatcher != null)
{
songWatcher.OnTick = () =>
{
if (musicPlaylist.CurrentSongIsBackground && currentSong != null)
currentSong = null;
if (Game.Sound.CurrentMusic == null || currentSong == Game.Sound.CurrentMusic || musicPlaylist.CurrentSongIsBackground)
return;
currentSong = Game.Sound.CurrentMusic;
};
}
var backButton = panel.GetOrNull<ButtonWidget>("BACK_BUTTON");
if (backButton != null)
backButton.OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); };
}