create widgets on demand
This commit is contained in:
@@ -279,6 +279,35 @@ namespace OpenRA
|
||||
|
||||
JoinLocal();
|
||||
StartGame(modData.Manifest.ShellmapUid);
|
||||
|
||||
Game.BeforeGameStart = () => Widget.OpenWindow("INGAME_ROOT");
|
||||
|
||||
Game.ConnectionStateChanged = () =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
switch( Game.orderManager.Connection.ConnectionState )
|
||||
{
|
||||
case ConnectionState.PreConnecting:
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
break;
|
||||
case ConnectionState.Connecting:
|
||||
Widget.OpenWindow("CONNECTING_BG");
|
||||
break;
|
||||
case ConnectionState.NotConnected:
|
||||
Widget.OpenWindow("CONNECTION_FAILED_BG");
|
||||
break;
|
||||
case ConnectionState.Connected:
|
||||
var lobby = Widget.OpenWindow("SERVER_LOBBY");
|
||||
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
|
||||
lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true;
|
||||
lobby.GetWidget("DISCONNECT_BUTTON").Visible = true;
|
||||
//r.GetWidget("INGAME_ROOT").GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
|
||||
ResetTimer();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace OpenRA
|
||||
public readonly SheetBuilder SheetBuilder;
|
||||
public readonly CursorSheetBuilder CursorSheetBuilder;
|
||||
public readonly Dictionary<string, MapStub> AvailableMaps;
|
||||
public readonly WidgetLoader WidgetLoader;
|
||||
public ILoadScreen LoadScreen = null;
|
||||
|
||||
public ModData( params string[] mods )
|
||||
@@ -39,6 +40,7 @@ namespace OpenRA
|
||||
SheetBuilder = new SheetBuilder( TextureChannel.Red );
|
||||
CursorSheetBuilder = new CursorSheetBuilder( this );
|
||||
AvailableMaps = FindMaps( mods );
|
||||
WidgetLoader = new WidgetLoader( this );
|
||||
}
|
||||
|
||||
// TODO: Do this nicer
|
||||
|
||||
@@ -14,56 +14,37 @@ namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
public class ConnectionDialogsDelegate : IWidgetDelegate
|
||||
{
|
||||
public ConnectionDialogsDelegate()
|
||||
[ObjectCreator.UseCtor]
|
||||
public ConnectionDialogsDelegate( [ObjectCreator.Param( "widget" )] Widget widget )
|
||||
{
|
||||
var r = Widget.RootWidget;
|
||||
r.GetWidget("CONNECTION_BUTTON_ABORT").OnMouseUp = mi => {
|
||||
r.GetWidget("CONNECTION_BUTTON_ABORT").Parent.Visible = false;
|
||||
widget.GetWidget("CONNECTION_BUTTON_ABORT").OnMouseUp = mi => {
|
||||
widget.GetWidget("CONNECTION_BUTTON_ABORT").Parent.Visible = false;
|
||||
Game.Disconnect();
|
||||
return true;
|
||||
};
|
||||
r.GetWidget("CONNECTION_BUTTON_CANCEL").OnMouseUp = mi => {
|
||||
r.GetWidget("CONNECTION_BUTTON_CANCEL").Parent.Visible = false;
|
||||
|
||||
widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () =>
|
||||
"Connecting to {0}:{1}...".F(Game.CurrentHost, Game.CurrentPort);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConnectionFailedDelegate : IWidgetDelegate
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public ConnectionFailedDelegate( [ObjectCreator.Param( "widget" )] Widget widget )
|
||||
{
|
||||
widget.GetWidget("CONNECTION_BUTTON_CANCEL").OnMouseUp = mi => {
|
||||
widget.GetWidget("CONNECTION_BUTTON_CANCEL").Parent.Visible = false;
|
||||
Game.Disconnect();
|
||||
return true;
|
||||
};
|
||||
r.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => {
|
||||
widget.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => {
|
||||
Game.JoinServer(Game.CurrentHost, Game.CurrentPort);
|
||||
return true;
|
||||
};
|
||||
|
||||
r.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () =>
|
||||
"Connecting to {0}:{1}...".F(Game.CurrentHost, Game.CurrentPort);
|
||||
|
||||
r.GetWidget<LabelWidget>("CONNECTION_FAILED_DESC").GetText = () =>
|
||||
widget.GetWidget<LabelWidget>("CONNECTION_FAILED_DESC").GetText = () =>
|
||||
"Could not connect to {0}:{1}".F(Game.CurrentHost, Game.CurrentPort);
|
||||
|
||||
Game.ConnectionStateChanged += () =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
switch( Game.orderManager.Connection.ConnectionState )
|
||||
{
|
||||
case ConnectionState.PreConnecting:
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
break;
|
||||
case ConnectionState.Connecting:
|
||||
Widget.OpenWindow("CONNECTING_BG");
|
||||
break;
|
||||
case ConnectionState.NotConnected:
|
||||
Widget.OpenWindow("CONNECTION_FAILED_BG");
|
||||
break;
|
||||
case ConnectionState.Connected:
|
||||
Widget.OpenWindow("SERVER_LOBBY");
|
||||
|
||||
var lobby = r.GetWidget("SERVER_LOBBY");
|
||||
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
|
||||
lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true;
|
||||
lobby.GetWidget("DISCONNECT_BUTTON").Visible = true;
|
||||
r.GetWidget("INGAME_ROOT").GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,25 +15,17 @@ namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
public class CreateServerMenuDelegate : IWidgetDelegate
|
||||
{
|
||||
public CreateServerMenuDelegate()
|
||||
[ObjectCreator.UseCtor]
|
||||
public CreateServerMenuDelegate( [ObjectCreator.Param( "widget" )] Widget cs )
|
||||
{
|
||||
var settings = Game.Settings;
|
||||
|
||||
var r = Widget.RootWidget;
|
||||
var cs = r.GetWidget("CREATESERVER_BG");
|
||||
r.GetWidget("MAINMENU_BUTTON_CREATE").OnMouseUp = mi => {
|
||||
Widget.OpenWindow("CREATESERVER_BG");
|
||||
return true;
|
||||
};
|
||||
|
||||
cs.GetWidget("BUTTON_CANCEL").OnMouseUp = mi => {
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
cs.GetWidget("BUTTON_START").OnMouseUp = mi => {
|
||||
Widget.OpenWindow("SERVER_LOBBY");
|
||||
|
||||
var map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Key;
|
||||
|
||||
settings.Server.Name = cs.GetWidget<TextFieldWidget>("GAME_TITLE").Text;
|
||||
|
||||
@@ -27,7 +27,8 @@ namespace OpenRA.Widgets.Delegates
|
||||
public static Color CurrentColorPreview1;
|
||||
public static Color CurrentColorPreview2;
|
||||
|
||||
public LobbyDelegate()
|
||||
[ObjectCreator.UseCtor]
|
||||
public LobbyDelegate( [ObjectCreator.Param( "widget" )] Widget lobby )
|
||||
{
|
||||
Game.LobbyInfoChanged += UpdateCurrentMap;
|
||||
UpdateCurrentMap();
|
||||
@@ -35,9 +36,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
CurrentColorPreview1 = Game.Settings.Player.Color1;
|
||||
CurrentColorPreview2 = Game.Settings.Player.Color2;
|
||||
|
||||
var r = Widget.RootWidget;
|
||||
var lobby = r.GetWidget("SERVER_LOBBY");
|
||||
Players = Widget.RootWidget.GetWidget("SERVER_LOBBY").GetWidget("PLAYERS");
|
||||
Players = lobby.GetWidget("PLAYERS");
|
||||
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
|
||||
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
|
||||
EmptySlotTemplate = Players.GetWidget("TEMPLATE_EMPTY");
|
||||
@@ -74,8 +73,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
|
||||
mapButton.OnMouseUp = mi =>
|
||||
{
|
||||
r.GetWidget("MAP_CHOOSER").SpecialOneArg(MapUid);
|
||||
Widget.OpenWindow("MAP_CHOOSER");
|
||||
Widget.OpenWindow("MAP_CHOOSER").SpecialOneArg(MapUid); // WTF
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,13 +14,17 @@ namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
public class MainMenuButtonsDelegate : IWidgetDelegate
|
||||
{
|
||||
public MainMenuButtonsDelegate()
|
||||
[ObjectCreator.UseCtor]
|
||||
public MainMenuButtonsDelegate( [ObjectCreator.Param( "widget" )] Widget widget )
|
||||
{
|
||||
// Main menu is the default window
|
||||
Widget.WindowList.Push("MAINMENU_BG");
|
||||
Widget.RootWidget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => { Game.Exit(); return true; };
|
||||
widget.GetWidget( "MAINMENU_BUTTON_JOIN" ).OnMouseUp = mi => { Widget.OpenWindow( "JOINSERVER_BG" ); return true; };
|
||||
widget.GetWidget( "MAINMENU_BUTTON_CREATE" ).OnMouseUp = mi => { Widget.OpenWindow( "CREATESERVER_BG" ); return true; };
|
||||
widget.GetWidget( "MAINMENU_BUTTON_SETTINGS" ).OnMouseUp = mi => { Widget.OpenWindow( "SETTINGS_MENU" ); return true; };
|
||||
widget.GetWidget( "MAINMENU_BUTTON_MUSIC" ).OnMouseUp = mi => { Widget.OpenWindow( "MUSIC_MENU" ); return true; };
|
||||
widget.GetWidget( "MAINMENU_BUTTON_QUIT" ).OnMouseUp = mi => { Game.Exit(); return true; };
|
||||
|
||||
var version = Widget.RootWidget.GetWidget("MAINMENU_BG").GetWidget<LabelWidget>("VERSION_STRING");
|
||||
var version = widget.GetWidget<LabelWidget>("VERSION_STRING");
|
||||
|
||||
if (FileSystem.Exists("VERSION"))
|
||||
{
|
||||
|
||||
@@ -17,10 +17,10 @@ namespace OpenRA.Widgets.Delegates
|
||||
public class MapChooserDelegate : IWidgetDelegate
|
||||
{
|
||||
MapStub Map = null;
|
||||
public MapChooserDelegate()
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public MapChooserDelegate( [ObjectCreator.Param( "widget" )] Widget bg )
|
||||
{
|
||||
var r = Widget.RootWidget;
|
||||
var bg = r.GetWidget("MAP_CHOOSER");
|
||||
bg.SpecialOneArg = (map) => RefreshMapList(map);
|
||||
var ml = bg.GetWidget<ListBoxWidget>("MAP_LIST");
|
||||
|
||||
|
||||
@@ -28,11 +28,6 @@ namespace OpenRA.Widgets.Delegates
|
||||
return true;
|
||||
};
|
||||
|
||||
Widget.RootWidget.GetWidget("MAINMENU_BUTTON_MUSIC").OnMouseUp = mi => {
|
||||
Widget.OpenWindow("MUSIC_MENU");
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
|
||||
{
|
||||
if (CurrentSong == null)
|
||||
|
||||
@@ -23,29 +23,21 @@ namespace OpenRA.Widgets.Delegates
|
||||
GameServer currentServer = null;
|
||||
Widget ServerTemplate;
|
||||
|
||||
public ServerBrowserDelegate()
|
||||
[ObjectCreator.UseCtor]
|
||||
public ServerBrowserDelegate( [ObjectCreator.Param( "widget" )] Widget widget )
|
||||
{
|
||||
var r = Widget.RootWidget;
|
||||
var bg = r.GetWidget("JOINSERVER_BG");
|
||||
var dc = r.GetWidget("DIRECTCONNECT_BG");
|
||||
var bg = widget.GetWidget("JOINSERVER_BG");
|
||||
|
||||
MasterServerQuery.OnComplete += games => RefreshServerList(games);
|
||||
|
||||
r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.OpenWindow("JOINSERVER_BG");
|
||||
|
||||
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
r.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list...";
|
||||
widget.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
widget.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list...";
|
||||
|
||||
bg.Children.RemoveAll(a => GameButtons.Contains(a));
|
||||
GameButtons.Clear();
|
||||
|
||||
MasterServerQuery.Refresh(Game.Settings.Server.MasterServer);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("SERVER_INFO").IsVisible = () => currentServer != null;
|
||||
var preview = bg.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
||||
preview.Map = () => CurrentMap();
|
||||
@@ -70,8 +62,8 @@ namespace OpenRA.Widgets.Delegates
|
||||
|
||||
bg.GetWidget("REFRESH_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
r.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list...";
|
||||
widget.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
widget.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list...";
|
||||
|
||||
bg.Children.RemoveAll(a => GameButtons.Contains(a));
|
||||
GameButtons.Clear();
|
||||
@@ -90,8 +82,6 @@ namespace OpenRA.Widgets.Delegates
|
||||
bg.GetWidget("DIRECTCONNECT_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
|
||||
dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text = Game.Settings.Player.LastServer;
|
||||
Widget.OpenWindow("DIRECTCONNECT_BG");
|
||||
return true;
|
||||
};
|
||||
@@ -123,29 +113,6 @@ namespace OpenRA.Widgets.Delegates
|
||||
Game.JoinServer(currentServer.Address.Split(':')[0], int.Parse(currentServer.Address.Split(':')[1]));
|
||||
return true;
|
||||
};
|
||||
|
||||
// Direct Connect
|
||||
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
|
||||
var address = dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text;
|
||||
var cpts = address.Split(':').ToArray();
|
||||
if (cpts.Length != 2)
|
||||
return true;
|
||||
|
||||
Game.Settings.Player.LastServer = address;
|
||||
Game.Settings.Save();
|
||||
|
||||
Widget.CloseWindow();
|
||||
Game.JoinServer(cpts[0], int.Parse(cpts[1]));
|
||||
return true;
|
||||
};
|
||||
|
||||
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
return r.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp(mi);
|
||||
};
|
||||
}
|
||||
|
||||
MapStub CurrentMap()
|
||||
@@ -205,4 +172,37 @@ namespace OpenRA.Widgets.Delegates
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DirectConnectDelegate : IWidgetDelegate
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public DirectConnectDelegate( [ObjectCreator.Param( "widget" )] Widget widget )
|
||||
{
|
||||
var dc = widget.GetWidget("DIRECTCONNECT_BG");
|
||||
|
||||
dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text = Game.Settings.Player.LastServer;
|
||||
|
||||
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
|
||||
var address = dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text;
|
||||
var cpts = address.Split(':').ToArray();
|
||||
if (cpts.Length != 2)
|
||||
return true;
|
||||
|
||||
Game.Settings.Player.LastServer = address;
|
||||
Game.Settings.Save();
|
||||
|
||||
Widget.CloseWindow();
|
||||
Game.JoinServer(cpts[0], int.Parse(cpts[1]));
|
||||
return true;
|
||||
};
|
||||
|
||||
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
return widget.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp(mi);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,14 +153,6 @@ namespace OpenRA.Widgets.Delegates
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
// Menu Buttons
|
||||
Widget.RootWidget.GetWidget("MAINMENU_BUTTON_SETTINGS").OnMouseUp = mi => {
|
||||
Widget.OpenWindow("SETTINGS_MENU");
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
string open = null;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace OpenRA.Widgets
|
||||
public string Width = "0";
|
||||
public string Height = "0";
|
||||
public string Delegate = null;
|
||||
public string EventHandler = null;
|
||||
public bool ClickThrough = true;
|
||||
public bool Visible = true;
|
||||
public readonly List<Widget> Children = new List<Widget>();
|
||||
@@ -35,7 +36,7 @@ namespace OpenRA.Widgets
|
||||
public Widget Parent = null;
|
||||
|
||||
static List<string> Delegates = new List<string>();
|
||||
public static Stack<string> WindowList = new Stack<string>();
|
||||
public static Stack<Widget> WindowList = new Stack<Widget>();
|
||||
|
||||
// Common Funcs that most widgets will want
|
||||
public Action<object> SpecialOneArg = (arg) => {};
|
||||
@@ -48,23 +49,12 @@ namespace OpenRA.Widgets
|
||||
|
||||
public Widget() { IsVisible = () => Visible; }
|
||||
|
||||
public static Widget RootWidget {
|
||||
get
|
||||
public static Widget RootWidget
|
||||
{
|
||||
if (rootWidget == null)
|
||||
{
|
||||
rootWidget = new ContainerWidget();
|
||||
foreach( var file in Game.modData.Manifest.ChromeLayout.Select( a => MiniYaml.FromFile( a ) ) )
|
||||
foreach( var w in file )
|
||||
rootWidget.AddChild( WidgetLoader.LoadWidget( w ) );
|
||||
|
||||
rootWidget.Initialize();
|
||||
rootWidget.InitDelegates();
|
||||
get { return rootWidget; }
|
||||
set { rootWidget = value; }
|
||||
}
|
||||
return rootWidget;
|
||||
}
|
||||
}
|
||||
private static Widget rootWidget = null;
|
||||
private static Widget rootWidget = new ContainerWidget();
|
||||
|
||||
public Widget(Widget widget)
|
||||
{
|
||||
@@ -132,14 +122,15 @@ namespace OpenRA.Widgets
|
||||
Evaluator.Evaluate(Y, substitutions),
|
||||
width,
|
||||
height);
|
||||
}
|
||||
|
||||
// Non-static func definitions
|
||||
|
||||
if (Delegate != null && !Delegates.Contains(Delegate))
|
||||
Delegates.Add(Delegate);
|
||||
|
||||
foreach (var child in Children)
|
||||
child.Initialize();
|
||||
public void PostInit()
|
||||
{
|
||||
if( Delegate != null )
|
||||
{
|
||||
var createDict = new Dictionary<string, object> { { "widget", this } };
|
||||
Game.modData.ObjectCreator.CreateObject<IWidgetDelegate>( Delegate, createDict );
|
||||
}
|
||||
}
|
||||
|
||||
public void InitDelegates()
|
||||
@@ -324,18 +315,17 @@ namespace OpenRA.Widgets
|
||||
|
||||
public static void CloseWindow()
|
||||
{
|
||||
RootWidget.GetWidget(WindowList.Pop()).Visible = false;
|
||||
if (WindowList.Count > 0)
|
||||
RootWidget.GetWidget(WindowList.Peek()).Visible = true;
|
||||
RootWidget.Children.Remove( WindowList.Pop() );
|
||||
if( WindowList.Count > 0 )
|
||||
rootWidget.Children.Add( WindowList.Peek() );
|
||||
}
|
||||
|
||||
public static Widget OpenWindow(string id)
|
||||
{
|
||||
if (WindowList.Count > 0)
|
||||
RootWidget.GetWidget(WindowList.Peek()).Visible = false;
|
||||
WindowList.Push(id);
|
||||
var window = RootWidget.GetWidget(id);
|
||||
window.Visible = true;
|
||||
var window = Game.modData.WidgetLoader.LoadWidget( rootWidget, id );
|
||||
if( WindowList.Count > 0 )
|
||||
rootWidget.Children.Remove( WindowList.Peek() );
|
||||
WindowList.Push( window );
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,29 +8,57 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
class WidgetLoader
|
||||
public class WidgetLoader
|
||||
{
|
||||
public static Widget LoadWidget(MiniYamlNode node)
|
||||
// foreach( var file in Game.modData.Manifest.ChromeLayout.Select( a => MiniYaml.FromFile( a ) ) )
|
||||
// foreach( var w in file )
|
||||
// rootWidget.AddChild( WidgetLoader.LoadWidget( w ) );
|
||||
|
||||
// rootWidget.Initialize();
|
||||
// rootWidget.InitDelegates();
|
||||
|
||||
Dictionary<string, MiniYamlNode> widgets = new Dictionary<string, MiniYamlNode>();
|
||||
|
||||
public WidgetLoader( ModData modData )
|
||||
{
|
||||
foreach( var file in modData.Manifest.ChromeLayout.Select( a => MiniYaml.FromFile( a ) ) )
|
||||
foreach( var w in file )
|
||||
widgets.Add( w.Key.Substring( w.Key.IndexOf( '@' ) + 1 ), w );
|
||||
}
|
||||
|
||||
public Widget LoadWidget( Widget parent, string w )
|
||||
{
|
||||
return LoadWidget( parent, widgets[ w ] );
|
||||
}
|
||||
|
||||
public Widget LoadWidget( Widget parent, MiniYamlNode node)
|
||||
{
|
||||
var widget = NewWidget(node.Key);
|
||||
parent.AddChild( widget );
|
||||
|
||||
foreach (var child in node.Value.Nodes)
|
||||
if (child.Key != "Children")
|
||||
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
|
||||
|
||||
widget.Initialize();
|
||||
|
||||
foreach (var child in node.Value.Nodes)
|
||||
{
|
||||
if (child.Key == "Children")
|
||||
foreach (var c in child.Value.Nodes)
|
||||
widget.AddChild(LoadWidget(c));
|
||||
else
|
||||
FieldLoader.LoadField(widget, child.Key, child.Value.Value);
|
||||
}
|
||||
LoadWidget( widget, c);
|
||||
|
||||
widget.PostInit();
|
||||
return widget;
|
||||
}
|
||||
|
||||
static Widget NewWidget(string widgetType)
|
||||
Widget NewWidget(string widgetType)
|
||||
{
|
||||
widgetType = widgetType.Split('@')[0];
|
||||
return Game.CreateObject<Widget>(widgetType + "Widget");
|
||||
|
||||
@@ -21,9 +21,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
var gameRoot = r.GetWidget("INGAME_ROOT");
|
||||
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
|
||||
|
||||
Game.BeforeGameStart += () => Widget.OpenWindow("INGAME_ROOT");
|
||||
Game.AfterGameStart += () => gameRoot.GetWidget<RadarBinWidget>("INGAME_RADAR_BIN").SetWorld(Game.world);
|
||||
|
||||
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
|
||||
optionsBG.Visible = !optionsBG.Visible;
|
||||
return true;
|
||||
|
||||
@@ -163,6 +163,9 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
int updateTicks = 0;
|
||||
public override void Tick(World w)
|
||||
{
|
||||
if( world != w )
|
||||
SetWorld( w );
|
||||
|
||||
var hasRadarNew = world.Queries.OwnedBy[world.LocalPlayer]
|
||||
.WithTrait<ProvidesRadar>()
|
||||
.Any(a => a.Trait.IsActive);
|
||||
|
||||
@@ -5,7 +5,7 @@ Background@SERVER_LOBBY:
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:800
|
||||
Height:600
|
||||
Visible:false
|
||||
Visible:true
|
||||
Children:
|
||||
Label@LOBBY_TITLE:
|
||||
X:0
|
||||
@@ -396,7 +396,7 @@ Background@MAP_CHOOSER:
|
||||
Delegate:MapChooserDelegate
|
||||
Width:800
|
||||
Height:600
|
||||
Visible:false
|
||||
Visible:true
|
||||
Children:
|
||||
Label@MAPCHOOSER_TITLE:
|
||||
X:0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Container@INGAME_ROOT:
|
||||
Id:INGAME_ROOT
|
||||
Delegate:IngameChromeDelegate
|
||||
Visible:false
|
||||
Visible:true
|
||||
Children:
|
||||
WorldInteractionController:
|
||||
X:0
|
||||
|
||||
@@ -103,7 +103,7 @@ Background@MUSIC_MENU:
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width: 450
|
||||
Height: 250
|
||||
Visible: false
|
||||
Visible: true
|
||||
Children:
|
||||
Label@SETTINGS_LABEL_TITLE:
|
||||
Id:SETTINGS_LABEL_TITLE
|
||||
|
||||
@@ -5,7 +5,7 @@ Background@CREATESERVER_BG:
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:400
|
||||
Height:240
|
||||
Visible:false
|
||||
Visible:true
|
||||
Children:
|
||||
Label@LABEL_TITLE:
|
||||
Id:LABEL_TITLE
|
||||
@@ -100,7 +100,7 @@ Background@JOINSERVER_BG:
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:700
|
||||
Height:410
|
||||
Visible:false
|
||||
Visible:true
|
||||
Children:
|
||||
Label@JOINSERVER_LABEL_TITLE:
|
||||
Id:JOINSERVER_LABEL_TITLE
|
||||
@@ -252,7 +252,7 @@ Background@DIRECTCONNECT_BG:
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:400
|
||||
Height:155
|
||||
Visible:false
|
||||
Visible:true
|
||||
Children:
|
||||
Label@DIRECTCONNECT_LABEL_TITLE:
|
||||
Id:DIRECTCONNECT_LABEL_TITLE
|
||||
@@ -296,12 +296,12 @@ Background@DIRECTCONNECT_BG:
|
||||
Bold:True
|
||||
Background@CONNECTION_FAILED_BG:
|
||||
Id:CONNECTION_FAILED_BG
|
||||
Delegate:ConnectionDialogsDelegate
|
||||
Delegate:ConnectionFailedDelegate
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:450
|
||||
Height:150
|
||||
Visible:false
|
||||
Visible:true
|
||||
Children:
|
||||
Label@CONNECTION_FAILED_TITLE:
|
||||
Id:CONNECTION_FAILED_TITLE
|
||||
@@ -343,7 +343,7 @@ Background@CONNECTING_BG:
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:450
|
||||
Height:150
|
||||
Visible:false
|
||||
Visible:true
|
||||
Children:
|
||||
Label@CONNECTING_TITLE:
|
||||
Id:CONNECTING_TITLE
|
||||
|
||||
@@ -5,7 +5,7 @@ Background@SETTINGS_MENU:
|
||||
Y:(WINDOW_BOTTOM- HEIGHT)/2
|
||||
Width: 450
|
||||
Height: 350
|
||||
Visible: false
|
||||
Visible: true
|
||||
Children:
|
||||
Label@SETTINGS_LABEL_TITLE:
|
||||
Id:SETTINGS_LABEL_TITLE
|
||||
|
||||
Reference in New Issue
Block a user