This commit is contained in:
Paul Chote
2011-05-08 18:45:52 +12:00
parent 8957caeaca
commit 33b35f768e
4 changed files with 23 additions and 29 deletions

View File

@@ -30,17 +30,17 @@ namespace OpenRA.Mods.Cnc.Widgets
Dictionary<string, string> CountryNames; Dictionary<string, string> CountryNames;
string MapUid; string MapUid;
Map Map; Map Map;
public static ColorRamp CurrentColorPreview;
// Must be set only once on game start readonly Action OnGameStart;
// TODO: This is stupid readonly Action onExit;
readonly OrderManager orderManager;
readonly WorldRenderer worldRenderer;
public static ColorRamp CurrentColorPreview;
static bool staticSetup; static bool staticSetup;
public static CncLobbyLogic GetHandler() public static CncLobbyLogic GetHandler()
{ {
var panel = Widget.RootWidget.GetWidget("SERVER_LOBBY"); var panel = Widget.RootWidget.GetWidget("SERVER_LOBBY");
// The panel may not be open anymore
if (panel == null) if (panel == null)
return null; return null;
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Cnc.Widgets
if (handler == null) if (handler == null)
return; return;
handler.onGameStart(); handler.OnGameStart();
} }
static void AddChatLineStub(Color c, string from, string text) static void AddChatLineStub(Color c, string from, string text)
@@ -84,7 +84,6 @@ namespace OpenRA.Mods.Cnc.Widgets
handler.ConnectionStateChanged(om); handler.ConnectionStateChanged(om);
} }
// Listen for connection failures // Listen for connection failures
void ConnectionStateChanged(OrderManager om) void ConnectionStateChanged(OrderManager om)
{ {
@@ -98,7 +97,7 @@ namespace OpenRA.Mods.Cnc.Widgets
Game.OpenWindow("SERVER_LOBBY", new Dictionary<string, object>() Game.OpenWindow("SERVER_LOBBY", new Dictionary<string, object>()
{ {
{ "onExit", onExit }, { "onExit", onExit },
{ "onStart", onGameStart } { "onStart", OnGameStart }
}); });
}); });
@@ -118,11 +117,6 @@ namespace OpenRA.Mods.Cnc.Widgets
} }
} }
readonly Action onGameStart;
readonly Action onExit;
readonly OrderManager orderManager;
readonly WorldRenderer worldRenderer;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
internal CncLobbyLogic([ObjectCreator.Param( "widget" )] Widget lobby, internal CncLobbyLogic([ObjectCreator.Param( "widget" )] Widget lobby,
[ObjectCreator.Param] OrderManager orderManager, [ObjectCreator.Param] OrderManager orderManager,
@@ -132,7 +126,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
this.orderManager = orderManager; this.orderManager = orderManager;
this.worldRenderer = worldRenderer; this.worldRenderer = worldRenderer;
this.onGameStart = onStart; this.OnGameStart = onStart;
this.onExit = onExit; this.onExit = onExit;
if (!staticSetup) if (!staticSetup)

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
public class CncMapChooserLogic : IWidgetDelegate public class CncMapChooserLogic : IWidgetDelegate
{ {
Map map = null; Map map;
Widget scrollpanel; Widget scrollpanel;
Widget itemTemplate; Widget itemTemplate;

View File

@@ -22,21 +22,21 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
public class CncReplayBrowserLogic : IWidgetDelegate public class CncReplayBrowserLogic : IWidgetDelegate
{ {
Widget widget; Widget panel;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public CncReplayBrowserLogic([ObjectCreator.Param] Widget widget, public CncReplayBrowserLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] Action onExit, [ObjectCreator.Param] Action onExit,
[ObjectCreator.Param] Action onStart) [ObjectCreator.Param] Action onStart)
{ {
this.widget = widget; panel = widget.GetWidget("REPLAYBROWSER_PANEL");
widget.GetWidget<CncMenuButtonWidget>("CANCEL_BUTTON").OnClick = onExit; panel.GetWidget<CncMenuButtonWidget>("CANCEL_BUTTON").OnClick = onExit;
var rl = widget.GetWidget<ScrollPanelWidget>("REPLAY_LIST"); var rl = panel.GetWidget<ScrollPanelWidget>("REPLAY_LIST");
var replayDir = Path.Combine(Platform.SupportDir, "Replays"); var replayDir = Path.Combine(Platform.SupportDir, "Replays");
var template = widget.GetWidget("REPLAY_TEMPLATE"); var template = panel.GetWidget("REPLAY_TEMPLATE");
CurrentReplay = null; CurrentReplay = null;
rl.RemoveChildren(); rl.RemoveChildren();
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc.Widgets
CurrentReplay = files.FirstOrDefault(); CurrentReplay = files.FirstOrDefault();
} }
var watch = widget.GetWidget<CncMenuButtonWidget>("WATCH_BUTTON"); var watch = panel.GetWidget<CncMenuButtonWidget>("WATCH_BUTTON");
watch.IsDisabled = () => currentReplay == null || currentMap == null; watch.IsDisabled = () => currentReplay == null || currentMap == null;
watch.OnClick = () => watch.OnClick = () =>
{ {
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Cnc.Widgets
} }
}; };
widget.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null; panel.GetWidget("REPLAY_INFO").IsVisible = () => currentReplay != null;
} }
string currentReplay = null; string currentReplay = null;
@@ -78,14 +78,14 @@ namespace OpenRA.Mods.Cnc.Widgets
var summary = new ReplaySummary(currentReplay); var summary = new ReplaySummary(currentReplay);
currentMap = summary.Map(); currentMap = summary.Map();
widget.GetWidget<LabelWidget>("DURATION").GetText = panel.GetWidget<LabelWidget>("DURATION").GetText =
() => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */); () => WidgetUtils.FormatTime(summary.Duration * 3 /* todo: 3:1 ratio isnt always true. */);
widget.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => currentMap; panel.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => currentMap;
widget.GetWidget<LabelWidget>("MAP_TITLE").GetText = panel.GetWidget<LabelWidget>("MAP_TITLE").GetText =
() => currentMap != null ? currentMap.Title : "(Unknown Map)"; () => currentMap != null ? currentMap.Title : "(Unknown Map)";
var players = summary.LobbyInfo.Slots.Count(s => summary.LobbyInfo.ClientInSlot(s) != null || s.Bot != null); var players = summary.LobbyInfo.Slots.Count(s => summary.LobbyInfo.ClientInSlot(s) != null || s.Bot != null);
widget.GetWidget<LabelWidget>("PLAYERS").GetText = () => players.ToString(); panel.GetWidget<LabelWidget>("PLAYERS").GetText = () => players.ToString();
} }
catch(Exception e) catch(Exception e)
{ {

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
// Prevent repeated additions of RefreshServerList to the master server // Prevent repeated additions of RefreshServerList to the master server
static bool masterServerSetup; static bool masterServerSetup;
GameServer currentServer = null; GameServer currentServer;
Widget serverTemplate; Widget serverTemplate;
enum SearchStatus enum SearchStatus