Remove some unnecessary fields from chrome

This commit is contained in:
Paul Chote
2010-07-13 20:49:04 +12:00
parent 4a7c19cf93
commit 8d2693019d
6 changed files with 29 additions and 28 deletions

View File

@@ -48,13 +48,10 @@ namespace OpenRA
rootWidget = WidgetLoader.LoadWidget( widgetYaml.FirstOrDefault() ); rootWidget = WidgetLoader.LoadWidget( widgetYaml.FirstOrDefault() );
rootWidget.Initialize(); rootWidget.Initialize();
rootWidget.InitDelegates(); rootWidget.InitDelegates();
Widget.WindowList.Push("MAINMENU_BG");
} }
} }
public static Widget rootWidget = null; public static Widget rootWidget = null;
public static Widget selectedWidget;
public static ChatDisplayWidget chatWidget;
public void Tick(World world) public void Tick(World world)
{ {
@@ -71,7 +68,7 @@ namespace OpenRA
public int2 lastMousePos; public int2 lastMousePos;
public bool HandleInput(World world, MouseInput mi) public bool HandleInput(World world, MouseInput mi)
{ {
if (selectedWidget != null && selectedWidget.HandleMouseInputOuter(mi)) if (Widget.SelectedWidget != null && Widget.SelectedWidget.HandleMouseInputOuter(mi))
return true; return true;
if (rootWidget.HandleMouseInputOuter(mi)) if (rootWidget.HandleMouseInputOuter(mi))
@@ -88,8 +85,8 @@ namespace OpenRA
public bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers) public bool HandleKeyPress(System.Windows.Forms.KeyPressEventArgs e, Modifiers modifiers)
{ {
if (selectedWidget != null) if (Widget.SelectedWidget != null)
return selectedWidget.HandleKeyPressOuter(e, modifiers); return Widget.SelectedWidget.HandleKeyPressOuter(e, modifiers);
if (rootWidget.HandleKeyPressOuter(e, modifiers)) if (rootWidget.HandleKeyPressOuter(e, modifiers))
return true; return true;
@@ -98,7 +95,7 @@ namespace OpenRA
public bool HitTest(int2 mousePos) public bool HitTest(int2 mousePos)
{ {
if (selectedWidget != null) if (Widget.SelectedWidget != null)
return true; return true;
return rootWidget.HitTest(mousePos); return rootWidget.HitTest(mousePos);

View File

@@ -412,7 +412,7 @@ namespace OpenRA
{ {
LoadMap(LobbyInfo.GlobalSettings.Map); LoadMap(LobbyInfo.GlobalSettings.Map);
if (orderManager.GameStarted) return; if (orderManager.GameStarted) return;
Chrome.selectedWidget = null; Widget.SelectedWidget = null;
world.Queries = new World.AllQueries(world); world.Queries = new World.AllQueries(world);
@@ -626,10 +626,11 @@ namespace OpenRA
public static void Exit() { quit = true; } public static void Exit() { quit = true; }
public static Action<Color,string,string> AddChatLine = (c,n,s) => {};
public static void Debug(string s) public static void Debug(string s)
{ {
if (Chrome.chatWidget != null) AddChatLine(Color.White, "Debug", s);
Chrome.chatWidget.AddLine(Color.White, "Debug", s);
} }
public static void Disconnect() public static void Disconnect()

View File

@@ -33,14 +33,13 @@ namespace OpenRA.Network
case "Chat": case "Chat":
{ {
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId); var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId);
if (client != null && Chrome.chatWidget != null) Game.AddChatLine(Game.world.PlayerColors()[client.PaletteIndex].Color, client.Name, order.TargetString);
Chrome.chatWidget.AddLine(Game.world.PlayerColors()[client.PaletteIndex].Color, client.Name, order.TargetString);
break; break;
} }
case "TeamChat": case "TeamChat":
{ {
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId); var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == clientId);
if (client != null && Chrome.chatWidget != null) if (client != null)
{ {
var player = Game.world.players.Values.FirstOrDefault(p => p.Index == client.Index); var player = Game.world.players.Values.FirstOrDefault(p => p.Index == client.Index);
var isAlly = (world.GameHasStarted) ? var isAlly = (world.GameHasStarted) ?
@@ -48,15 +47,13 @@ namespace OpenRA.Network
client == Game.LocalClient || (client.Team == Game.LocalClient.Team && client.Team != 0); client == Game.LocalClient || (client.Team == Game.LocalClient.Team && client.Team != 0);
if (isAlly) if (isAlly)
Chrome.chatWidget.AddLine(Game.world.PlayerColors()[client.PaletteIndex].Color, client.Name + " (Team)", order.TargetString); Game.AddChatLine(Game.world.PlayerColors()[client.PaletteIndex].Color, client.Name + " (Team)", order.TargetString);
} }
break; break;
} }
case "StartGame": case "StartGame":
{ {
if (Chrome.chatWidget != null) Game.AddChatLine(Color.White, "Server", "The game has started.");
Chrome.chatWidget.AddLine(Color.White, "Server", "The game has started.");
Game.StartGame(); Game.StartGame();
break; break;
} }

View File

@@ -101,9 +101,7 @@ namespace OpenRA.Widgets.Delegates
}; };
Game.LobbyInfoChanged += UpdatePlayerList; Game.LobbyInfoChanged += UpdatePlayerList;
Game.AddChatLine += (c,n,s) => lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").AddLine(c,n,s);
Chrome.chatWidget = lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY");
bool teamChat = false; bool teamChat = false;
var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE"); var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE");
@@ -158,14 +156,13 @@ namespace OpenRA.Widgets.Delegates
if (name.Text.Length == 0) if (name.Text.Length == 0)
name.Text = c.Name; name.Text = c.Name;
Chrome.selectedWidget = null; name.LoseFocus();
if (name.Text == c.Name) if (name.Text == c.Name)
return true; return true;
Game.IssueOrder(Order.Command( "name "+name.Text )); Game.IssueOrder(Order.Command( "name "+name.Text ));
Game.Settings.PlayerName = name.Text; Game.Settings.PlayerName = name.Text;
Game.Settings.Save(); Game.Settings.Save();
Chrome.selectedWidget = null;
return true; return true;
}; };
name.OnLoseFocus = () => name.OnEnterKey(); name.OnLoseFocus = () => name.OnEnterKey();

