Building hotkeys

This commit is contained in:
Boomer
2010-05-09 15:37:10 +02:00
committed by Chris Forbes
parent ac75259efd
commit bd72146548
7 changed files with 1909 additions and 1818 deletions

View File

@@ -107,7 +107,7 @@ namespace OpenRA
public float2 CenterLocation;
Lazy<float2> Size;
OpenRA.FileFormats.Lazy<float2> Size;
public IEnumerable<Renderable> Render()
{

View File

@@ -33,6 +33,8 @@ using OpenRA.Network;
using OpenRA.Server;
using OpenRA.Support;
using OpenRA.Traits;
using OpenRA.Widgets;
using Timer = OpenRA.Support.Timer;
using XRandom = OpenRA.Thirdparty.Random;
@@ -103,7 +105,7 @@ namespace OpenRA
throw new InvalidOperationException("Cannot locate type: {0}".F(classname));
}
public static Dictionary<string,MapStub> AvailableMaps;
public static Dictionary<string, MapStub> AvailableMaps;
// TODO: Do this nicer
static Dictionary<string, MapStub> FindMaps(string[] mods)
@@ -121,42 +123,42 @@ namespace OpenRA
static void ChangeMods()
{
Timer.Time( "----ChangeMods" );
Timer.Time("----ChangeMods");
var manifest = new Manifest(LobbyInfo.GlobalSettings.Mods);
Timer.Time( "manifest: {0}" );
Timer.Time("manifest: {0}");
LoadModAssemblies(manifest);
SheetBuilder.Initialize(renderer);
LoadModPackages(manifest);
Timer.Time( "load assemblies, packages: {0}" );
Timer.Time("load assemblies, packages: {0}");
packageChangePending = false;
}
static void LoadMap(string mapName)
{
Timer.Time( "----LoadMap" );
Timer.Time("----LoadMap");
SheetBuilder.Initialize(renderer);
var manifest = new Manifest(LobbyInfo.GlobalSettings.Mods);
Timer.Time( "manifest: {0}" );
Timer.Time("manifest: {0}");
if (!Game.AvailableMaps.ContainsKey(mapName))
throw new InvalidDataException("Cannot find map with Uid {0}".F(mapName));
var map = new Map( Game.AvailableMaps[mapName].Package );
var map = new Map(Game.AvailableMaps[mapName].Package);
viewport = new Viewport(clientSize, map.TopLeft, map.BottomRight, renderer);
world = null; // trying to access the old world will NRE, rather than silently doing it wrong.
ChromeProvider.Initialize(manifest.Chrome);
Timer.Time( "viewport, ChromeProvider: {0}" );
world = new World(manifest,map);
Timer.Time( "world: {0}" );
Timer.Time("viewport, ChromeProvider: {0}");
world = new World(manifest, map);
Timer.Time("world: {0}");
SequenceProvider.Initialize(manifest.Sequences);
Timer.Time( "ChromeProv, SeqProv: {0}" );
Timer.Time("ChromeProv, SeqProv: {0}");
chrome = new Chrome(renderer, manifest);
Timer.Time( "chrome: {0}" );
Timer.Time("chrome: {0}");
Timer.Time( "----end LoadMap" );
Timer.Time("----end LoadMap");
Debug("Map change {0} -> {1}".F(Game.mapName, mapName));
}
@@ -175,7 +177,7 @@ namespace OpenRA
CurrentHost = host;
CurrentPort = port;
orderManager = new OrderManager(new NetworkConnection( host, port ), ChooseReplayFilename());
orderManager = new OrderManager(new NetworkConnection(host, port), ChooseReplayFilename());
}
static string ChooseReplayFilename()
@@ -242,7 +244,7 @@ namespace OpenRA
return sb.ToString();
}
internal static void DumpSyncReport( int frame )
internal static void DumpSyncReport(int frame)
{
var f = syncReports.FirstOrDefault(a => a.First == frame);
if (f == null)
@@ -262,7 +264,7 @@ namespace OpenRA
// TODO: Only do this on mod change
Timer.Time("----begin maplist");
AvailableMaps = FindMaps(LobbyInfo.GlobalSettings.Mods);
Timer.Time( "maplist: {0}" );
Timer.Time("maplist: {0}");
ChangeMods();
return;
}
@@ -281,9 +283,9 @@ namespace OpenRA
using (new PerfSample("tick_time"))
{
lastTime += Settings.Timestep;
chrome.Tick( world );
chrome.Tick(world);
orderManager.TickImmediate( world );
orderManager.TickImmediate(world);
var isNetTick = LocalTick % NetTickScale == 0;
@@ -309,7 +311,7 @@ namespace OpenRA
using (new PerfSample("render"))
{
++RenderFrame;
viewport.DrawRegions( world );
viewport.DrawRegions(world);
}
PerfHistory.items["render"].Tick();
@@ -411,7 +413,7 @@ namespace OpenRA
foreach (var gs in world.WorldActor.traits.WithInterface<IGameStarted>())
gs.GameStarted(world);
viewport.GoToStartLocation( world.LocalPlayer );
viewport.GoToStartLocation(world.LocalPlayer);
orderManager.StartGame();
}
@@ -450,7 +452,7 @@ namespace OpenRA
lastPos = p;
}
viewport.DispatchMouseInput( world,
viewport.DispatchMouseInput(world,
new MouseInput
{
Button = (MouseButton)(int)e.Button,
@@ -459,8 +461,8 @@ namespace OpenRA
Modifiers = modifierKeys,
});
if( sync != world.SyncHash() && world == initialWorld )
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
if (sync != world.SyncHash() && world == initialWorld)
throw new InvalidOperationException("Desync in DispatchMouseInput");
}
internal static bool IsHost
@@ -487,11 +489,11 @@ namespace OpenRA
{ ')', '0' },
};
public static void HandleKeyPress( KeyPressEventArgs e, Modifiers modifiers )
public static void HandleKeyPress(KeyPressEventArgs e, Modifiers modifiers)
{
int sync = world.SyncHash();
if( e.KeyChar == '\r' )
if (e.KeyChar == '\r')
chat.Toggle();
else if (Game.chat.isChatting)
chat.TypeChar(e.KeyChar);
@@ -503,12 +505,17 @@ namespace OpenRA
Game.controller.selection.DoControlGroup(world,
c - '0', modifiers);
if (c == 'h')
if (c == 08)
Game.controller.GotoNextBase();
if (c == 09)
BuildPaletteWidget.TabChange((Control.ModifierKeys & Keys.Shift) == Keys.Shift ? true : false);
BuildPaletteWidget.DoBuildingHotkey(c, world);
}
if( sync != Game.world.SyncHash() )
throw new InvalidOperationException( "Desync in OnKeyPress" );
if (sync != Game.world.SyncHash())
throw new InvalidOperationException("Desync in OnKeyPress");
}
public static void HandleModifierKeys(Modifiers mods)
@@ -565,8 +572,8 @@ namespace OpenRA
ChangeMods();
if( Settings.Replay != "" )
orderManager = new OrderManager( new ReplayConnection( Settings.Replay ) );
if (Settings.Replay != "")
orderManager = new OrderManager(new ReplayConnection(Settings.Replay));
else
JoinLocal();

