Merge branch 'master' of git://github.com/chrisforbes/OpenRA

This commit is contained in:
pchote
2010-02-22 21:36:45 +13:00
7 changed files with 58 additions and 200 deletions

View File

@@ -177,7 +177,7 @@ namespace OpenRa
buttons.Clear();
renderer.Device.DisableScissor();
renderer.DrawText("RenderFrame {0} ({2:F1} ms)\nTick {1} ({3:F1} ms)\n".F(
renderer.RegularFont.DrawText("RenderFrame {0} ({2:F1} ms)\nTick {1} ({3:F1} ms)\n".F(
Game.RenderFrame,
Game.orderManager.FrameNumber,
PerfHistory.items["render"].LastValue,
@@ -233,7 +233,7 @@ namespace OpenRa
public void DrawDialog(string text)
{
var w = renderer.MeasureText2(text).X + 120;
var w = renderer.BoldFont.Measure(text).X + 120;
var h = 100;
var r = new Rectangle((Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h);
DrawDialogBackground(r, "dialog");
@@ -326,7 +326,7 @@ namespace OpenRa
if (map == currentMap)
DrawDialogBackground(itemRect, "panel");
renderer.DrawText(map.Map.Title, new int2(r.Left + 60, y), Color.White);
renderer.RegularFont.DrawText(map.Map.Title, new int2(r.Left + 60, y), Color.White);
var closureMap = map;
AddButton(itemRect, _ => { currentMap = closureMap; mapPreviewDirty = true; });
}
@@ -444,11 +444,12 @@ namespace OpenRa
});
}
renderer.DrawText2("Name", new int2(r.Left + 40, r.Top + 50), Color.White);
renderer.DrawText2("Color", new int2(r.Left + 140, r.Top + 50), Color.White);
renderer.DrawText2("Faction", new int2(r.Left + 220, r.Top + 50), Color.White);
renderer.DrawText2("Status", new int2(r.Left + 290, r.Top + 50), Color.White);
renderer.DrawText2("Spawn", new int2(r.Left + 390, r.Top + 50), Color.White);
var f = renderer.BoldFont;
f.DrawText("Name", new int2(r.Left + 40, r.Top + 50), Color.White);
f.DrawText("Color", new int2(r.Left + 140, r.Top + 50), Color.White);
f.DrawText("Faction", new int2(r.Left + 220, r.Top + 50), Color.White);
f.DrawText("Status", new int2(r.Left + 290, r.Top + 50), Color.White);
f.DrawText("Spawn", new int2(r.Left + 390, r.Top + 50), Color.White);
var y = r.Top + 80;
foreach (var client in Game.LobbyInfo.Clients)
@@ -480,16 +481,17 @@ namespace OpenRa
shpRenderer.Flush();
renderer.DrawText(client.Name, new int2(r.Left + 40, y), Color.White);
f = renderer.RegularFont;
f.DrawText(client.Name, new int2(r.Left + 40, y), Color.White);
lineRenderer.FillRect(RectangleF.FromLTRB(paletteRect.Left + Game.viewport.Location.X + 5,
paletteRect.Top + Game.viewport.Location.Y + 5,
paletteRect.Right + Game.viewport.Location.X - 5,
paletteRect.Bottom+Game.viewport.Location.Y - 5),
Player.PlayerColors[client.PaletteIndex].c);
lineRenderer.Flush();
renderer.DrawText(client.Country, new int2(r.Left + 220, y), Color.White);
renderer.DrawText(client.State.ToString(), new int2(r.Left + 290, y), Color.White);
renderer.DrawText((client.SpawnPoint == 0)? "-" : client.SpawnPoint.ToString(), new int2(r.Left + 410, y), Color.White);
f.DrawText(client.Country, new int2(r.Left + 220, y), Color.White);
f.DrawText(client.State.ToString(), new int2(r.Left + 290, y), Color.White);
f.DrawText((client.SpawnPoint == 0)? "-" : client.SpawnPoint.ToString(), new int2(r.Left + 410, y), Color.White);
y += 30;
}
@@ -738,8 +740,8 @@ namespace OpenRa
AddButton(optionsRect, isLmb => optionsPressed = !optionsPressed);
shpRenderer.DrawSprite(optionsButton.Image, optionsDrawPos, "chrome");
shpRenderer.Flush();
renderer.DrawText("Options", new int2((int)(optionsButton.Image.size.X - renderer.MeasureText("Options").X)/2, -2) , Color.White);
renderer.RegularFont.DrawText("Options", new int2((int)(optionsButton.Image.size.X - renderer.RegularFont.Measure("Options").X) / 2, -2), Color.White);
}
void DrawOptionsMenu()
@@ -815,9 +817,9 @@ namespace OpenRa
void RenderChatLine(Tuple<Color, string, string> line, int2 p)
{
var size = renderer.MeasureText(line.b);
renderer.DrawText(line.b, p, line.a);
renderer.DrawText(line.c, p + new int2(size.X + 10, 0), Color.White);
var size = renderer.RegularFont.Measure(line.b);
renderer.RegularFont.DrawText(line.b, p, line.a);
renderer.RegularFont.DrawText(line.c, p + new int2(size.X + 10, 0), Color.White);
}
void TickPaletteAnimation()
@@ -1063,12 +1065,12 @@ namespace OpenRa
void DrawRightAligned(string text, int2 pos, Color c)
{
renderer.DrawText2(text, pos - new int2(renderer.MeasureText2(text).X, 0), c);
renderer.BoldFont.DrawText(text, pos - new int2(renderer.BoldFont.Measure(text).X, 0), c);
}
void DrawCentered(string text, int2 pos, Color c)
{
renderer.DrawText2(text, pos - new int2(renderer.MeasureText2(text).X/2, 0), c);
renderer.BoldFont.DrawText(text, pos - new int2(renderer.BoldFont.Measure(text).X / 2, 0), c);
}
void DrawProductionTooltip(World world, string unit, int2 pos)
@@ -1081,7 +1083,7 @@ namespace OpenRa
var info = Rules.Info[unit];
var buildable = info.Traits.Get<BuildableInfo>();
renderer.DrawText2(buildable.Description, p.ToInt2() + new int2(5,5), Color.White);
renderer.BoldFont.DrawText(buildable.Description, p.ToInt2() + new int2(5, 5), Color.White);
DrawRightAligned( "${0}".F(buildable.Cost), pos + new int2(-5,5),
world.LocalPlayer.Cash + world.LocalPlayer.Ore >= buildable.Cost ? Color.White : Color.Red);
@@ -1099,14 +1101,14 @@ namespace OpenRa
{
var prereqs = buildable.Prerequisites
.Select( a => Description( a ) );
renderer.DrawText("Requires {0}".F( string.Join( ", ", prereqs.ToArray() ) ), p.ToInt2(),
renderer.RegularFont.DrawText("Requires {0}".F( string.Join( ", ", prereqs.ToArray() ) ), p.ToInt2(),
Color.White);
}
if (buildable.LongDesc != null)
{
p += new int2(0, 15);
renderer.DrawText(buildable.LongDesc.Replace( "\\n", "\n" ), p.ToInt2(), Color.White);
renderer.RegularFont.DrawText(buildable.LongDesc.Replace( "\\n", "\n" ), p.ToInt2(), Color.White);
}
}
@@ -1200,7 +1202,7 @@ namespace OpenRa
pos += new int2(5, 5);
renderer.DrawText2(sp.Info.Description, pos, Color.White);
renderer.BoldFont.DrawText(sp.Info.Description, pos, Color.White);
var timer = "Charge Time: {0}".F(FormatTime(sp.RemainingTime));
DrawRightAligned(timer, pos + new int2((int)tooltipSprite.size.X - 10, 0), Color.White);
@@ -1208,7 +1210,7 @@ namespace OpenRa
if (sp.Info.LongDesc != null)
{
pos += new int2(0, 25);
renderer.DrawText(sp.Info.LongDesc.Replace("\\n", "\n"), pos, Color.White);
renderer.RegularFont.DrawText(sp.Info.LongDesc.Replace("\\n", "\n"), pos, Color.White);
}
}

