本文整理汇总了C#中OpenRA.Widgets.Widget类的典型用法代码示例。如果您正苦于以下问题:C# Widget类的具体用法?C# Widget怎么用?C# Widget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Widget类属于OpenRA.Widgets命名空间,在下文中一共展示了Widget类的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;
}
示例2: IngameMenuLogic
public IngameMenuLogic(Widget widget, World world, Action onExit)
{
widget.Get<ButtonWidget>("DISCONNECT").OnClick = () =>
{
onExit();
LeaveGame(world);
};
widget.Get<ButtonWidget>("SETTINGS").OnClick = () =>
{
widget.Visible = false;
Ui.OpenWindow("SETTINGS_MENU", new WidgetArgs { { "onExit", () => { widget.Visible = true; } } });
};
widget.Get<ButtonWidget>("MUSIC").OnClick = () =>
{
widget.Visible = false;
Ui.OpenWindow("MUSIC_MENU", new WidgetArgs { { "onExit", () => { widget.Visible = true; } } });
};
widget.Get<ButtonWidget>("RESUME").OnClick = () => onExit();
widget.Get<ButtonWidget>("SURRENDER").OnClick = () =>
{
world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
onExit();
};
widget.Get("SURRENDER").IsVisible = () => world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Undefined;
}
示例3: RAInstallLogic
public RAInstallLogic(Widget widget, Dictionary<string,string> installData, Action continueLoading)
{
var panel = widget.Get("INSTALL_PANEL");
var args = new WidgetArgs()
{
{ "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } },
{ "installData", installData },
{ "continueLoading", continueLoading }
};
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args);
panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
Ui.OpenWindow("INSTALL_FROMCD_PANEL", args);
panel.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
panel.Get<ButtonWidget>("MODS_BUTTON").OnClick = () =>
{
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", () => {} },
// Close this panel
{ "onSwitch", Ui.CloseWindow },
});
};
}
示例4: 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());
}
示例5: InstallMusicLogic
public InstallMusicLogic(Widget widget)
{
var installMusicContainer = widget.Get("INSTALL_MUSIC_PANEL");
var cancelButton = installMusicContainer.GetOrNull<ButtonWidget>("CANCEL_BUTTON");
if (cancelButton != null)
cancelButton.OnClick = () => Game.InitializeMod(Game.Settings.Game.Mod, null);
var copyFromDiscButton = installMusicContainer.GetOrNull<ButtonWidget>("COPY_FROM_CD_BUTTON");
if (copyFromDiscButton != null)
{
copyFromDiscButton.OnClick = () =>
{
Ui.OpenWindow("INSTALL_FROMCD_PANEL", new WidgetArgs() {
{ "continueLoading", () => Game.InitializeMod(Game.Settings.Game.Mod, null) },
});
};
}
var downloadButton = installMusicContainer.GetOrNull<ButtonWidget>("DOWNLOAD_BUTTON");
if (downloadButton != null)
{
var installData = Game.ModData.Manifest.Get<ContentInstaller>();
downloadButton.IsVisible = () => !string.IsNullOrEmpty(installData.MusicPackageMirrorList);
downloadButton.OnClick = () =>
{
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", new WidgetArgs() {
{ "afterInstall", () => Game.InitializeMod(Game.Settings.Game.Mod, null) },
{ "mirrorListUrl", installData.MusicPackageMirrorList },
});
};
}
}
示例6: LoadWidget
public Widget LoadWidget(WidgetArgs args, Widget parent, MiniYamlNode node)
{
var widget = NewWidget(node.Key, args);
if (parent != null)
parent.AddChild( widget );
if (node.Key.Contains("@"))
FieldLoader.LoadField(widget, "Id", node.Key.Split('@')[1]);
foreach (var child in node.Value.Nodes)
if (child.Key != "Children")
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
if (!args.ContainsKey("modRules"))
args = new WidgetArgs(args) { { "modRules", modData.DefaultRules } };
widget.Initialize(args);
foreach (var child in node.Value.Nodes)
if (child.Key == "Children")
foreach (var c in child.Value.Nodes)
LoadWidget( args, widget, c);
widget.PostInit(args);
return widget;
}
示例7: MainMenuButtonsLogic
public MainMenuButtonsLogic(Widget widget)
{
rootMenu = widget;
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Ui.Root, "PERF_BG" );
widget.Get<ButtonWidget>("MAINMENU_BUTTON_JOIN").OnClick = () => OpenGamePanel("JOINSERVER_BG");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_CREATE").OnClick = () => OpenGamePanel("CREATESERVER_BG");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_DIRECTCONNECT").OnClick = () => OpenGamePanel("DIRECTCONNECT_BG");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_SETTINGS").OnClick = () => Ui.OpenWindow("SETTINGS_MENU");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_MUSIC").OnClick = () => Ui.OpenWindow("MUSIC_MENU");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_MODS").OnClick = () =>
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", () => {} },
{ "onSwitch", RemoveShellmapUI }
});
widget.Get<ButtonWidget>("MAINMENU_BUTTON_REPLAY_VIEWER").OnClick = () =>
Ui.OpenWindow("REPLAYBROWSER_BG", new WidgetArgs()
{
{ "onExit", () => {} },
{ "onStart", RemoveShellmapUI }
});
widget.Get<ButtonWidget>("MAINMENU_BUTTON_QUIT").OnClick = () => Game.Exit();
}
示例8: 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;
}
示例9: 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;
}
}
示例10: 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);
}
示例11: ReplayBrowserLogic
public ReplayBrowserLogic( [ObjectCreator.Param] Widget widget )
{
this.widget = widget;
widget.GetWidget<ButtonWidget>("CANCEL_BUTTON").OnClick = () => Widget.CloseWindow();
/* find some replays? */
var rl = widget.GetWidget<ScrollPanelWidget>("REPLAY_LIST");
var replayDir = Path.Combine(Platform.SupportDir, "Replays");
var template = widget.GetWidget<ScrollItemWidget>("REPLAY_TEMPLATE");
CurrentReplay = null;
rl.RemoveChildren();
if (Directory.Exists(replayDir))
foreach (var replayFile in Directory.GetFiles(replayDir, "*.rep").Reverse())
AddReplay(rl, replayFile, template);
widget.GetWidget<ButtonWidget>("WATCH_BUTTON").OnClick = () =>
{
if (currentReplay != null)
{
Widget.CloseWindow();
Game.JoinReplay(CurrentReplay);
}
};
widget.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null;
}
示例12: PreReleaseWarningPrompt
public PreReleaseWarningPrompt(Widget widget, World world, ModData modData)
{
if (!promptAccepted && modData.Manifest.Metadata.Version != "{DEV_VERSION}")
widget.Get<ButtonWidget>("CONTINUE_BUTTON").OnClick = () => ShowMainMenu(world);
else
ShowMainMenu(world);
}
示例13: InstallLogic
public InstallLogic(Widget widget, Action continueLoading)
{
var installData = Game.ModData.Manifest.Get<ContentInstaller>();
var panel = widget.Get("INSTALL_PANEL");
var widgetArgs = new WidgetArgs()
{
{ "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } },
{ "continueLoading", continueLoading },
{ "mirrorListUrl", installData.PackageMirrorList },
};
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", widgetArgs);
panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
Ui.OpenWindow("INSTALL_FROMCD_PANEL", widgetArgs);
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
{
Game.RunAfterTick(() =>
{
Game.Settings.Game.PreviousMod = Game.ModData.Manifest.Mod.Id;
Game.InitializeMod("modchooser", null);
});
};
}
示例14: LoadIngamePlayerOrObserverUILogic
public LoadIngamePlayerOrObserverUILogic(Widget widget, World world)
{
var ingameRoot = widget.Get("INGAME_ROOT");
var worldRoot = ingameRoot.Get("WORLD_ROOT");
var menuRoot = ingameRoot.Get("MENU_ROOT");
var playerRoot = worldRoot.Get("PLAYER_ROOT");
if (world.LocalPlayer == null)
Game.LoadWidget(world, "OBSERVER_WIDGETS", playerRoot, new WidgetArgs());
else
{
var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs());
var sidebarTicker = playerWidgets.Get<LogicTickerWidget>("SIDEBAR_TICKER");
sidebarTicker.OnTick = () =>
{
// Switch to observer mode after win/loss
if (world.ObserveAfterWinOrLose && world.LocalPlayer.WinState != WinState.Undefined)
Game.RunAfterTick(() =>
{
playerRoot.RemoveChildren();
Game.LoadWidget(world, "OBSERVER_WIDGETS", playerRoot, new WidgetArgs());
});
};
}
Game.LoadWidget(world, "CHAT_PANEL", worldRoot, new WidgetArgs());
world.GameOver += () =>
{
worldRoot.RemoveChildren();
menuRoot.RemoveChildren();
Game.LoadWidget(world, "LEAVE_MAP_WIDGET", menuRoot, new WidgetArgs());
};
}
示例15: 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);
};
}
}