当前位置: 首页>>代码示例>>C#>>正文


C# Widget.GetOrNull方法代码示例

本文整理汇总了C#中OpenRA.Widgets.Widget.GetOrNull方法的典型用法代码示例。如果您正苦于以下问题:C# Widget.GetOrNull方法的具体用法?C# Widget.GetOrNull怎么用?C# Widget.GetOrNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenRA.Widgets.Widget的用法示例。


在下文中一共展示了Widget.GetOrNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GameTimerLogic

		public GameTimerLogic(Widget widget, OrderManager orderManager, World world)
		{
			var timer = widget.GetOrNull<LabelWidget>("GAME_TIMER");
			if (timer != null)
				timer.GetText = () => WidgetUtils.FormatTime(world.WorldTick);

			var status = widget.GetOrNull<LabelWidget>("GAME_TIMER_STATUS");
			if (status != null)
			{
				var startTick = Ui.LastTickTime;
				// Blink the status line
				status.IsVisible = () => (world.Paused || world.Timestep != Game.Timestep)
					&& (Ui.LastTickTime - startTick) / 1000 % 2 == 0;

				status.GetText = () =>
				{
					if (world.Paused || world.Timestep == 0)
						return "Paused";

					if (world.Timestep == 1)
						return "Max Speed";

					return "{0:F1}x Speed".F(Game.Timestep * 1f / world.Timestep);
				};
			}
		}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:26,代码来源:GameTimerLogic.cs

示例2: ServerBrowserLogic

        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();
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:60,代码来源:ServerBrowserLogic.cs

