152 lines
4.5 KiB
C#
152 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using JD.Application.Plugin;
|
|
using JD.Core.ProjectManaging;
|
|
using JD.Interfaces.Remoting;
|
|
using JD.Perforce;
|
|
using JD.Remoting;
|
|
using Blob = JD.Remoting.Blob;
|
|
using IBlob = JD.Remoting.IBlob;
|
|
|
|
namespace ResourceViewer
|
|
{
|
|
public class ResourceViewerPlugin : BasePlugin
|
|
{
|
|
public delegate void UpdateEventHandler(object sender, UpdateEventArgs e);
|
|
public delegate void UpdateRootDataPathEventHandler(object sender, UpdateDataRootPathEventArgs e);
|
|
|
|
#region members
|
|
private string _platform = string.Empty;
|
|
private readonly UIElement _uiElementDispatcher = new UIElement();
|
|
public event UpdateEventHandler UpdateHandler;
|
|
public event UpdateRootDataPathEventHandler UpdateDataRootHandler;
|
|
private cookerWrapper _cookerWrapper;
|
|
private engineWrapper _engineWrapper;
|
|
#endregion
|
|
|
|
#region properties
|
|
public string Platform
|
|
{
|
|
get { return _platform; }
|
|
}
|
|
// list of resource from engine
|
|
public List<ResourceInfo> ResourceList
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
// list of resource type, receive from engine
|
|
public List<string> ResourceTypeList
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public ResourceViewerPlugin()
|
|
: base("ResourceTools_Plugin")
|
|
{
|
|
RegisterCommands();
|
|
}
|
|
|
|
#region commands
|
|
|
|
private void RegisterCommands()
|
|
{
|
|
RegisterHandler("dumpresources", DumpResources);
|
|
RegisterHandler("updateresource", UpdateResource);
|
|
RegisterHandler("platform", UpdatePlatfom);
|
|
RegisterHandler("dataroot", UpdateDataRoot);
|
|
ConnectedChanged += OnConnectedChanged;
|
|
}
|
|
|
|
private void OnConnectedChanged(object sender, IPlugin eventArgs)
|
|
{
|
|
if (IsConnected)
|
|
{
|
|
_engineWrapper = new engineWrapper("ResourceViewerPlugin");
|
|
_cookerWrapper = new cookerWrapper();
|
|
_cookerWrapper.init(DataPath.Value);
|
|
_cookerWrapper.registerVersionCallback();
|
|
}
|
|
}
|
|
|
|
private void DumpResources(IBlob currentBlob)
|
|
{
|
|
ResourceList = currentBlob.ExtractDumpResources();
|
|
if (ResourceList.Count > 0)
|
|
{
|
|
UpdateResourceTypeList(ResourceList);
|
|
}
|
|
if (this.UpdateHandler != null)
|
|
this.UpdateHandler(this, new UpdateEventArgs(ResourceList, ResourceTypeList));
|
|
}
|
|
|
|
private void UpdateResource(IBlob currentBlob)
|
|
{
|
|
ResourceInfo resourceInfo = currentBlob.ExtractUpdateResource();
|
|
|
|
int index = ResourceList.FindIndex(res => res.ShortName == resourceInfo.ShortName);
|
|
if (index >= 0)
|
|
{
|
|
ResourceList[index] = resourceInfo;
|
|
}
|
|
}
|
|
|
|
private void UpdatePlatfom(IBlob currentBlob)
|
|
{
|
|
_platform = currentBlob.ExtractString();
|
|
}
|
|
|
|
private void UpdateDataRoot(IBlob currentBlob)
|
|
{
|
|
var dataRootPath = currentBlob.ExtractString();
|
|
|
|
if (UpdateDataRootHandler != null)
|
|
UpdateDataRootHandler(this, new UpdateDataRootPathEventArgs(dataRootPath));
|
|
|
|
// Autoconnect perforce
|
|
P4Manager.Instance.Connect();
|
|
}
|
|
|
|
public void RequestDumpResources(string resourceType)
|
|
{
|
|
var blob = new Blob();
|
|
blob.Push(resourceType);
|
|
Send(new Message("dumpresources", blob));
|
|
}
|
|
|
|
public void RequestInitPlugin()
|
|
{
|
|
Send(new Message("init"));
|
|
}
|
|
|
|
public void RequestReloadResource(string filePath)
|
|
{
|
|
var blob = new Blob();
|
|
blob.PushPath(filePath);
|
|
Send(new Message("reloadresource", blob));
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
_cookerWrapper.destroy();
|
|
base.Dispose();
|
|
}
|
|
|
|
#endregion
|
|
|
|
public bool CookTexture(string platform, string file)
|
|
{
|
|
return _cookerWrapper.cookTexture(platform, file, true);
|
|
}
|
|
|
|
private void UpdateResourceTypeList(IEnumerable<ResourceInfo> resList)
|
|
{
|
|
ResourceTypeList = resList.Select(ri => ResourceUtils.TypeHelper.ConvertEngineTypeToUIType(ri.TypeName)).Distinct().ToList();
|
|
}
|
|
}
|
|
}
|