View File

@@ -25,6 +25,8 @@ namespace OpenRA.Widgets.Delegates
{ {
public MainMenuButtonsDelegate() public MainMenuButtonsDelegate()
{ {
// Main menu is the default window
Widget.WindowList.Push("MAINMENU_BG");
Chrome.rootWidget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => {Game.Exit(); return true;}; Chrome.rootWidget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => {Game.Exit(); return true;};
var version = Chrome.rootWidget.GetWidget("MAINMENU_BG").GetWidget<LabelWidget>("VERSION_STRING"); var version = Chrome.rootWidget.GetWidget("MAINMENU_BG").GetWidget<LabelWidget>("VERSION_STRING");

View File

@@ -152,23 +152,30 @@ namespace OpenRA.Widgets
} }
public bool Focused { get { return Chrome.selectedWidget == this; } } public static Widget SelectedWidget;
public bool Focused { get { return SelectedWidget == this; } }
public virtual bool TakeFocus(MouseInput mi) public virtual bool TakeFocus(MouseInput mi)
{ {
if (Focused) if (Focused)
return true; return true;
if (Chrome.selectedWidget != null && !Chrome.selectedWidget.LoseFocus(mi)) if (SelectedWidget != null && !SelectedWidget.LoseFocus(mi))
return false; return false;
Chrome.selectedWidget = this; SelectedWidget = this;
return true; return true;
} }
// Remove focus from this widget; return false if you don't want to give it up // Remove focus from this widget; return false if you don't want to give it up
public virtual bool LoseFocus(MouseInput mi) public virtual bool LoseFocus(MouseInput mi)
{ {
if (Chrome.selectedWidget == this) // Some widgets may need to override focus depending on mouse click
Chrome.selectedWidget = null; return LoseFocus();
}
public virtual bool LoseFocus()
{
if (SelectedWidget == this)
SelectedWidget = null;
return true; return true;
} }