示例3: ColorPickerLogic

        public ColorPickerLogic(Widget widget, HSLColor initialColor, Action<HSLColor> onChange, WorldRenderer worldRenderer)
        {
            var ticker = widget.GetOrNull<LogicTickerWidget>("ANIMATE_PREVIEW");
            if (ticker != null)
            {
                var preview = widget.Get<SpriteSequenceWidget>("PREVIEW");
                var anim = preview.GetAnimation();
                anim.PlayRepeating(anim.CurrentSequence.Name);
                ticker.OnTick = anim.Tick;
            }

            var hueSlider = widget.Get<SliderWidget>("HUE");
            var mixer = widget.Get<ColorMixerWidget>("MIXER");
            var randomButton = widget.GetOrNull<ButtonWidget>("RANDOM_BUTTON");

            hueSlider.OnChange += _ => mixer.Set(hueSlider.Value);
            mixer.OnChange += () => onChange(mixer.Color);

            if (randomButton != null)
                randomButton.OnClick = () =>
                {
                    // Avoid colors with low sat or lum
                    var hue = (byte)Game.CosmeticRandom.Next(255);
                    var sat = (byte)Game.CosmeticRandom.Next(70, 255);
                    var lum = (byte)Game.CosmeticRandom.Next(70, 255);

                    mixer.Set(new HSLColor(hue, sat, lum));
                    hueSlider.Value = hue / 255f;
                };

            // Set the initial state
            mixer.Set(initialColor);
            hueSlider.Value = initialColor.H / 255f;
            onChange(mixer.Color);
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:35,代码来源:ColorPickerLogic.cs

示例4: GameTimerLogic

        public GameTimerLogic(Widget widget, OrderManager orderManager, World world)
        {
            var timer = widget.GetOrNull<LabelWidget>("GAME_TIMER");
            var status = widget.GetOrNull<LabelWidget>("GAME_TIMER_STATUS");
            var startTick = Ui.LastTickTime;

            Func<bool> shouldShowStatus = () => (world.Paused || world.Timestep != world.LobbyInfo.GlobalSettings.Timestep)
                && (Ui.LastTickTime - startTick) / 1000 % 2 == 0;

            Func<string> statusText = () =>
            {
                if (world.Paused || world.Timestep == 0)
                    return "Paused";

                if (world.Timestep == 1)
                    return "Max Speed";

                return "{0}% Speed".F(world.LobbyInfo.GlobalSettings.Timestep * 100 / world.Timestep);
            };

            if (timer != null)
            {
                // Timers in replays should be synced to the effective game time, not the playback time.
                var timestep = world.Timestep;
                if (world.IsReplay)
                {
                    GameSpeed speed;
                    var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>();
                    if (gameSpeeds.Speeds.TryGetValue(world.LobbyInfo.GlobalSettings.GameSpeedType, out speed))
                        timestep = speed.Timestep;
                }

                timer.GetText = () =>
                {
                    if (status == null && shouldShowStatus())
                        return statusText();

                    return WidgetUtils.FormatTime(world.WorldTick, timestep);
                };
            }

            if (status != null)
            {
                // Blink the status line
                status.IsVisible = shouldShowStatus;
                status.GetText = statusText;
            }

            var percentage = widget.GetOrNull<LabelWidget>("GAME_TIMER_PERCENTAGE");
            if (percentage != null)
            {
                var connection = orderManager.Connection as ReplayConnection;
                if (connection != null && connection.TickCount != 0)
                    percentage.GetText = () => "({0}%)".F(orderManager.NetFrameNumber * 100 / connection.TickCount);
                else if (timer != null)
                    timer.Bounds.Width += percentage.Bounds.Width;
            }
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:58,代码来源:GameTimerLogic.cs

示例5: 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);
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:56,代码来源:MapChooserLogic.cs

示例6: ServerCreationLogic

        public ServerCreationLogic(Widget widget, Action onExit, Action openLobby)
        {
            panel = widget;
            onCreate = openLobby;
            this.onExit = onExit;

            var settings = Game.Settings;
            preview = Game.ModData.MapCache[WidgetUtils.ChooseInitialMap(Game.Settings.Server.Map)];

            panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
            panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = CreateAndJoin;

            var mapButton = panel.GetOrNull<ButtonWidget>("MAP_BUTTON");
            if (mapButton != null)
            {
                panel.Get<ButtonWidget>("MAP_BUTTON").OnClick = () =>
                {
                    Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs()
                    {
                        { "initialMap", preview.Uid },
                        { "initialTab", MapClassification.System },
                        { "onExit", () => { } },
                        { "onSelect", (Action<string>)(uid => preview = Game.ModData.MapCache[uid]) },
                        { "filter", MapVisibility.Lobby },
                        { "onStart", () => { } }
                    });
                };

                panel.Get<MapPreviewWidget>("MAP_PREVIEW").Preview = () => preview;
                panel.Get<LabelWidget>("MAP_NAME").GetText = () => preview.Title;
            }

            panel.Get<TextFieldWidget>("SERVER_NAME").Text = settings.Server.Name ?? "";
            panel.Get<TextFieldWidget>("LISTEN_PORT").Text = settings.Server.ListenPort.ToString();
            advertiseOnline = Game.Settings.Server.AdvertiseOnline;

            var externalPort = panel.Get<TextFieldWidget>("EXTERNAL_PORT");
            externalPort.Text = settings.Server.ExternalPort.ToString();
            externalPort.IsDisabled = () => !advertiseOnline;

            var advertiseCheckbox = panel.Get<CheckboxWidget>("ADVERTISE_CHECKBOX");
            advertiseCheckbox.IsChecked = () => advertiseOnline;
            advertiseCheckbox.OnClick = () => advertiseOnline ^= true;

            allowPortForward = Game.Settings.Server.AllowPortForward;
            var checkboxUPnP = panel.Get<CheckboxWidget>("UPNP_CHECKBOX");
            checkboxUPnP.IsChecked = () => allowPortForward;
            checkboxUPnP.OnClick = () => allowPortForward ^= true;
            checkboxUPnP.IsDisabled = () => !Game.Settings.Server.NatDeviceAvailable;

            var passwordField = panel.GetOrNull<PasswordFieldWidget>("PASSWORD");
            if (passwordField != null)
                passwordField.Text = Game.Settings.Server.Password;
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:54,代码来源:ServerCreationLogic.cs

示例7: GameTimerLogic

        public GameTimerLogic(Widget widget, OrderManager orderManager, World world)
        {
            var timer = widget.GetOrNull<LabelWidget>("GAME_TIMER");
            var status = widget.GetOrNull<LabelWidget>("GAME_TIMER_STATUS");
            var startTick = Ui.LastTickTime;

            Func<bool> shouldShowStatus = () => (world.Paused || world.Timestep != world.LobbyInfo.GlobalSettings.Timestep)
                && (Ui.LastTickTime - startTick) / 1000 % 2 == 0;

            Func<string> statusText = () =>
            {
                if (world.Paused || world.Timestep == 0)
                    return "Paused";

                if (world.Timestep == 1)
                    return "Max Speed";

                return "{0}% Speed".F(world.LobbyInfo.GlobalSettings.Timestep * 100 / world.Timestep);
            };

            if (timer != null)
            {
                // Timers in replays should be synced to the effective game time, not the playback time.
                var timestep = world.Timestep;
                if (world.IsReplay)
                    timestep = world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;

                timer.GetText = () =>
                {
                    if (status == null && shouldShowStatus())
                        return statusText();

                    return WidgetUtils.FormatTime(world.WorldTick, timestep);
                };
            }

            if (status != null)
            {
                // Blink the status line
                status.IsVisible = shouldShowStatus;
                status.GetText = statusText;
            }

            var timerTooltip = timer as LabelWithTooltipWidget;
            if (timerTooltip != null)
            {
                var connection = orderManager.Connection as ReplayConnection;
                if (connection != null && connection.TickCount != 0)
                    timerTooltip.GetTooltipText = () => "{0}% complete".F(orderManager.NetFrameNumber * 100 / connection.TickCount);
                else
                    timerTooltip.GetTooltipText = null;
            }
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:53,代码来源:GameTimerLogic.cs

示例8: SupportPowerBinLogic

        public SupportPowerBinLogic(Widget widget, World world)
        {
            var palette = widget.Get<SupportPowersWidget>("SUPPORT_PALETTE");

            var background = widget.GetOrNull("PALETTE_BACKGROUND");
            var foreground = widget.GetOrNull("PALETTE_FOREGROUND");
            if (background != null || foreground != null)
            {
                Widget backgroundTemplate = null;
                Widget foregroundTemplate = null;

                if (background != null)
                    backgroundTemplate = background.Get("ICON_TEMPLATE");

                if (foreground != null)
                    foregroundTemplate = foreground.Get("ICON_TEMPLATE");

                Action<int, int> updateBackground = (_, icons) =>
                {
                    var rowHeight = palette.IconSize.Y + palette.IconMargin;

                    if (background != null)
                    {
                        background.RemoveChildren();

                        for (var i = 0; i < icons; i++)
                        {
                            var row = backgroundTemplate.Clone();
                            row.Bounds.Y += i * rowHeight;
                            background.AddChild(row);
                        }
                    }

                    if (foreground != null)
                    {
                        foreground.RemoveChildren();

                        for (var i = 0; i < icons; i++)
                        {
                            var row = foregroundTemplate.Clone();
                            row.Bounds.Y += i * rowHeight;
                            foreground.AddChild(row);
                        }
                    }
                };

                palette.OnIconCountChanged += updateBackground;

                // Set the initial palette state
                updateBackground(0, 0);
            }
        }
开发者ID:Carbs0126,项目名称:OpenRA,代码行数:52,代码来源:SupportPowerBinLogic.cs

示例9: ReplayBrowserLogic

		public ReplayBrowserLogic(Widget widget, Action onExit, Action onStart)
		{
			panel = widget;

			this.onStart = onStart;

			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 = Game.ModData.Manifest.Mod;
			var dir = Platform.ResolvePath("^", "Replays", mod.Id, mod.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)
				type.GetText = () => selectedReplay.GameInfo.MapPreview.Type;

			panel.Get<LabelWidget>("DURATION").GetText = () => WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds);

			SetupFilters();
			SetupManagement();
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:51,代码来源:ReplayBrowserLogic.cs

示例10: GameTimerLogic

        public GameTimerLogic(Widget widget, OrderManager orderManager, World world)
        {
            var timer = widget.GetOrNull<LabelWidget>("GAME_TIMER");
            var status = widget.GetOrNull<LabelWidget>("GAME_TIMER_STATUS");
            var startTick = Ui.LastTickTime;

            Func<bool> shouldShowStatus = () => (world.Paused || world.Timestep != Game.Timestep)
                && (Ui.LastTickTime - startTick) / 1000 % 2 == 0;

            Func<string> statusText = () =>
            {
                if (world.Paused || world.Timestep == 0)
                    return "Paused";

                if (world.Timestep == 1)
                    return "Max Speed";

                return "{0}% Speed".F(Game.Timestep * 100 / world.Timestep);
            };

            if (timer != null)
            {
                timer.GetText = () =>
                {
                    if (status == null && shouldShowStatus())
                        return statusText();

                    return WidgetUtils.FormatTime(world.WorldTick);
                };
            }

            if (status != null)
            {
                // Blink the status line
                status.IsVisible = shouldShowStatus;
                status.GetText = statusText;
            }

            var percentage = widget.GetOrNull<LabelWidget>("GAME_TIMER_PERCENTAGE");
            if (percentage != null)
            {
                var connection = orderManager.Connection as ReplayConnection;
                if (connection != null && connection.TickCount != 0)
                    percentage.GetText = () => "({0}%)".F(orderManager.NetFrameNumber * 100 / connection.TickCount);
                else
                    timer.Bounds.Width += percentage.Bounds.Width;
            }
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:48,代码来源:GameTimerLogic.cs

示例11: IngameRadarDisplayLogic

        public IngameRadarDisplayLogic(Widget widget, World world)
        {
            var radarEnabled = false;
            var cachedRadarEnabled = false;
            var blockColor = Color.Transparent;
            var radar = widget.Get<RadarWidget>("RADAR_MINIMAP");
            radar.IsEnabled = () => radarEnabled;
            var devMode = world.LocalPlayer.PlayerActor.Trait<DeveloperMode>();

            var ticker = widget.Get<LogicTickerWidget>("RADAR_TICKER");
            ticker.OnTick = () =>
            {
                radarEnabled = devMode.DisableShroud || world.ActorsHavingTrait<ProvidesRadar>(r => r.IsActive)
                    .Any(a => a.Owner == world.LocalPlayer);

                if (radarEnabled != cachedRadarEnabled)
                    Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", radarEnabled ? "RadarUp" : "RadarDown", null);
                cachedRadarEnabled = radarEnabled;
            };

            var block = widget.GetOrNull<ColorBlockWidget>("RADAR_FADETOBLACK");
            if (block != null)
            {
                radar.Animating = x => blockColor = Color.FromArgb((int)(255 * x), Color.Black);
                block.IsVisible = () => blockColor.A != 0;
                block.GetColor = () => blockColor;
            }
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:28,代码来源:IngameRadarDisplayLogic.cs

示例12: CncInstallMusicLogic

        public CncInstallMusicLogic(Widget widget, Ruleset modRules, Action onExit)
        {
            var installButton = widget.GetOrNull<ButtonWidget>("INSTALL_BUTTON");
            if (installButton != null)
            {
                Action afterInstall = () =>
                {
                    try
                    {
                        var path = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mod.Id }.Aggregate(Path.Combine);
                        GlobalFileSystem.Mount(Path.Combine(path, "scores.mix"));
                        GlobalFileSystem.Mount(Path.Combine(path, "transit.mix"));

                        modRules.Music.Do(m => m.Value.Reload());

                        var musicPlayerLogic = (MusicPlayerLogic)installButton.Parent.LogicObject;
                        musicPlayerLogic.BuildMusicTable();
                    }
                    catch (Exception e)
                    {
                        Log.Write("debug", "Mounting the new mixfile and rebuild of scores list failed:\n{0}", e);
                    }
                };

                installButton.OnClick = () =>
                    Ui.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs() {
                        { "afterInstall", afterInstall },
                        { "filesToCopy", new[] { "SCORES.MIX" } },
                        { "filesToExtract", new[] { "transit.mix" } },
                    });
                installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length < 3; // HACK around music being split between transit.mix and scores.mix
            }
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:33,代码来源:CncInstallMusicLogic.cs

示例13: ColorPickerLogic

        public ColorPickerLogic(Widget widget, HSLColor initialColor, Action<HSLColor> onChange, WorldRenderer worldRenderer)
        {
            var hueSlider = widget.Get<SliderWidget>("HUE");
            var mixer = widget.Get<ColorMixerWidget>("MIXER");
            var randomButton = widget.GetOrNull<ButtonWidget>("RANDOM_BUTTON");

            hueSlider.OnChange += _ => mixer.Set(hueSlider.Value);
            mixer.OnChange += () =>	onChange(mixer.Color);

            if (randomButton != null)
                randomButton.OnClick = () =>
                {
                    // Avoid colors with low sat or lum
                    var hue = (byte)Game.CosmeticRandom.Next(255);
                    var sat = (byte)Game.CosmeticRandom.Next(70, 255);
                    var lum = (byte)Game.CosmeticRandom.Next(70, 255);

                    mixer.Set(new HSLColor(hue, sat, lum));
                    hueSlider.Value = hue / 255f;
                };

            // Set the initial state
            mixer.Set(initialColor);
            hueSlider.Value = initialColor.H / 255f;
            onChange(mixer.Color);
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:26,代码来源:ColorPickerLogic.cs

示例14: MapEditorLogic

        public MapEditorLogic(Widget widget, World world, WorldRenderer worldRenderer)
        {
            var gridButton = widget.GetOrNull<ButtonWidget>("GRID_BUTTON");
            var terrainGeometryTrait = world.WorldActor.Trait<TerrainGeometryOverlay>();

            if (gridButton != null && terrainGeometryTrait != null)
            {
                gridButton.OnClick = () => terrainGeometryTrait.Enabled ^= true;
                gridButton.IsHighlighted = () => terrainGeometryTrait.Enabled;
            }

            var zoomDropdown = widget.GetOrNull<DropDownButtonWidget>("ZOOM_BUTTON");
            if (zoomDropdown != null)
            {
                var selectedZoom = Game.Settings.Graphics.PixelDouble ? 2f : 1f;
                var selectedLabel = selectedZoom.ToString();
                Func<float, ScrollItemWidget, ScrollItemWidget> setupItem = (zoom, itemTemplate) =>
                {
                    var item = ScrollItemWidget.Setup(itemTemplate,
                        () => selectedZoom == zoom,
                        () => { worldRenderer.Viewport.Zoom = selectedZoom = zoom; selectedLabel = zoom.ToString(); });

                    var label = zoom.ToString();
                    item.Get<LabelWidget>("LABEL").GetText = () => label;

                    return item;
                };

                var options = new[] { 2f, 1f, 0.5f, 0.25f };
                zoomDropdown.OnMouseDown = _ => zoomDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
                zoomDropdown.GetText = () => selectedLabel;
                zoomDropdown.GetKey = _ => Game.Settings.Keys.TogglePixelDoubleKey;
                zoomDropdown.OnKeyPress = e =>
                {
                    var key = Hotkey.FromKeyInput(e);
                    if (key != Game.Settings.Keys.TogglePixelDoubleKey)
                        return;

                    var selected = (options.IndexOf(selectedZoom) + 1) % options.Length;
                    worldRenderer.Viewport.Zoom = selectedZoom = options[selected];
                    selectedLabel = selectedZoom.ToString();
                };
            }
        }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:44,代码来源:MapEditorLogic.cs

示例15: ColorPickerLogic

        public ColorPickerLogic(Widget widget, ModData modData, World world, HSLColor initialColor, Action<HSLColor> onChange, WorldRenderer worldRenderer)
        {
            string actorType;
            if (!ChromeMetrics.TryGet("ColorPickerActorType", out actorType))
                actorType = "mcv";

            var preview = widget.GetOrNull<ActorPreviewWidget>("PREVIEW");
            var actor = world.Map.Rules.Actors[actorType];

            var td = new TypeDictionary();
            td.Add(new HideBibPreviewInit());
            td.Add(new OwnerInit(world.WorldActor.Owner));
            td.Add(new FactionInit(world.WorldActor.Owner.PlayerReference.Faction));

            if (preview != null)
                preview.SetPreview(actor, td);

            var hueSlider = widget.Get<SliderWidget>("HUE");
            var mixer = widget.Get<ColorMixerWidget>("MIXER");
            var randomButton = widget.GetOrNull<ButtonWidget>("RANDOM_BUTTON");

            hueSlider.OnChange += _ => mixer.Set(hueSlider.Value);
            mixer.OnChange += () => onChange(mixer.Color);

            if (randomButton != null)
                randomButton.OnClick = () =>
                {
                    // Avoid colors with low sat or lum
                    var hue = (byte)Game.CosmeticRandom.Next(255);
                    var sat = (byte)Game.CosmeticRandom.Next(70, 255);
                    var lum = (byte)Game.CosmeticRandom.Next(70, 255);

                    mixer.Set(new HSLColor(hue, sat, lum));
                    hueSlider.Value = hue / 255f;
                };

            // Set the initial state
            var validator = modData.Manifest.Get<ColorValidator>();
            mixer.SetPaletteRange(validator.HsvSaturationRange[0], validator.HsvSaturationRange[1], validator.HsvValueRange[0], validator.HsvValueRange[1]);
            mixer.Set(initialColor);

            hueSlider.Value = initialColor.H / 255f;
            onChange(mixer.Color);
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:44,代码来源:ColorPickerLogic.cs


注:本文中的OpenRA.Widgets.Widget.GetOrNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。