コード例 #1
0
		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();
			};
		}
コード例 #2
0
		void PlayVideo(VqaPlayerWidget player, string video, PlayingVideo pv, Action onComplete)
		{
			StopVideo(player);

			playingVideo = pv;
			player.Load(video);

			// video playback runs asynchronously
			player.PlayThen(onComplete);

			// Mute other distracting sounds
			MuteSounds();
		}
コード例 #3
0
		void StopVideo(VqaPlayerWidget player)
		{
			if (playingVideo == PlayingVideo.None)
				return;

			UnMuteSounds();
			player.Stop();
			playingVideo = PlayingVideo.None;
		}
コード例 #4
0
        bool LoadAsset(string filename)
        {
            if (isVideoLoaded)
            {
                player.Stop();
                player = null;
                isVideoLoaded = false;
            }

            if (string.IsNullOrEmpty(filename))
                return false;

            if (!GlobalFileSystem.Exists(filename))
                return false;

            if (Path.GetExtension(filename) == ".vqa")
            {
                player = panel.Get<VqaPlayerWidget>("PLAYER");
                currentFilename = filename;
                player.Load(filename);
                isVideoLoaded = true;
                frameSlider.MaximumValue = (float)player.Video.Frames - 1;
                frameSlider.Ticks = 0;
            }
            else
            {
                currentFilename = filename;
                currentSprites = world.Map.SequenceProvider.SpriteCache[filename];
                currentFrame = 0;
                frameSlider.MaximumValue = (float)currentSprites.Length - 1;
                frameSlider.Ticks = currentSprites.Length;
            }

            return true;
        }
コード例 #5
0
ファイル: MissionBrowserLogic.cs プロジェクト: pchote/OpenRA
        public MissionBrowserLogic(Widget widget, ModData modData, World world, Action onStart, Action onExit)
        {
            this.modData = modData;
            this.onStart = onStart;
            Game.BeforeGameStart += OnGameStart;

            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 ? selectedMap.Title : title.Text;

            widget.Get("MISSION_INFO").IsVisible = () => selectedMap != null;

            var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW");
            previewWidget.Preview = () => selectedMap;
            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 allPreviews = new List<MapPreview>();
            missionList.RemoveChildren();

            // Add a group for each campaign
            if (modData.Manifest.Missions.Any())
            {
                var yaml = MiniYaml.Merge(modData.Manifest.Missions.Select(
                    m => MiniYaml.FromStream(modData.DefaultFileSystem.Open(m), m)));

                foreach (var kv in yaml)
                {
                    var missionMapPaths = kv.Value.Nodes.Select(n => Path.GetFullPath(n.Key)).ToList();

                    var previews = modData.MapCache
                        .Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(p.Package.Name))
                        .OrderBy(p => missionMapPaths.IndexOf(p.Package.Name));

                    CreateMissionGroup(kv.Key, previews);
                    allPreviews.AddRange(previews);
                }
            }

            // Add an additional group for loose missions
            var loosePreviews = modData.MapCache
                .Where(p => p.Status == MapStatus.Available && p.Visibility.HasFlag(MapVisibility.MissionSelector) && !allPreviews.Any(a => a.Uid == p.Uid));

            if (loosePreviews.Any())
            {
                CreateMissionGroup("Missions", loosePreviews);
                allPreviews.AddRange(loosePreviews);
            }

            if (allPreviews.Any())
                SelectMap(allPreviews.First());

            // Preload map preview and rules to reduce jank
            new Thread(() =>
            {
                foreach (var p in allPreviews)
                {
                    p.GetMinimap();
                    p.PreloadRules();
                }
            }).Start();

            var startButton = widget.Get<ButtonWidget>("STARTGAME_BUTTON");
            startButton.OnClick = StartMissionClicked;
            startButton.IsDisabled = () => selectedMap == null || selectedMap.InvalidCustomRules;

            widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
            {
                StopVideo(videoPlayer);
                Game.Disconnect();
                Ui.CloseWindow();
                onExit();
            };
        }