View File

@@ -29,17 +29,9 @@ namespace OpenRa
{
public class Controller : IHandleInput
{
public IOrderGenerator orderGenerator;
public IOrderGenerator orderGenerator = new UnitOrderGenerator();
public Selection selection = new Selection();
readonly Func<Modifiers> GetModifierKeys;
public Controller(Func<Modifiers> getModifierKeys)
{
GetModifierKeys = getModifierKeys;
CancelInputMode();
}
public void CancelInputMode() { orderGenerator = new UnitOrderGenerator(); }
public bool ToggleInputMode<T>() where T : IOrderGenerator, new()
@@ -123,6 +115,7 @@ namespace OpenRa
}
public float2 MousePosition { get { return dragEnd; } }
Modifiers modifiers;
public string ChooseCursor( World world )
{
@@ -134,7 +127,7 @@ namespace OpenRa
{
Location = ( Game.CellSize * MousePosition - Game.viewport.Location ).ToInt2(),
Button = MouseButton.Right,
Modifiers = GetModifierKeys(),
Modifiers = modifiers
};
return orderGenerator.GetCursor( world, MousePosition.ToInt2(), mi );
@@ -145,5 +138,7 @@ namespace OpenRa
throw new InvalidOperationException( "Desync in Controller.ChooseCursor" );
}
}
public void SetModifiers(Modifiers mods) { modifiers = mods; }
}
}

View File

@@ -341,6 +341,11 @@ namespace OpenRa
throw new InvalidOperationException( "Desync in OnKeyPress" );
}
public static void HandleModifierKeys(Modifiers mods)
{
controller.SetModifiers(mods);
}
static Size GetResolution(Settings settings)
{
var desktopResolution = Screen.PrimaryScreen.Bounds.Size;
@@ -354,9 +359,6 @@ namespace OpenRa
desktopResolution.Height);
}
// [DllImport("user32")]
// static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible);
public static void PreInit(Settings settings)
{
while (!Directory.Exists("mods"))
@@ -383,7 +385,7 @@ namespace OpenRa
renderer = new Renderer(resolution, windowed);
resolution = renderer.Resolution;
var controller = new Controller(() => (Modifiers)(int)0/*ModifierKeys*/); /* a bit of insane input routing */
var controller = new Controller(); /* a bit of insane input routing */
Game.Initialize(Game.Settings.Map, renderer, new int2(resolution), Game.Settings.Player, controller);

View File

@@ -43,7 +43,7 @@ namespace OpenRa.Graphics
public ITexture PaletteTexture;
readonly IFont regularFont, boldFont;
public readonly IFont RegularFont, BoldFont;
public Size Resolution { get { return device.WindowSize; } }
@@ -56,8 +56,8 @@ namespace OpenRa.Graphics
RgbaSpriteShader = device.CreateShader(FileSystem.Open("shaders/chrome-rgba.fx"));
WorldSpriteShader = device.CreateShader(FileSystem.Open("shaders/chrome-shp.fx"));
regularFont = device.CreateFont( "FreeSans.ttf" );
boldFont = device.CreateFont( "FreeSansBold.ttf" );
RegularFont = device.CreateFont( "FreeSans.ttf" );
BoldFont = device.CreateFont( "FreeSansBold.ttf" );
}
IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, bool windowed, bool vsync )
@@ -127,26 +127,5 @@ namespace OpenRa.Graphics
PerfHistory.Increment("batches", 1);
}
public void DrawText( string text, int2 pos, Color c )
{
using (new PerfSample("text"))
regularFont.DrawText( text, pos, c );
}
public void DrawText2( string text, int2 pos, Color c )
{
using (new PerfSample("text"))
boldFont.DrawText( text, pos, c );
}
public int2 MeasureText(string text)
{
return regularFont.Measure( text );
}
public int2 MeasureText2(string text)
{
return boldFont.Measure( text );
}
}
}

