Move the easy things from the hardcoded map chooser into widgets

This commit is contained in:
Paul Chote
2010-07-11 12:52:41 +12:00
parent 424aa5c2d2
commit ca07318dc5
4 changed files with 135 additions and 41 deletions

View File

@@ -77,15 +77,6 @@ namespace OpenRA
buttons.Clear();
renderer.Device.DisableScissor();
}
void AddUiButton(int2 pos, string text, Action<bool> a)
{
var rect = new Rectangle(pos.X - 160 / 2, pos.Y - 4, 160, 24);
DrawDialogBackground( rect, "dialog2");
DrawCentered(text, new int2(pos.X, pos.Y), Color.White);
rgbaRenderer.Flush();
AddButton(rect, a);
}
public void DrawMapChooser()
{
@@ -94,22 +85,6 @@ namespace OpenRA
var w = 800;
var h = 600;
var r = new Rectangle( (Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h );
AddUiButton(new int2(r.Left + 200, r.Bottom - 40), "OK",
_ =>
{
Game.IssueOrder(Order.Chat("/map " + currentMap.Uid));
Chrome.rootWidget.CloseWindow();
});
AddUiButton(new int2(r.Right - 200, r.Bottom - 40), "Cancel",
_ =>
{
Chrome.rootWidget.CloseWindow();
});
var mapContainer = new Rectangle(r.Right - 280, r.Top + 30, 256, 256);
var y = r.Top + 50;
// Don't bother showing a subset of the data
@@ -133,21 +108,6 @@ namespace OpenRA
AddButton(itemRect, _ => { currentMap = closureMap; });
y += 20;
}
y = mapContainer.Bottom + 20;
DrawCentered("Title: {0}".F(currentMap.Title),
new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White);
y += 20;
DrawCentered("Size: {0}x{1}".F(currentMap.Width, currentMap.Height),
new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White);
y += 20;
DrawCentered("Theater: {0}".F(Rules.TileSets[currentMap.Tileset].Name),
new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White);
y += 20;
DrawCentered("Spawnpoints: {0}".F(currentMap.PlayerCount),
new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White);
AddButton(r, _ => { });
}

View File

@@ -226,6 +226,7 @@
<Compile Include="Traits\World\HazardLayer.cs" />
<Compile Include="Widgets\TextFieldWidget.cs" />
<Compile Include="Widgets\ChatDisplayWidget.cs" />
<Compile Include="Widgets\Delegates\MapChooserDelegate.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -0,0 +1,53 @@
#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 System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
namespace OpenRA.Widgets.Delegates
{
public class MapChooserDelegate : IWidgetDelegate
{
public MapChooserDelegate()
{
var r = Chrome.rootWidget;
var bg = r.GetWidget("MAP_CHOOSER");
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => {return Game.chrome.currentMap.Title;};
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => {return "{0}x{1}".F(Game.chrome.currentMap.Width, Game.chrome.currentMap.Height);};
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => {return Rules.TileSets[Game.chrome.currentMap.Tileset].Name;};
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => {return Game.chrome.currentMap.PlayerCount.ToString();};
bg.GetWidget("BUTTON_OK").OnMouseUp = mi => {
Game.IssueOrder(Order.Chat("/map " + Game.chrome.currentMap.Uid));
r.CloseWindow();
return true;
};
bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi => {
r.CloseWindow();
return true;
};
}
}
}