fix crashy behavior in TextFieldWidget

This commit is contained in:
Chris Forbes
2011-05-16 21:54:03 +12:00
committed by Paul Chote
parent a96b1ce01c
commit aa772db9a7
5 changed files with 31 additions and 34 deletions

View File

@@ -46,6 +46,7 @@ namespace OpenRA.Mods.Cnc.Widgets
ChromeProvider.GetImage("checkbox", "checked"),
new float2(rect.Left + 2, rect.Top + 2));
}
public override Widget Clone() { return new CncCheckboxWidget(this); }
}
@@ -243,6 +244,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
Font = other.Font;
}
public override Widget Clone() { return new CncDropDownButtonWidget(this); }
public override void DrawInner()

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Widgets
var files = Directory.GetFiles(replayDir, "*.rep").Reverse();
foreach (var replayFile in files)
AddReplay(rl, replayFile, template);
SelectReplay(files.FirstOrDefault());
}
@@ -59,9 +59,10 @@ namespace OpenRA.Mods.Cnc.Widgets
panel.GetWidget("REPLAY_INFO").IsVisible = () => currentSummary != null;
}
ReplaySummary currentSummary;
Map currentMap;
void SelectReplay(string filename)
{
if (filename == null)
@@ -81,7 +82,7 @@ namespace OpenRA.Mods.Cnc.Widgets
var players = currentSummary.LobbyInfo.Slots.Count(s => currentSummary.LobbyInfo.ClientInSlot(s) != null || s.Bot != null);
panel.GetWidget<LabelWidget>("PLAYERS").GetText = () => players.ToString();
}
catch(Exception e)
catch (Exception e)
{
Log.Write("debug", "Exception while parsing replay: {0}", e.ToString());
currentSummary = null;

View File

@@ -43,20 +43,21 @@ namespace OpenRA.Mods.Cnc.Widgets
{
{ "initialMap", map.Uid },
{ "onExit", () => {} },
{ "onSelect", new Action<Map>(m => map = m) }
{ "onSelect", (Action<Map>)(m => map = m) }
});
};
if (string.IsNullOrEmpty(Game.Settings.Server.Map) || !Game.modData.AvailableMaps.TryGetValue(Game.Settings.Server.Map, out map))
if (string.IsNullOrEmpty(Game.Settings.Server.Map) ||
!Game.modData.AvailableMaps.TryGetValue(Game.Settings.Server.Map, out map))
map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Value;
panel.GetWidget<MapPreviewWidget>("MAP_PREVIEW").Map = () => map;
panel.GetWidget<LabelWidget>("MAP_NAME").GetText = () => map.Title;
panel.GetWidget<TextFieldWidget>("SERVER_NAME").Text = settings.Server.Name ?? "";
panel.GetWidget<TextFieldWidget>("LISTEN_PORT").Text = settings.Server.ListenPort.ToString();
advertiseOnline = Game.Settings.Server.AdvertiseOnline;
var externalPort = panel.GetWidget<CncTextFieldWidget>("EXTERNAL_PORT");
externalPort.Text = settings.Server.ExternalPort.ToString();
externalPort.IsDisabled = () => !advertiseOnline;