コード例 #6
0
ファイル: MissionBrowserLogic.cs プロジェクト: pchote/OpenRA
        void PlayVideo(VqaPlayerWidget player, string video, PlayingVideo pv, Action onComplete = null)
        {
            if (!modData.DefaultFileSystem.Exists(video))
            {
                ConfirmationDialogs.ButtonPrompt(
                    title: "Video not installed",
                    text: "The game videos can be installed from the\n\"Manage Content\" menu in the mod chooser.",
                    cancelText: "Back",
                    onCancel: () => { });
            }
            else
            {
                StopVideo(player);

                playingVideo = pv;
                player.Load(video);

                // video playback runs asynchronously
                player.PlayThen(() =>
                {
                    StopVideo(player);
                    if (onComplete != null)
                        onComplete();
                });

                // Mute other distracting sounds
                MuteSounds();
            }
        }
コード例 #7
0
        public MissionBrowserLogic(Widget widget, 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 = () => showVideoPlayer ? selectedMapPreview.Title : title.Text;

            widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null;

            var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW");
            previewWidget.Preview = () => selectedMapPreview;
            previewWidget.IsVisible = () => !showVideoPlayer;

            videoPlayer = widget.Get<VqaPlayerWidget>("MISSION_VIDEO");
            widget.Get("MISSION_BIN").IsVisible = () => showVideoPlayer;

            descriptionPanel = widget.Get<ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL");

            description = descriptionPanel.Get<LabelWidget>("MISSION_DESCRIPTION");
            descriptionFont = Game.Renderer.Fonts[description.Font];

            startVideoButton = widget.Get<ButtonWidget>("START_VIDEO_BUTTON");
            stopVideoButton = widget.Get<ButtonWidget>("STOP_VIDEO_BUTTON");
            stopVideoButton.IsVisible = () => showVideoPlayer;
            stopVideoButton.OnClick = StopVideo;

            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
            // Loose missions must define Type: Mission and Selectable: false.
            var looseMissions = Game.modData.MapCache
                .Where(p => p.Status == MapStatus.Available && p.Map.Type == "Mission" && !p.Map.Selectable && !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 = StartMission;
            startButton.IsDisabled = () => selectedMapPreview.RuleStatus != MapRuleStatus.Cached;

            widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
            {
                StopVideo();
                Game.Disconnect();
                Ui.CloseWindow();
                onExit();
            };
        }
コード例 #8
0
ファイル: AssetBrowserLogic.cs プロジェクト: pchote/OpenRA
        bool LoadAsset(string filename)
        {
            if (isVideoLoaded)
            {
                player.Stop();
                player = null;
                isVideoLoaded = false;
            }

            if (string.IsNullOrEmpty(filename))
                return false;

            if (!modData.DefaultFileSystem.Exists(filename))
                return false;

            errorLabelWidget.Visible = false;

            try
            {
                if (Path.GetExtension(filename.ToLowerInvariant()) == ".vqa")
                {
                    player = panel.Get<VqaPlayerWidget>("PLAYER");
                    currentFilename = filename;
                    player.Load(filename);
                    player.DrawOverlay = false;
                    isVideoLoaded = true;
                    frameSlider.MaximumValue = (float)player.Video.Frames - 1;
                    frameSlider.Ticks = 0;
                    return true;
                }

                currentFilename = filename;
                currentSprites = world.Map.Rules.Sequences.SpriteCache[filename];
                currentFrame = 0;
                frameSlider.MaximumValue = (float)currentSprites.Length - 1;
                frameSlider.Ticks = currentSprites.Length;
            }
            catch (Exception ex)
            {
                if (errorLabelWidget != null)
                {
                    errorLabelWidget.Text = WidgetUtils.TruncateText(errorLabelWidget.Text.Replace("{filename}", filename),
                        errorLabelWidget.Bounds.Width, errorFont);

                    currentSprites = new Sprite[0];
                    errorLabelWidget.Visible = true;
                }

                Log.AddChannel("assetbrowser", "assetbrowser.log");
                Log.Write("assetbrowser", "Error reading {0}:{3} {1}{3}{2}", filename, ex.Message, ex.StackTrace, Environment.NewLine);

                return false;
            }

            return true;
        }