Skip to content

Commit f115dda

Browse files
committed
Merge pull request OpenRA#5550 from pavlos256/reload-chrome
Add developer shortcut to reload chrome files
2 parents 5e986b3 + db53f8e commit f115dda

File tree

6 files changed

+130
-57
lines changed

6 files changed

+130
-57
lines changed

OpenRA.Game/Graphics/ChromeProvider.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,22 @@ struct Collection
2727
static Dictionary<string, Sheet> cachedSheets;
2828
static Dictionary<string, Dictionary<string, Sprite>> cachedSprites;
2929

30+
static string[] storedChromeFiles;
31+
3032
public static void Initialize(params string[] chromeFiles)
3133
{
3234
collections = new Dictionary<string, Collection>();
3335
cachedSheets = new Dictionary<string, Sheet>();
3436
cachedSprites = new Dictionary<string, Dictionary<string, Sprite>>();
3537

3638
if (chromeFiles.Length == 0)
37-
return;
39+
{
40+
chromeFiles = storedChromeFiles;
41+
if (chromeFiles == null || chromeFiles.Length == 0)
42+
return;
43+
}
44+
else
45+
storedChromeFiles = chromeFiles;
3846

3947
var chrome = chromeFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal);
4048

OpenRA.Game/OpenRA.Game.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
<Compile Include="GameRules\RulesetCache.cs" />
251251
<Compile Include="Support\MersenneTwister.cs" />
252252
<Compile Include="GameInformation.cs" />
253+
<Compile Include="Widgets\RootWidget.cs" />
253254
</ItemGroup>
254255
<ItemGroup>
255256
<Compile Include="FileSystem\D2kSoundResources.cs" />

OpenRA.Game/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ public class KeySettings
176176
public Hotkey ObserverWorldView = new Hotkey(Keycode.EQUALS, Modifiers.None);
177177

178178
public Hotkey TogglePixelDoubleKey = new Hotkey(Keycode.PERIOD, Modifiers.None);
179+
180+
public Hotkey DevReloadChromeKey = new Hotkey(Keycode.C, Modifiers.Ctrl | Modifiers.Shift);
179181
}
180182

181183
public class IrcSettings

OpenRA.Game/Widgets/RootWidget.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#region Copyright & License Information
2+
/*
3+
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
4+
* This file is part of OpenRA, which is free software. It is made
5+
* available to you under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation. For more information,
7+
* see COPYING.
8+
*/
9+
#endregion
10+
11+
using System;
12+
using OpenRA.Graphics;
13+
14+
namespace OpenRA.Widgets
15+
{
16+
public class RootWidget : ContainerWidget
17+
{
18+
public RootWidget()
19+
{
20+
IgnoreMouseOver = true;
21+
}
22+
23+
public override bool HandleKeyPress(KeyInput e)
24+
{
25+
if (e.Event == KeyInputEvent.Down)
26+
{
27+
var hk = Hotkey.FromKeyInput(e);
28+
29+
if (hk == Game.Settings.Keys.DevReloadChromeKey)
30+
{
31+
ChromeProvider.Initialize();
32+
return true;
33+
}
34+
}
35+
36+
return base.HandleKeyPress(e);
37+
}
38+
}
39+
}

