projectbrowser.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. #ifndef _XBOX
  2. #include "projectbrowser.h"
  3. #include "mainwindow.h"
  4. #include "systemselect.h"
  5. #include "..\CustomControls\StrUtil.h"
  6. #include "..\EditorMain.h"
  7. #include "..\..\manager\particlemanager.h"
  8. #include "..\..\..\Common_h\FileService.h"
  9. #define PACK_PATH "Resource\\Missions\\"
  10. extern string PakName;
  11. extern ParticleEditor* pEditor;
  12. bool AlphabetSortFuncCompare (const string &a1, const string &a2)
  13. {
  14. if (a1 > a2) return false;
  15. return true;
  16. }
  17. TProjectBrowser::TProjectBrowser () : GUIWindow (NULL, 0, 0, 550, 600)
  18. {
  19. //Надо отрелизить все паки !!!! при старте!!!!
  20. //==========================
  21. UserSelectSystemToOpen = false;
  22. bSystemButton = false;
  23. pFS = (IFileService*)api->GetService("FileService");
  24. pFont->SetName("arialcyrsmall");
  25. Caption = "Projects Editor v1.10";
  26. SetScreenCenter();
  27. pProjectList = NEW GUIListBox(this, 10, 10, 220, 550);
  28. pProjectList->MakeFlat(true);
  29. pProjectList->OnChange = (CONTROL_EVENT)&TProjectBrowser::OnSelectProject;
  30. pAvailableSystemsList = NEW GUIListBox(this, 245, 70, 290, 490);
  31. pAvailableSystemsList->MakeFlat(true);
  32. pAvailableSystemsList->OnMouseDBLClick = (CONTROL_EVENT)&TProjectBrowser::OnSystemDblClick;
  33. pTextureNameField = NEW GUIEdit(this, 245, 10, 180, 22);
  34. pTextureNameField->Flat = true;
  35. pTextureNameField->Hint = "Project texture name";
  36. pPackName = NEW GUIComboBox(this, 245, 40, 180, 22);
  37. pPackName->MakeFlat(true);
  38. pPackName->Edit->Hint = "Pack file name";
  39. pPackName->ListBox->Items.Add("mission17");
  40. pPackName->ListBox->Items.Add("mis18");
  41. pPackName->ListBox->Items.Add("mis19");
  42. pPackName->bUserCanTypeText = true;
  43. pPackName->Edit->OnAccept = (CONTROL_EVENT)&TProjectBrowser::OnCreateNewPackInList;
  44. pPackName->OnSelect = (CONTROL_EVENT)&TProjectBrowser::OnPackIsChange;
  45. pOpenTexture = NEW GUIButton (this, 427, 10, 22, 22);
  46. pOpenTexture->FlatButton = true;
  47. pOpenTexture->Glyph->Load("peditor\\open");
  48. pOpenTexture->Hint = "Select texture";
  49. pOpenTexture->OnMouseClick = (CONTROL_EVENT)&TProjectBrowser::OnSelectTexture;
  50. pNewSystem = NEW GUIButton (this, 457-26, 40, 22, 22);
  51. pNewSystem->FlatButton = true;
  52. pNewSystem->Hint = "Create new system in project";
  53. pNewSystem->Glyph->Load("peditor\\create");
  54. pAddSystem = NEW GUIButton (this, 457+26*0, 40, 22, 22);
  55. pAddSystem->FlatButton = true;
  56. pAddSystem->Hint = "Add system to project";
  57. pAddSystem->Glyph->Load("peditor\\addsystem");
  58. pAddSystem->OnMouseClick = (CONTROL_EVENT)&TProjectBrowser::OnAddSystem;
  59. pRemoveSystem = NEW GUIButton (this, 457+26*1, 40, 22, 22);
  60. pRemoveSystem->FlatButton = true;
  61. pRemoveSystem->Hint = "Remove system from project";
  62. pRemoveSystem->Glyph->Load("peditor\\delsystem");
  63. pRemoveSystem->OnMouseClick = (CONTROL_EVENT)&TProjectBrowser::OnRemoveSystem;
  64. pCloseBrowser = NEW GUIButton (this, 457+26*2, 40, 22, 22);
  65. pCloseBrowser->FlatButton = true;
  66. pCloseBrowser->Hint = "Close browser";
  67. pCloseBrowser->Glyph->Load("peditor\\exit");
  68. pCloseBrowser->OnMouseClick = (CONTROL_EVENT)&TProjectBrowser::ExitFromBrowser;
  69. /*
  70. pUpdateGeomCache = NEW GUIButton (this, 457+26*2, 40, 22, 22);
  71. pUpdateGeomCache->FlatButton = true;
  72. pUpdateGeomCache->Hint = "Refresh geometry cache info";
  73. pUpdateGeomCache->Glyph->Load("peditor\\refresh");
  74. pUpdateGeomCache->OnMouseClick = (CONTROL_EVENT)UpdateGeomCacheInfo;
  75. */
  76. BuildProjectList ();
  77. }
  78. TProjectBrowser::~TProjectBrowser ()
  79. {
  80. // pFS->ReleasePak(PakName);
  81. }
  82. void TProjectBrowser::Draw ()
  83. {
  84. GUIWindow::Draw();
  85. }
  86. void TProjectBrowser::BuildProjectList ()
  87. {
  88. pProjectList->Items.Clear();
  89. IFinder* finder = pFS->CreateFinder(PARTICLES_PLACE, "*.prj", find_all_files_no_mirrors | find_no_files_from_packs, _FL_);
  90. for (dword i = 0; i < finder->Count(); i++)
  91. {
  92. string filename = string(finder->FilePath(i)).GetRelativePath (PARTICLES_PLACE);
  93. string name;
  94. name.GetFileName(filename);
  95. if (finder->IsMirror(i))
  96. name = string ("#c0000FF") + name;
  97. else
  98. name = string ("#c000000") + name;
  99. pProjectList->Items.Add(name);
  100. }
  101. finder->Release();
  102. string cProjectName = "FIXME!";//pEditor->Manager()->GetProjectFileName();
  103. string ShortProjectName;
  104. ShortProjectName.GetFileName(cProjectName);
  105. for (int n = 0; n < pProjectList->Items.Size(); n++)
  106. {
  107. const char* pItemName = pProjectList->Items[n].GetBuffer() + 8;
  108. if (crt_stricmp (pItemName, ShortProjectName) == 0)
  109. {
  110. pProjectList->SelectedLine = n;
  111. //pProjectList->SelectedLine
  112. break;
  113. }
  114. }
  115. //pProjectList->SelectedLine
  116. OnSelectProject (NULL);
  117. }
  118. void _cdecl TProjectBrowser::OnSelectProject (GUIControl* sender)
  119. {
  120. pAvailableSystemsList->Items.Clear();
  121. if (pProjectList->SelectedLine < 0) return;
  122. string ProjectName = pProjectList->Items[pProjectList->SelectedLine];
  123. string LongFileName = "resource\\particles\\";
  124. LongFileName += (const char*)(ProjectName.GetBuffer()+8);
  125. LongFileName.AddExtention(".prj");
  126. CurrentProjectName = LongFileName;
  127. CurrentProjectNameShort = (ProjectName.GetBuffer()+8);
  128. IFileService* pFS = (IFileService*)api->GetService("FileService");
  129. IIniFile* IniFile = pFS->OpenIniFile(LongFileName.GetBuffer(), _FL_);
  130. Assert (IniFile);
  131. pTextureNameField->Text = IniFile->GetString("Textures", "MainTexture", "none");
  132. //Загружаем данные
  133. for (int n = 0; n < 9999; n++)
  134. {
  135. string Section;
  136. Section.Format("System_%04d", n);
  137. const char* pSysName = IniFile->GetString("Manager", Section.GetBuffer(), NULL);
  138. if (!pSysName) break;
  139. string SystemName = pSysName;
  140. string LongFileName = "resource\\particles\\";
  141. LongFileName+=SystemName;
  142. LongFileName.AddExtention(".xps");
  143. if (pFS->IsExist(LongFileName))
  144. SystemName = string ("#c000000") + SystemName;
  145. else
  146. SystemName = string ("#cFF0000") + SystemName;
  147. pAvailableSystemsList->Items.Add(SystemName);
  148. }
  149. pAvailableSystemsList->Items.Sort(AlphabetSortFuncCompare);
  150. IniFile->Release();
  151. }
  152. void _cdecl TProjectBrowser::OnCreateNewPackInList (GUIControl* sender)
  153. {
  154. string PackName = pPackName->Edit->Text;
  155. for (int n = 0; n < pPackName->ListBox->Items.Size(); n++)
  156. {
  157. if (pPackName->ListBox->Items[n] == PackName)
  158. {
  159. return;
  160. }
  161. }
  162. int NewIndex = pPackName->ListBox->Items.Add(PackName);
  163. pPackName->SelectItem(NewIndex);
  164. }
  165. void _cdecl TProjectBrowser::OnPackIsChange (GUIControl* sender)
  166. {
  167. // pFS->ReleasePak(PakName);
  168. string PakFileName = PACK_PATH;
  169. PakFileName += pPackName->ListBox->Items[pPackName->ListBox->SelectedLine];
  170. // pFS->AddPak(PakFileName);
  171. PakName = PakFileName;
  172. BuildProjectList ();
  173. }
  174. void _cdecl TProjectBrowser::OnAddSystem (GUIControl* sender)
  175. {
  176. TSystemSelector* pSystemSelector = NEW TSystemSelector;
  177. Application->ShowModal(pSystemSelector);
  178. pSystemSelector->OnClose = (CONTROL_EVENT)&TProjectBrowser::AddSystemClosed;
  179. }
  180. void _cdecl TProjectBrowser::OnSelectTexture (GUIControl* sender)
  181. {
  182. GUIFileOpen* TextureSelector = NEW GUIFileOpen;
  183. TextureSelector->Caption = "Select project texture";
  184. TextureSelector->StartDirectory = string(pEditor->GetStartDir()) + "\\resource\\textures\\";
  185. TextureSelector->Filters.Add(".txx");
  186. TextureSelector->FiltersDesc.Add("Texture file");
  187. TextureSelector->OnOK = (CONTROL_EVENT)&TProjectBrowser::TextureSelected;
  188. Application->ShowModal(TextureSelector);
  189. TextureSelector->Filter->SelectItem(1);
  190. }
  191. void _cdecl TProjectBrowser::TextureSelected (GUIControl* sender)
  192. {
  193. if (CurrentProjectName.IsEmpty()) return;
  194. GUIFileOpen* TextureFileSelector = (GUIFileOpen*)sender;
  195. string CropPath = string(pEditor->GetStartDir()) + "\\resource\\textures\\";
  196. string TextureName = TextureFileSelector->FileName;
  197. TextureName.GetRelativePath(CropPath);
  198. //pEditor->Manager()->SetProjectTexture(TextureName);
  199. //pPS->SetProjectTextureName(tName);
  200. IFileService* pFS = (IFileService*)api->GetService("FileService");
  201. IEditableIniFile * IniFile = pFS->OpenEditableIniFile(CurrentProjectName.GetBuffer(), file_open_always, _FL_);
  202. Assert(IniFile);
  203. IniFile->SetString("Textures", "MainTexture", TextureName.GetBuffer());
  204. IniFile->Release();
  205. OnSelectProject (NULL);
  206. }
  207. void _cdecl TProjectBrowser::AddSystemClosed (GUIControl* sender)
  208. {
  209. if (CurrentProjectName.IsEmpty()) return;
  210. TSystemSelector* pSystemSelector = (TSystemSelector*)sender;
  211. if (!pSystemSelector->OkPressed) return;
  212. //pSystemSelector->SystemName
  213. IFileService* pFS = (IFileService*)api->GetService("FileService");
  214. IEditableIniFile* IniFile = pFS->OpenEditableIniFile(CurrentProjectName.GetBuffer(), file_open_always, _FL_);
  215. Assert (IniFile);
  216. string Section;
  217. //Загружаем данные
  218. for (int n = 0; n < 9999; n++)
  219. {
  220. Section.Format("System_%04d", n);
  221. const char* szIniStr = IniFile->GetString("Manager", Section.GetBuffer(), NULL);
  222. if (!szIniStr) break;
  223. //system already exist in project...
  224. if (crt_stricmp (szIniStr, pSystemSelector->SystemName.GetBuffer()) == 0)
  225. {
  226. IniFile->Release();
  227. return;
  228. }
  229. }
  230. IniFile->SetString("Manager", (char*)Section.GetBuffer(), pSystemSelector->SystemName.GetBuffer());
  231. IniFile->Release();
  232. OnSelectProject (NULL);
  233. }
  234. void _cdecl TProjectBrowser::OnRemoveSystem (GUIControl* sender)
  235. {
  236. if (CurrentProjectName.IsEmpty()) return;
  237. if (pAvailableSystemsList->SelectedLine < 0) return;
  238. pAvailableSystemsList->Items.Delete(pAvailableSystemsList->SelectedLine);
  239. IEditableIniFile* IniFile = pFS->OpenEditableIniFile(CurrentProjectName.GetBuffer(), file_open_always, _FL_);
  240. Assert (IniFile);
  241. int n = 0;
  242. string Section;
  243. for (n = 0; n < pAvailableSystemsList->Items.Size(); n++)
  244. {
  245. char* pSystemName = (char*)pAvailableSystemsList->Items[n].GetBuffer() + 8;
  246. Section.Format("System_%04d", n);
  247. IniFile->SetString("Manager", (char*)Section.GetBuffer(), pSystemName);
  248. }
  249. for (DWORD m = n; m < 9999; m++)
  250. {
  251. Section.Format("System_%04d", m);
  252. if (!IniFile->IsKeyCreated("Manager", (char*)Section.GetBuffer())) break;
  253. IniFile->DelKey("Manager", (char*)Section.GetBuffer());
  254. }
  255. IniFile->Release();
  256. OnSelectProject (NULL);
  257. }
  258. /*
  259. void _cdecl TProjectBrowser::UpdateGeomCacheInfo (GUIControl* sender)
  260. {
  261. if (CurrentProjectName.IsEmpty()) return;
  262. GUIMessageBox* pMB = Application->MessageBox("This action close all edited system\nYou sure ?", "Warning", GUIMB_YESNO);
  263. pMB->OnOK = (CONTROL_EVENT)UpdateGeomCacheInfoReal;
  264. }
  265. void _cdecl TProjectBrowser::UpdateGeomCacheInfoReal (GUIControl* sender)
  266. {
  267. if (CurrentProjectName.IsEmpty()) return;
  268. UsedGeomNames.DelAll();
  269. string OldProjectName = pEditor->Manager()->GetProjectFileName();
  270. pEditor->Manager()->OpenProject(CurrentProjectNameShort.GetBuffer());
  271. INIFILE* IniFile = pFS->OpenIniFile(CurrentProjectName.GetBuffer(), _FL_);
  272. Assert (IniFile);
  273. DWORD GeomIndex = 0;
  274. string Section;
  275. for (int n = 0; n < pAvailableSystemsList->Items.GetCount(); n++)
  276. {
  277. char* pSystemName = (char*)pAvailableSystemsList->Items[n].GetBuffer() + 8;
  278. const char* GeomName = NULL;
  279. GeomName = pEditor->Manager()->GetFirstGeomName(pSystemName);
  280. while (GeomName)
  281. {
  282. bool DuplicateFound = false;
  283. for (DWORD x = 0; x < UsedGeomNames.Size(); x++)
  284. {
  285. if (crt_stricmp(UsedGeomNames[x].GetBuffer(), GeomName) == 0)
  286. {
  287. DuplicateFound = true;
  288. break;
  289. }
  290. }
  291. if (!DuplicateFound)
  292. {
  293. UsedGeomNames.Add(GeomName);
  294. string Section;
  295. Section.Format("Model_%04d", GeomIndex);
  296. IniFile->WriteString("ModelsCache", (char*)Section.GetBuffer(), (char*)GeomName);
  297. GeomIndex++;
  298. }
  299. GeomName = pEditor->Manager()->GetNextGeomName();
  300. }
  301. }
  302. for (DWORD m = GeomIndex; m < 9999; m++)
  303. {
  304. Section.Format("Model_%04d", m);
  305. if (!IniFile->TestKey("ModelsCache", (char*)Section.GetBuffer(), NULL)) break;
  306. IniFile->DeleteKey("ModelsCache", (char*)Section.GetBuffer());
  307. }
  308. delete IniFile;
  309. pEditor->Manager()->OpenProject(OldProjectName);
  310. }
  311. */
  312. void _cdecl TProjectBrowser::OnSystemDblClick (GUIControl* sender)
  313. {
  314. if (pAvailableSystemsList->SelectedLine < 0) return;
  315. CurrentSystemName = (pAvailableSystemsList->Items[pAvailableSystemsList->SelectedLine].GetBuffer() + 8);
  316. UserSelectSystemToOpen = true;
  317. Close (this);
  318. }
  319. void _cdecl TProjectBrowser::ExitFromBrowser (GUIControl* sender)
  320. {
  321. UserSelectSystemToOpen = false;
  322. Close (this);
  323. }
  324. #endif