View File

@@ -19,139 +19,10 @@
#endregion
using System;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using OpenRa.FileFormats;
using OpenRa.GameRules;
using OpenRa.Graphics;
namespace OpenRa
{
//class MainWindow : Form
//{
// readonly Renderer renderer;
// static Size GetResolution(Settings settings)
// {
// var desktopResolution = Screen.PrimaryScreen.Bounds.Size;
// if (Game.Settings.Width > 0 && Game.Settings.Height > 0)
// {
// desktopResolution.Width = Game.Settings.Width;
// desktopResolution.Height = Game.Settings.Height;
// }
// return new Size(
// desktopResolution.Width,
// desktopResolution.Height);
// }
// [DllImport("user32")]
// static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible);
// public MainWindow(Settings settings)
// {
// Icon = Resources1.OpenRA;
// FormBorderStyle = FormBorderStyle.None;
// BackColor = Color.Black;
// StartPosition = FormStartPosition.Manual;
// Location = Point.Empty;
// Visible = true;
// while (!File.Exists("redalert.mix"))
// {
// var current = Directory.GetCurrentDirectory();
// if (Directory.GetDirectoryRoot(current) == current)
// throw new InvalidOperationException("Unable to load MIX files.");
// Directory.SetCurrentDirectory("..");
// }
// LoadUserSettings(settings);
// Game.LobbyInfo.GlobalSettings.Mods = Game.Settings.InitialMods;
// // Load the default mod to access required files
// Game.LoadModPackages(new Manifest(Game.LobbyInfo.GlobalSettings.Mods));
// UiOverlay.ShowUnitDebug = Game.Settings.UnitDebug;
// WorldRenderer.ShowUnitPaths = Game.Settings.PathDebug;
// Renderer.SheetSize = Game.Settings.SheetSize;
// bool windowed = !Game.Settings.Fullscreen;
// renderer = new Renderer(this, GetResolution(settings), windowed);
// var controller = new Controller(() => (Modifiers)(int)ModifierKeys); /* a bit of insane input routing */
// Game.Initialize(Game.Settings.Map, renderer, new int2(ClientSize), Game.Settings.Player, controller);
// ShowCursor(false);
// Game.ResetTimer();
// }
// static void LoadUserSettings(Settings settings)
// {
// Game.Settings = new UserSettings();
// var settingsFile = settings.GetValue("settings", "settings.ini");
// FileSystem.Mount("./");
// if (FileSystem.Exists(settingsFile))
// FieldLoader.Load(Game.Settings,
// new IniFile(FileSystem.Open(settingsFile)).GetSection("Settings"));
// FileSystem.UnmountAll();
// }
// internal void Run()
// {
// while (Created && Visible)
// {
// Game.Tick();
// Application.DoEvents();
// }
// }
// int2 lastPos;
// protected override void OnMouseDown(MouseEventArgs e)
// {
// base.OnMouseDown(e);
// lastPos = new int2(e.Location);
// Game.DispatchMouseInput(MouseInputEvent.Down, e, ModifierKeys);
// }
// protected override void OnMouseMove(MouseEventArgs e)
// {
// base.OnMouseMove(e);
// if (e.Button == MouseButtons.Middle || e.Button == (MouseButtons.Left | MouseButtons.Right))
// {
// int2 p = new int2(e.Location);
// Game.viewport.Scroll(lastPos - p);
// lastPos = p;
// }
// Game.DispatchMouseInput(MouseInputEvent.Move, e, ModifierKeys);
// }
// protected override void OnMouseUp(MouseEventArgs e)
// {
// base.OnMouseUp(e);
// Game.DispatchMouseInput(MouseInputEvent.Up, e, ModifierKeys);
// }
// protected override void OnKeyDown(KeyEventArgs e)
// {
// base.OnKeyDown(e);
// Game.HandleKeyDown( e );
// }
// protected override void OnKeyPress(KeyPressEventArgs e)
// {
// base.OnKeyPress(e);
// Game.HandleKeyPress( e );
// }
//}
[Flags]
public enum MouseButton
{

View File

@@ -25,6 +25,7 @@ namespace OpenRa.Traits
class LimitedAmmoInfo : ITraitInfo
{
public readonly int Ammo = 0;
public readonly int PipCount = 0;
public object Create(Actor self) { return new LimitedAmmo(self); }
}
@@ -53,9 +54,10 @@ namespace OpenRa.Traits
public IEnumerable<PipType> GetPips(Actor self)
{
var maxAmmo = self.Info.Traits.Get<LimitedAmmoInfo>().Ammo;
return Graphics.Util.MakeArray(maxAmmo,
i => ammo > i ? PipType.Green : PipType.Transparent);
var info = self.Info.Traits.Get<LimitedAmmoInfo>();
var pips = info.PipCount != 0 ? info.PipCount : info.Ammo;
return Graphics.Util.MakeArray(pips,
i => (ammo * pips) / info.Ammo > i ? PipType.Green : PipType.Transparent);
}
}
}

