本文整理汇总了C#中OpenRA.Widgets.Widget.RemoveChildren方法的典型用法代码示例。如果您正苦于以下问题:C# Widget.RemoveChildren方法的具体用法?C# Widget.RemoveChildren怎么用?C# Widget.RemoveChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenRA.Widgets.Widget
的用法示例。
在下文中一共展示了Widget.RemoveChildren方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleTooltipLogic
public SimpleTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, Func<string> getText)
{
var label = widget.Get<LabelWidget>("LABEL");
var spacing = widget.Get("LINE_HEIGHT");
widget.RemoveChildren();
var font = Game.Renderer.Fonts[label.Font];
var horizontalPadding = label.Bounds.Width - widget.Bounds.Width;
if (horizontalPadding <= 0)
horizontalPadding = 2 * label.Bounds.X;
var cachedText = "";
tooltipContainer.BeforeRender = () =>
{
var text = getText();
if (text == cachedText)
return;
var lines = text.Split('\n');
var textWidth = font.Measure(text).X;
// Set up label widgets
widget.RemoveChildren();
var bottom = 0;
for (var i = 0; i < lines.Length; i++)
{
var line = (LabelWidget)label.Clone();
var lineText = lines[i];
line.Bounds.Y += spacing.Bounds.Y + i * spacing.Bounds.Height;
line.Bounds.Width = textWidth;
line.GetText = () => lineText;
widget.AddChild(line);
bottom = line.Bounds.Y + line.Bounds.Height;
}
widget.Bounds.Width = horizontalPadding + textWidth;
widget.Bounds.Height = bottom + spacing.Bounds.Y;
cachedText = text;
};
}
示例2: InitPlayerWidgets
public void InitPlayerWidgets(World world, Widget playerRoot)
{
// Real player
var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs());
playerWidgets.IsVisible = () => true;
var sidebarRoot = playerWidgets.GetWidget("SIDEBAR_BACKGROUND");
var sellButton = sidebarRoot.GetWidget<ToggleButtonWidget>("SELL_BUTTON");
sellButton.OnClick = () => world.ToggleInputMode<SellOrderGenerator>();
sellButton.IsToggled = () => world.OrderGenerator is SellOrderGenerator;
var sellIcon = sellButton.GetWidget<ImageWidget>("ICON");
sellIcon.GetImageName = () => world.OrderGenerator is SellOrderGenerator ? "sell-active" : "sell";
var repairButton = sidebarRoot.GetWidget<ToggleButtonWidget>("REPAIR_BUTTON");
repairButton.IsDisabled = () => !RepairOrderGenerator.PlayerIsAllowedToRepair( world );
repairButton.OnClick = () => world.ToggleInputMode<RepairOrderGenerator>();
repairButton.IsToggled = () => world.OrderGenerator is RepairOrderGenerator;
var repairIcon = repairButton.GetWidget<ImageWidget>("ICON");
repairIcon.GetImageName = () => repairButton.IsDisabled() ? "repair-disabled" :
world.OrderGenerator is RepairOrderGenerator ? "repair-active" : "repair";
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
sidebarRoot.GetWidget<LabelWidget>("CASH_DISPLAY").GetText = () =>
"${0}".F(playerResources.DisplayCash + playerResources.DisplayOre);
queueTabs = playerWidgets.GetWidget<ProductionTabsWidget>("PRODUCTION_TABS");
world.ActorAdded += queueTabs.ActorChanged;
world.ActorRemoved += queueTabs.ActorChanged;
var queueTypes = sidebarRoot.GetWidget("PRODUCTION_TYPES");
SetupProductionGroupButton(queueTypes.GetWidget<ToggleButtonWidget>("BUILDING"), "Building");
SetupProductionGroupButton(queueTypes.GetWidget<ToggleButtonWidget>("DEFENSE"), "Defense");
SetupProductionGroupButton(queueTypes.GetWidget<ToggleButtonWidget>("INFANTRY"), "Infantry");
SetupProductionGroupButton(queueTypes.GetWidget<ToggleButtonWidget>("VEHICLE"), "Vehicle");
SetupProductionGroupButton(queueTypes.GetWidget<ToggleButtonWidget>("AIRCRAFT"), "Aircraft");
playerWidgets.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = OptionsClicked;
var cheatsButton = playerWidgets.GetWidget<ButtonWidget>("CHEATS_BUTTON");
cheatsButton.OnClick = () =>
{
if (menu != MenuType.None)
Widget.CloseWindow();
menu = MenuType.Cheats;
Game.OpenWindow("CHEATS_PANEL", new WidgetArgs() {{"onExit", () => menu = MenuType.None }});
};
cheatsButton.IsVisible = () => world.LocalPlayer != null && world.LobbyInfo.GlobalSettings.AllowCheats;
var winLossWatcher = playerWidgets.GetWidget<LogicTickerWidget>("WIN_LOSS_WATCHER");
winLossWatcher.OnTick = () =>
{
if (world.LocalPlayer.WinState != WinState.Undefined)
Game.RunAfterTick(() =>
{
playerRoot.RemoveChildren();
InitObserverWidgets(world, playerRoot);
});
};
}
示例3: InitPlayerWidgets
public void InitPlayerWidgets(World world, Widget playerRoot)
{
// Real player
var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs());
playerWidgets.IsVisible = () => true;
var sidebarRoot = playerWidgets.Get("SIDEBAR_BACKGROUND");
var powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
sidebarRoot.Get<LabelWidget>("CASH").GetText = () =>
"${0}".F(playerResources.DisplayCash + playerResources.DisplayOre);
playerWidgets.Get<ButtonWidget>("OPTIONS_BUTTON").OnClick = OptionsClicked;
var radarEnabled = false;
var cachedRadarEnabled = false;
sidebarRoot.Get<RadarWidget>("RADAR_MINIMAP").IsEnabled = () => radarEnabled;
var sidebarTicker = playerWidgets.Get<LogicTickerWidget>("SIDEBAR_TICKER");
sidebarTicker.OnTick = () =>
{
// Update radar bin
radarEnabled = world.ActorsWithTrait<ProvidesRadar>()
.Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
if (radarEnabled != cachedRadarEnabled)
Sound.PlayNotification(world.Map.Rules, null, "Sounds", radarEnabled ? "RadarUp" : "RadarDown", null);
cachedRadarEnabled = radarEnabled;
// Switch to observer mode after win/loss
if (world.LocalPlayer.WinState != WinState.Undefined)
Game.RunAfterTick(() =>
{
playerRoot.RemoveChildren();
InitObserverWidgets(world, playerRoot);
});
};
var siloBar = playerWidgets.Get<ResourceBarWidget>("SILOBAR");
siloBar.GetProvided = () => playerResources.OreCapacity;
siloBar.GetUsed = () => playerResources.Ore;
siloBar.TooltipFormat = "Silo Usage: {0}/{1}";
siloBar.GetBarColor = () =>
{
if (playerResources.Ore == playerResources.OreCapacity)
return Color.Red;
if (playerResources.Ore >= 0.8 * playerResources.OreCapacity)
return Color.Orange;
return Color.LimeGreen;
};
var powerBar = playerWidgets.Get<ResourceBarWidget>("POWERBAR");
powerBar.GetProvided = () => powerManager.PowerProvided;
powerBar.GetUsed = () => powerManager.PowerDrained;
powerBar.TooltipFormat = "Power Usage: {0}/{1}";
powerBar.GetBarColor = () =>
{
if (powerManager.PowerState == PowerState.Critical)
return Color.Red;
if (powerManager.PowerState == PowerState.Low)
return Color.Orange;
return Color.LimeGreen;
};
}
示例4: BuildMusicTable
void BuildMusicTable(Widget list)
{
music = Rules.Music.Where(a => a.Value.Exists).Select(a => a.Value).ToArray();
random = music.Shuffle(Game.CosmeticRandom).ToArray();
list.RemoveChildren();
foreach (var s in music)
{
var song = s;
if (currentSong == null)
currentSong = song;
var item = ScrollItemWidget.Setup(itemTemplate, () => currentSong == song, () => { currentSong = song; Play(); });
item.Get<LabelWidget>("TITLE").GetText = () => song.Title;
item.Get<LabelWidget>("LENGTH").GetText = () => SongLengthLabel(song);
list.AddChild(item);
}
}