2012-10-19 20:04:05 +00:00
|
|
|
|
#region Using Statements
|
|
|
|
|
using System;
|
2012-11-17 17:52:49 +00:00
|
|
|
|
using System.ComponentModel.Design;
|
2012-10-18 18:52:05 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
2012-09-22 17:44:30 +00:00
|
|
|
|
using System.Windows.Forms;
|
2012-11-17 17:52:49 +00:00
|
|
|
|
using ANX.Framework;
|
|
|
|
|
using ANX.Framework.Content;
|
2012-10-18 18:52:05 +00:00
|
|
|
|
using ANX.Framework.Content.Pipeline;
|
|
|
|
|
using ANX.Framework.Content.Pipeline.Tasks;
|
|
|
|
|
using ANX.Framework.Graphics;
|
2012-10-19 20:04:05 +00:00
|
|
|
|
using ANX.Framework.NonXNA.Development;
|
2012-11-17 17:52:49 +00:00
|
|
|
|
using Point = System.Drawing.Point;
|
2012-10-18 18:52:05 +00:00
|
|
|
|
using Timer = System.Windows.Forms.Timer;
|
2012-10-19 20:04:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
// This file is part of the EES Content Compiler 4,
|
|
|
|
|
// © 2008 - 2012 by Eagle Eye Studios.
|
|
|
|
|
// The EES Content Compiler 4 is released under the Ms-PL license.
|
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2012-09-22 17:44:30 +00:00
|
|
|
|
|
|
|
|
|
namespace ANX.ContentCompiler.GUI.Dialogues
|
|
|
|
|
{
|
2012-11-17 17:52:49 +00:00
|
|
|
|
[PercentageComplete(60)]
|
2012-10-19 20:04:05 +00:00
|
|
|
|
[Developer("SilentWarrior/Eagle Eye Studios")]
|
|
|
|
|
[TestState(TestStateAttribute.TestState.InProgress)]
|
2012-09-22 17:44:30 +00:00
|
|
|
|
public partial class PreviewScreen : Form
|
|
|
|
|
{
|
|
|
|
|
#region Fields
|
|
|
|
|
private Point _lastPos;
|
|
|
|
|
private bool _mouseDown;
|
2012-10-19 20:04:05 +00:00
|
|
|
|
private BuildItem _item;
|
2012-10-18 18:52:05 +00:00
|
|
|
|
private Thread _loaderThread;
|
2012-10-19 20:04:05 +00:00
|
|
|
|
private string _outputFile;
|
|
|
|
|
private string _outputDir;
|
2012-10-18 18:52:05 +00:00
|
|
|
|
private volatile bool _started;
|
|
|
|
|
private volatile bool _error;
|
|
|
|
|
private volatile string _errorMessage;
|
|
|
|
|
private string _processor;
|
|
|
|
|
private Timer _checkTimer;
|
|
|
|
|
private Timer _tickTimer;
|
|
|
|
|
private readonly GraphicsDevice _graphicsDevice;
|
|
|
|
|
private SpriteBatch _batch;
|
2012-11-17 17:52:49 +00:00
|
|
|
|
private ContentManager _contentManager;
|
|
|
|
|
private GameServiceContainer _services;
|
2012-09-22 17:44:30 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2012-10-19 20:04:05 +00:00
|
|
|
|
#region Constructor
|
|
|
|
|
public PreviewScreen()
|
2012-09-22 17:44:30 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2012-10-18 18:52:05 +00:00
|
|
|
|
_graphicsDevice = new GraphicsDevice(
|
|
|
|
|
GraphicsAdapter.DefaultAdapter,
|
|
|
|
|
GraphicsProfile.HiDef,
|
|
|
|
|
new PresentationParameters
|
|
|
|
|
{
|
|
|
|
|
BackBufferWidth = drawSurface.Width,
|
|
|
|
|
BackBufferHeight = drawSurface.Height,
|
|
|
|
|
BackBufferFormat = SurfaceFormat.Color,
|
two commits were missing, both by KorsarNek:
"Removed the SupportedPlatformsImpl classes and replaced them with a new SupportedPlatforms attribute on the assembly level.
Removed a few class constructors which could cause problems when loading a game.
Made ResetElapsedTime in the game class reset to 0 instead of TimeSpan.MinValue.
Removed the restriction in the InputDeviceFactory for which InputDevices are supported.
Added a Logger for Metro which works with the current Logger implementation.
Changed that when a platform is recognized that is higher than Windows 8, it gets treated like Windows 8, not like Windows 7.
Due to the SupportedPlatforms change, the assembly loader is now faster in finding out which assemblies contains addIns. For not Metro system, it's also added that a warning gets written if an AddIn references a different ANX version than that of the running assembly.
OpenGL and DirectX have been updated to the newest versions.
XAudio system uses now the same SharpDX version as all the other systems.
ParameterBuffer for WindowsMetro gets now correctly created by considering the size constraints for constant buffers.
Fixed an erroneous finalizer in the xaudio system.
Made the metro projects convert to Windows 8.1, as Windows 8.0 is not supported by the newer SharpDX versions. It's now also necessary to use at least Visual Studio 2013 to build the Metro versions.
Made the samples work again on Windows."
"Fixed the creation of the swap chain for windows metro and removed the dependency of the Metro Rendersystem onto the Metro Platformsytem.
All occurrences of WindowHandles have been replaced with a custom WindowHandle type which should work out of the box in most cases, but does still represent a breaking change to XNA.
The ProjectConverter for Metro was adjusted so that with just changing the way the application is initialized, most projects that worked with ANX before should now work under win rt. The sample SimpleNoContent does now work out of the box for win rt, after a project conversion.
The application name for win rt apps is now a guid, the display name stayed the same though. That's to be more compliant with the way win rt apps are normally created.
The default namespace and namespace of the classes for the Sample "SimpleNoContent" is renamed from "SimpleModernUI" to "SimpleNoContent".
With the new way win rt apps are initialized for ANX, it's necessary to first create the WindowsGameHost for WinRT with a handler how to create the game instance and give that to the CoreApplication object to run it.
Also took care of a few annoying bugs when working with win rt and ANX where no InputDevices could be created on the first frame (Issue #1164 ) and that it wasn't possible to use the localfolder of the application on the first update and all the other stuff for which an instance of the Application class was necessary."
2015-03-29 13:48:33 +02:00
|
|
|
|
DeviceWindowHandle = new Framework.NonXNA.WindowHandle(drawSurface.Handle),
|
2012-10-18 18:52:05 +00:00
|
|
|
|
PresentationInterval = PresentInterval.Default,
|
|
|
|
|
});
|
2012-11-17 17:52:49 +00:00
|
|
|
|
_services = new GameServiceContainer();
|
|
|
|
|
_services.AddService(typeof(GraphicsDevice), _graphicsDevice);
|
|
|
|
|
_contentManager = new ContentManager(_services);
|
2015-09-03 23:43:55 +02:00
|
|
|
|
|
|
|
|
|
_checkTimer = new Timer { Interval = 1000 };
|
|
|
|
|
_checkTimer.Tick += CheckThread;
|
|
|
|
|
|
|
|
|
|
_tickTimer = new Timer { Interval = 120 };
|
|
|
|
|
_tickTimer.Tick += Tick;
|
|
|
|
|
_batch = new SpriteBatch(_graphicsDevice);
|
2012-09-22 17:44:30 +00:00
|
|
|
|
}
|
2012-10-19 20:04:05 +00:00
|
|
|
|
#endregion
|
2012-09-22 17:44:30 +00:00
|
|
|
|
|
|
|
|
|
#region WindowMoveMethods
|
|
|
|
|
|
|
|
|
|
private void LabelTitleMouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!_mouseDown) return;
|
|
|
|
|
int xoffset = MousePosition.X - _lastPos.X;
|
|
|
|
|
int yoffset = MousePosition.Y - _lastPos.Y;
|
|
|
|
|
Left += xoffset;
|
|
|
|
|
Top += yoffset;
|
|
|
|
|
_lastPos = MousePosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LabelTitleMouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_mouseDown = true;
|
|
|
|
|
_lastPos = MousePosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LabelTitleMouseUp(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_mouseDown = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2012-10-19 20:04:05 +00:00
|
|
|
|
#region Events
|
2012-09-22 17:44:30 +00:00
|
|
|
|
private void ButtonQuitClick(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-11-17 17:52:49 +00:00
|
|
|
|
Hide();
|
2012-09-22 17:44:30 +00:00
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
}
|
2012-10-18 18:52:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CheckThread(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!_started)
|
|
|
|
|
{
|
2012-10-19 20:04:05 +00:00
|
|
|
|
((Timer)sender).Interval = 100;
|
2012-10-18 18:52:05 +00:00
|
|
|
|
_loaderThread = new Thread(CompileFile);
|
|
|
|
|
_loaderThread.Start();
|
|
|
|
|
_started = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (_loaderThread.IsAlive)
|
|
|
|
|
return;
|
|
|
|
|
if (_error)
|
|
|
|
|
{
|
|
|
|
|
labelStatus.Text = "Loading of Preview failed with: \n" + _errorMessage;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
labelStatus.Text = "Loading successful";
|
|
|
|
|
labelStatus.Hide();
|
|
|
|
|
_tickTimer.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-09-03 23:43:55 +02:00
|
|
|
|
try
|
2012-11-17 17:52:49 +00:00
|
|
|
|
{
|
2015-09-03 23:43:55 +02:00
|
|
|
|
if (!_outputFile.EndsWith(".xnb") && !File.Exists(_outputFile + ".xnb"))
|
|
|
|
|
{
|
|
|
|
|
File.Move(_outputFile, _outputFile + ".xnb");
|
|
|
|
|
}
|
|
|
|
|
_graphicsDevice.Clear(Framework.Color.CornflowerBlue);
|
|
|
|
|
if (_processor == "TextureProcessor")
|
|
|
|
|
{
|
|
|
|
|
_batch.Begin();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var tex = _contentManager.Load<Texture2D>(_outputFile);
|
|
|
|
|
_batch.Draw(tex, Vector2.Zero, Color.White);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_batch.End();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (_processor == "FontDescriptionProcessor")
|
|
|
|
|
{
|
|
|
|
|
_batch.Begin();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var font = _contentManager.Load<SpriteFont>(_outputFile);
|
|
|
|
|
_batch.DrawString(font, "The quick brown fox jumps over the lazy dog. äöü@", Vector2.One, Color.DarkRed);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_batch.End();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_graphicsDevice.Present();
|
2012-11-17 17:52:49 +00:00
|
|
|
|
}
|
2015-09-03 23:43:55 +02:00
|
|
|
|
catch (Exception exc)
|
2012-11-17 17:52:49 +00:00
|
|
|
|
{
|
2015-09-03 23:43:55 +02:00
|
|
|
|
_error = true;
|
|
|
|
|
_errorMessage = exc.Message;
|
2012-10-18 18:52:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-19 20:04:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Public methods
|
|
|
|
|
public void CompileFile()
|
|
|
|
|
{
|
2015-09-03 23:43:55 +02:00
|
|
|
|
//TODO: use ContentBuilder instead
|
|
|
|
|
|
|
|
|
|
var builderTask = new BuildContentTask
|
2012-10-19 20:04:05 +00:00
|
|
|
|
{
|
|
|
|
|
TargetPlatform = TargetPlatform.Windows,
|
|
|
|
|
TargetProfile = GraphicsProfile.HiDef,
|
2015-09-03 23:43:55 +02:00
|
|
|
|
CompressContent = false,
|
|
|
|
|
BaseDirectory = new Uri(MainWindow.Instance.ProjectFolder, _item.AssetName)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
builderTask.PrepareAssetBuildCallback = (BuildContentTask sender, BuildItem item, out ContentImporterContext importerContext, out ContentProcessorContext processorContext) =>
|
|
|
|
|
{
|
|
|
|
|
importerContext = new DefaultContentImporterContext(new CCompilerBuildLogger(), _outputDir, _outputDir);
|
|
|
|
|
processorContext = new DefaultContentProcessorContext(sender, MainWindow.Instance.ActiveConfiguration.Name, _outputDir, _outputDir, _outputFile);
|
2012-10-19 20:04:05 +00:00
|
|
|
|
};
|
2015-09-03 23:43:55 +02:00
|
|
|
|
|
|
|
|
|
var importerManager = new ImporterManager();
|
|
|
|
|
|
2012-10-19 20:04:05 +00:00
|
|
|
|
if (String.IsNullOrEmpty(_item.ImporterName))
|
|
|
|
|
{
|
2015-09-03 23:43:55 +02:00
|
|
|
|
_item.ImporterName = importerManager.GuessImporterByFileExtension(_item.SourceFilename);
|
2012-10-19 20:04:05 +00:00
|
|
|
|
}
|
|
|
|
|
if (String.IsNullOrEmpty(_item.ProcessorName))
|
|
|
|
|
{
|
|
|
|
|
_item.ProcessorName =
|
2015-09-03 23:43:55 +02:00
|
|
|
|
new ProcessorManager().GetProcessorForImporter(importerManager.GetInstance(_item.ImporterName));
|
2012-10-19 20:04:05 +00:00
|
|
|
|
}
|
|
|
|
|
_processor = _item.ProcessorName;
|
2015-09-03 23:43:55 +02:00
|
|
|
|
|
|
|
|
|
try
|
2012-10-19 20:04:05 +00:00
|
|
|
|
{
|
2015-09-03 23:43:55 +02:00
|
|
|
|
builderTask.Execute(new[] { _item });
|
2012-10-19 20:04:05 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_error = true;
|
|
|
|
|
_errorMessage = ex.Message;
|
2015-09-03 23:43:55 +02:00
|
|
|
|
}
|
2012-10-19 20:04:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetFile(BuildItem item)
|
|
|
|
|
{
|
2015-09-03 23:43:55 +02:00
|
|
|
|
_tickTimer.Stop();
|
|
|
|
|
_checkTimer.Stop();
|
|
|
|
|
_started = false;
|
|
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
|
|
|
|
_item = item;
|
|
|
|
|
_outputFile = Path.GetTempFileName();
|
|
|
|
|
_outputDir = Path.GetTempPath();
|
|
|
|
|
_checkTimer.Start();
|
|
|
|
|
|
|
|
|
|
labelStatus.Text = "Loading Preview...";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
labelStatus.Text = "No item selected";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
labelStatus.Show();
|
2012-10-19 20:04:05 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
2012-09-22 17:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|