View File

@@ -53,11 +53,11 @@ namespace OpenRA
public ShroudRenderer Shroud;
public World World { get; private set; }
public static List<Tuple<string, string, Color>> PlayerColors( World world )
public static List<OpenRA.FileFormats.Tuple<string, string, Color>> PlayerColors(World world)
{
return world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>()
.Where(p => p.Playable)
.Select(p => Tuple.New(p.Name, p.DisplayName, p.Color))
.Select(p => OpenRA.FileFormats.Tuple.New(p.Name, p.DisplayName, p.Color))
.ToList();
}

View File

@@ -39,6 +39,7 @@ namespace OpenRA.Traits
public readonly string Icon = null;
public readonly string[] AlternateName = { };
public readonly int BuildPaletteOrder = 50;
public readonly string Hotkey = null;
public override object Create(Actor self) { return new Buildable(); }
}

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Traits
public class ScreenShaker : ITick
{
int ticks = 0;
List<Tuple<int, float2, int>> shakeEffects = new List<Tuple<int, float2, int>>();
List<OpenRA.FileFormats.Tuple<int, float2, int>> shakeEffects = new List<OpenRA.FileFormats.Tuple<int, float2, int>>();
public void Tick (Actor self)
{
@@ -44,7 +44,7 @@ namespace OpenRA.Traits
public void AddEffect(int time, float2 position, int intensity)
{
shakeEffects.Add(Tuple.New(ticks + time, position, intensity));
shakeEffects.Add(OpenRA.FileFormats.Tuple.New(ticks + time, position, intensity));
}
public float2 getScrollOffset()

View File

@@ -320,6 +320,15 @@ namespace OpenRA.Widgets
};
}
static void Hotkey(World world, String name)
{
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
Sound.Play(eva.TabClick);
if (name != null)
HandleBuildPalette(world, name, true);
}
Action<MouseInput> HandleTabClick(string button, World world)
{
return mi => {
@@ -344,7 +353,7 @@ namespace OpenRA.Widgets
return Rules.Info[ a.ToLowerInvariant() ].Traits.Get<BuildableInfo>().Description;
}
void HandleBuildPalette( World world, string item, bool isLmb )
static void HandleBuildPalette( World world, string item, bool isLmb )
{
var player = world.LocalPlayer;
var unit = Rules.Info[item];
@@ -391,7 +400,7 @@ namespace OpenRA.Widgets
}
}
void StartProduction( World world, string item )
static void StartProduction( World world, string item )
{
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
var unit = Rules.Info[item];
@@ -481,6 +490,9 @@ namespace OpenRA.Widgets
DrawRightAligned( "${0}".F(buildable.Cost), pos + new int2(-5,5),
world.LocalPlayer.Cash + world.LocalPlayer.Ore >= buildable.Cost ? Color.White : Color.Red);
if (buildable.Hotkey != null)
DrawRightAligned("{0}".F(buildable.Hotkey.ToUpper()), pos + new int2(-5, 35),Color.White);
var bi = info.Traits.GetOrDefault<BuildingInfo>();
if (bi != null)
DrawRightAligned("{1}{0}".F(bi.Power, bi.Power > 0 ? "+" : ""), pos + new int2(-5, 20),
@@ -507,5 +519,42 @@ namespace OpenRA.Widgets
Game.chrome.renderer.RgbaSpriteRenderer.Flush();
}
public static void DoBuildingHotkey(char c, World world)
{
if (Game.world.LocalPlayer == null) return;
var buildable = Rules.TechTree.BuildableItems(Game.world.LocalPlayer, Chrome.rootWidget.GetWidget<BuildPaletteWidget>("INGAME_BUILD_PALETTE").currentTab);
var toBuild = buildable.FirstOrDefault(b => Rules.Info[b.ToLowerInvariant()].Traits.Get<BuildableInfo>().Hotkey == c.ToString());
if (toBuild != null) Hotkey(world, toBuild);
}
public static void TabChange(bool shift)
{
var p = Chrome.rootWidget.GetWidget<BuildPaletteWidget>("INGAME_BUILD_PALETTE");
int size = p.visibleTabs.Count();
if (size > 0)
{
string last = p.visibleTabs.Last();
string first = p.visibleTabs.First();
int current = p.visibleTabs.IndexOf(p.currentTab);
if (!shift)
{
if (current + 1 >= size)
p.SetCurrentTab(p.visibleTabs.FirstOrDefault());
else
p.SetCurrentTab(p.visibleTabs[current + 1]);
}
else
{
if (current - 1 < 0)
p.SetCurrentTab(p.visibleTabs.LastOrDefault());
else
p.SetCurrentTab(p.visibleTabs[current - 1]);
}
}
}
}
}

