mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-23 08:41:47 -05:00
Add cursor tests to UILayoutTest, fix cursor file search.
This commit is contained in:
parent
e58bc23597
commit
12c532f77e
4 changed files with 52 additions and 12 deletions
|
@ -203,7 +203,7 @@ namespace OpenTS2.Content
|
|||
/// Adds a DBPF Package to the filesystem, or returns existing package if already loaded.
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the package.</param>
|
||||
/// <returns>Content entry for package.</returns>
|
||||
/// <returns>Package.</returns>
|
||||
public DBPFFile AddPackage(string path)
|
||||
{
|
||||
path = Filesystem.GetRealPath(path);
|
||||
|
|
|
@ -59,6 +59,14 @@ namespace OpenTS2.Engine.Tests
|
|||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
var currentCursor = CursorController.Cursor;
|
||||
currentCursor++;
|
||||
if ((int)currentCursor >= Enum.GetValues(typeof(CursorController.CursorType)).Length)
|
||||
currentCursor = 0;
|
||||
CursorController.Cursor = currentCursor;
|
||||
}
|
||||
if (Reload)
|
||||
{
|
||||
CreateUI();
|
||||
|
|
|
@ -47,6 +47,25 @@ namespace OpenTS2.Files
|
|||
s_epManager = EPManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given a file path relative to TSData, tries to find the absolute path to the file in the latest installed product where the file is available.
|
||||
/// For example, given "Res/UI/Fonts/FontStyle.ini" in an unmodified installation with all products, this would return the University path, as it's the newest EP that has this file.
|
||||
/// </summary>
|
||||
/// <param name="filepath">File path relative to TSData</param>
|
||||
/// <returns>Absolute file path. Null if file can't be found in any Product.</returns>
|
||||
public static string GetFilepathInNewestAvailableProduct(string filepath)
|
||||
{
|
||||
var installedProducts = s_epManager.GetInstalledProducts();
|
||||
for(var i=installedProducts.Count-1;i>=0;i--)
|
||||
{
|
||||
var dataPath = GetDataPathForProduct(installedProducts[i]);
|
||||
var absolutePath = Path.Combine(dataPath, filepath);
|
||||
if (File.Exists(absolutePath))
|
||||
return absolutePath;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<string> GetStartupDownloadPackages()
|
||||
{
|
||||
var userPath = s_pathProvider.GetUserPath();
|
||||
|
|
|
@ -17,20 +17,33 @@ namespace OpenTS2.UI {
|
|||
Sledgehammer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current Hardware Cursor being rendered.
|
||||
/// </summary>
|
||||
public static CursorType Cursor = CursorType.Default;
|
||||
|
||||
private void RegisterCursorFromLatestProduct(CursorType type, string filename)
|
||||
/// <summary>
|
||||
/// Registers a cursor relative to TSData, in the newest Product it can be found in.
|
||||
/// </summary>
|
||||
/// <param name="type">Cursor type to register.</param>
|
||||
/// <param name="filename">Cursor path relative to TSData.</param>
|
||||
private void RegisterCursorRelativePath(CursorType type, string filename)
|
||||
{
|
||||
var epManager = EPManager.Get();
|
||||
RegisterCursor(type, epManager.GetLatestProduct(), filename);
|
||||
var absolutePath = Filesystem.GetFilepathInNewestAvailableProduct(Path.Combine("Res/UI/Cursors",filename));
|
||||
if (absolutePath != null)
|
||||
RegisterCursorAbsolutePath(type, absolutePath);
|
||||
}
|
||||
|
||||
private void RegisterCursor(CursorType type, ProductFlags product, string filename)
|
||||
/// <summary>
|
||||
/// Registers a cursor by its absolute path.
|
||||
/// </summary>
|
||||
/// <param name="type">Cursor type to register.</param>
|
||||
/// <param name="filename">Path to cursor file.</param>
|
||||
private void RegisterCursorAbsolutePath(CursorType type, string filename)
|
||||
{
|
||||
var cursorLocation = Path.Combine(Filesystem.GetDataPathForProduct(product), "Res/UI/Cursors", filename);
|
||||
if (File.Exists(cursorLocation))
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
HardwareCursors.InitializeCursor((int)type, cursorLocation);
|
||||
HardwareCursors.InitializeCursor((int)type, filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,10 +61,10 @@ namespace OpenTS2.UI {
|
|||
|
||||
void RegisterCursors()
|
||||
{
|
||||
RegisterCursor(CursorType.Default, ProductFlags.BaseGame, "arrow_8.cur");
|
||||
RegisterCursor(CursorType.Hourglass, ProductFlags.BaseGame, "Hourglass_8.ani");
|
||||
// Sledgehammer was added in Pets, so Pets and later all come with the cursor in the UI files.
|
||||
RegisterCursorFromLatestProduct(CursorType.Sledgehammer, "Sledgehammer_8.cur");
|
||||
RegisterCursorRelativePath(CursorType.Default, "arrow_8.cur");
|
||||
RegisterCursorRelativePath(CursorType.Hourglass, "Hourglass_8.ani");
|
||||
// Sledgehammer was added in Pets.
|
||||
RegisterCursorRelativePath(CursorType.Sledgehammer, "Sledgehammer_8.cur");
|
||||
}
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
|
|
Loading…
Reference in a new issue