Rev 50 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#pragma once
#include <spk.h>
#define VERSION 1.30
#undef GetTempPath
namespace XspConvert {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(System::String ^open)
{
InitializeComponent();
this->UpdateTitle();
m_bLoading = false;
m_bDontChange = false;
m_bDontUpdate = false;
m_bChanged = false;
m_bReadText = false;
m_pLoadedShip = NULL;
m_pDirList = new CyStringList;
m_pTextList = new CLinkList<CyStringList>;
m_pLaserList = new CLinkList<CyStringList>;
m_pMissileList = new CLinkList<CyStringList>;
m_pCockpit = NULL;
this->PanelMain->Hide();
this->PanelNotLoaded->Show();
m_iOldGame = -1;
this->Setup();
if ( open )
m_sOpenFile = open;
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if ( m_pLoadedShip )
delete m_pLoadedShip;
if ( m_pDirList )
delete m_pDirList;
if ( m_pTextList )
delete m_pTextList;
if ( m_pLaserList )
delete m_pLaserList;
if ( m_pMissileList )
delete m_pMissileList;
if (components)
{
delete components;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1;
protected:
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ openToolStripMenuItem;
private: System::Windows::Forms::Panel^ panel1;
private: System::Windows::Forms::Button^ ButExit;
private: System::Windows::Forms::Panel^ PanelMain;
private:
bool m_bLoading;
bool m_bDontUpdate;
bool m_bChanged;
bool m_bReadText;
bool m_bDontChange;
CyStringList *m_pDirList;
CLinkList<CyStringList> *m_pTextList;
CLinkList<CyStringList> *m_pLaserList;
CLinkList<CyStringList> *m_pMissileList;
CXspFile *m_pLoadedShip;
int m_iOldGame;
array<System::Windows::Forms::ToolStripMenuItem^> ^m_aTools;
System::String ^m_sOpenFile;
SCockpit *m_pCockpit;
int m_iLoadedLaserMask;
int m_iLoadedMissileMask;
int m_iLaserMask;
int m_iMissileMask;
private: System::Windows::Forms::Panel^ PanelNotLoaded;
private: System::Windows::Forms::Label^ LabelNotLoaded;
private: System::Windows::Forms::ComboBox^ ComboGame;
private: System::Windows::Forms::Panel^ panel2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::ToolStripMenuItem^ saveToolStripMenuItem;
private: System::Windows::Forms::CheckedListBox^ WeaponList;
private: System::Windows::Forms::ToolStripMenuItem^ settingsToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ gamesToolStripMenuItem;
private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator1;
private: System::Windows::Forms::ToolStripMenuItem^ updateGameDataToolStripMenuItem;
private: System::Windows::Forms::TabControl^ tabControl1;
private: System::Windows::Forms::TabPage^ tabPage1;
private: System::Windows::Forms::TabPage^ tabPage2;
private: System::Windows::Forms::CheckedListBox^ MissileList;
private: System::Windows::Forms::ToolStripMenuItem^ loadGameTextToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ saveAsToolStripMenuItem;
private: System::Windows::Forms::TabPage^ tabPage3;
private: System::Windows::Forms::CheckedListBox^ CockpitWeapons;
private: System::Windows::Forms::ComboBox^ ComboCockpits;
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void Setup()
{
this->Closed += gcnew System::EventHandler(this, &Form1::CloseEvent);
this->CockpitWeapons->ItemCheck += gcnew ItemCheckEventHandler(this, &Form1::Event_Changed);
// read data file
System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
CFileIO Config;
if ( Config.Open(CyStringFromSystemString(mydoc) + "/Egosoft/xspconvert.dat") )
{
std::vector<CyString> *lines = Config.ReadLines();
if ( lines )
{
for ( int i = 0; i < (int)lines->size(); i++ )
{
CyString line(lines->at(i));
CyString start = line.GetToken(":", 1, 1).ToLower();
CyString rest = line.GetToken(":", 2).RemoveFirstSpace();
if ( start.Compare("Dir") )
{
CyString game = rest.GetToken(" ", 1, 1);
CyString dir = rest.GetToken(" ", 2);
SStringList *str = m_pDirList->FindData(game);
if ( str )
str->str = dir;
else
m_pDirList->PushBack(dir, game);
}
else if ( line.Compare("ReadText") )
m_bReadText = true;
}
}
}
this->UpdateGames();
this->loadGameTextToolStripMenuItem->Checked = m_bReadText;
}
void UpdateGames()
{
this->gamesToolStripMenuItem->DropDownItems->Clear();
this->ComboGame->Items->Clear();
CPackages p;
p.Startup(".", ".", ".");
// start at 1 to skip X2
for ( int i = 1; i < p.GetGameExe()->GetNumGames(); i++ )
{
bool added = false;
if ( m_pDirList->FindData(CyString::Number(i)) )
{
if ( m_pDirList->FindData(CyString::Number(i))->str != "-1" )
added = true;
}
SGameExe *exe = p.GetGameExe()->GetGame(i);
this->ComboGame->Items->Add(SystemStringFromCyString(exe->sName));
System::Windows::Forms::ToolStripMenuItem ^newMenu = gcnew System::Windows::Forms::ToolStripMenuItem;
newMenu->Text = SystemStringFromCyString(exe->sName);
this->gamesToolStripMenuItem->DropDownItems->Add(newMenu);
System::Windows::Forms::ToolStripMenuItem ^newMenuDir = gcnew System::Windows::Forms::ToolStripMenuItem;
if ( added )
newMenuDir->Text = SystemStringFromCyString(m_pDirList->FindData(CyString::Number(i))->str);
else
newMenuDir->Text = "No Directory";
newMenuDir->Enabled = false;
newMenu->DropDownItems->Add(newMenuDir);
newMenu->DropDownItems->Add(gcnew System::Windows::Forms::ToolStripSeparator);
System::Windows::Forms::ToolStripMenuItem ^newMenuChange = gcnew System::Windows::Forms::ToolStripMenuItem;
newMenuChange->Text = "Set Directory";
newMenuChange->Tag = SystemStringFromCyString(CyString::Number(i)) + " " + SystemStringFromCyString(exe->sName);
newMenuChange->Click += gcnew System::EventHandler(this, &Form1::Event_ChangeDirectory);
newMenu->DropDownItems->Add(newMenuChange);
if ( added )
{
System::Windows::Forms::ToolStripMenuItem ^newMenuRemove = gcnew System::Windows::Forms::ToolStripMenuItem;
newMenu->DropDownItems->Add(newMenuRemove);
newMenuRemove->Text = "Remove Directory";
newMenuRemove->Tag = SystemStringFromCyString(CyString::Number(i)) + " " + SystemStringFromCyString(exe->sName);
newMenuRemove->Click += gcnew System::EventHandler(this, &Form1::Event_RemoveDirectory);
}
}
}
void UpdateTitle()
{
System::String ^title = "XSP Convertor V" + SystemStringFromCyString(CyString::CreateFromFloat((float)VERSION, 2));
if ( m_pLoadedShip )
{
if ( m_bChanged || m_pLoadedShip->IsChanged() )
this->Text = title + " [*" + SystemStringFromCyString(m_pLoadedShip->GetFilename()) + "]";
else
this->Text = title + " [" + SystemStringFromCyString(m_pLoadedShip->GetFilename()) + "]";
}
else
this->Text = title;
}
void SaveShip()
{
if ( !m_pLoadedShip )
MessageBox::Show(this, "There is currently no ship loaded to convert", "Ship Save", MessageBoxButtons::OK, MessageBoxIcon::Warning);
else
{
this->SaveMasks();
if ( m_pLoadedShip->WriteFile(m_pLoadedShip->GetFilename()) )
{
MessageBox::Show(this, "Ship File: " + SystemStringFromCyString(m_pLoadedShip->GetFilename()) + "\n\nHas been written", "Ship Saved", MessageBoxButtons::OK, MessageBoxIcon::Information);
m_bChanged = false;
}
}
this->UpdateTitle();
}
void SaveShipAs()
{
if ( !m_pLoadedShip )
MessageBox::Show(this, "There is currently no ship loaded to convert", "Ship Save", MessageBoxButtons::OK, MessageBoxIcon::Warning);
else
{
SaveFileDialog ^ofd = gcnew SaveFileDialog();
ofd->Filter = "Ship Files (*.xsp)|*.xsp";
ofd->FilterIndex = 1;
ofd->RestoreDirectory = true;
if ( ofd->ShowDialog() == System::Windows::Forms::DialogResult::OK )
{
this->SaveMasks();
if ( m_pLoadedShip->WriteFile(CyStringFromSystemString(ofd->FileName)) )
{
MessageBox::Show(this, "Ship File: " + ofd->FileName + "\n\nHas been written", "Ship Saved", MessageBoxButtons::OK, MessageBoxIcon::Information);
m_bChanged = false;
}
}
}
this->UpdateTitle();
}
CyString GetObjectString(int desc, CyString idText)
{
if ( m_bReadText )
{
if ( this->ComboGame->SelectedIndex < m_pMissileList->size() )
{
CyStringList *textList = m_pTextList->Get(this->ComboGame->SelectedIndex);
if ( textList )
{
SStringList *str = textList->FindData(CyString::Number(desc));
if ( str )
{
// perform recursive lookup
CyString s = str->str;
while (s.IsIn("{17,") && s.IsIn("}"))
{
int pos = s.FindPos("{17,");
pos += 4;
CyString check = s.Right(-pos);
check = check.GetToken("}", 1, 1);
int num = check.ToInt();
CyString newDesc = this->GetObjectString(num, CyString("#") + check + "#");
s = s.FindReplace(CyString("{17,") + check + "}", newDesc);
}
// remove anything in brackets
while(s.IsIn("(") && s.IsIn(")"))
{
int pos = s.FindPos("(");
s.Erase(pos, (s.FindPos(")", pos) + 1) - pos);
}
return s;
}
}
}
}
return idText;
}
void UpdateNames()
{
this->WeaponList->Items->Clear();
this->MissileList->Items->Clear();
this->CockpitWeapons->Items->Clear();
bool addedLaser = false;
bool addedMissile = false;
CyStringList missiles;
if ( this->ComboGame->SelectedIndex < m_pMissileList->size() )
{
CyStringList *missileList = m_pMissileList->Get(this->ComboGame->SelectedIndex);
if ( missileList )
{
for ( SStringList *strNode = missileList->Head(); strNode; strNode = strNode->next )
{
CyString id = strNode->str.GetToken(";", 6, 6);
SStringList *found = missiles.FindString(id);
CyString str = this->GetObjectString(strNode->str.GetToken(";", 7, 7).ToInt(), strNode->str.GetToken(";", 37, 37));
if ( found )
{
found->data += ", ";
found->data += str;
}
else
missiles.PushBack(id, str);
}
}
}
CyStringList lasers;
if ( this->ComboGame->SelectedIndex < m_pLaserList->size() )
{
CyStringList *laserList = m_pLaserList->Get(this->ComboGame->SelectedIndex);
if ( laserList )
{
for ( SStringList *strNode = laserList->Head(); strNode; strNode = strNode->next )
{
CyString id = strNode->str.GetToken(";", 6, 6);
SStringList *found = lasers.FindString(id);
CyString str = this->GetObjectString(strNode->str.GetToken(";", 7, 7).ToInt(), strNode->str.GetToken(";", 23, 23));
if ( found )
{
found->data += ", ";
found->data += str;
}
else
lasers.PushBack(id, str);
}
}
}
for ( int i = 0; i < 32; i++ )
{
if ( lasers.Count() > i )
{
this->WeaponList->Items->Add(SystemStringFromCyString(lasers.GetAt(i)->data));
this->CockpitWeapons->Items->Add(SystemStringFromCyString(lasers.GetAt(i)->data));
addedLaser = true;
}
if ( missiles.Count() > i )
{
this->MissileList->Items->Add(SystemStringFromCyString(missiles.GetAt(i)->data));
addedMissile = true;
}
if ( !addedLaser )
{
this->WeaponList->Items->Add(SystemStringFromCyString(CyString::Number(i + 1)));
this->CockpitWeapons->Items->Add(SystemStringFromCyString(CyString::Number(i + 1)));
}
if ( !addedMissile )
this->MissileList->Items->Add(SystemStringFromCyString(CyString::Number(i + 1)));
}
}
void OpenFile(System::String ^open)
{
CXspFile *shipFile = new CXspFile;
int check = CSpkFile::CheckFile(CyStringFromSystemString(open));
bool loaded = false;
m_bChanged = false;
if ( check == SPKFILE_SINGLESHIP )
loaded = shipFile->ReadFile(CyStringFromSystemString(open));
else if ( check == SPKFILE_INVALID )
{
loaded = shipFile->ConvertOld(CyStringFromSystemString(open));
if ( loaded )
m_bChanged = true;
}
this->ComboCockpits->Items->Clear();
m_pCockpit = NULL;
if ( loaded )
{
m_bLoading = true;
if ( m_pLoadedShip )
delete m_pLoadedShip;
m_pLoadedShip = shipFile;
m_pLoadedShip->SetFilename(CyStringFromSystemString(open));
this->PanelMain->Show();
this->PanelNotLoaded->Hide();
m_iOldGame = -1;
if ( m_pLoadedShip->AnyCockpits() )
{
for ( SCockpit *c = m_pLoadedShip->GetCockpits()->First(); c; c = m_pLoadedShip->GetCockpits()->Next() )
this->ComboCockpits->Items->Add(SystemStringFromCyString(c->sCockpit.GetToken(";", 19, 19)));
this->CockpitWeapons->Show();
this->ComboCockpits->Enabled = true;
//m_pCockpit = m_pLoadedShip->GetCockpits()->First();
}
else
{
this->CockpitWeapons->Hide();
this->ComboCockpits->Enabled = false;
}
this->ComboGame->SelectedIndex = 0;
if ( this->ComboCockpits->Items->Count )
this->ComboCockpits->SelectedIndex = 0;
m_bChanged = false;
this->UpdateTitle();
MessageBox::Show(this, "Ship File: " + open + "\nHas been loaded", "Ship Loaded", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
else
{
delete shipFile;
if ( m_pLoadedShip )
{
this->PanelMain->Hide();
this->PanelNotLoaded->Show();
}
else
{
this->PanelMain->Show();
this->PanelNotLoaded->Hide();
}
MessageBox::Show(this, "Ship File: " + open + "\nHas failed to load", "Ship Failed", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
m_bLoading = false;
}
void CheckSave()
{
if ( (m_pLoadedShip && m_pLoadedShip->IsChanged()) || m_bChanged )
{
if ( MessageBox::Show(this, "The current ship has been modified, do you wish to save it?", "Save Ship", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
this->SaveShip();
}
}
void OpenFile()
{
// check if we need to save
this->CheckSave();
OpenFileDialog ^ofd = gcnew OpenFileDialog();
ofd->Filter = "Ship Files (*.xsp)|*.xsp";
ofd->FilterIndex = 1;
ofd->RestoreDirectory = true;
if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
this->OpenFile(ofd->FileName);
this->UpdateTitle();
}
void LoadGameData()
{
m_pLaserList->MemoryClear();
m_pMissileList->MemoryClear();
m_pTextList->MemoryClear();
System::String ^tempDir = System::IO::Path::GetTempPath();
CyString sTempDir = CyStringFromSystemString(tempDir);
CPackages p;
bool tcText = false;
for ( SStringList *strNode = m_pDirList->Head(); strNode; strNode = strNode->next )
{
CyStringList *laserList = new CyStringList;
m_pLaserList->push_back(laserList);
CyStringList *missileList = new CyStringList;
m_pMissileList->push_back(missileList);
CyStringList *textList = new CyStringList;
m_pTextList->push_back(textList);
if ( p.ExtractGameFile("types/TLaser.pck", sTempDir + "/TLaser.txt", strNode->str) )
{
CFileIO Open(sTempDir + "/TLaser.txt");
std::vector<CyString> *lines = Open.ReadLines();
if ( lines )
{
bool first = false;
for ( int j = 0; j < (int)lines->size(); j++ )
{
CyString line(lines->at(j));
if ( line[0] == '/' )
continue;
line.RemoveChar('\r');
line = line.RemoveFirstSpace();
line = line.RemoveEndSpace();
if ( line.Empty() )
continue;
if ( !first )
{
first = true;
continue;
}
laserList->PushBack(line);
}
}
Open.Remove();
}
if ( p.ExtractGameFile("types/TMissiles.pck", sTempDir + "/TMissiles.txt", strNode->str) )
{
CFileIO Open(sTempDir + "/TMissiles.txt");
std::vector<CyString> *lines = Open.ReadLines();
if ( lines )
{
bool first = false;
for ( int j = 0; j < (int)lines->size(); j++ )
{
CyString line(lines->at(j));
if ( line[0] == '/' )
continue;
line.RemoveChar('\r');
line = line.RemoveFirstSpace();
line = line.RemoveEndSpace();
if ( line.Empty() )
continue;
if ( !first )
{
first = true;
continue;
}
missileList->PushBack(line);
}
}
Open.Remove();
}
if ( !m_bReadText )
continue;
// load the text file
CyString textFormat;
if ( tcText )
textFormat = "0001-L044";
else
textFormat = "440001";
if ( p.ExtractGameFile(CyString("t/") + textFormat + ".pck", sTempDir + "/" + textFormat + ".xml", strNode->str) )
{
CFileIO Open(sTempDir + textFormat + ".xml");
if ( Open.StartReadOld() )
{
int donePage = (tcText) ? 3 : 2;
int inPage = 0;
while ( !Open.AtEnd() )
{
CyString line = Open.ReadToEndLine(false);
if ( line.Empty() )
continue;
line = line.RemoveFirstSpace();
line = line.Remove('\t');
if ( !inPage )
{
if ( line.Left(5).Compare("<page") )
{
int pos = line.FindPos(" id=\"");
if ( pos != -1 )
{
int endpos = line.FindPos("\"", pos + 5);
if ( endpos != -1 )
{
CyString check = line.Mid(pos + 6, endpos - pos - 5);
int iPage = check.ToInt();
if ( iPage == 17 || iPage == 300017 || iPage == 350017 )
inPage = iPage;
}
}
}
}
else
{
if ( line.Left(6).Compare("</page") )
{
inPage = 0;
--donePage;
if ( donePage <= 0 )
break;
}
else
{
int pos = line.FindPos("t id=\"");
if ( pos != -1 )
{
int endpos = line.FindPos("\"", pos + 6);
if ( endpos != -1 )
{
CyString check = line.Mid(pos + 7, endpos - pos - 6);
CyString data;
int pos = line.FindPos(">", endpos);
if ( pos != -1 )
{
endpos = line.FindPos("</", pos);
if ( endpos != -1 )
data = line.Mid(pos + 2, endpos - pos - 1);
}
SStringList *str = textList->FindData(check);
if ( str )
str->str = data;
else
textList->PushBack(data, check);
}
}
}
}
}
Open.StopRead();
}
}
tcText = true;
}
}
void LoadGameDirectory()
{
CPackages p;
p.Startup(".", ".", ".");
for ( int i = 1; i < p.GetGameExe()->GetNumGames(); i++ )
{
SGameExe *exe = p.GetGameExe()->GetGame(i);
if ( !m_pDirList->FindData(CyString::Number(i)) )
{
if ( MessageBox::Show(this, "You have no directories set for " + SystemStringFromCyString(exe->sName) + "\n\nWould you like to set it now?", "Game Directory", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
{
FolderBrowserDialog ^fbd = gcnew FolderBrowserDialog;
fbd->Description = "Select the path for " + SystemStringFromCyString(exe->sName);
if ( fbd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
{
CDirIO Dir(CyStringFromSystemString(fbd->SelectedPath));
if ( !Dir.Exists(exe->sExe) )
MessageBox::Show(this, "Unable to find " + SystemStringFromCyString(exe->sExe) + " in " + fbd->SelectedPath, "Game Directory", MessageBoxButtons::OK, MessageBoxIcon::Warning);
else
m_pDirList->PushBack(CyStringFromSystemString(fbd->SelectedPath), CyString::Number(i));
}
}
else
m_pDirList->PushBack("-1", CyString::Number(i));
}
}
if ( !m_pDirList->Empty() )
{
if ( MessageBox::Show(this, "Would you like to load the game data?", "Load Game Data", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
this->LoadGameData();
}
this->UpdateGames();
}
void CloseDialog()
{
System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
CFileIO Config(CyStringFromSystemString(mydoc) + "/Egosoft/xspconvert.dat");
std::vector<CyString> lines;
for ( SStringList *str = m_pDirList->Head(); str; str = str->next )
lines.push_back(CyString("Dir:") + str->data + " " + str->str);
if ( m_bReadText )
lines.push_back("ReadText");
Config.WriteFile(&lines);
}
void CheckListChanged()
{
if ( m_bDontUpdate )
return;
if ( m_bDontChange )
return;
if ( m_pLoadedShip )
m_bChanged = true;
this->UpdateTitle();
}
int GetMask(CheckedListBox ^list)
{
int oldMask = 0;
// First show the index and check state of all selected items.
IEnumerator^ myEnum1 = list->CheckedIndices->GetEnumerator();
while ( myEnum1->MoveNext() )
{
int indexChecked = *safe_cast<int^>(myEnum1->Current);
oldMask |= (1 << indexChecked);
}
return oldMask;
}
void SaveMasks()
{
if ( m_pLoadedShip )
{
if ( m_iOldGame != -1 )
{
m_pLoadedShip->SetLaserMask(m_iOldGame, m_iLaserMask);
m_pLoadedShip->SetMissileMask(m_iOldGame, m_iMissileMask);
}
if ( m_pCockpit )
m_pLoadedShip->AddCockpit(m_pCockpit->sCockpit, (m_iOldGame == -1) ? (this->ComboGame->SelectedIndex + 2) : m_iOldGame, this->GetMask(this->CockpitWeapons));
}
}
void ChangeGame()
{
if ( !m_pLoadedShip )
return;
bool oldChanged = m_pLoadedShip->IsChanged();
m_bDontUpdate = true;
// save old mask
if ( !m_bLoading )
this->SaveMasks();
m_iOldGame = this->ComboGame->SelectedIndex + 2;
this->UpdateNames();
int mask = m_pLoadedShip->GetLaserMask(this->ComboGame->SelectedIndex + 2, true);
for ( int i = 0; i < this->WeaponList->Items->Count; i++ )
this->WeaponList->SetItemChecked(i, (mask & (1 << i)) ? true : false);
m_iLaserMask = m_iLoadedLaserMask = mask;
mask = m_pLoadedShip->GetMissileMask(this->ComboGame->SelectedIndex + 2, true);
for ( int i = 0; i < this->MissileList->Items->Count; i++ )
this->MissileList->SetItemChecked(i, (mask & (1 << i)) ? true : false);
m_iMissileMask = m_iLoadedMissileMask = mask;
if ( this->ComboCockpits->Items->Count )
{
if ( this->ComboCockpits->SelectedIndex < 0 )
this->ComboCockpits->SelectedIndex = 0;
else
this->UpdateCockpitList();
}
m_pLoadedShip->SetChanged(oldChanged);
m_bDontUpdate = false;
this->UpdateTitle();
}
void Event_RemoveDirectory(System::Object ^sender, System::EventArgs ^E)
{
System::Windows::Forms::ToolStripMenuItem ^item = cli::safe_cast<System::Windows::Forms::ToolStripMenuItem ^>(sender);
if ( item )
{
CyString game = CyStringFromSystemString(cli::safe_cast<System::String ^>(item->Tag));
game = game.GetToken(" ", 1, 1);
if ( m_pDirList->FindData(game) )
{
m_pDirList->FindData(game)->str = "-1";
this->UpdateGames();
}
}
}
void Event_ChangeDirectory(System::Object ^sender, System::EventArgs ^E)
{
System::Windows::Forms::ToolStripMenuItem ^item = cli::safe_cast<System::Windows::Forms::ToolStripMenuItem ^>(sender);
if ( item )
{
CyString tag = CyStringFromSystemString(cli::safe_cast<System::String ^>(item->Tag));
CyString game = tag.GetToken(" ", 1, 1);
if ( m_pDirList->FindData(game) )
{
FolderBrowserDialog ^fbd = gcnew FolderBrowserDialog;
fbd->Description = "Select the path for " + SystemStringFromCyString(tag.GetToken(" ", 2));
if ( fbd->ShowDialog() == System::Windows::Forms::DialogResult::OK )
{
m_pDirList->FindData(game)->str = CyStringFromSystemString(fbd->SelectedPath);
this->UpdateGames();
}
}
}
}
void UpdateCockpitList()
{
if ( !m_pLoadedShip )
return;
m_bDontChange = true;
if ( !m_bDontUpdate && m_pCockpit )
m_pLoadedShip->AddCockpit(m_pCockpit->sCockpit, (m_iOldGame == -1) ? (this->ComboGame->SelectedIndex + 2) : m_iOldGame, this->GetMask(this->CockpitWeapons));
m_pCockpit = NULL;
// find the cockpit pointer
m_pCockpit = m_pLoadedShip->GetCockpits()->Get(this->ComboCockpits->SelectedIndex);
int mask = 0;
if ( m_pCockpit )
{
mask = m_pCockpit->sCockpit.GetToken(";", 9, 9).ToInt();
for ( SWeaponMask *wm = m_pCockpit->lWeaponMask.First(); wm; wm = m_pCockpit->lWeaponMask.Next() )
{
if ( wm->iGame == (this->ComboGame->SelectedIndex + 2) )
{
mask = wm->iMask;
break;
}
}
}
for ( int i = 0; i < this->CockpitWeapons->Items->Count; i++ )
this->CockpitWeapons->SetItemChecked(i, (mask & (1 << i)) ? true : false);
m_bDontChange = false;
}
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->openToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->saveToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->saveAsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->settingsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->gamesToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->loadGameTextToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->updateGameDataToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->panel1 = (gcnew System::Windows::Forms::Panel());
this->ButExit = (gcnew System::Windows::Forms::Button());
this->PanelMain = (gcnew System::Windows::Forms::Panel());
this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
this->WeaponList = (gcnew System::Windows::Forms::CheckedListBox());
this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
this->MissileList = (gcnew System::Windows::Forms::CheckedListBox());
this->tabPage3 = (gcnew System::Windows::Forms::TabPage());
this->CockpitWeapons = (gcnew System::Windows::Forms::CheckedListBox());
this->ComboCockpits = (gcnew System::Windows::Forms::ComboBox());
this->panel2 = (gcnew System::Windows::Forms::Panel());
this->ComboGame = (gcnew System::Windows::Forms::ComboBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->PanelNotLoaded = (gcnew System::Windows::Forms::Panel());
this->LabelNotLoaded = (gcnew System::Windows::Forms::Label());
this->menuStrip1->SuspendLayout();
this->panel1->SuspendLayout();
this->PanelMain->SuspendLayout();
this->tabControl1->SuspendLayout();
this->tabPage1->SuspendLayout();
this->tabPage2->SuspendLayout();
this->tabPage3->SuspendLayout();
this->panel2->SuspendLayout();
this->PanelNotLoaded->SuspendLayout();
this->SuspendLayout();
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->fileToolStripMenuItem,
this->settingsToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(416, 24);
this->menuStrip1->TabIndex = 0;
this->menuStrip1->Text = L"menuStrip1";
//
// fileToolStripMenuItem
//
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {this->openToolStripMenuItem,
this->saveToolStripMenuItem, this->saveAsToolStripMenuItem});
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20);
this->fileToolStripMenuItem->Text = L"&File";
//
// openToolStripMenuItem
//
this->openToolStripMenuItem->Name = L"openToolStripMenuItem";
this->openToolStripMenuItem->Size = System::Drawing::Size(114, 22);
this->openToolStripMenuItem->Text = L"&Open";
this->openToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::openToolStripMenuItem_Click);
//
// saveToolStripMenuItem
//
this->saveToolStripMenuItem->Name = L"saveToolStripMenuItem";
this->saveToolStripMenuItem->Size = System::Drawing::Size(114, 22);
this->saveToolStripMenuItem->Text = L"&Save";
this->saveToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::saveToolStripMenuItem_Click);
//
// saveAsToolStripMenuItem
//
this->saveAsToolStripMenuItem->Name = L"saveAsToolStripMenuItem";
this->saveAsToolStripMenuItem->Size = System::Drawing::Size(114, 22);
this->saveAsToolStripMenuItem->Text = L"Save &As";
this->saveAsToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::saveAsToolStripMenuItem_Click);
//
// settingsToolStripMenuItem
//
this->settingsToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {this->gamesToolStripMenuItem,
this->loadGameTextToolStripMenuItem, this->toolStripSeparator1, this->updateGameDataToolStripMenuItem});
this->settingsToolStripMenuItem->Name = L"settingsToolStripMenuItem";
this->settingsToolStripMenuItem->Size = System::Drawing::Size(61, 20);
this->settingsToolStripMenuItem->Text = L"Settings";
//
// gamesToolStripMenuItem
//
this->gamesToolStripMenuItem->Name = L"gamesToolStripMenuItem";
this->gamesToolStripMenuItem->Size = System::Drawing::Size(173, 22);
this->gamesToolStripMenuItem->Text = L"Games";
//
// loadGameTextToolStripMenuItem
//
this->loadGameTextToolStripMenuItem->Name = L"loadGameTextToolStripMenuItem";
this->loadGameTextToolStripMenuItem->Size = System::Drawing::Size(173, 22);
this->loadGameTextToolStripMenuItem->Text = L"Load Game Text";
this->loadGameTextToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::loadGameTextToolStripMenuItem_Click);
//
// toolStripSeparator1
//
this->toolStripSeparator1->Name = L"toolStripSeparator1";
this->toolStripSeparator1->Size = System::Drawing::Size(170, 6);
//
// updateGameDataToolStripMenuItem
//
this->updateGameDataToolStripMenuItem->Name = L"updateGameDataToolStripMenuItem";
this->updateGameDataToolStripMenuItem->Size = System::Drawing::Size(173, 22);
this->updateGameDataToolStripMenuItem->Text = L"Update Game Data";
this->updateGameDataToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::updateGameDataToolStripMenuItem_Click);
//
// panel1
//
this->panel1->Controls->Add(this->ButExit);
this->panel1->Dock = System::Windows::Forms::DockStyle::Bottom;
this->panel1->Location = System::Drawing::Point(0, 376);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(416, 33);
this->panel1->TabIndex = 1;
//
// ButExit
//
this->ButExit->DialogResult = System::Windows::Forms::DialogResult::Cancel;
this->ButExit->Dock = System::Windows::Forms::DockStyle::Right;
this->ButExit->Location = System::Drawing::Point(303, 0);
this->ButExit->Name = L"ButExit";
this->ButExit->Size = System::Drawing::Size(113, 33);
this->ButExit->TabIndex = 0;
this->ButExit->Text = L"Exit";
this->ButExit->UseVisualStyleBackColor = true;
this->ButExit->Click += gcnew System::EventHandler(this, &Form1::ButExit_Click);
//
// PanelMain
//
this->PanelMain->Controls->Add(this->tabControl1);
this->PanelMain->Controls->Add(this->panel2);
this->PanelMain->Dock = System::Windows::Forms::DockStyle::Fill;
this->PanelMain->Location = System::Drawing::Point(0, 24);
this->PanelMain->Name = L"PanelMain";
this->PanelMain->Size = System::Drawing::Size(416, 352);
this->PanelMain->TabIndex = 2;
//
// tabControl1
//
this->tabControl1->Controls->Add(this->tabPage1);
this->tabControl1->Controls->Add(this->tabPage2);
this->tabControl1->Controls->Add(this->tabPage3);
this->tabControl1->Dock = System::Windows::Forms::DockStyle::Fill;
this->tabControl1->Location = System::Drawing::Point(0, 22);
this->tabControl1->Name = L"tabControl1";
this->tabControl1->SelectedIndex = 0;
this->tabControl1->Size = System::Drawing::Size(416, 330);
this->tabControl1->TabIndex = 2;
//
// tabPage1
//
this->tabPage1->Controls->Add(this->WeaponList);
this->tabPage1->Location = System::Drawing::Point(4, 22);
this->tabPage1->Name = L"tabPage1";
this->tabPage1->Padding = System::Windows::Forms::Padding(3);
this->tabPage1->Size = System::Drawing::Size(408, 304);
this->tabPage1->TabIndex = 0;
this->tabPage1->Text = L"Lasers";
this->tabPage1->UseVisualStyleBackColor = true;
//
// WeaponList
//
this->WeaponList->CheckOnClick = true;
this->WeaponList->Dock = System::Windows::Forms::DockStyle::Fill;
this->WeaponList->FormattingEnabled = true;
this->WeaponList->HorizontalScrollbar = true;
this->WeaponList->Location = System::Drawing::Point(3, 3);
this->WeaponList->Name = L"WeaponList";
this->WeaponList->Size = System::Drawing::Size(402, 289);
this->WeaponList->TabIndex = 3;
this->WeaponList->ItemCheck += gcnew System::Windows::Forms::ItemCheckEventHandler(this, &Form1::WeaponListEvent_Changed);
//
// tabPage2
//
this->tabPage2->Controls->Add(this->MissileList);
this->tabPage2->Location = System::Drawing::Point(4, 22);
this->tabPage2->Name = L"tabPage2";
this->tabPage2->Padding = System::Windows::Forms::Padding(3);
this->tabPage2->Size = System::Drawing::Size(408, 304);
this->tabPage2->TabIndex = 1;
this->tabPage2->Text = L"Missiles";
this->tabPage2->UseVisualStyleBackColor = true;
//
// MissileList
//
this->MissileList->Dock = System::Windows::Forms::DockStyle::Fill;
this->MissileList->FormattingEnabled = true;
this->MissileList->HorizontalScrollbar = true;
this->MissileList->Location = System::Drawing::Point(3, 3);
this->MissileList->Name = L"MissileList";
this->MissileList->Size = System::Drawing::Size(402, 289);
this->MissileList->TabIndex = 4;
this->MissileList->ItemCheck += gcnew System::Windows::Forms::ItemCheckEventHandler(this, &Form1::MissileListEvent_Changed);
//
// tabPage3
//
this->tabPage3->Controls->Add(this->CockpitWeapons);
this->tabPage3->Controls->Add(this->ComboCockpits);
this->tabPage3->Location = System::Drawing::Point(4, 22);
this->tabPage3->Name = L"tabPage3";
this->tabPage3->Padding = System::Windows::Forms::Padding(3);
this->tabPage3->Size = System::Drawing::Size(408, 304);
this->tabPage3->TabIndex = 2;
this->tabPage3->Text = L"Cockpits";
this->tabPage3->UseVisualStyleBackColor = true;
//
// CockpitWeapons
//
this->CockpitWeapons->CheckOnClick = true;
this->CockpitWeapons->Dock = System::Windows::Forms::DockStyle::Fill;
this->CockpitWeapons->FormattingEnabled = true;
this->CockpitWeapons->HorizontalScrollbar = true;
this->CockpitWeapons->Location = System::Drawing::Point(3, 24);
this->CockpitWeapons->Name = L"CockpitWeapons";
this->CockpitWeapons->Size = System::Drawing::Size(402, 274);
this->CockpitWeapons->TabIndex = 4;
//
// ComboCockpits
//
this->ComboCockpits->Dock = System::Windows::Forms::DockStyle::Top;
this->ComboCockpits->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
this->ComboCockpits->FormattingEnabled = true;
this->ComboCockpits->Location = System::Drawing::Point(3, 3);
this->ComboCockpits->Name = L"ComboCockpits";
this->ComboCockpits->Size = System::Drawing::Size(402, 21);
this->ComboCockpits->TabIndex = 5;
this->ComboCockpits->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::ComboCockpits_SelectedIndexChanged);
//
// panel2
//
this->panel2->Controls->Add(this->ComboGame);
this->panel2->Controls->Add(this->label1);
this->panel2->Dock = System::Windows::Forms::DockStyle::Top;
this->panel2->Location = System::Drawing::Point(0, 0);
this->panel2->Name = L"panel2";
this->panel2->Size = System::Drawing::Size(416, 22);
this->panel2->TabIndex = 2;
//
// ComboGame
//
this->ComboGame->Dock = System::Windows::Forms::DockStyle::Fill;
this->ComboGame->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
this->ComboGame->FormattingEnabled = true;
this->ComboGame->Location = System::Drawing::Point(188, 0);
this->ComboGame->Name = L"ComboGame";
this->ComboGame->Size = System::Drawing::Size(228, 21);
this->ComboGame->TabIndex = 0;
this->ComboGame->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::ComboGame_SelectedIndexChanged);
//
// label1
//
this->label1->Dock = System::Windows::Forms::DockStyle::Left;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(0, 0);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(188, 22);
this->label1->TabIndex = 1;
this->label1->Text = L"X-Universe Game:";
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
//
// PanelNotLoaded
//
this->PanelNotLoaded->Controls->Add(this->LabelNotLoaded);
this->PanelNotLoaded->Dock = System::Windows::Forms::DockStyle::Fill;
this->PanelNotLoaded->Location = System::Drawing::Point(0, 24);
this->PanelNotLoaded->Name = L"PanelNotLoaded";
this->PanelNotLoaded->Size = System::Drawing::Size(416, 352);
this->PanelNotLoaded->TabIndex = 3;
//
// LabelNotLoaded
//
this->LabelNotLoaded->Dock = System::Windows::Forms::DockStyle::Fill;
this->LabelNotLoaded->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->LabelNotLoaded->Location = System::Drawing::Point(0, 0);
this->LabelNotLoaded->Name = L"LabelNotLoaded";
this->LabelNotLoaded->Size = System::Drawing::Size(416, 352);
this->LabelNotLoaded->TabIndex = 0;
this->LabelNotLoaded->Text = L"No ship file is currently loaded";
this->LabelNotLoaded->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->CancelButton = this->ButExit;
this->ClientSize = System::Drawing::Size(416, 409);
this->Controls->Add(this->PanelMain);
this->Controls->Add(this->PanelNotLoaded);
this->Controls->Add(this->panel1);
this->Controls->Add(this->menuStrip1);
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
this->MainMenuStrip = this->menuStrip1;
this->Name = L"Form1";
this->Text = L"XSP Ship Convertor";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->panel1->ResumeLayout(false);
this->PanelMain->ResumeLayout(false);
this->tabControl1->ResumeLayout(false);
this->tabPage1->ResumeLayout(false);
this->tabPage2->ResumeLayout(false);
this->tabPage3->ResumeLayout(false);
this->panel2->ResumeLayout(false);
this->PanelNotLoaded->ResumeLayout(false);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
this->OpenFile();
}
private: System::Void ButExit_Click(System::Object^ sender, System::EventArgs^ e) {
this->Close();
}
private: System::Void saveToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
this->SaveShip();
}
private: System::Void ComboGame_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
this->ChangeGame();
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
this->LoadGameDirectory();
if ( m_sOpenFile )
this->OpenFile(m_sOpenFile);
}
private: void CloseEvent(System::Object ^Sender, System::EventArgs ^E) {
this->CheckSave();
this->CloseDialog();
}
private: System::Void updateGameDataToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
this->LoadGameData();
}
private: System::Void loadGameTextToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
m_bReadText = !m_bReadText;
this->loadGameTextToolStripMenuItem->Checked = m_bReadText;
}
private: System::Void WeaponListEvent_Changed(System::Object^ sender, ItemCheckEventArgs^ e) {
if ( !m_bLoading )
{
int index = (1 << e->Index);
if ( e->NewValue == CheckState::Checked )
m_iLaserMask |= index;
else if ( e->NewValue == CheckState::Unchecked )
m_iLaserMask &= ~(index);
this->CheckListChanged();
}
}
private: System::Void MissileListEvent_Changed(System::Object^ sender, ItemCheckEventArgs^ e) {
if ( !m_bLoading )
{
int index = (1 << e->Index);
if ( e->NewValue == CheckState::Checked )
m_iMissileMask |= index;
else if ( e->NewValue == CheckState::Unchecked )
m_iMissileMask &= ~(index);
this->CheckListChanged();
}
}
private: System::Void Event_Changed(System::Object^ sender, ItemCheckEventArgs^ e) {
if ( !m_bLoading )
{
this->CheckListChanged();
}
}
private: System::Void saveAsToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
this->SaveShipAs();
}
private: System::Void ComboCockpits_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
this->UpdateCockpitList();
}
};
}