本文整理汇总了C#中Widget.GetWidget方法的典型用法代码示例。如果您正苦于以下问题:C# Widget.GetWidget方法的具体用法?C# Widget.GetWidget怎么用?C# Widget.GetWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Widget
的用法示例。
在下文中一共展示了Widget.GetWidget方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LobbyDelegate
public LobbyDelegate( [ObjectCreator.Param( "widget" )] Widget lobby )
{
Game.LobbyInfoChanged += UpdateCurrentMap;
UpdateCurrentMap();
CurrentColorPreview1 = Game.Settings.Player.Color1;
CurrentColorPreview2 = Game.Settings.Player.Color2;
Players = lobby.GetWidget("PLAYERS");
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
EmptySlotTemplate = Players.GetWidget("TEMPLATE_EMPTY");
EmptySlotTemplateHost = Players.GetWidget("TEMPLATE_EMPTY_HOST");
var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
mapPreview.Map = () => Map;
mapPreview.OnSpawnClick = sp =>
{
if (Game.LocalClient.State == Session.ClientState.Ready) return;
var owned = Game.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
if (sp == 0 || !owned)
Game.IssueOrder(Order.Command("spawn {0}".F(sp)));
};
mapPreview.SpawnColors = () =>
{
var spawns = Map.SpawnPoints;
var sc = new Dictionary<int2, Color>();
for (int i = 1; i <= spawns.Count(); i++)
{
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
if (client == null)
continue;
sc.Add(spawns.ElementAt(i - 1), client.Color1);
}
return sc;
};
CountryNames = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>().ToDictionary(a => a.Race, a => a.Name);
CountryNames.Add("random", "Random");
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
mapButton.OnMouseUp = mi =>
{
Widget.OpenWindow("MAP_CHOOSER").SpecialOneArg(MapUid); // WTF
return true;
};
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
disconnectButton.OnMouseUp = mi =>
{
Game.Disconnect();
return true;
};
var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX");
lockTeamsCheckbox.IsVisible = () => lockTeamsCheckbox.Visible && true;
lockTeamsCheckbox.Checked = () => Game.LobbyInfo.GlobalSettings.LockTeams;
lockTeamsCheckbox.OnMouseDown = mi =>
{
if (Game.IsHost)
Game.IssueOrder(Order.Command(
"lockteams {0}".F(!Game.LobbyInfo.GlobalSettings.LockTeams)));
return true;
};
var startGameButton = lobby.GetWidget("START_GAME_BUTTON");
startGameButton.OnMouseUp = mi =>
{
mapButton.Visible = false;
disconnectButton.Visible = false;
lockTeamsCheckbox.Visible = false;
Game.IssueOrder(Order.Command("startgame"));
return true;
};
startGameButton.IsVisible = () => Game.IsHost;
Game.LobbyInfoChanged += JoinedServer;
Game.ConnectionStateChanged += ResetConnectionState;
Game.LobbyInfoChanged += UpdatePlayerList;
Game.AddChatLine += lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").AddLine;
bool teamChat = false;
var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE");
var chatTextField = lobby.GetWidget<TextFieldWidget>("CHAT_TEXTFIELD");
chatTextField.OnEnterKey = () =>
{
if (chatTextField.Text.Length == 0)
return true;
var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text);
Game.IssueOrder(order);
chatTextField.Text = "";
return true;
};
//.........这里部分代码省略.........
示例2: SettingsMenuDelegate
public SettingsMenuDelegate()
{
bg = Widget.RootWidget.GetWidget<BackgroundWidget>("SETTINGS_MENU");
var tabs = bg.GetWidget<ContainerWidget>("TAB_CONTAINER");
//Tabs
tabs.GetWidget<ButtonWidget>("GENERAL").OnMouseUp = mi => FlipToTab("GENERAL_PANE");
tabs.GetWidget<ButtonWidget>("AUDIO").OnMouseUp = mi => FlipToTab("AUDIO_PANE");
tabs.GetWidget<ButtonWidget>("DISPLAY").OnMouseUp = mi => FlipToTab("DISPLAY_PANE");
tabs.GetWidget<ButtonWidget>("DEBUG").OnMouseUp = mi => FlipToTab("DEBUG_PANE");
FlipToTab("GENERAL_PANE");
//General
var general = bg.GetWidget("GENERAL_PANE");
var name = general.GetWidget<TextFieldWidget>("NAME");
name.Text = Game.Settings.Player.Name;
name.OnLoseFocus = () =>
{
name.Text = name.Text.Trim();
if (name.Text.Length == 0)
name.Text = Game.Settings.Player.Name;
else
Game.Settings.Player.Name = name.Text;
};
name.OnEnterKey = () => { name.LoseFocus(); return true; };
var edgeScroll = general.GetWidget<CheckboxWidget>("EDGE_SCROLL");
edgeScroll.Checked = () => Game.Settings.Game.ViewportEdgeScroll;
edgeScroll.OnMouseDown = mi =>
{
Game.Settings.Game.ViewportEdgeScroll ^= true;
return true;
};
// Added scroll sensitivity - Gecko
var edgeScrollSlider = general.GetWidget<SliderWidget>("EDGE_SCROLL_AMOUNT");
if (edgeScrollSlider != null) // Backwards compatible - Gecko
{
edgeScrollSlider.SetOffset(Game.Settings.Game.ViewportEdgeScrollStep);
edgeScrollSlider.OnChange += _ => { Game.Settings.Game.ViewportEdgeScrollStep = edgeScrollSlider.GetOffset(); };
Game.Settings.Game.ViewportEdgeScrollStep = edgeScrollSlider.GetOffset();
}
var inverseScroll = general.GetWidget<CheckboxWidget>("INVERSE_SCROLL");
inverseScroll.Checked = () => Game.Settings.Game.InverseDragScroll;
inverseScroll.OnMouseDown = mi =>
{
Game.Settings.Game.InverseDragScroll ^= true;
return true;
};
var teamChatToggle = general.GetWidget<CheckboxWidget>("TEAMCHAT_TOGGLE");
teamChatToggle.Checked = () => Game.Settings.Game.TeamChatToggle;
teamChatToggle.OnMouseDown = mi =>
{
Game.Settings.Game.TeamChatToggle ^= true;
return true;
};
// Audio
var audio = bg.GetWidget("AUDIO_PANE");
var soundslider = audio.GetWidget<SliderWidget>("SOUND_VOLUME");
soundslider.OnChange += x => { Sound.SoundVolume = x; };
soundslider.GetOffset = () => { return Sound.SoundVolume; };
soundslider.SetOffset(Sound.SoundVolume);
var musicslider = audio.GetWidget<SliderWidget>("MUSIC_VOLUME");
musicslider.OnChange += x => { Sound.MusicVolume = x; };
musicslider.GetOffset = () => { return Sound.MusicVolume; };
musicslider.SetOffset(Sound.MusicVolume);
// Display
var display = bg.GetWidget("DISPLAY_PANE");
var fullscreen = display.GetWidget<CheckboxWidget>("FULLSCREEN_CHECKBOX");
fullscreen.Checked = () => {return Game.Settings.Graphics.Mode != WindowMode.Windowed;};
fullscreen.OnMouseDown = mi =>
{
Game.Settings.Graphics.Mode = (Game.Settings.Graphics.Mode == WindowMode.Windowed) ? WindowMode.PseudoFullscreen : WindowMode.Windowed;
return true;
};
var width = display.GetWidget<TextFieldWidget>("SCREEN_WIDTH");
Game.Settings.Graphics.WindowedSize.X = (Game.Settings.Graphics.WindowedSize.X < Game.Settings.Graphics.MinResolution.X)?
Game.Settings.Graphics.MinResolution.X : Game.Settings.Graphics.WindowedSize.X;
width.Text = Game.Settings.Graphics.WindowedSize.X.ToString();
width.OnLoseFocus = () =>
{
try {
var w = int.Parse(width.Text);
if (w > Game.Settings.Graphics.MinResolution.X && w <= Screen.PrimaryScreen.Bounds.Size.Width)
Game.Settings.Graphics.WindowedSize = new int2(w, Game.Settings.Graphics.WindowedSize.Y);
else
width.Text = Game.Settings.Graphics.WindowedSize.X.ToString();
}
catch (FormatException) {
width.Text = Game.Settings.Graphics.WindowedSize.X.ToString();
}
//.........这里部分代码省略.........