Adds a TASEdit project structure and functionality for NewProject(). Added TODO comments to show what needs to be done next update.

This commit is contained in:
chris220 2009-06-15 20:39:37 +00:00
parent 4c6762ef52
commit 88911bf871
1 changed files with 79 additions and 29 deletions

View File

@ -1,5 +1,6 @@
#include <set> #include <set>
#include <fstream> #include <fstream>
#include <iostream> //Allows us to save the project and other data :)
#include "common.h" #include "common.h"
#include "tasedit.h" #include "tasedit.h"
@ -40,32 +41,61 @@ extern EMOVIEMODE movieMode;
//The project file struct //The project file struct
struct TASEDIT_PROJECT struct TASEDIT_PROJECT
{ {
std::string mainFilename; //The main fm2's file name and location //The TASEdit Project's name
std::string getFilename(); std::string projectName;
std::string setFilename(); //The FM2's file name
std::string projectFilename; //Name of the actual project's file std::string fm2FileName;
}; //The TASEdit Project's filename (For saving purposes)
std::string projectFile;
std::string GetProjectName();
void SetProjectName(std::string e);
std::string GetFM2Name();
void SetFM2Name(std::string e);
std::string GetProjectFile();
void SetProjectFile(std::string e);
};
TASEDIT_PROJECT project; //Create an instance of the project TASEDIT_PROJECT project; //Create an instance of the project
std::string getFilename() //Get fm2 file name
//All the get/set functions...
std::string TASEDIT_PROJECT::GetProjectName()
{ {
return project.mainFilename; //Speaks for itself really! return project.projectName;
}
void TASEDIT_PROJECT::SetProjectName(std::string e)
{
project.projectName = e;
}
std::string TASEDIT_PROJECT::GetFM2Name()
{
return project.fm2FileName;
}
void TASEDIT_PROJECT::SetFM2Name(std::string e)
{
project.fm2FileName = e;
}
std::string TASEDIT_PROJECT::GetProjectFile()
{
return project.projectFile;
}
void TASEDIT_PROJECT::SetProjectFile(std::string e)
{
project.projectFile = e;
} }
void setFilename(std::string e) //Guess what? Sets the project's fm2 file name!
{
project.mainFilename = e; //Yep
}
std::string getProjectname() //Get TASEedit project's name void SaveProjectToDisk()
{ {
return project.projectFilename; //Speaks for itself really! std::string PFN = project.GetProjectFile();
} const char* filename = PFN.c_str();
ofstream ofs;
void setProjectname(std::string e) //Guess what? Sets the project's name! ofs.open(filename);
{ ofs << project.GetProjectName() << endl;
project.projectFilename = e; //Yep ofs << project.GetFM2Name() << endl;
ofs.close();
} }
static void GetDispInfo(NMLVDISPINFO* nmlvDispInfo) static void GetDispInfo(NMLVDISPINFO* nmlvDispInfo)
@ -559,29 +589,49 @@ static void NewProject()
//determine if current project changed //determine if current project changed
//if so, ask to save changes //if so, ask to save changes
//close current project //close current project
//create new project //Creation of a save window
const char TPfilter[]="TASEdit Project (*.tas)\0*.tas\0"; const char TPfilter[]="TASEdit Project (*.tas)\0*.tas\0"; //Filetype filter
OPENFILENAME ofn; OPENFILENAME ofn; //New instance of OPENFILENAME
memset(&ofn,0,sizeof(ofn)); memset(&ofn,0,sizeof(ofn)); //Set aside some memory
ofn.lStructSize=sizeof(ofn); ofn.lStructSize=sizeof(ofn); //Various parameters
ofn.hInstance=fceu_hInstance; ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Save TASEdit Project As..."; ofn.lpstrTitle="Save TASEdit Project As...";
ofn.lpstrFilter=TPfilter; ofn.lpstrFilter=TPfilter;
char nameo[2048]; char nameo[2048]; //File name
strcpy(nameo, GetRomName()); strcpy(nameo, GetRomName()); //For now, just use ROM name
ofn.lpstrFile=nameo; ofn.lpstrFile=nameo; //More parameters
ofn.nMaxFile=256; ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT; ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
string initdir = FCEU_GetPath(FCEUMKF_MOVIE); string initdir = FCEU_GetPath(FCEUMKF_MOVIE); //Initial directory
ofn.lpstrInitialDir=initdir.c_str(); ofn.lpstrInitialDir=initdir.c_str();
if(GetSaveFileName(&ofn)) if(GetSaveFileName(&ofn)) //If it is a valid filename
{ {
//TODO: Save project and reinitialise TASEdit std::string tempstr = nameo; //Make a temporary string for filename
char drv[512], dir[512], name[512], ext[512]; //For getting the filename!
if(tempstr.rfind(".tas") == std::string::npos) //If they haven't put ".tas" after it
{
tempstr.append(".tas"); //Stick it on ourselves
splitpath(tempstr.c_str(), drv, dir, name, ext); //Split the path...
std::string filename = name; //Get the filename
filename.append(ext); //Shove the extension back onto it...
project.SetProjectFile(filename); //And update the project's filename.
} else { //If they've been nice and done it for us...
splitpath(tempstr.c_str(), drv, dir, name, ext); //Split it up...
std::string filename = name; //Grab the name...
filename.append(ext); //Stick extension back on...
project.SetProjectFile(filename); //And update the project's filename.
}
project.SetProjectName(GetRomName()); //Set the project's name to the ROM name
std::string thisfm2name = project.GetProjectName();
thisfm2name.append(".fm2"); //Setup the fm2 name
project.SetFM2Name(thisfm2name); //Set the project's fm2 name
SaveProjectToDisk();
} }
//TODO: Reinitialise project
} }
//Opens a new Project file //Opens a new Project file