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


C# Widget.Get方法代码示例

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


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

示例1: ModContentDiscTooltipLogic

        public ModContentDiscTooltipLogic(Widget widget, Func<string> getText)
        {
            var discs = widget.Get<ContainerWidget>("DISCS");
            var template = discs.Get<LabelWidget>("DISC_TEMPLATE");
            discs.RemoveChildren();

            var desc = widget.Get<LabelWidget>("DESCRIPTION");

            var font = Game.Renderer.Fonts[template.Font];
            var discTitles = getText().Split('\n');

            var maxWidth = Game.Renderer.Fonts[desc.Font].Measure(desc.Text).X;
            var sideMargin = desc.Bounds.X;
            var bottomMargin = discs.Bounds.Height;
            foreach (var disc in discTitles)
            {
                var label = (LabelWidget)template.Clone();
                var title = disc;
                label.GetText = () => title;
                label.Bounds.Y = discs.Bounds.Height;
                label.Bounds.Width = font.Measure(disc).X;

                maxWidth = Math.Max(maxWidth, label.Bounds.Width + label.Bounds.X);
                discs.AddChild(label);
                discs.Bounds.Height += label.Bounds.Height;
            }

            widget.Bounds.Width = 2 * sideMargin + maxWidth;
            widget.Bounds.Height = discs.Bounds.Y + bottomMargin + discs.Bounds.Height;
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:30,代码来源:ModContentDiscTooltipLogic.cs

示例2: FactionTooltipLogic

        public FactionTooltipLogic(Widget widget, ButtonWidget button)
        {
            var lines = button.GetTooltipText().Replace("\\n", "\n").Split('\n');

            var header = widget.Get<LabelWidget>("HEADER");
            var headerLine = lines[0];
            var headerFont = Game.Renderer.Fonts[header.Font];
            var headerSize = headerFont.Measure(headerLine);
            header.Bounds.Width += headerSize.X;
            header.Bounds.Height += headerSize.Y;
            header.GetText = () => headerLine;

            if (lines.Length > 1)
            {
                var description = widget.Get<LabelWidget>("DESCRIPTION");
                var descriptionLines = lines.Skip(1).ToArray();
                var descriptionFont = Game.Renderer.Fonts[description.Font];
                description.Bounds.Y += header.Bounds.Y + header.Bounds.Height;
                description.Bounds.Width += descriptionLines.Select(l => descriptionFont.Measure(l).X).Max();
                description.Bounds.Height += descriptionFont.Measure(descriptionLines.First()).Y * descriptionLines.Length;
                description.GetText = () => string.Join("\n", descriptionLines);

                widget.Bounds.Width = Math.Max(header.Bounds.X + header.Bounds.Width, description.Bounds.X + description.Bounds.Width);
                widget.Bounds.Height = description.Bounds.Y + description.Bounds.Height;
            }
            else
            {
                widget.Bounds.Width = header.Bounds.X + header.Bounds.Width;
                widget.Bounds.Height = header.Bounds.Y + header.Bounds.Height;
            }
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:31,代码来源:FactionTooltipLogic.cs

示例3: 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

示例4: ReplayBrowserLogic

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

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

            var rl = panel.Get<ScrollPanelWidget>("REPLAY_LIST");
            var replayDir = Path.Combine(Platform.SupportDir, "Replays");

            var template = panel.Get<ScrollItemWidget>("REPLAY_TEMPLATE");

            rl.RemoveChildren();
            if (Directory.Exists(replayDir))
            {
                var files = Directory.GetFiles(replayDir, "*.rep").Reverse();
                foreach (var replayFile in files)
                    AddReplay(rl, replayFile, template);

                SelectReplay(files.FirstOrDefault());
            }

            var watch = panel.Get<ButtonWidget>("WATCH_BUTTON");
            watch.IsDisabled = () => currentReplay == null || currentMap == null || currentReplay.Duration == 0;
            watch.OnClick = () =>
            {
                if (currentReplay != null)
                {
                    Game.JoinReplay(currentReplay.Filename);
                    Ui.CloseWindow();
                    onStart();
                }
            };

            panel.Get("REPLAY_INFO").IsVisible = () => currentReplay != null;
        }
开发者ID:sonygod,项目名称:OpenRA-Dedicated-20120504,代码行数:35,代码来源:ReplayBrowserLogic.cs

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

示例6: GameInfoObjectivesLogic

        public GameInfoObjectivesLogic(Widget widget, World world)
        {
            var lp = world.LocalPlayer;

            var missionStatus = widget.Get<LabelWidget>("MISSION_STATUS");
            missionStatus.GetText = () => lp.WinState == WinState.Undefined ? "In progress" :
                lp.WinState == WinState.Won ? "Accomplished" : "Failed";
            missionStatus.GetColor = () => lp.WinState == WinState.Undefined ? Color.White :
                lp.WinState == WinState.Won ? Color.LimeGreen : Color.Red;

            var mo = lp.PlayerActor.TraitOrDefault<MissionObjectives>();
            if (mo == null)
                return;

            var objectivesPanel = widget.Get<ScrollPanelWidget>("OBJECTIVES_PANEL");
            template = objectivesPanel.Get<ContainerWidget>("OBJECTIVE_TEMPLATE");

            PopulateObjectivesList(mo, objectivesPanel, template);

            Action<Player> redrawObjectives = player =>
            {
                if (player == lp)
                    PopulateObjectivesList(mo, objectivesPanel, template);
            };
            mo.ObjectiveAdded += redrawObjectives;
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:26,代码来源:GameInfoObjectivesLogic.cs

示例7: SettingsLogic

        public SettingsLogic(Widget widget, Action onExit, WorldRenderer worldRenderer)
        {
            this.worldRenderer = worldRenderer;

            panelContainer = widget.Get("SETTINGS_PANEL");
            tabContainer = widget.Get("TAB_CONTAINER");

            RegisterSettingsPanel(PanelType.Display, InitDisplayPanel, ResetDisplayPanel, "DISPLAY_PANEL", "DISPLAY_TAB");
            RegisterSettingsPanel(PanelType.Audio, InitAudioPanel, ResetAudioPanel, "AUDIO_PANEL", "AUDIO_TAB");
            RegisterSettingsPanel(PanelType.Input, InitInputPanel, ResetInputPanel, "INPUT_PANEL", "INPUT_TAB");
            RegisterSettingsPanel(PanelType.Advanced, InitAdvancedPanel, ResetAdvancedPanel, "ADVANCED_PANEL", "ADVANCED_TAB");

            panelContainer.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
            {
                leavePanelActions[settingsPanel]();
                Game.Settings.Save();
                Ui.CloseWindow();
                onExit();
            };

            panelContainer.Get<ButtonWidget>("RESET_BUTTON").OnClick = () =>
            {
                resetPanelActions[settingsPanel]();
                Game.Settings.Save();
            };
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:26,代码来源:SettingsLogic.cs

示例8: ReplayControlBarLogic

		public ReplayControlBarLogic(Widget widget, World world)
		{
			if (world.IsReplay)
			{
				var container = widget.Get("REPLAY_PLAYER");

				var background = widget.Parent.GetOrNull("OBSERVER_CONTROL_BG");
				if (background != null)
					background.Bounds.Height += container.Bounds.Height;

				container.Visible = true;

				var pauseButton = widget.Get<ButtonWidget>("BUTTON_PAUSE");
				pauseButton.IsHighlighted = () => world.Timestep == 0;
				pauseButton.OnClick = () => world.Timestep = 0;

				var slowButton = widget.Get<ButtonWidget>("BUTTON_SLOW");
				slowButton.IsHighlighted = () => world.Timestep > Game.Timestep;
				slowButton.OnClick = () => world.Timestep = Game.Timestep * 2;

				var normalSpeedButton = widget.Get<ButtonWidget>("BUTTON_NORMALSPEED");
				normalSpeedButton.IsHighlighted = () => world.Timestep == Game.Timestep;
				normalSpeedButton.OnClick = () => world.Timestep = Game.Timestep;

				var fastforwardButton = widget.Get<ButtonWidget>("BUTTON_FASTFORWARD");
				fastforwardButton.IsHighlighted = () => world.Timestep == 1;
				fastforwardButton.OnClick = () => world.Timestep = 1;
			}
		}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:29,代码来源:ReplayControlBarLogic.cs

示例9: 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

示例10: SpawnSelectorTooltipLogic

		public SpawnSelectorTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, MapPreviewWidget preview)
		{
			widget.IsVisible = () => preview.TooltipSpawnIndex != -1;
			var label = widget.Get<LabelWidget>("LABEL");
			var flag = widget.Get<ImageWidget>("FLAG");
			var team = widget.Get<LabelWidget>("TEAM");
			var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height;
			var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height;
			var ownerFont = Game.Renderer.Fonts[label.Font];
			var teamFont = Game.Renderer.Fonts[team.Font];

			// Width specified in YAML is used as the margin between flag / label and label / border
			var labelMargin = widget.Bounds.Width;

			var cachedWidth = 0;
			var labelText = "";
			string playerFaction = null;
			var playerTeam = -1;

			tooltipContainer.BeforeRender = () =>
			{
				var occupant = preview.SpawnOccupants().Values.FirstOrDefault(c => c.SpawnPoint == preview.TooltipSpawnIndex);

				var teamWidth = 0;
				if (occupant == null)
				{
					labelText = "Available spawn";
					playerFaction = null;
					playerTeam = 0;
					widget.Bounds.Height = singleHeight;
				}
				else
				{
					labelText = occupant.PlayerName;
					playerFaction = occupant.Faction;
					playerTeam = occupant.Team;
					widget.Bounds.Height = playerTeam > 0 ? doubleHeight : singleHeight;
					teamWidth = teamFont.Measure(team.GetText()).X;
				}

				label.Bounds.X = playerFaction != null ? flag.Bounds.Right + labelMargin : labelMargin;

				var textWidth = ownerFont.Measure(labelText).X;
				if (textWidth != cachedWidth)
				{
					label.Bounds.Width = textWidth;
					widget.Bounds.Width = 2 * label.Bounds.X + textWidth;
				}

				widget.Bounds.Width = Math.Max(teamWidth + 2 * labelMargin, label.Bounds.Right + labelMargin);
				team.Bounds.Width = widget.Bounds.Width;
			};

			label.GetText = () => labelText;
			flag.IsVisible = () => playerFaction != null;
			flag.GetImageCollection = () => "flags";
			flag.GetImageName = () => playerFaction;
			team.GetText = () => "Team {0}".F(playerTeam);
			team.IsVisible = () => playerTeam > 0;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:60,代码来源:SpawnSelectorTooltipLogic.cs

示例11: 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

示例12: ConnectionFailedLogic

        public ConnectionFailedLogic(Widget widget, OrderManager orderManager, Action onAbort, Action<string> onRetry)
        {
            var panel = widget;
            var abortButton = panel.Get<ButtonWidget>("ABORT_BUTTON");
            var retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON");

            abortButton.Visible = onAbort != null;
            abortButton.OnClick = () => { Ui.CloseWindow(); onAbort(); };

            retryButton.Visible = onRetry != null;
            retryButton.OnClick = () =>
            {
                var password = passwordField != null && passwordField.IsVisible() ? passwordField.Text : orderManager.Password;

                Ui.CloseWindow();
                onRetry(password);
            };

            widget.Get<LabelWidget>("CONNECTING_DESC").GetText = () =>
                "Could not connect to {0}:{1}".F(orderManager.Host, orderManager.Port);

            var connectionError = widget.Get<LabelWidget>("CONNECTION_ERROR");
            connectionError.GetText = () => orderManager.ServerError;

            passwordField = panel.GetOrNull<PasswordFieldWidget>("PASSWORD");
            if (passwordField != null)
            {
                passwordField.Text = orderManager.Password;
                passwordField.IsVisible = () => orderManager.AuthenticationFailed;
                var passwordLabel = widget.Get<LabelWidget>("PASSWORD_LABEL");
                passwordLabel.IsVisible = passwordField.IsVisible;
                passwordField.OnEnterKey = () => { retryButton.OnClick(); return true; };
                passwordField.OnEscKey = () => { abortButton.OnClick(); return true; };
            }

            passwordOffsetAdjusted = false;
            var connectionFailedTicker = panel.GetOrNull<LogicTickerWidget>("CONNECTION_FAILED_TICKER");
            if (connectionFailedTicker != null)
            {
                connectionFailedTicker.OnTick = () =>
                {
                    // Adjust the dialog once the AuthenticationError is parsed.
                    if (passwordField.IsVisible() && !passwordOffsetAdjusted)
                    {
                        var offset = passwordField.Bounds.Y - connectionError.Bounds.Y;
                        abortButton.Bounds.Y += offset;
                        retryButton.Bounds.Y += offset;
                        panel.Bounds.Height += offset;
                        panel.Bounds.Y -= offset / 2;

                        var background = panel.GetOrNull("CONNECTION_BACKGROUND");
                        if (background != null)
                            background.Bounds.Height += offset;

                        passwordOffsetAdjusted = true;
                    }
                };
            }
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:59,代码来源:ConnectionLogic.cs

示例13: SupportPowerTooltipLogic

		public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, SupportPowersWidget palette, World world)
		{
			widget.IsVisible = () => palette.TooltipIcon != null;
			var nameLabel = widget.Get<LabelWidget>("NAME");
			var hotkeyLabel = widget.Get<LabelWidget>("HOTKEY");
			var timeLabel = widget.Get<LabelWidget>("TIME");
			var descLabel = widget.Get<LabelWidget>("DESC");
			var nameFont = Game.Renderer.Fonts[nameLabel.Font];
			var timeFont = Game.Renderer.Fonts[timeLabel.Font];
			var descFont = Game.Renderer.Fonts[descLabel.Font];
			var name = "";
			var time = "";
			var desc = "";
			var baseHeight = widget.Bounds.Height;
			var timeOffset = timeLabel.Bounds.X;

			SupportPowerInstance lastPower = null;
			tooltipContainer.BeforeRender = () =>
			{
				var icon = palette.TooltipIcon;

				if (icon == null)
					return;

				var sp = icon.Power;

				if (sp.Info == null)
					return;		// no instances actually exist (race with destroy)

				var remaining = WidgetUtils.FormatTime(sp.RemainingTime, world.Timestep);
				var total = WidgetUtils.FormatTime(sp.Info.ChargeTime * 25, world.Timestep);
				time = "{0} / {1}".F(remaining, total);

				if (sp == lastPower)
					return;

				name = sp.Info.Description;
				desc = sp.Info.LongDesc.Replace("\\n", "\n");

				var hotkey = icon.Hotkey;
				var hotkeyText = "({0})".F(hotkey.DisplayString());
				var hotkeyWidth = hotkey.IsValid() ? nameFont.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0;
				hotkeyLabel.GetText = () => hotkeyText;
				hotkeyLabel.Bounds.X = nameFont.Measure(name).X + 2 * nameLabel.Bounds.X;
				hotkeyLabel.Visible = hotkey.IsValid();

				var timeWidth = timeFont.Measure(time).X;
				var topWidth = nameFont.Measure(name).X + hotkeyWidth + timeWidth + timeOffset;
				var descSize = descFont.Measure(desc);
				widget.Bounds.Width = 2 * nameLabel.Bounds.X + Math.Max(topWidth, descSize.X);
				widget.Bounds.Height = baseHeight + descSize.Y;
				timeLabel.Bounds.X = widget.Bounds.Width - nameLabel.Bounds.X - timeWidth;
				lastPower = sp;
			};

			nameLabel.GetText = () => name;
			timeLabel.GetText = () => time;
			descLabel.GetText = () => desc;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:59,代码来源:SupportPowerTooltipLogic.cs

示例14: ProductionTooltipLogic

        public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, ProductionPaletteWidget palette)
        {
            var pm = palette.world.LocalPlayer.PlayerActor.Trait<PowerManager>();
            var pr = palette.world.LocalPlayer.PlayerActor.Trait<PlayerResources>();

            widget.IsVisible = () => palette.TooltipActor != null;
            var nameLabel = widget.Get<LabelWidget>("NAME");
            var requiresLabel = widget.Get<LabelWidget>("REQUIRES");
            var powerLabel = widget.Get<LabelWidget>("POWER");
            var timeLabel = widget.Get<LabelWidget>("TIME");
            var costLabel = widget.Get<LabelWidget>("COST");

            var font = Game.Renderer.Fonts[nameLabel.Font];
            var requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
            string lastActor = null;

            tooltipContainer.BeforeRender = () =>
            {
                var actor = palette.TooltipActor;
                if (actor == null || actor == lastActor)
                    return;

                var info = Rules.Info[actor];
                var tooltip = info.Traits.Get<TooltipInfo>();
                var buildable = info.Traits.Get<BuildableInfo>();
                var cost = info.Traits.Get<ValuedInfo>().Cost;
                var bi = info.Traits.GetOrDefault<BuildingInfo>();

                nameLabel.GetText = () => tooltip.Name;

                var prereqs = buildable.Prerequisites.Select(a => ActorName(a));
                var requiresString = prereqs.Any() ? "Requires {0}".F(prereqs.JoinWith(", ")) : "";
                requiresLabel.GetText = () => requiresString;

                var power = bi != null ? bi.Power : 0;
                var powerString = "P: {0}".F(power);
                powerLabel.GetText = () => powerString;
                powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
                    ? Color.White : Color.Red;
                powerLabel.IsVisible = () => power != 0;

                var timeString = "T: {0}".F(WidgetUtils.FormatTime(palette.CurrentQueue.GetBuildTime(actor)));
                timeLabel.GetText = () => timeString;

                var costString = "$: {0}".F(cost);
                costLabel.GetText = () => costString;
                costLabel.GetColor = () => pr.DisplayCash + pr.DisplayOre >= cost
                    ? Color.White : Color.Red;

                var leftWidth = Math.Max(font.Measure(tooltip.Name).X, requiresFont.Measure(requiresString).X);
                var rightWidth = new [] {font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X}.Aggregate(Math.Max);
                timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2*nameLabel.Bounds.X;
                widget.Bounds.Width = leftWidth + rightWidth + 3*nameLabel.Bounds.X;

                widget.Bounds.Height = power != 0 ? 65 : 45;
                lastActor = actor;
            };
        }
开发者ID:sonygod,项目名称:OpenRA-Dedicated-20120504,代码行数:58,代码来源:ProductionTooltipLogic.cs

示例15: 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


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