?? mainwindow.cpp
字號(hào):
if(!Register.RegisterExtention("mdx", "Warcraft 3 Model", ModelIconPath.c_str())) return FALSE;
}
if(RegisterInfo.Mpq)
{
if(!Register.RegisterExtention("mpq", "MPQ Archive", ArchiveIconPath.c_str())) return FALSE;
}
if(RegisterInfo.W3m)
{
if(!Register.RegisterExtention("w3m", "MPQ Archive", ArchiveIconPath.c_str())) return FALSE;
}
if(RegisterInfo.W3x)
{
if(!Register.RegisterExtention("w3x", "MPQ Archive", ArchiveIconPath.c_str())) return FALSE;
}
if(RegisterInfo.W3n)
{
if(!Register.RegisterExtention("w3n", "MPQ Archive", ArchiveIconPath.c_str())) return FALSE;
}
if(RegisterInfo.Bmp)
{
if(!Register.RegisterExtention("bmp", "Warcraft 3 Texture", ImageIconPath.c_str())) return FALSE;
}
if(RegisterInfo.Tga)
{
if(!Register.RegisterExtention("tga", "Warcraft 3 Texture", ImageIconPath.c_str())) return FALSE;
}
if(RegisterInfo.Png)
{
if(!Register.RegisterExtention("png", "Warcraft 3 Texture", ImageIconPath.c_str())) return FALSE;
}
if(RegisterInfo.Jpg)
{
if(!Register.RegisterExtention("jpg", "Warcraft 3 Texture", ImageIconPath.c_str())) return FALSE;
}
if(RegisterInfo.Jpeg)
{
if(!Register.RegisterExtention("jpeg", "Warcraft 3 Texture", ImageIconPath.c_str())) return FALSE;
}
if(RegisterInfo.Pcx)
{
if(!Register.RegisterExtention("pcx", "Warcraft 3 Texture", ImageIconPath.c_str())) return FALSE;
}
if(RegisterInfo.Blp)
{
if(!Register.RegisterExtention("blp", "Warcraft 3 Texture", ImageIconPath.c_str())) return FALSE;
}
if(RegisterInfo.OpenWith)
{
if(!Register.RegisterOpenWith("Open with War3ModelEditor")) return FALSE;
}
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Creates a new file (model)
//+-----------------------------------------------------------------------------
BOOL MAIN_WINDOW::NewFile()
{
CloseFile(TRUE);
ModelLoaded = TRUE;
ModelSaved = FALSE;
ModelNeverSaved = TRUE;
ModelFileName = DEFAULT_MODEL_NAME;
Camera.Reset(Window);
UpdateWindowStatus(TRUE);
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Opens an existing file
//+-----------------------------------------------------------------------------
BOOL MAIN_WINDOW::OpenFile()
{
BUFFER Buffer;
std::string FileName;
WINDOW_FILE_DIALOG FileDialog;
FileDialog.SetTitle("Open Model or Texture");
FileDialog.SetFilter(FILTER_BOTH);
if(!FileDialog.OpenFile(Window, FileName)) return TRUE;
if(!FileLoader.LoadFromFile(FileName, Buffer)) return FALSE;
if(!LoadFileFromBuffer(FileName, Buffer, TRUE)) return FALSE;
ModelHistory.AddFileName(FileName);
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Imports an existing file
//+-----------------------------------------------------------------------------
BOOL MAIN_WINDOW::ImportFile()
{
BUFFER Buffer;
FLOAT Distance;
std::string FileName;
WINDOW_FILE_DIALOG FileDialog;
FileDialog.SetTitle("Import Model");
FileDialog.SetFilter(ModelImporter.GetFilter());
if(!FileDialog.OpenFile(Window, FileName)) return TRUE;
if(!FileLoader.LoadFromFile(FileName, Buffer)) return FALSE;
if(!CloseFile(TRUE)) return FALSE;
if(!ModelImporter.ImportModel(FileName, Buffer)) return FALSE;
Model.CalculateBoundsRadius();
Distance = std::max(Model.GetBoundsRadius(), Model.Data().Info.Extent.Radius);
Camera.SetDefaultTarget(Model.GetBoundsCenter());
Camera.SetDefaultDistance(Distance * CAMERA_FACTOR_MODEL);
ModelLoaded = TRUE;
ModelSaved = TRUE;
ModelNeverSaved = TRUE;
ModelFileName = Common.GetFileName(FileName);
Camera.Reset(Window);
UpdateWindowStatus(TRUE);
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Saves the file
//+-----------------------------------------------------------------------------
BOOL MAIN_WINDOW::SaveFile(BOOL& Cancel, BOOL ForceNewName)
{
BUFFER Buffer;
std::string FileName;
WINDOW_FILE_DIALOG FileDialog;
Cancel = FALSE;
if(ForceNewName || ModelNeverSaved)
{
FileName = (ModelFileName == "") ? DEFAULT_MODEL_NAME : ModelFileName;
FileDialog.SetTitle("Save Model");
FileDialog.SetFilter(FILTER_MODEL);
if(!FileDialog.SaveFile(Window, FileName))
{
Cancel = TRUE;
return TRUE;
}
ModelFileName = FileName;
}
if(!ResourceLoader.SaveModel(Model, ModelFileName, Buffer)) return FALSE;
if(!FileLoader.SaveToFile(ModelFileName, Buffer)) return FALSE;
ModelLoaded = TRUE;
ModelSaved = TRUE;
ModelNeverSaved = FALSE;
UpdateWindowStatus(TRUE);
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Saves the file if neccessary
//+-----------------------------------------------------------------------------
BOOL MAIN_WINDOW::SaveFileIfNeccessary(BOOL& Cancel)
{
Cancel = FALSE;
if(!ModelLoaded) return TRUE;
if(ModelSaved) return TRUE;
switch(MessageBoxEx(Window, "Model has not been saved!\nSave now?", "Message", MB_YESNOCANCEL | MB_ICONINFORMATION, CURRENT_LANGUAGE))
{
case IDYES:
{
return SaveFile(Cancel, FALSE);
}
case IDNO:
{
return TRUE;
}
case IDCANCEL:
{
Cancel = TRUE;
return TRUE;
}
}
Error.SetMessage("Unexpected code reached!");
return FALSE;
}
//+-----------------------------------------------------------------------------
//| Closes the file
//+-----------------------------------------------------------------------------
BOOL MAIN_WINDOW::CloseFile(BOOL NoWindowHide)
{
Model.Clear();
ModelLoaded = FALSE;
ModelSaved = FALSE;
ModelNeverSaved = FALSE;
ModelFileName = "";
WINDOW_DIALOG::CloseAllOpenDialogs();
AnimationWindow.ClearAllAnimations();
NodeManagerWindow.ClearAllNodes();
CameraManagerWindow.ClearAllNames();
GeosetManagerWindow.ClearAllNames();
GeosetAnimationManagerWindow.ClearAllNames();
TextureManagerWindow.ClearAllNames();
TextureAnimationManagerWindow.ClearAllNames();
MaterialManagerWindow.ClearAllNames();
SequenceManagerWindow.ClearAllNames();
GlobalSequenceManagerWindow.ClearAllNames();
Camera.SetDefaultDefaults();
TextureManager.Clear();
UpdateWindowStatus(NoWindowHide);
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Creates a new loading screen model
//+-----------------------------------------------------------------------------
BOOL MAIN_WINDOW::NewLoadingScreen(CONST std::string& TextureFileName)
{
CloseFile(TRUE);
if(!TextureManager.Load(TextureFileName)) return FALSE;
if(!Model.CreateLoadingScreenModel(TextureFileName)) return FALSE;
ModelLoaded = TRUE;
ModelSaved = FALSE;
ModelNeverSaved = TRUE;
ModelFileName = "LoadingScreen.mdl";
Model.CalculateBoundsRadius();
Camera.Reset(Window);
UpdateWindowStatus(TRUE);
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Displays the help file
//+-----------------------------------------------------------------------------
BOOL MAIN_WINDOW::DisplayHelp()
{
std::string FileName;
std::string FileNameAndPath;
SHELLEXECUTEINFO Info;
FileName = "War3ModelEditor.chm";
FileNameAndPath = Common.GetProgramDirectory() + "\\" + FileName;
ZeroMemory(&Info, sizeof(SHELLEXECUTEINFO));
Info.cbSize = sizeof(SHELLEXECUTEINFO);
Info.fMask = SEE_MASK_NOCLOSEPROCESS;
Info.hwnd = Window;
Info.lpVerb = "open";
Info.lpFile = FileNameAndPath.c_str();
Info.hInstApp = GetModuleHandle(NULL);
Info.nShow = SW_SHOW;
if(!ShellExecuteEx(&Info))
{
Error.SetMessage("Unable to open \"" + FileName + "\"!");
return FALSE;
}
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Calculates the extents of all model components
//+-----------------------------------------------------------------------------
BOOL MAIN_WINDOW::CalculateExtents()
{
INT i;
FLOAT Min;
FLOAT Max;
EXTENT Extent;
EXTENT TempExtent;
Max = std::numeric_limits<FLOAT>::max();
Min = -Max;
Extent.Radius = 0.0f;
Extent.Min = D3DXVECTOR3(Max, Max, Max);
Extent.Max = D3DXVECTOR3(Min, Min, Min);
if(MessageBox(Window, "This will calculate the extents of all model components. Proceed?\n(It may destroy existing extents)", "Message", MB_YESNO | MB_ICONQUESTION) == IDNO) return TRUE;
for(i = 0; i < Model.Data().GeosetContainer.GetTotalSize(); i++)
{
if(Model.Data().GeosetContainer.ValidIndex(i))
{
Model.Data().GeosetContainer[i]->CalculateExtent(TempExtent);
if(TempExtent.Radius > Extent.Radius) Extent.Radius = TempExtent.Radius;
if(TempExtent.Min.x < Extent.Min.x) Extent.Min.x = TempExtent.Min.x;
if(TempExtent.Min.y < Extent.Min.y) Extent.Min.y = TempExtent.Min.y;
if(TempExtent.Min.z < Extent.Min.z) Extent.Min.z = TempExtent.Min.z;
if(TempExtent.Max.x > Extent.Max.x) Extent.Max.x = TempExtent.Max.x;
if(TempExtent.Max.y > Extent.Max.y) Extent.Max.y = TempExtent.Max.y;
if(TempExtent.Max.z > Extent.Max.z) Extent.Max.z = TempExtent.Max.z;
}
}
for(i = 0; i < Model.Data().SequenceContainer.GetTotalSize(); i++)
{
if(Model.Data().SequenceContainer.ValidIndex(i))
{
Model.Data().SequenceContainer[i]->Data().Extent = Extent;
}
}
Model.Data().Info.Extent = Extent;
MakeModelUnsaved();
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Updates the window status
//+-----------------------------------------------------------------------------
VOID MAIN_WINDOW::UpdateWindowStatus(BOOL NoWindowHide)
{
BOOL Gray;
std::string Title;
Gray = !ModelLoaded;
GrayMenuItem(MainFileSave, Gray);
GrayMenuItem(MainFileSaveAs, Gray);
GrayMenuItem(MainFileClose, Gray);
GrayMenuItem(MainViewResetCamera, Gray);
GrayMenuItem(MainEditCalculateExtents, Gray);
GrayMenuItem(MainEditModelProperties, Gray);
GrayMenuItem(MainEditModelInfo, Gray);
GrayMenuItem(MainWindowsModelEditor, Gray);
GrayMenuItem(MainWindowsAnimationController, Gray);
GrayMenuItem(MainWindowsNodeManager, Gray);
GrayMenuItem(MainWindowsCameraManager, Gray);
GrayMenuItem(MainWindowsGeosetManager, Gray);
GrayMenuItem(MainWindowsGeosetAnimationManager, Gray);
GrayMenuItem(MainWindowsTextureManager, Gray);
GrayMenuItem(MainWindowsTextureAnimationManager, Gray);
GrayMenuItem(MainWindowsMaterialManager, Gray);
GrayMenuItem(MainWindowsSequenceManager, Gray);
GrayMenuItem(MainWindowsGlobalSequenceManager, Gray);
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//GrayMenuItem(MainWindowsModelEditor, TRUE);
if(Gray && !NoWindowHide)
{
ModelWindow.Hide();
AnimationWindow.Hide();
NodeManagerWindow.Hide();
CameraManagerWindow.Hide();
GeosetManagerWindow.Hide();
GeosetAnimationManagerWindow.Hide();
TextureWindow.Hide();
TextureManagerWindow.Hide();
TextureAnimationManagerWindow.Hide();
MaterialManagerWindow.Hide();
SequenceManagerWindow.Hide();
GlobalSequenceManagerWindow.Hide();
}
Title = EDITOR_NAME;
if(ModelLoaded)
{
Title += (" (" + Common.GetFileName(ModelFileName) + ")");
if(!ModelSaved) Title += " *";
}
SetText(Title);
}
//+-----------------------------------------------------------------------------
//| Renders the window
//+-----------------------------------------------------------------------------
VOID MAIN_WINDOW::Render(INT TimeDifference)
{
if(!ModelLoaded)
{
Graphics.RenderFill(PROPERTIES_NO_BACKGROUND);
return;
}
Graphics.RenderFill(Properties().Background);
Graphics.RenderGroundTexture();
Model.Render(TimeDifference);
ParticleManager.Render();
Graphics.RenderAxises();
Graphics.RenderDebug();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -