diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 449df6c7db..654a06b348 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -47,12 +47,6 @@ namespace OpenRA // Special power bin readonly Dictionary spsprites; - // Options menu (to be refactored) - bool optionsPressed = false; - - // Buttons - readonly Animation optionsButton; - // Build Palette tabs string currentTab = "Building"; bool paletteOpen = false; @@ -99,10 +93,7 @@ namespace OpenRA rgbaRenderer = new SpriteRenderer(renderer, true, renderer.RgbaSpriteShader); lineRenderer = new LineRenderer(renderer); shpRenderer = new SpriteRenderer(renderer, true, renderer.WorldSpriteShader); - - optionsButton = new Animation("tabs"); - optionsButton.PlayRepeating("left-normal"); - + tabSprites = Rules.Info.Values .Where(u => u.Traits.Contains()) .ToDictionary( @@ -202,7 +193,6 @@ namespace OpenRA DrawSupportPowers( world ); DrawBuildTabs(world, paletteHeight); DrawChat(); - DrawOptionsMenu(); } public void DrawDownloadBar() @@ -716,31 +706,6 @@ namespace OpenRA AddButton(new RectangleF(origin.X, origin.Y, image.size.X, image.size.Y), _ => { if (button.Enabled) button.OnClick(); }); } - - //Options - Rectangle optionsRect = new Rectangle(0,0, optionsButton.Image.bounds.Width, - optionsButton.Image.bounds.Height); - - var optionsDrawPos = new float2(optionsRect.Location); - - optionsButton.ReplaceAnim(optionsPressed ? "left-pressed" : "left-normal"); - - AddButton(optionsRect, isLmb => optionsPressed = !optionsPressed); - shpRenderer.DrawSprite(optionsButton.Image, optionsDrawPos, "chrome"); - shpRenderer.Flush(); - - renderer.RegularFont.DrawText(rgbaRenderer, "Options", new int2((int)(optionsButton.Image.size.X - renderer.RegularFont.Measure("Options").X) / 2, -2), Color.White); - } - - void DrawOptionsMenu() - { - if (optionsPressed){ - var width = 500; - var height = 300; - - DrawDialogBackground(new Rectangle((Game.viewport.Width - width)/ 2, (Game.viewport.Height-height) / 2, - width, height), "dialog"); - } } void DrawDialogBackground(Rectangle r, string collection) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 9bf71ffff7..cce13b8f02 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -63,6 +63,7 @@ namespace OpenRA.Graphics } ConnectionState lastConnectionState = ConnectionState.PreConnecting; + bool gameWasStarted = false; public void DrawRegions( World world ) { world.WorldRenderer.palette.Update( @@ -73,10 +74,15 @@ namespace OpenRA.Graphics renderer.BeginFrame(r1, r2, scrollPosition.ToInt2()); world.WorldRenderer.Draw(); - if( Game.orderManager.GameStarted ) + if( Game.orderManager.GameStarted && world.LocalPlayer != null) { - if (world.LocalPlayer != null) - Game.chrome.Draw( world ); + if (!gameWasStarted) + { + Chrome.rootWidget.ShowMenu("INGAME_ROOT"); + gameWasStarted = true; + } + + Game.chrome.Draw( world ); if( Game.orderManager.Connection.ConnectionState == ConnectionState.NotConnected ) Game.chrome.DrawDialog("Connection lost."); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 410f144abf..46ec2f7900 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -294,6 +294,7 @@ + diff --git a/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs new file mode 100644 index 0000000000..d2c90c74dd --- /dev/null +++ b/OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs @@ -0,0 +1,54 @@ +#region Copyright & License Information +/* + * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. + * This file is part of OpenRA. + * + * OpenRA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OpenRA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OpenRA. If not, see . + */ +#endregion +using System; +using OpenRA.FileFormats; +namespace OpenRA.Widgets.Delegates +{ + public class IngameChromeDelegate : IWidgetDelegate + { + public IngameChromeDelegate() + { + var r = Chrome.rootWidget; + var optionsBG = r.GetWidget("INGAME_OPTIONS_BG"); + r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => { + optionsBG.Visible = !optionsBG.Visible; + return true; + }; + + optionsBG.GetWidget("BUTTON_DISCONNECT").OnMouseUp = mi => { + // Todo: Do this cleanly, so we don't crash + //Game.JoinLocal(); + //Game.LoadShellMap(new Manifest(Game.LobbyInfo.GlobalSettings.Mods).ShellmapUid); + return true; + }; + + optionsBG.GetWidget("BUTTON_SETTINGS").OnMouseUp = mi => { + // Todo: Unfail ShowMenu to work with multiple root menus + return true; + }; + + optionsBG.GetWidget("BUTTON_QUIT").OnMouseUp = mi => { + Game.Exit(); + return true; + }; + + } + } +} diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index a86697c9bd..84025f06f8 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -152,7 +152,9 @@ namespace OpenRA.Widgets public Widget ShowMenu(string menu) { - GetCurrentMenu().Visible = false; + var m = GetCurrentMenu(); + if (m != null) + m.Visible = false; var widget = GetWidget(menu); if (widget != null) diff --git a/mods/ra/menus.yaml b/mods/ra/menus.yaml index 3328de4a2c..8e7778d2b1 100644 --- a/mods/ra/menus.yaml +++ b/mods/ra/menus.yaml @@ -256,4 +256,56 @@ Container: Width:160 Height:25 Text:Abort - Delegate:ConnectionDialogsDelegate \ No newline at end of file + Delegate:ConnectionDialogsDelegate + Container@INGAME_ROOT: + Id:INGAME_ROOT + Visible:false + Children: + Button@INGAME_OPTIONS_BUTTON: + Id:INGAME_OPTIONS_BUTTON + X:0 + Y:0 + Width:160 + Height:25 + Text:Options + Delegate:IngameChromeDelegate + Background@INGAME_OPTIONS_BG: + Id:INGAME_OPTIONS_BG + X:(WINDOW_RIGHT - WIDTH)/2 + Y:(WINDOW_BOTTOM - HEIGHT)/2 + Width:300 + Height:220 + Visible:false + Children: + Label@LABEL_TITLE: + Id:LABEL_TITLE + X:(PARENT_RIGHT - WIDTH)/2 + Y:20 + Width:250 + Height:25 + Text:Options + Align:Center + Button@BUTTON_SETTINGS: + Id:BUTTON_SETTINGS + X:(PARENT_RIGHT - WIDTH)/2 + Y:80 + Width:160 + Height:25 + Text:Settings + Delegate:IngameChromeDelegate + Button@BUTTON_DISCONNECT: + Id:BUTTON_DISCONNECT + X:(PARENT_RIGHT - WIDTH)/2 + Y:120 + Width:160 + Height:25 + Text:Disconnect + Delegate:IngameChromeDelegate + Button@BUTTON_QUIT: + Id:BUTTON_QUIT + X:(PARENT_RIGHT - WIDTH)/2 + Y:160 + Width:160 + Height:25 + Text:Quit + Delegate:IngameChromeDelegate \ No newline at end of file