Ingame options: chrome -> widgets
This commit is contained in:
@@ -47,12 +47,6 @@ namespace OpenRA
|
|||||||
// Special power bin
|
// Special power bin
|
||||||
readonly Dictionary<string, Sprite> spsprites;
|
readonly Dictionary<string, Sprite> spsprites;
|
||||||
|
|
||||||
// Options menu (to be refactored)
|
|
||||||
bool optionsPressed = false;
|
|
||||||
|
|
||||||
// Buttons
|
|
||||||
readonly Animation optionsButton;
|
|
||||||
|
|
||||||
// Build Palette tabs
|
// Build Palette tabs
|
||||||
string currentTab = "Building";
|
string currentTab = "Building";
|
||||||
bool paletteOpen = false;
|
bool paletteOpen = false;
|
||||||
@@ -100,9 +94,6 @@ namespace OpenRA
|
|||||||
lineRenderer = new LineRenderer(renderer);
|
lineRenderer = new LineRenderer(renderer);
|
||||||
shpRenderer = new SpriteRenderer(renderer, true, renderer.WorldSpriteShader);
|
shpRenderer = new SpriteRenderer(renderer, true, renderer.WorldSpriteShader);
|
||||||
|
|
||||||
optionsButton = new Animation("tabs");
|
|
||||||
optionsButton.PlayRepeating("left-normal");
|
|
||||||
|
|
||||||
tabSprites = Rules.Info.Values
|
tabSprites = Rules.Info.Values
|
||||||
.Where(u => u.Traits.Contains<BuildableInfo>())
|
.Where(u => u.Traits.Contains<BuildableInfo>())
|
||||||
.ToDictionary(
|
.ToDictionary(
|
||||||
@@ -202,7 +193,6 @@ namespace OpenRA
|
|||||||
DrawSupportPowers( world );
|
DrawSupportPowers( world );
|
||||||
DrawBuildTabs(world, paletteHeight);
|
DrawBuildTabs(world, paletteHeight);
|
||||||
DrawChat();
|
DrawChat();
|
||||||
DrawOptionsMenu();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawDownloadBar()
|
public void DrawDownloadBar()
|
||||||
@@ -716,31 +706,6 @@ namespace OpenRA
|
|||||||
AddButton(new RectangleF(origin.X, origin.Y, image.size.X, image.size.Y),
|
AddButton(new RectangleF(origin.X, origin.Y, image.size.X, image.size.Y),
|
||||||
_ => { if (button.Enabled) button.OnClick(); });
|
_ => { 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)
|
void DrawDialogBackground(Rectangle r, string collection)
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConnectionState lastConnectionState = ConnectionState.PreConnecting;
|
ConnectionState lastConnectionState = ConnectionState.PreConnecting;
|
||||||
|
bool gameWasStarted = false;
|
||||||
public void DrawRegions( World world )
|
public void DrawRegions( World world )
|
||||||
{
|
{
|
||||||
world.WorldRenderer.palette.Update(
|
world.WorldRenderer.palette.Update(
|
||||||
@@ -73,9 +74,14 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
renderer.BeginFrame(r1, r2, scrollPosition.ToInt2());
|
renderer.BeginFrame(r1, r2, scrollPosition.ToInt2());
|
||||||
world.WorldRenderer.Draw();
|
world.WorldRenderer.Draw();
|
||||||
if( Game.orderManager.GameStarted )
|
if( Game.orderManager.GameStarted && world.LocalPlayer != null)
|
||||||
{
|
{
|
||||||
if (world.LocalPlayer != null)
|
if (!gameWasStarted)
|
||||||
|
{
|
||||||
|
Chrome.rootWidget.ShowMenu("INGAME_ROOT");
|
||||||
|
gameWasStarted = true;
|
||||||
|
}
|
||||||
|
|
||||||
Game.chrome.Draw( world );
|
Game.chrome.Draw( world );
|
||||||
|
|
||||||
if( Game.orderManager.Connection.ConnectionState == ConnectionState.NotConnected )
|
if( Game.orderManager.Connection.ConnectionState == ConnectionState.NotConnected )
|
||||||
|
|||||||
@@ -294,6 +294,7 @@
|
|||||||
<Compile Include="Traits\RepairsUnits.cs" />
|
<Compile Include="Traits\RepairsUnits.cs" />
|
||||||
<Compile Include="Traits\World\BibLayer.cs" />
|
<Compile Include="Traits\World\BibLayer.cs" />
|
||||||
<Compile Include="Traits\World\SmudgeLayer.cs" />
|
<Compile Include="Traits\World\SmudgeLayer.cs" />
|
||||||
|
<Compile Include="Widgets\Delegates\IngameChromeDelegate.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
54
OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs
Normal file
54
OpenRA.Game/Widgets/Delegates/IngameChromeDelegate.cs
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -152,7 +152,9 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public Widget ShowMenu(string menu)
|
public Widget ShowMenu(string menu)
|
||||||
{
|
{
|
||||||
GetCurrentMenu().Visible = false;
|
var m = GetCurrentMenu();
|
||||||
|
if (m != null)
|
||||||
|
m.Visible = false;
|
||||||
|
|
||||||
var widget = GetWidget(menu);
|
var widget = GetWidget(menu);
|
||||||
if (widget != null)
|
if (widget != null)
|
||||||
|
|||||||
@@ -257,3 +257,55 @@ Container:
|
|||||||
Height:25
|
Height:25
|
||||||
Text:Abort
|
Text:Abort
|
||||||
Delegate:ConnectionDialogsDelegate
|
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
|
||||||
Reference in New Issue
Block a user