View File

@@ -60,12 +60,13 @@ namespace OpenRa.GlRenderer
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8);
Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_ALPHA_SIZE, 8);
Sdl.SDL_putenv( "SDL_VIDEO_WINDOW_POS=0,0" );
Environment.SetEnvironmentVariable("SDL_VIDEO_WINDOW_POS", "0,0");
surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_OPENGL | (windowed ? 0 : Sdl.SDL_FULLSCREEN));
surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_NOFRAME | Sdl.SDL_OPENGL | (windowed ? 0 : Sdl.SDL_FULLSCREEN));
Sdl.SDL_WM_SetCaption("OpenRA", "OpenRA");
Sdl.SDL_ShowCursor(0);
Sdl.SDL_EnableUNICODE( 1 );
Sdl.SDL_EnableKeyRepeat(Sdl.SDL_DEFAULT_REPEAT_INTERVAL, Sdl.SDL_DEFAULT_REPEAT_DELAY);
CheckGlError();
@@ -124,7 +125,6 @@ namespace OpenRa.GlRenderer
CheckGlError();
}
Modifiers mods = 0;
MouseButtons lastButtonBits = (MouseButtons)0;
static MouseButtons MakeButton(byte b)
@@ -135,10 +135,20 @@ namespace OpenRa.GlRenderer
: 0;
}
static Modifiers MakeModifiers(int raw)
{
return ((raw & Sdl.KMOD_ALT) != 0 ? Modifiers.Alt : 0)
| ((raw & Sdl.KMOD_CTRL) != 0 ? Modifiers.Ctrl : 0)
| ((raw & Sdl.KMOD_SHIFT) != 0 ? Modifiers.Shift : 0);
}
public void Present()
{
Sdl.SDL_GL_SwapBuffers();
var mods = MakeModifiers(Sdl.SDL_GetModState());
Game.HandleModifierKeys(mods);
Sdl.SDL_Event e;
while (Sdl.SDL_PollEvent(out e) != 0)
{
@@ -177,9 +187,6 @@ namespace OpenRa.GlRenderer
case Sdl.SDL_KEYDOWN:
{
mods = ( ( e.key.keysym.mod & Sdl.KMOD_ALT ) != 0 ? Modifiers.Alt : 0 )
| ( ( e.key.keysym.mod & Sdl.KMOD_CTRL ) != 0 ? Modifiers.Ctrl : 0 )
| ( ( e.key.keysym.mod & Sdl.KMOD_SHIFT ) != 0 ? Modifiers.Shift : 0 );
if( e.key.keysym.unicode != 0 )
Game.HandleKeyPress( new KeyPressEventArgs( (char)e.key.keysym.unicode ), mods );