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()); }
protected ScrollItemWidget(ScrollItemWidget other) : base(other) { IsVisible = () => false; VisualHeight = 0; IgnoreChildMouseOver = true; }
public static ScrollItemWidget Setup(string key, ScrollItemWidget template, Func<bool> isSelected, Action onClick, Action onDoubleClick) { var w = Setup(template, isSelected, onClick); w.OnDoubleClick = onDoubleClick; w.ItemKey = key; return w; }
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; }
public ServerBrowserLogic(Widget widget, Action onStart, Action onExit) { panel = widget; this.onStart = onStart; serverList = panel.Get<ScrollPanelWidget>("SERVER_LIST"); serverTemplate = serverList.Get<ScrollItemWidget>("SERVER_TEMPLATE"); // Menu buttons var refreshButton = panel.Get<ButtonWidget>("REFRESH_BUTTON"); refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching; refreshButton.GetText = () => searchStatus == SearchStatus.Fetching ? "Refreshing..." : "Refresh"; refreshButton.OnClick = RefreshServerList; panel.Get<ButtonWidget>("DIRECTCONNECT_BUTTON").OnClick = OpenDirectConnectPanel; panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = OpenCreateServerPanel; var join = panel.Get<ButtonWidget>("JOIN_BUTTON"); join.IsDisabled = () => currentServer == null || !currentServer.CanJoin(); join.OnClick = () => Join(currentServer); panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; // Display the progress label over the server list // The text is only visible when the list is empty var progressText = panel.Get<LabelWidget>("PROGRESS_LABEL"); progressText.IsVisible = () => searchStatus != SearchStatus.Hidden; progressText.GetText = ProgressLabelText; var showWaitingCheckbox = panel.GetOrNull<CheckboxWidget>("WAITING_FOR_PLAYERS"); if (showWaitingCheckbox != null) { showWaitingCheckbox.IsChecked = () => showWaiting; showWaitingCheckbox.OnClick = () => { showWaiting ^= true; RefreshServerList(); }; } var showEmptyCheckbox = panel.GetOrNull<CheckboxWidget>("EMPTY"); if (showEmptyCheckbox != null) { showEmptyCheckbox.IsChecked = () => showEmpty; showEmptyCheckbox.OnClick = () => { showEmpty ^= true; RefreshServerList(); }; } var showAlreadyStartedCheckbox = panel.GetOrNull<CheckboxWidget>("ALREADY_STARTED"); if (showAlreadyStartedCheckbox != null) { showAlreadyStartedCheckbox.IsChecked = () => showStarted; showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; RefreshServerList(); }; } var showIncompatibleCheckbox = panel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION"); if (showIncompatibleCheckbox != null) { showIncompatibleCheckbox.IsChecked = () => showIncompatible; showIncompatibleCheckbox.OnClick = () => { showIncompatible ^= true; RefreshServerList(); }; } // Game.LoadWidget(null, "SERVERBROWSER_IRC", panel.Get("IRC_ROOT"), new WidgetArgs()); RefreshServerList(); }
public static ScrollItemWidget Setup(ScrollItemWidget template, Func<bool> isSelected, Action onClick) { var w = template.Clone() as ScrollItemWidget; w.IsVisible = () => true; w.IsSelected = isSelected; w.OnClick = onClick; return w; }
public CncServerBrowserLogic([ObjectCreator.Param] Widget widget, [ObjectCreator.Param] Action openLobby, [ObjectCreator.Param] Action onExit) { var panel = widget.GetWidget("SERVERBROWSER_PANEL"); var sl = panel.GetWidget<ScrollPanelWidget>("SERVER_LIST"); // Menu buttons var refreshButton = panel.GetWidget<ButtonWidget>("REFRESH_BUTTON"); refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching; refreshButton.OnClick = () => { searchStatus = SearchStatus.Fetching; sl.RemoveChildren(); currentServer = null; ServerList.Query(games => RefreshServerList(panel, games)); }; var join = panel.GetWidget<ButtonWidget>("JOIN_BUTTON"); join.IsDisabled = () => currentServer == null || !currentServer.CanJoin(); join.OnClick = () => { if (currentServer == null) return; var host = currentServer.Address.Split(':')[0]; var port = int.Parse(currentServer.Address.Split(':')[1]); Widget.CloseWindow(); CncConnectingLogic.Connect(host, port, openLobby, onExit); }; panel.GetWidget<ButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); }; // Server list serverTemplate = sl.GetWidget<ScrollItemWidget>("SERVER_TEMPLATE"); // Display the progress label over the server list // The text is only visible when the list is empty var progressText = panel.GetWidget<LabelWidget>("PROGRESS_LABEL"); progressText.IsVisible = () => searchStatus != SearchStatus.Hidden; progressText.GetText = ProgressLabelText; // Map preview var preview = panel.GetWidget<MapPreviewWidget>("MAP_PREVIEW"); preview.Map = () => CurrentMap(); preview.IsVisible = () => CurrentMap() != null; // Server info var infoPanel = panel.GetWidget("SERVER_INFO"); infoPanel.IsVisible = () => currentServer != null; infoPanel.GetWidget<LabelWidget>("SERVER_IP").GetText = () => currentServer.Address; infoPanel.GetWidget<LabelWidget>("SERVER_MODS").GetText = () => ServerBrowserLogic.GenerateModsLabel(currentServer); infoPanel.GetWidget<LabelWidget>("MAP_TITLE").GetText = () => (CurrentMap() != null) ? CurrentMap().Title : "Unknown"; infoPanel.GetWidget<LabelWidget>("MAP_PLAYERS").GetText = () => GetPlayersLabel(currentServer); ServerList.Query(games => RefreshServerList(panel, games)); }
public ServerBrowserLogic(Widget widget, Action openLobby, Action onExit) { var panel = widget; OpenLobby = openLobby; OnExit = onExit; var sl = panel.Get<ScrollPanelWidget>("SERVER_LIST"); // Menu buttons var refreshButton = panel.Get<ButtonWidget>("REFRESH_BUTTON"); refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching; refreshButton.OnClick = () => ServerList.Query(games => RefreshServerList(panel, games)); var join = panel.Get<ButtonWidget>("JOIN_BUTTON"); join.IsDisabled = () => currentServer == null || !currentServer.CanJoin(); join.OnClick = () => Join(currentServer); panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; // Server list serverTemplate = sl.Get<ScrollItemWidget>("SERVER_TEMPLATE"); // Display the progress label over the server list // The text is only visible when the list is empty var progressText = panel.Get<LabelWidget>("PROGRESS_LABEL"); progressText.IsVisible = () => searchStatus != SearchStatus.Hidden; progressText.GetText = ProgressLabelText; var showWaitingCheckbox = panel.GetOrNull<CheckboxWidget>("WAITING_FOR_PLAYERS"); if (showWaitingCheckbox != null) { showWaitingCheckbox.IsChecked = () => showWaiting; showWaitingCheckbox.OnClick = () => { showWaiting ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; } var showEmptyCheckbox = panel.GetOrNull<CheckboxWidget>("EMPTY"); if (showEmptyCheckbox != null) { showEmptyCheckbox.IsChecked = () => showEmpty; showEmptyCheckbox.OnClick = () => { showEmpty ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; } var showAlreadyStartedCheckbox = panel.GetOrNull<CheckboxWidget>("ALREADY_STARTED"); if (showAlreadyStartedCheckbox != null) { showAlreadyStartedCheckbox.IsChecked = () => showStarted; showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; } var showIncompatibleCheckbox = panel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION"); if (showIncompatibleCheckbox != null) { showIncompatibleCheckbox.IsChecked = () => showIncompatible; showIncompatibleCheckbox.OnClick = () => { showIncompatible ^= true; ServerList.Query(games => RefreshServerList(panel, games)); }; } ServerList.Query(games => RefreshServerList(panel, games)); }
void AddReplay(ScrollPanelWidget list, string filename, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, () => currentReplay != null && currentReplay.Filename == filename, () => SelectReplay(filename)); var f = Path.GetFileName(filename); item.Get<LabelWidget>("TITLE").GetText = () => f; list.AddChild(item); }
public ReplayBrowserLogic(Widget widget, ModData modData, Action onExit, Action onStart) { panel = widget; this.modData = modData; this.onStart = onStart; Game.BeforeGameStart += OnGameStart; playerList = panel.Get<ScrollPanelWidget>("PLAYER_LIST"); playerHeader = playerList.Get<ScrollItemWidget>("HEADER"); playerTemplate = playerList.Get<ScrollItemWidget>("TEMPLATE"); playerList.RemoveChildren(); panel.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => { cancelLoadingReplays = true; Ui.CloseWindow(); onExit(); }; replayList = panel.Get<ScrollPanelWidget>("REPLAY_LIST"); var template = panel.Get<ScrollItemWidget>("REPLAY_TEMPLATE"); var mod = modData.Manifest; var dir = Platform.ResolvePath("^", "Replays", mod.Id, mod.Metadata.Version); if (Directory.Exists(dir)) ThreadPool.QueueUserWorkItem(_ => LoadReplays(dir, template)); var watch = panel.Get<ButtonWidget>("WATCH_BUTTON"); watch.IsDisabled = () => selectedReplay == null || selectedReplay.GameInfo.MapPreview.Status != MapStatus.Available; watch.OnClick = () => { WatchReplay(); }; panel.Get("REPLAY_INFO").IsVisible = () => selectedReplay != null; var preview = panel.Get<MapPreviewWidget>("MAP_PREVIEW"); preview.SpawnOccupants = () => selectedSpawns; preview.Preview = () => selectedReplay != null ? selectedReplay.GameInfo.MapPreview : null; var titleLabel = panel.GetOrNull<LabelWidget>("MAP_TITLE"); if (titleLabel != null) { titleLabel.IsVisible = () => selectedReplay != null; var font = Game.Renderer.Fonts[titleLabel.Font]; var title = new CachedTransform<MapPreview, string>(m => WidgetUtils.TruncateText(m.Title, titleLabel.Bounds.Width, font)); titleLabel.GetText = () => title.Update(selectedReplay.GameInfo.MapPreview); } var type = panel.GetOrNull<LabelWidget>("MAP_TYPE"); if (type != null) { var mapType = new CachedTransform<MapPreview, string>(m => m.Categories.FirstOrDefault() ?? ""); type.GetText = () => mapType.Update(selectedReplay.GameInfo.MapPreview); } panel.Get<LabelWidget>("DURATION").GetText = () => WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds); SetupFilters(); SetupManagement(); }
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); }
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; }
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(); }; }
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); }
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(); }
internal MapChooserLogic([ObjectCreator.Param] Widget widget, [ObjectCreator.Param] string initialMap, [ObjectCreator.Param] Action onExit, [ObjectCreator.Param] Action<Map> onSelect) { map = Game.modData.AvailableMaps[WidgetUtils.ChooseInitialMap(initialMap)]; widget.GetWidget<ButtonWidget>("BUTTON_OK").OnClick = () => { Widget.CloseWindow(); onSelect(map); }; widget.GetWidget<ButtonWidget>("BUTTON_CANCEL").OnClick = () => { Widget.CloseWindow(); onExit(); }; scrollpanel = widget.GetWidget<ScrollPanelWidget>("MAP_LIST"); itemTemplate = scrollpanel.GetWidget<ScrollItemWidget>("MAP_TEMPLATE"); var gameModeDropdown = widget.GetWidget<DropDownButtonWidget>("GAMEMODE_FILTER"); if (gameModeDropdown != null) { var selectableMaps = Game.modData.AvailableMaps.Where(m => m.Value.Selectable); 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(); }); item.GetWidget<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)); } EnumerateMaps(); }
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; }
public ServerBrowserLogic(Widget widget, Action openLobby, Action onExit) { var panel = widget; var sl = panel.GetWidget<ScrollPanelWidget>("SERVER_LIST"); // Menu buttons var refreshButton = panel.GetWidget<ButtonWidget>("REFRESH_BUTTON"); refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching; refreshButton.OnClick = () => { searchStatus = SearchStatus.Fetching; sl.RemoveChildren(); currentServer = null; ServerList.Query(games => RefreshServerList(panel, games)); }; var join = panel.GetWidget<ButtonWidget>("JOIN_BUTTON"); join.IsDisabled = () => currentServer == null || !currentServer.CanJoin(); join.OnClick = () => { if (currentServer == null) return; var host = currentServer.Address.Split(':')[0]; var port = int.Parse(currentServer.Address.Split(':')[1]); Ui.CloseWindow(); ConnectionLogic.Connect(host, port, openLobby, onExit); }; panel.GetWidget<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; // Server list serverTemplate = sl.GetWidget<ScrollItemWidget>("SERVER_TEMPLATE"); // Display the progress label over the server list // The text is only visible when the list is empty var progressText = panel.GetWidget<LabelWidget>("PROGRESS_LABEL"); progressText.IsVisible = () => searchStatus != SearchStatus.Hidden; progressText.GetText = ProgressLabelText; ServerList.Query(games => RefreshServerList(panel, games)); }
ScrollItemWidget SetupPlayerScrollItemWidget(ScrollItemWidget template, Player player) { return ScrollItemWidget.Setup(template, () => false, () => { var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead && a.Info.HasTraitInfo<BaseBuildingInfo>() && a.Owner == player); if (playerBase != null) worldRenderer.Viewport.Center(playerBase.CenterPosition); }); }
public MissionBrowserLogic(Widget widget, World world, Action onStart, Action onExit) { this.onStart = onStart; missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST"); headerTemplate = widget.Get<ScrollItemWidget>("HEADER"); template = widget.Get<ScrollItemWidget>("TEMPLATE"); var title = widget.GetOrNull<LabelWidget>("MISSIONBROWSER_TITLE"); if (title != null) title.GetText = () => playingVideo != PlayingVideo.None ? selectedMapPreview.Title : title.Text; widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null; var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW"); previewWidget.Preview = () => selectedMapPreview; previewWidget.IsVisible = () => playingVideo == PlayingVideo.None; videoPlayer = widget.Get<VqaPlayerWidget>("MISSION_VIDEO"); widget.Get("MISSION_BIN").IsVisible = () => playingVideo != PlayingVideo.None; fullscreenVideoPlayer = Ui.LoadWidget<BackgroundWidget>("FULLSCREEN_PLAYER", Ui.Root, new WidgetArgs { { "world", world } }); descriptionPanel = widget.Get<ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL"); description = descriptionPanel.Get<LabelWidget>("MISSION_DESCRIPTION"); descriptionFont = Game.Renderer.Fonts[description.Font]; difficultyButton = widget.Get<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON"); gameSpeedButton = widget.GetOrNull<DropDownButtonWidget>("GAMESPEED_DROPDOWNBUTTON"); startBriefingVideoButton = widget.Get<ButtonWidget>("START_BRIEFING_VIDEO_BUTTON"); stopBriefingVideoButton = widget.Get<ButtonWidget>("STOP_BRIEFING_VIDEO_BUTTON"); stopBriefingVideoButton.IsVisible = () => playingVideo == PlayingVideo.Briefing; stopBriefingVideoButton.OnClick = () => StopVideo(videoPlayer); startInfoVideoButton = widget.Get<ButtonWidget>("START_INFO_VIDEO_BUTTON"); stopInfoVideoButton = widget.Get<ButtonWidget>("STOP_INFO_VIDEO_BUTTON"); stopInfoVideoButton.IsVisible = () => playingVideo == PlayingVideo.Info; stopInfoVideoButton.OnClick = () => StopVideo(videoPlayer); var allMaps = new List<Map>(); missionList.RemoveChildren(); // Add a group for each campaign if (Game.ModData.Manifest.Missions.Any()) { var yaml = Game.ModData.Manifest.Missions.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal); foreach (var kv in yaml) { var missionMapPaths = kv.Value.Nodes.Select(n => Path.GetFullPath(n.Key)); var maps = Game.ModData.MapCache .Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(Path.GetFullPath(p.Map.Path))) .Select(p => p.Map); CreateMissionGroup(kv.Key, maps); allMaps.AddRange(maps); } } // Add an additional group for loose missions var looseMissions = Game.ModData.MapCache .Where(p => p.Status == MapStatus.Available && p.Map.Visibility.HasFlag(MapVisibility.MissionSelector) && !allMaps.Contains(p.Map)) .Select(p => p.Map); if (looseMissions.Any()) { CreateMissionGroup("Missions", looseMissions); allMaps.AddRange(looseMissions); } if (allMaps.Any()) SelectMap(allMaps.First()); var startButton = widget.Get<ButtonWidget>("STARTGAME_BUTTON"); startButton.OnClick = StartMissionClicked; startButton.IsDisabled = () => selectedMapPreview == null || selectedMapPreview.RuleStatus != MapRuleStatus.Cached; widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { StopVideo(videoPlayer); Game.Disconnect(); Ui.CloseWindow(); onExit(); }; }
public ServerBrowserLogic(Widget widget, Action onStart, Action onExit, string directConnectHost, int directConnectPort) { panel = widget; this.onStart = onStart; incompatibleGameColor = ChromeMetrics.Get<Color>("IncompatibleGameColor"); cantJoinGameColor = ChromeMetrics.Get<Color>("CantJoinGameColor"); protectedGameColor = ChromeMetrics.Get<Color>("ProtectedGameColor"); incompatibleProtectedGameColor = ChromeMetrics.Get<Color>("IncompatibleProtectedGameColor"); waitingGameColor = ChromeMetrics.Get<Color>("WaitingGameColor"); incompatibleWaitingGameColor = ChromeMetrics.Get<Color>("IncompatibleWaitingGameColor"); gameStartedColor = ChromeMetrics.Get<Color>("GameStartedColor"); incompatibleGameStartedColor = ChromeMetrics.Get<Color>("IncompatibleGameStartedColor"); serverList = panel.Get<ScrollPanelWidget>("SERVER_LIST"); headerTemplate = serverList.Get<ScrollItemWidget>("HEADER_TEMPLATE"); serverTemplate = serverList.Get<ScrollItemWidget>("SERVER_TEMPLATE"); // Menu buttons var refreshButton = panel.Get<ButtonWidget>("REFRESH_BUTTON"); refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching; refreshButton.GetText = () => searchStatus == SearchStatus.Fetching ? "Refreshing..." : "Refresh"; refreshButton.OnClick = RefreshServerList; panel.Get<ButtonWidget>("DIRECTCONNECT_BUTTON").OnClick = OpenDirectConnectPanel; panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = OpenCreateServerPanel; var join = panel.Get<ButtonWidget>("JOIN_BUTTON"); join.IsDisabled = () => currentServer == null || !currentServer.IsJoinable; join.OnClick = () => Join(currentServer); panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; // Display the progress label over the server list // The text is only visible when the list is empty var progressText = panel.Get<LabelWidget>("PROGRESS_LABEL"); progressText.IsVisible = () => searchStatus != SearchStatus.Hidden; progressText.GetText = ProgressLabelText; var showWaitingCheckbox = panel.GetOrNull<CheckboxWidget>("WAITING_FOR_PLAYERS"); if (showWaitingCheckbox != null) { showWaitingCheckbox.IsChecked = () => showWaiting; showWaitingCheckbox.OnClick = () => { showWaiting ^= true; RefreshServerList(); }; } var showEmptyCheckbox = panel.GetOrNull<CheckboxWidget>("EMPTY"); if (showEmptyCheckbox != null) { showEmptyCheckbox.IsChecked = () => showEmpty; showEmptyCheckbox.OnClick = () => { showEmpty ^= true; RefreshServerList(); }; } var showAlreadyStartedCheckbox = panel.GetOrNull<CheckboxWidget>("ALREADY_STARTED"); if (showAlreadyStartedCheckbox != null) { showAlreadyStartedCheckbox.IsChecked = () => showStarted; showAlreadyStartedCheckbox.OnClick = () => { showStarted ^= true; RefreshServerList(); }; } var showProtectedCheckbox = panel.GetOrNull<CheckboxWidget>("PASSWORD_PROTECTED"); if (showProtectedCheckbox != null) { showProtectedCheckbox.IsChecked = () => showProtected; showProtectedCheckbox.OnClick = () => { showProtected ^= true; RefreshServerList(); }; } var showIncompatibleCheckbox = panel.GetOrNull<CheckboxWidget>("INCOMPATIBLE_VERSION"); if (showIncompatibleCheckbox != null) { showIncompatibleCheckbox.IsChecked = () => showIncompatible; showIncompatibleCheckbox.OnClick = () => { showIncompatible ^= true; RefreshServerList(); }; } 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; }); } }
ScrollItemWidget SetupPlayerScrollItemWidget(ScrollItemWidget template, Player player) { return ScrollItemWidget.Setup(template, () => false, () => { var playerBase = world.Actors.FirstOrDefault(a => !a.IsDead() && a.HasTrait<BaseBuilding>() && a.Owner == player); if (playerBase != null) { Game.MoveViewport(playerBase.Location.ToFloat2()); } }); }
void SetupMapTab(MapClassification tab, MapVisibility filter, string tabButtonName, string tabContainerName, ScrollItemWidget itemTemplate) { var tabContainer = widget.Get<ContainerWidget>(tabContainerName); tabContainer.IsVisible = () => currentTab == tab; var tabScrollpanel = tabContainer.Get<ScrollPanelWidget>("MAP_LIST"); tabScrollpanel.Layout = new GridLayout(tabScrollpanel); scrollpanels.Add(tab, tabScrollpanel); var tabButton = widget.Get<ButtonWidget>(tabButtonName); tabButton.IsHighlighted = () => currentTab == tab; tabButton.IsVisible = () => tabMaps[tab].Any(); tabButton.OnClick = () => SwitchTab(tab, itemTemplate); RefreshMaps(tab, filter); }
void SetupGameModeDropdown(MapClassification tab, DropDownButtonWidget gameModeDropdown, ScrollItemWidget itemTemplate) { if (gameModeDropdown != null) { var gameModes = tabMaps[tab] .GroupBy(m => m.Type) .Select(g => Pair.New(g.Key, g.Count())).ToList(); // 'all game types' extra item gameModes.Insert(0, Pair.New(null as string, tabMaps[tab].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(tab, itemTemplate); }); item.Get<LabelWidget>("LABEL").GetText = () => showItem(ii); return item; }; gameModeDropdown.OnClick = () => gameModeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, gameModes, setupItem); gameModeDropdown.GetText = () => { var item = gameModes.FirstOrDefault(m => m.First == gameMode); if (item == default(Pair<string, int>)) item.First = "No matches"; return showItem(item); }; } }
void EnumerateMaps(MapClassification tab, ScrollItemWidget template) { var maps = tabMaps[tab] .Where(m => gameMode == null || m.Type == gameMode) .Where(m => mapFilter == null || m.Title.IndexOf(mapFilter, StringComparison.OrdinalIgnoreCase) >= 0 || m.Author.IndexOf(mapFilter, StringComparison.OrdinalIgnoreCase) >= 0) .OrderBy(m => m.PlayerCount) .ThenBy(m => m.Title); scrollpanels[tab].RemoveChildren(); foreach (var loop in maps) { var preview = loop; // Access the minimap to trigger async generation of the minimap. preview.GetMinimap(); Action dblClick = () => { if (onSelect != null) { Ui.CloseWindow(); onSelect(preview.Uid); } }; var item = ScrollItemWidget.Setup(preview.Uid, template, () => selectedUid == preview.Uid, () => selectedUid = preview.Uid, dblClick); item.IsVisible = () => item.RenderBounds.IntersectsWith(scrollpanels[tab].RenderBounds); var titleLabel = item.Get<LabelWidget>("TITLE"); titleLabel.GetText = () => preview.Title; var previewWidget = item.Get<MapPreviewWidget>("PREVIEW"); previewWidget.Preview = () => preview; var detailsWidget = item.GetOrNull<LabelWidget>("DETAILS"); if (detailsWidget != null) detailsWidget.GetText = () => "{0} ({1} players)".F(preview.Type, preview.PlayerCount); var authorWidget = item.GetOrNull<LabelWidget>("AUTHOR"); if (authorWidget != null) authorWidget.GetText = () => "Created by {0}".F(preview.Author); var sizeWidget = item.GetOrNull<LabelWidget>("SIZE"); if (sizeWidget != null) { var size = preview.Bounds.Width + "x" + preview.Bounds.Height; var numberPlayableCells = preview.Bounds.Width * preview.Bounds.Height; if (numberPlayableCells >= 120 * 120) size += " (Huge)"; else if (numberPlayableCells >= 90 * 90) size += " (Large)"; else if (numberPlayableCells >= 60 * 60) size += " (Medium)"; else size += " (Small)"; sizeWidget.GetText = () => size; } scrollpanels[tab].AddChild(item); } if (tab == currentTab) { visibleMaps = maps.Select(m => m.Uid).ToArray(); SetupGameModeDropdown(currentTab, gameModeDropdown, template); } if (visibleMaps.Contains(selectedUid)) scrollpanels[tab].ScrollToItem(selectedUid); }
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 = () => { Ui.CloseWindow(); Ui.Root.RemoveChild(widget); onExit(); }; }
public MusicPlayerLogic(Widget widget, Ruleset modRules, World world, Action onExit) { var panel = widget.Get("MUSIC_PANEL"); musicList = panel.Get<ScrollPanelWidget>("MUSIC_LIST"); itemTemplate = musicList.Get<ScrollItemWidget>("MUSIC_TEMPLATE"); musicPlaylist = world.WorldActor.Trait<MusicPlaylist>(); BuildMusicTable(); Func<bool> noMusic = () => !musicPlaylist.IsMusicAvailable; 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 = () => { 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; 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; var installButton = widget.GetOrNull<ButtonWidget>("INSTALL_BUTTON"); if (installButton != null) { installButton.IsDisabled = () => world == null || world.Type != WorldType.Shellmap; var args = new string[] { "Install.Music=true" }; installButton.OnClick = () => Game.RunAfterTick(() => Game.InitializeMod(Game.Settings.Game.Mod, new Arguments(args))); var installData = Game.ModData.Manifest.Get<ContentInstaller>(); installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length <= installData.ShippedSoundtracks; } var songWatcher = widget.GetOrNull<LogicTickerWidget>("SONG_WATCHER"); if (songWatcher != null) { songWatcher.OnTick = () => { if (Sound.CurrentMusic == null || currentSong == Sound.CurrentMusic) return; currentSong = Sound.CurrentMusic; }; } panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); }; }
void SwitchTab(MapClassification tab, ScrollItemWidget itemTemplate) { currentTab = tab; EnumerateMaps(tab, itemTemplate); }
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; }; }
public CncMusicPlayerLogic(Widget widget, Action onExit) { panel = widget.Get("MUSIC_PANEL"); var ml = panel.Get<ScrollPanelWidget>("MUSIC_LIST"); itemTemplate = ml.Get<ScrollItemWidget>("MUSIC_TEMPLATE"); BuildMusicTable(ml); currentSong = Sound.CurrentMusic ?? GetNextSong(); installed = Rules.Music.Where(m => m.Value.Exists).Any(); Func<bool> noMusic = () => !installed; panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); }; Action afterInstall = () => { // Mount the new mixfile and rebuild the scores list try { var path = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine); FileSystem.Mount(Path.Combine(path, "scores.mix")); FileSystem.Mount(Path.Combine(path, "transit.mix")); Rules.Music.Do(m => m.Value.Reload()); } catch (Exception) { } installed = Rules.Music.Where(m => m.Value.Exists).Any(); BuildMusicTable(ml); }; var installButton = panel.Get<ButtonWidget>("INSTALL_BUTTON"); installButton.OnClick = () => Ui.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs() { { "afterInstall", afterInstall }, { "filesToCopy", new [] { "SCORES.MIX" } }, { "filesToExtract", new [] { "transit.mix" } }, }); installButton.IsVisible = () => music.Length < 3; // Hack around music being split between transit.mix and scores.mix panel.Get("NO_MUSIC_LABEL").IsVisible = noMusic; var playButton = panel.Get<ButtonWidget>("BUTTON_PLAY"); playButton.OnClick = Play; playButton.IsDisabled = noMusic; var pauseButton = panel.Get<ButtonWidget>("BUTTON_PAUSE"); pauseButton.OnClick = Pause; pauseButton.IsDisabled = noMusic; var stopButton = panel.Get<ButtonWidget>("BUTTON_STOP"); stopButton.OnClick = Stop; 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); panel.Get<LabelWidget>("TITLE_LABEL").GetText = () => (currentSong == null) ? "" : currentSong.Title; var musicSlider = panel.Get<SliderWidget>("MUSIC_SLIDER"); musicSlider.OnChange += x => Sound.MusicVolume = x; musicSlider.Value = Sound.MusicVolume; }