View File

@@ -9,6 +9,7 @@ MSLO:
Cost: 2500
Description: Missile Silo
LongDesc: Launches a devastating nuclear strike.\n Strong vs Infantry, Buildings\n Weak vs Tanks\n Special Ability: Nuclear Missile
Hotkey: m
Building:
Power: -100
Footprint: xx
@@ -33,6 +34,7 @@ GAP:
Cost: 500
Description: Gap Generator
LongDesc: Regenerates the Fog of War nearby, \nobscuring the area.\n Unarmed
Hotkey: g
Building:
Power: -60
Footprint: _ x
@@ -54,6 +56,7 @@ SPEN:
Cost: 650
Description: Sub Pen
LongDesc: Produces and repairs submarines and \ntransports
Hotkey: s
Building:
Power: -30
Footprint: xxx xxx xxx
@@ -81,6 +84,7 @@ SYRD:
Description: Shipyard
LongDesc: Produces and repairs ships
BuildPaletteOrder: 4
Hotkey: s
Building:
Power: -30
Footprint: xxx xxx xxx
@@ -109,6 +113,7 @@ IRON:
Cost: 2800
Description: Iron Curtain
LongDesc: Makes a group of units invulnerable for a \nshort time.\n Special Ability: Invulnerability
Hotkey: c
Building:
Power: -200
Footprint: xx xx
@@ -134,6 +139,7 @@ PDOX:
Cost: 2800
Description: Chronosphere
LongDesc: Teleports a unit from one place \nto another, for a limited time.\n Special Ability: Chronoshift
Hotkey: o
Building:
Power: -200
Footprint: xx xx
@@ -159,6 +165,7 @@ TSLA:
Cost: 1500
Description: Tesla Coil
LongDesc: Advanced base defense. Requires power\nto operate.\n Strong vs Tanks, Infantry\n Weak vs Aircraft
Hotkey: t
Building:
Power: -150
Footprint: _ x
@@ -188,6 +195,7 @@ AGUN:
Cost: 600
Description: AA Gun
LongDesc: Anti-Air base defense.\n Strong vs Aircraft\n Weak vs Infantry, Tanks
Hotkey: a
Building:
Power: -50
Footprint: _ x
@@ -220,6 +228,7 @@ DOME:
Description: Radar Dome
LongDesc: Provides an overview of the battlefield.\n Requires power to operate.
BuildPaletteOrder: 6
Hotkey: r
Building:
Power: -40
Footprint: xx xx
@@ -243,6 +252,7 @@ PBOX:
Cost: 400
Description: Pillbox
LongDesc: Basic defensive structure.\n Strong vs Infantry, Light Vehicles\n Weak vs Tanks, Aircraft
Hotkey: x
Building:
Power: -15
HP: 400
@@ -265,6 +275,7 @@ HBOX:
Cost: 600
Description: Camo Pillbox
LongDesc: Hidden defensive structure.\n Strong vs Infantry, Light Vehicles\n Weak vs Tanks, Aircraft
Hotkey: c
Building:
Power: -15
HP: 600
@@ -287,6 +298,7 @@ GUN:
Cost: 600
Description: Turret
LongDesc: Anti-Armor base defense.\n Strong vs Tanks\n Weak vs Infantry, Aircraft
Hotkey: t
Building:
Power: -40
HP: 400
@@ -314,6 +326,7 @@ FTUR:
Cost: 600
Description: Flame Turret
LongDesc: Anti-Infantry base defense.\n Strong vs Infantry\n Weak vs Aircraft
Hotkey: f
Building:
Power: -20
HP: 400
@@ -337,6 +350,7 @@ SAM:
Cost: 750
Description: SAM Site
LongDesc: Anti-Air base defense.\n Strong vs Aircraft\n Weak vs Infantry, Tanks
Hotkey: s
Building:
Power: -20
Footprint: xx
@@ -366,6 +380,7 @@ ATEK:
Description: Allied Tech Center
LongDesc: Provides Allied advanced technologies.\n Special Ability: GPS Satellite
AlternateName: @Tech Center
Hotkey: t
Building:
Power: -200
Footprint: xx xx
@@ -389,6 +404,7 @@ WEAP:
Description: War Factory
LongDesc: Produces tanks & light vehicles.
BuildPaletteOrder: 5
Hotkey: w
Building:
Power: -30
Footprint: xxx xxx
@@ -438,6 +454,7 @@ PROC:
Description: Ore Refinery
LongDesc: Converts Ore and Gems into money
BuildPaletteOrder: 1
Hotkey: e
Building:
Power: -30
Footprint: _x_ xxx x==
@@ -470,6 +487,7 @@ SILO:
Cost: 150
Description: Silo
LongDesc: Stores excess harvested Ore
Hotkey: o
Building:
Power: -10
Capturable: true
@@ -492,6 +510,7 @@ HPAD:
Cost: 1500
Description: Helipad
LongDesc: Produces and reloads helicopters
Hotkey: i
Building:
Power: -10
Footprint: xx xx
@@ -518,6 +537,7 @@ AFLD:
Cost: 600
Description: Airstrip
LongDesc: Produces and reloads planes\n Special Ability: Paratroopers\n Special Ability: Spy Plane
Hotkey: a
Building:
Power: -30
Footprint: xxx xxx
@@ -543,6 +563,7 @@ POWR:
LongDesc: Provides power for other structures
BuildPaletteOrder: 0
AlternateName: @Power Plant
Hotkey: p
Building:
Power: 100
Footprint: xx xx
@@ -565,6 +586,7 @@ APWR:
Description: Advanced Power Plant
LongDesc: Provides more power, cheaper than the \nstandard Power Plant
BuildPaletteOrder:2
Hotkey: l
AlternateName: @Power Plant
Building:
Power: 200
@@ -588,6 +610,7 @@ STEK:
Description: Soviet Tech Center
LongDesc: Provides Soviet advanced technologies
AlternateName: @Tech Center
Hotkey: t
Building:
Power: -100
Footprint: xxx xxx
@@ -610,6 +633,7 @@ BARR:
Description: Soviet Barracks
LongDesc: Produces infantry
BuildPaletteOrder: 3
Hotkey: b
Building:
Power: -20
Footprint: xx xx
@@ -635,6 +659,7 @@ TENT:
Description: Allied Barracks
LongDesc: Produces infantry
BuildPaletteOrder: 3
Hotkey: b
Building:
Power: -20
Footprint: xx xx
@@ -659,6 +684,7 @@ KENN:
Cost: 200
Description: Kennel
LongDesc: Produces attack dogs
Hotkey: k
Building:
Power: -10
HP: 400
@@ -677,6 +703,7 @@ FIX:
Cost: 1200
Description: Service Depot
LongDesc: Repairs vehicles, reloads minelayers, and \nallows the construction of additional bases.
Hotkey: d
Building:
Power: -30
Footprint: _x_ xxx _x_
@@ -700,6 +727,7 @@ FACF:
Description: Fake Construction Yard
LongDesc: Looks like a Construction Yard.
BuildPaletteOrder: 90
Hotkey: c
Building:
Power: -2
Footprint: xxx xxx xxx
@@ -724,6 +752,7 @@ WEAF:
Description: Fake War Factory
LongDesc: Looks like a War Factory.
BuildPaletteOrder: 90
Hotkey: x
Building:
Power: -2
Footprint: xxx xxx
@@ -749,6 +778,7 @@ SYRF:
Description: Fake Shipyard
LongDesc: Looks like a Shipyard
BuildPaletteOrder: 90
Hotkey: z
Building:
Power: -2
Footprint: xxx xxx xxx
@@ -791,6 +821,7 @@ DOMF:
Description: Fake Radar Dome
LongDesc: Looks like a Radar Dome
BuildPaletteOrder: 90
Hotkey: v
Building:
Power: -2
Footprint: xx xx
@@ -815,6 +846,7 @@ SBAG:
Description: Sandbag Wall
LongDesc: Stops infantry and blocks enemy fire.\nCan be crushed by tanks.
BuildPaletteOrder: 100
Hotkey: b
Building:
HP: 100
Armor: none
@@ -832,6 +864,7 @@ FENC:
Description: Wire Fence
LongDesc: Stops infantry and blocks enemy fire.\nCan be crushed by tanks.
BuildPaletteOrder: 100
Hotkey: n
Building:
HP: 100
Armor: none
@@ -849,6 +882,7 @@ BRIK:
Description: Concrete Wall
LongDesc: Stop units and blocks enemy fire.
BuildPaletteOrder: 100
Hotkey: w
Building:
HP: 100
Armor: none