Load the game into an intermediate state where RAInitDelegate can install packages, etc (an even bigger hack).

This commit is contained in:
Paul Chote
2011-01-19 22:51:18 +13:00
parent 6776d6f906
commit 6c14b78b7c
7 changed files with 44 additions and 45 deletions

View File

@@ -253,15 +253,17 @@ namespace OpenRA
JoinLocal();
viewport = new Viewport(new int2(Renderer.Resolution), Rectangle.Empty, Renderer);
//StartGame(ChooseShellmap());
// TODO: unhardcode this
modData.WidgetLoader.LoadWidget( new Dictionary<string,object>(), Widget.RootWidget, "PERF_BG" );
Widget.OpenWindow("MAINMENU_BG");
Widget.OpenWindow("MAINMENU_INIT");
Game.orderManager.LastTickTime = Environment.TickCount;
}
public static void LoadShellMap()
{
StartGame(ChooseShellmap());
}
static string ChooseShellmap()
{
var shellmaps = modData.AvailableMaps

View File

@@ -51,6 +51,9 @@ namespace OpenRA.Graphics
public void AddPalette(string name, Palette p)
{
if (palettes.ContainsKey(name))
throw new InvalidOperationException("Palette {0} has already been defined".F(name));
palettes.Add(name, p);
indices.Add(name, allocated++);
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA
public SheetBuilder SheetBuilder;
public CursorSheetBuilder CursorSheetBuilder;
public SpriteLoader SpriteLoader;
public readonly HardwarePalette Palette;
public HardwarePalette Palette { get; private set; }
public ModData( params string[] mods )
{
@@ -38,7 +38,12 @@ namespace OpenRA
AvailableMaps = FindMaps( Manifest.Mods );
WidgetLoader = new WidgetLoader( this );
}
void LoadHackyPalettes()
{
Palette = new HardwarePalette();
Palette.AddPalette("cursor", new Palette( FileSystem.Open( "cursor.pal" ), false ));
}
public void Sucks()
@@ -48,15 +53,19 @@ namespace OpenRA
FileSystem.UnmountAll();
foreach (var dir in Manifest.Folders) FileSystem.Mount(dir);
//foreach (var pkg in Manifest.Packages) FileSystem.Mount(pkg);
Palette.AddPalette("cursor", new Palette( FileSystem.Open( "cursor.pal" ), false ));
ChromeProvider.Initialize( Manifest.Chrome );
SheetBuilder = new SheetBuilder( TextureChannel.Red );
CursorSheetBuilder = new CursorSheetBuilder( this );
SpriteLoader = new SpriteLoader(new[]{".shp"}, SheetBuilder);
CursorProvider.Initialize(Manifest.Cursors);
LoadHackyPalettes();
}
public void LoadPackages()
{
foreach (var pkg in Manifest.Packages) FileSystem.Mount(pkg);
}
public static IEnumerable<string> FindMapsIn(string dir)
@@ -124,6 +133,7 @@ namespace OpenRA
}
previousMapHadSequences = map.Sequences.Count > 0;
LoadHackyPalettes();
return map;
}

View File

@@ -328,6 +328,7 @@
<Compile Include="Buildings\ShakeOnDeath.cs" />
<Compile Include="Buildings\SoundOnDamageTransition.cs" />
<Compile Include="Activities\RAHarvesterDockSequence.cs" />
<Compile Include="Widgets\Delegates\RAInitDelegate.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -18,8 +18,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
{
public class MainMenuButtonsDelegate : IWidgetDelegate
{
static bool FirstInit = true;
[ObjectCreator.UseCtor]
public MainMenuButtonsDelegate([ObjectCreator.Param] Widget widget)
{
@@ -30,37 +28,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
widget.GetWidget("MAINMENU_BUTTON_MUSIC").OnMouseUp = mi => { Widget.OpenWindow("MUSIC_MENU"); return true; };
widget.GetWidget("MAINMENU_BUTTON_REPLAY_VIEWER").OnMouseUp = mi => { Widget.OpenWindow("REPLAYBROWSER_BG"); return true; };
widget.GetWidget("MAINMENU_BUTTON_QUIT").OnMouseUp = mi => { Game.Exit(); return true; };
if (FirstInit)
{
FirstInit = false;
Game.ConnectionStateChanged += orderManager =>
{
Widget.CloseWindow();
switch( orderManager.Connection.ConnectionState )
{
case ConnectionState.PreConnecting:
Widget.OpenWindow("MAINMENU_BG");
break;
case ConnectionState.Connecting:
Widget.OpenWindow( "CONNECTING_BG",
new Dictionary<string, object> { { "host", orderManager.Host }, { "port", orderManager.Port } } );
break;
case ConnectionState.NotConnected:
Widget.OpenWindow( "CONNECTION_FAILED_BG",
new Dictionary<string, object> { { "orderManager", orderManager } } );
break;
case ConnectionState.Connected:
var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY");
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true;
lobby.GetWidget("DISCONNECT_BUTTON").Visible = true;
//r.GetWidget("INGAME_ROOT").GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
break;
}
};
}
}
}
}

View File

@@ -1,9 +1,28 @@
Background@MAINMENU_INIT:
Id:MAINMENU_INIT
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:250
Height:330
Visible:true
Delegate:RAInitDelegate
Children:
Button@FINISH_INIT:
Id:FINISH_INIT
X:45
Y:70
Width:160
Height:25
Text:START
Bold:True
Background@MAINMENU_BG:
Id:MAINMENU_BG
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:250
Height:330
Visible:true
Delegate:MainMenuButtonsDelegate
Children:
Label@MAINMENU_LABEL_TITLE:

View File

@@ -116,9 +116,6 @@ World:
PaletteFromFile@effect:
Name: effect
Filename: temperat.pal
PaletteFromFile@cursor:
Name: cursor
Filename: temperat.pal
PaletteFromRGBA@shadow:
Name: shadow
R: 0