OpenRA.Game/Widgets/Widget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace OpenRA.Widgets
1919
{
2020
public static class Ui
2121
{
22-
public static Widget Root = new ContainerWidget();
22+
public static Widget Root = new RootWidget();
2323

2424
public static int LastTickTime = Environment.TickCount;
2525

OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs

Lines changed: 78 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -244,46 +244,6 @@ Action ResetAudioPanel(Widget panel)
244244

245245
Action InitInputPanel(Widget panel)
246246
{
247-
// TODO: Extract these to a yaml file
248-
var specialHotkeys = new Dictionary<string, string>()
249-
{
250-
{ "CycleBaseKey", "Jump to base" },
251-
{ "ToLastEventKey", "Jump to last radar event" },
252-
{ "ToSelectionKey", "Jump to selection" },
253-
{ "SelectAllUnitsKey", "Select all units on screen" },
254-
{ "SelectUnitsByTypeKey", "Select units by type" },
255-
256-
{ "PlaceBeaconKey", "Place beacon" },
257-
258-
{ "PauseKey", "Pause / Unpause" },
259-
{ "SellKey", "Sell mode" },
260-
{ "PowerDownKey", "Power-down mode" },
261-
{ "RepairKey", "Repair mode" },
262-
263-
{ "NextProductionTabKey", "Next production tab" },
264-
{ "PreviousProductionTabKey", "Previous production tab" },
265-
{ "CycleProductionBuildingsKey", "Cycle production facilities" },
266-
267-
{ "ToggleStatusBarsKey", "Toggle status bars" },
268-
{ "TogglePixelDoubleKey", "Toggle pixel doubling" },
269-
};
270-
271-
var unitHotkeys = new Dictionary<string, string>()
272-
{
273-
{ "AttackMoveKey", "Attack Move" },
274-
{ "StopKey", "Stop" },
275-
{ "ScatterKey", "Scatter" },
276-
{ "StanceCycleKey", "Cycle Stance" },
277-
{ "DeployKey", "Deploy" },
278-
{ "GuardKey", "Guard" }
279-
};
280-
281-
var observerHotkeys = new Dictionary<string, string>()
282-
{
283-
{ "ObserverCombinedView", "All Players" },
284-
{ "ObserverWorldView", "Disable Shroud" }
285-
};
286-
287247
var gs = Game.Settings.Game;
288248
var ks = Game.Settings.Keys;
289249

@@ -304,26 +264,89 @@ Action InitInputPanel(Widget panel)
304264
var unitTemplate = hotkeyList.Get("UNIT_TEMPLATE");
305265
hotkeyList.RemoveChildren();
306266

307-
var globalHeader = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
308-
globalHeader.Get<LabelWidget>("LABEL").GetText = () => "Global Commands";
309-
hotkeyList.AddChild(globalHeader);
267+
// Game
268+
{
269+
var hotkeys = new Dictionary<string, string>()
270+
{
271+
{ "CycleBaseKey", "Jump to base" },
272+
{ "ToLastEventKey", "Jump to last radar event" },
273+
{ "ToSelectionKey", "Jump to selection" },
274+
{ "SelectAllUnitsKey", "Select all units on screen" },
275+
{ "SelectUnitsByTypeKey", "Select units by type" },
276+
277+
{ "PlaceBeaconKey", "Place beacon" },
278+
279+
{ "PauseKey", "Pause / Unpause" },
280+
{ "SellKey", "Sell mode" },
281+
{ "PowerDownKey", "Power-down mode" },
282+
{ "RepairKey", "Repair mode" },
283+
284+
{ "NextProductionTabKey", "Next production tab" },
285+
{ "PreviousProductionTabKey", "Previous production tab" },
286+
{ "CycleProductionBuildingsKey", "Cycle production facilities" },
287+
288+
{ "ToggleStatusBarsKey", "Toggle status bars" },
289+
{ "TogglePixelDoubleKey", "Toggle pixel doubling" },
290+
};
291+
292+
var header = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
293+
header.Get<LabelWidget>("LABEL").GetText = () => "Game Commands";
294+
hotkeyList.AddChild(header);
295+
296+
foreach (var kv in hotkeys)
297+
BindHotkeyPref(kv, ks, globalTemplate, hotkeyList);
298+
}
310299

311-
foreach (var kv in specialHotkeys)
312-
BindHotkeyPref(kv, ks, globalTemplate, hotkeyList);
300+
// Observer
301+
{
302+
var hotkeys = new Dictionary<string, string>()
303+
{
304+
{ "ObserverCombinedView", "All Players" },
305+
{ "ObserverWorldView", "Disable Shroud" }
306+
};
313307

314-
var observerHeader = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
315-
observerHeader.Get<LabelWidget>("LABEL").GetText = () => "Observer Commands";
316-
hotkeyList.AddChild(observerHeader);
308+
var header = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
309+
header.Get<LabelWidget>("LABEL").GetText = () => "Observer Commands";
310+
hotkeyList.AddChild(header);
317311

318-
foreach (var kv in observerHotkeys)
319-
BindHotkeyPref(kv, ks, globalTemplate, hotkeyList);
312+
foreach (var kv in hotkeys)
313+
BindHotkeyPref(kv, ks, globalTemplate, hotkeyList);
314+
}
315+
316+
// Unit
317+
{
318+
var hotkeys = new Dictionary<string, string>()
319+
{
320+
{ "AttackMoveKey", "Attack Move" },
321+
{ "StopKey", "Stop" },
322+
{ "ScatterKey", "Scatter" },
323+
{ "StanceCycleKey", "Cycle Stance" },
324+
{ "DeployKey", "Deploy" },
325+
{ "GuardKey", "Guard" }
326+
};
327+
328+
var header = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
329+
header.Get<LabelWidget>("LABEL").GetText = () => "Unit Commands";
330+
hotkeyList.AddChild(header);
331+
332+
foreach (var kv in hotkeys)
333+
BindHotkeyPref(kv, ks, unitTemplate, hotkeyList);
334+
}
335+
336+
// Developer
337+
{
338+
var hotkeys = new Dictionary<string, string>()
339+
{
340+
{ "DevReloadChromeKey", "Reload Chrome" }
341+
};
320342

321-
var unitHeader = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
322-
unitHeader.Get<LabelWidget>("LABEL").GetText = () => "Unit Commands";
323-
hotkeyList.AddChild(unitHeader);
343+
var header = ScrollItemWidget.Setup(hotkeyHeader, () => true, () => {});
344+
header.Get<LabelWidget>("LABEL").GetText = () => "Developer commands";
345+
hotkeyList.AddChild(header);
324346

325-
foreach (var kv in unitHotkeys)
326-
BindHotkeyPref(kv, ks, unitTemplate, hotkeyList);
347+
foreach (var kv in hotkeys)
348+
BindHotkeyPref(kv, ks, globalTemplate, hotkeyList);
349+
}
327350

328351
return () =>
329352
{

0 commit comments

Comments
 (0)