| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- // PresetsForm.cpp : implementation file
- //
- #include "stdafx.h"
- #include "leveledit.h"
- #include "presetslibform.h"
- #include "utils.h"
- #include "filemgr.h"
- #include "definitionfactorymgr.h"
- #include "definitionclassids.h"
- #include "definitionfactory.h"
- #include "definitionmgr.h"
- #include "definition.h"
- #include "icons.h"
- #include "terraindefinition.h"
- #include "preset.h"
- #include "presetmgr.h"
- #include "sceneeditor.h"
- #include "saveload.h"
- #include "rawfile.h"
- #include "chunkio.h"
- #include "filelocations.h"
- #include "nodecategories.h"
- #include "editorchunkids.h"
- #include "regkeys.h"
- #include "nodemgr.h"
- #include "LevelEditView.h"
- #include "PlaySoundDialog.h"
- #include "AudibleSound.h"
- #include "UpdatePresetDialog.h"
- #include "definitionutils.h"
- #include "presetlogger.h"
- #include "rendobj.h"
- #include "phys.h"
- #include "textfile.h"
- #include "node.h"
- #include "ramfile.h"
- #include "editorbuild.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- ///////////////////////////////////////////////////////////////////////
- //
- // Helper objects
- //
- ///////////////////////////////////////////////////////////////////////
- class SelectionCaptureClass
- {
- public:
- SelectionCaptureClass (PresetsFormClass *preset_form)
- {
- m_PresetForm = preset_form;
- HTREEITEM tree_item = m_PresetForm->m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = m_PresetForm->Get_Item_Preset (tree_item);
- DefinitionFactoryClass *factory = m_PresetForm->Get_Item_Factory (tree_item);
- if (preset != NULL) {
- m_ID = preset->Get_ID ();
- m_IsFactory = false;
- } else {
- m_ID = factory->Get_Class_ID ();
- m_IsFactory = true;
- }
- return ;
- }
- void Restore (void)
- {
- m_PresetForm->Reselect_Item (m_ID, m_IsFactory);
- return ;
- }
- private:
- PresetsFormClass * m_PresetForm;
- int m_ID;
- bool m_IsFactory;
- };
- ///////////////////////////////////////////////////////////////////////
- //
- // Macros
- //
- ///////////////////////////////////////////////////////////////////////
- #ifndef TreeView_SetOverlay
- #define TreeView_SetOverlay(hwndLV, i, overlay) \
- { \
- TVITEMEX item_info = { TVIF_STATE, i, INDEXTOOVERLAYMASK(overlay), TVIS_OVERLAYMASK, 0 }; \
- TreeView_SetItem(hwndLV, &item_info); \
- }
- #endif
- ///////////////////////////////////////////////////////////////////////
- //
- // Constants
- //
- ///////////////////////////////////////////////////////////////////////
- typedef enum
- {
- TYPE_FACTORY,
- TYPE_PRESET,
- } ITEM_TYPE;
- typedef struct
- {
- ITEM_TYPE type;
- union
- {
- DefinitionFactoryClass *factory;
- PresetClass *preset;
- };
- } ITEM_DATA;
- static const int TOOLBAR_HEIGHT = 36;
- static const int TOOLBAR_V_SPACING = 5;
- static const int TOOLBAR_V_BORDER = TOOLBAR_V_SPACING * 2;
- static const int TOOLBAR_H_SPACING = 5;
- static const int TOOLBAR_H_BORDER = TOOLBAR_H_SPACING * 2;
- /////////////////////////////////////////////////////////////////////////////
- //
- // PresetsFormClass
- //
- /////////////////////////////////////////////////////////////////////////////
- PresetsFormClass::PresetsFormClass(CWnd *parent_wnd)
- : m_DragItem (NULL),
- m_IsDragging (false),
- m_DragImageList (NULL),
- CDialog(PresetsFormClass::IDD)
- {
- //{{AFX_DATA_INIT(PresetsFormClass)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- Create (PresetsFormClass::IDD, parent_wnd);
- return ;
- }
- PresetsFormClass::~PresetsFormClass()
- {
- return ;
- }
- void PresetsFormClass::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(PresetsFormClass)
- DDX_Control(pDX, IDC_PRESETS_TREE, m_TreeCtrl);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(PresetsFormClass, CDialog)
- //{{AFX_MSG_MAP(PresetsFormClass)
- ON_WM_SIZE()
- ON_COMMAND(IDC_ADD, OnAdd)
- ON_NOTIFY(TVN_DELETEITEM, IDC_PRESETS_TREE, OnDeleteitemPresetsTree)
- ON_COMMAND(IDC_MODIFY, OnModify)
- ON_COMMAND(IDC_MAKE, OnMake)
- ON_COMMAND(IDC_ADD_TEMP, OnAddTemp)
- ON_COMMAND(IDC_DELETE, OnDelete)
- ON_NOTIFY(TVN_SELCHANGED, IDC_PRESETS_TREE, OnSelchangedPresetsTree)
- ON_COMMAND(IDC_PLAY, OnPlay)
- ON_COMMAND(IDC_INFO, OnInfo)
- ON_COMMAND(IDC_EXTRA, OnExtra)
- ON_UPDATE_COMMAND_UI(IDC_CONVERT, OnUpdateConvert)
- ON_UPDATE_COMMAND_UI(IDC_INFO, OnUpdateInfo)
- ON_UPDATE_COMMAND_UI(IDC_PLAY, OnUpdatePlay)
- ON_UPDATE_COMMAND_UI(IDC_UPDATE_VSS, OnUpdateUpdateVss)
- ON_WM_DRAWITEM()
- ON_WM_MEASUREITEM()
- ON_COMMAND(IDC_CONVERT, OnConvert)
- ON_COMMAND(IDC_UPDATE_VSS, OnUpdateVss)
- ON_COMMAND(IDM_BATCH_IMPORT_TERRAIN, OnBatchImportTerrain)
- ON_COMMAND(IDM_UPDATE_EMBEDDED_NODE_LIST, OnBuildEmbedNodeList)
- ON_COMMAND(IDM_CLEAR_EMBEDDED_NODE_LIST, OnClearEmbeddedNodeList)
- ON_UPDATE_COMMAND_UI(IDM_BATCH_IMPORT_TERRAIN, OnUpdateBatchImportTerrain)
- ON_UPDATE_COMMAND_UI(IDM_UPDATE_EMBEDDED_NODE_LIST, OnUpdateEmbeddedNodeList)
- ON_UPDATE_COMMAND_UI(IDM_CLEAR_EMBEDDED_NODE_LIST, OnUpdateClearEmbeddedNodeList)
- ON_NOTIFY(TVN_BEGINDRAG, IDC_PRESETS_TREE, OnBegindragPresetsTree)
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // PresetsFormClass diagnostics
- #ifdef _DEBUG
- void PresetsFormClass::AssertValid() const
- {
- CDialog::AssertValid();
- }
- void PresetsFormClass::Dump(CDumpContext& dc) const
- {
- CDialog::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnSize
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnSize
- (
- UINT nType,
- int cx,
- int cy
- )
- {
- CDialog::OnSize(nType, cx, cy);
-
- if (::IsWindow (m_TreeCtrl) && (cx > 0) && (cy > 0)) {
- // Get the bounding rectangle of the form window
- CRect parentrect;
- GetWindowRect (&parentrect);
-
- // Get the bounding rectangle of the toolbar
- CRect toolbar_rect;
- m_Toolbar.GetWindowRect (&toolbar_rect);
- ScreenToClient (&toolbar_rect);
- // Move the toolbar so it is in its correct position
- m_Toolbar.SetWindowPos (NULL,
- TOOLBAR_H_SPACING,
- (cy - TOOLBAR_V_SPACING) - toolbar_rect.Height (),
- cx - TOOLBAR_H_BORDER,
- toolbar_rect.Height (),
- SWP_NOZORDER);
- // Get the bounding rectnagle of the list ctrl
- RECT list_rect;
- m_TreeCtrl.GetWindowRect (&list_rect);
-
- CRect client_rect = list_rect;
- ScreenToClient (&client_rect);
- int list_height = ((cy - TOOLBAR_V_BORDER) - toolbar_rect.Height ()) - client_rect.top;
- //
- // Resize the tab control to fill the empty contents of the client area
- //
- m_TreeCtrl.SetWindowPos ( NULL,
- 0,
- 0,
- cx-((list_rect.left-parentrect.left) << 1),
- list_height,
- SWP_NOZORDER | SWP_NOMOVE);
- }
-
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnInitDialog
- //
- /////////////////////////////////////////////////////////////////////////////
- BOOL
- PresetsFormClass::OnInitDialog (void)
- {
- CDialog::OnInitDialog ();
- CRect rect;
- GetClientRect (&rect);
- m_Toolbar.CreateEx (this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect(0, 0, 0, 0), 101);
- m_Toolbar.SetOwner (this);
- m_Toolbar.LoadToolBar (IDR_PRESET_TOOLBAR1);
- m_Toolbar.SetBarStyle (m_Toolbar.GetBarStyle () | CBRS_TOOLTIPS | CBRS_FLYBY);
- m_Toolbar.GetToolBarCtrl ().SetExtendedStyle (TBSTYLE_EX_DRAWDDARROWS);
-
- TBBUTTONINFO button_info = { sizeof (TBBUTTONINFO), TBIF_STYLE, 0 };
- int index = m_Toolbar.CommandToIndex (IDC_EXTRA);
- m_Toolbar.GetToolBarCtrl ().GetButtonInfo (IDC_EXTRA, &button_info);
- button_info.fsStyle |= TBSTYLE_DROPDOWN;
- m_Toolbar.GetToolBarCtrl ().SetButtonInfo (IDC_EXTRA, &button_info);
- //
- // Get the bounding rectangle of the form window
- //
- CRect parentrect;
- GetWindowRect (&parentrect);
- m_Toolbar.SetWindowPos (NULL, 0, 0, parentrect.Width () - TOOLBAR_H_BORDER, TOOLBAR_HEIGHT, SWP_NOZORDER | SWP_NOMOVE);
- m_Toolbar.Enable_Button (IDC_ADD, Enable_Button (IDC_ADD));
- m_Toolbar.Enable_Button (IDC_DELETE, Enable_Button (IDC_DELETE));
- //
- // Pass the general use imagelist onto the tree control
- //
- m_TreeCtrl.SetImageList (::Get_Global_Image_List (), TVSIL_NORMAL);
- Reload_Presets ();
-
- //
- // Select the first item in the tree control
- //
- HTREEITEM first_item = m_TreeCtrl.GetNextItem (NULL, TVGN_CHILD);
- if (first_item != NULL) {
- m_TreeCtrl.SelectItem (first_item);
- }
- SetProp (m_TreeCtrl, "TRANS_ACCS", (HANDLE)1);
- SetProp (m_hWnd, "TRANS_ACCS", (HANDLE)1);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Reload_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Reload_Presets (void)
- {
- m_TreeCtrl.SetRedraw (FALSE);
- m_TreeCtrl.SelectItem (NULL);
- m_TreeCtrl.DeleteAllItems ();
- //
- // Loop through and add all the registered definition factories to
- // the tree control
- //
- for (int index = 0; index < PRESET_CATEGORY_COUNT; index ++) {
- //
- // Add this factory to the tree
- //
- HTREEITEM tree_item = m_TreeCtrl.InsertItem (PRESET_CATEGORIES[index].name, FOLDER_ICON, FOLDER_ICON);
-
- //
- // Is there a factory to create this class of defintion?
- //
- DefinitionFactoryClass *factory = DefinitionFactoryMgrClass::Find_Factory (PRESET_CATEGORIES[index].clsid);
- if (factory != NULL) {
-
- //
- // Add all presets for this factory into the tree
- //
- if (factory->Is_Displayed ()) {
- Set_Item_Data (tree_item, factory);
- Fill_In_Presets (tree_item);
- }
- } else {
- //
- // Find all the sub-factories
- //
- for ( factory = DefinitionFactoryMgrClass::Get_First (PRESET_CATEGORIES[index].clsid);
- factory != NULL;
- factory = DefinitionFactoryMgrClass::Get_Next (factory, PRESET_CATEGORIES[index].clsid))
- {
- //
- // Add this sub-factory and all its definitions to the tree
- //
- if (factory->Is_Displayed ()) {
- LPCTSTR name = factory->Get_Name ();
- HTREEITEM child_item = m_TreeCtrl.InsertItem (factory->Get_Name (), FOLDER_ICON, FOLDER_ICON, tree_item);
- Set_Item_Data (child_item, factory);
- Fill_In_Presets (child_item);
- }
- }
- }
- }
-
- Sort_Nodes (TVI_ROOT);
- m_TreeCtrl.SetRedraw (TRUE);
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Fill_In_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Fill_In_Presets (HTREEITEM root_item)
- {
- DefinitionFactoryClass *factory = Get_Item_Factory (root_item);
- if (factory != NULL && factory->Is_Displayed ()) {
- uint32 class_id = factory->Get_Class_ID ();
- //
- // Find all the presets that belong to this class
- //
- PresetClass *preset = NULL;
- for ( preset = PresetMgrClass::Get_First (class_id, PresetMgrClass::ID_CLASS);
- preset != NULL;
- preset = PresetMgrClass::Get_Next (preset, class_id, PresetMgrClass::ID_CLASS))
- {
-
- //
- // Add this preset to the tree
- //
- if (preset->Get_Parent () == NULL) {
- HTREEITEM tree_item = Insert_Preset (root_item, preset);
- if (tree_item != NULL) {
- //
- // Recursively fill in this definition's 'children'
- //
- Fill_In_Preset_Children (tree_item, preset->Get_ID ());
- }
- }
- }
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Fill_In_Preset_Children
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Fill_In_Preset_Children
- (
- HTREEITEM root_item,
- uint32 parent_id
- )
- {
- //
- // Lookup the parent preset
- //
- PresetClass *parent_preset = PresetMgrClass::Find_Preset (parent_id);
- if (parent_preset == NULL) {
- return ;
- }
- //
- // Loop over all the children of this preset
- //
- int count = parent_preset->Get_Child_Preset_Count ();
- for (int index = 0; index < count; index ++) {
- PresetClass *child_preset = parent_preset->Get_Child_Preset (index);
- if (child_preset != NULL) {
- //
- // Check to make sure we have no recursive links
- //
- PresetClass *parent = child_preset->Get_Parent ();
- if (parent == child_preset || parent->Get_ID () == child_preset->Get_ID ()) {
- CString message;
- message.Format ("Preset '%s' is recursively linked to itself.\r\n", child_preset->Get_Name ());
- MessageBox (message, "Preset Error", MB_ICONERROR | MB_OK | MB_SETFOREGROUND);
- continue ;
- }
- //
- // Check to make sure the parent is correct
- //
- if (parent != NULL && child_preset->Get_Class_ID () != parent->Get_Class_ID ()) {
- CString message;
- message.Format ("Preset '%s' is incorrectly linked as a child of '%s'.\r\n", child_preset->Get_Name (), parent->Get_Name ());
- MessageBox (message, "Preset Error", MB_ICONERROR | MB_OK | MB_SETFOREGROUND);
- }
-
- //
- // Add this preset to the tree
- //
- HTREEITEM tree_item = Insert_Preset (root_item, child_preset);
- if (tree_item != NULL) {
- //
- // Recursively fill in this definition's 'children'
- //
- Fill_In_Preset_Children (tree_item, child_preset->Get_ID ());
- }
- }
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Find_Preset
- //
- /////////////////////////////////////////////////////////////////////////////
- HTREEITEM
- PresetsFormClass::Find_Preset (HTREEITEM root_item, uint32 id)
- {
- HTREEITEM preset_item = NULL;
- //
- // Look for the preset in this item's children (recursive)
- //
- for ( HTREEITEM tree_item = m_TreeCtrl.GetChildItem (root_item);
- (tree_item != NULL) && (preset_item == NULL);
- tree_item = m_TreeCtrl.GetNextSiblingItem (tree_item))
- {
- DefinitionClass *definition = Get_Item_Definition (tree_item);
- //
- // Is this the preset we were looking for?
- //
- if ((definition != NULL) && (definition->Get_ID () == id)) {
- preset_item = tree_item;
- } else if (m_TreeCtrl.ItemHasChildren (tree_item)) {
-
- //
- // Recursively call this method for all sub-folders in this tree
- //
- preset_item = Find_Preset (tree_item, id);
- }
- }
- return preset_item;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Find_Factory
- //
- /////////////////////////////////////////////////////////////////////////////
- HTREEITEM
- PresetsFormClass::Find_Factory (HTREEITEM root_item, uint32 id)
- {
- HTREEITEM factory_item = NULL;
- //
- // Look for the preset in this item's children (recursive)
- //
- for ( HTREEITEM tree_item = m_TreeCtrl.GetChildItem (root_item);
- (tree_item != NULL) && (factory_item == NULL);
- tree_item = m_TreeCtrl.GetNextSiblingItem (tree_item))
- {
- DefinitionFactoryClass *factory = Get_Item_Factory (tree_item);
- //
- // Is this the factory we were looking for?
- //
- if ((factory != NULL) && (factory->Get_Class_ID () == id)) {
- factory_item = tree_item;
- } else if (m_TreeCtrl.ItemHasChildren (tree_item)) {
-
- //
- // Recursively call this method for all sub-folders in this tree
- //
- factory_item = Find_Factory (tree_item, id);
- }
- }
- return factory_item;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Get_Selected_Factory
- //
- /////////////////////////////////////////////////////////////////////////////
- DefinitionFactoryClass *
- PresetsFormClass::Get_Selected_Factory (void)
- {
- HTREEITEM curr_item = m_TreeCtrl.GetSelectedItem ();
- DefinitionFactoryClass *factory = Get_Item_Factory (curr_item);
-
- // Does this item represent a definition?
- if (factory == NULL) {
-
- //
- // Find the defintion's factory (if possible)
- //
- DefinitionClass *definition = Get_Item_Definition (curr_item);
- if (definition != NULL) {
- uint32 class_id = definition->Get_Class_ID ();
- factory = DefinitionFactoryMgrClass::Find_Factory (class_id);
- }
- }
- return factory;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Set_Item_Data
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Set_Item_Data (HTREEITEM item, DefinitionFactoryClass *factory)
- {
- //
- // Allocate a new wrapper if we need to
- //
- ITEM_DATA *item_data = (ITEM_DATA *)m_TreeCtrl.GetItemData (item);
- if (item_data == NULL) {
- item_data = new ITEM_DATA;
- }
- //
- // Set a flag in the wrapper so we know what kind of data
- // this tree item contains.
- //
- item_data->type = TYPE_FACTORY;
- item_data->factory = factory;
- m_TreeCtrl.SetItemData (item, (DWORD)item_data);
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Set_Item_Data
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Set_Item_Data (HTREEITEM item, PresetClass *preset)
- {
- //
- // Allocate a new wrapper if we need to
- //
- ITEM_DATA *item_data = (ITEM_DATA *)m_TreeCtrl.GetItemData (item);
- if (item_data == NULL) {
- item_data = new ITEM_DATA;
- }
- //
- // Set a flag in the wrapper so we know what kind of data
- // this tree item contains.
- //
- item_data->type = TYPE_PRESET;
- item_data->preset = preset;
- m_TreeCtrl.SetItemData (item, (DWORD)item_data);
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Get_Item_Factory
- //
- /////////////////////////////////////////////////////////////////////////////
- DefinitionFactoryClass *
- PresetsFormClass::Get_Item_Factory (HTREEITEM item)
- {
- DefinitionFactoryClass *factory = NULL;
- if (item != NULL) {
- //
- // If this item represents a factory, then return the factory
- // pointer to the caller.
- //
- ITEM_DATA *item_data = (ITEM_DATA *)m_TreeCtrl.GetItemData (item);
- if ((item_data != NULL) && (item_data->type == TYPE_FACTORY)) {
- factory = item_data->factory;
- }
- }
- return factory;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Get_Item_Definition
- //
- /////////////////////////////////////////////////////////////////////////////
- DefinitionClass *
- PresetsFormClass::Get_Item_Definition (HTREEITEM item)
- {
- DefinitionClass *definition = NULL;
- if (item != NULL) {
- //
- // Get the definition from the preset this item
- // represents
- //
- PresetClass *preset = Get_Item_Preset (item);
- if (preset != NULL) {
- definition = preset->Get_Definition ();
- }
- }
- return definition;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Get_Item_Preset
- //
- /////////////////////////////////////////////////////////////////////////////
- PresetClass *
- PresetsFormClass::Get_Item_Preset (HTREEITEM item)
- {
- PresetClass *preset = NULL;
- if (item != NULL) {
- //
- // If this item represents a definition, then return the definition
- // pointer to the caller.
- //
- ITEM_DATA *item_data = (ITEM_DATA *)m_TreeCtrl.GetItemData (item);
- if ((item_data != NULL) && (item_data->type == TYPE_PRESET)) {
- preset = item_data->preset;
- }
- }
- return preset;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Get_Icon
- //
- /////////////////////////////////////////////////////////////////////////////
- int
- PresetsFormClass::Get_Icon (PresetClass *preset)
- {
- int icon = FOLDER_ICON;
-
- DefinitionClass *definition = preset->Get_Definition ();
- if (definition != NULL) {
- int class_id = definition->Get_Class_ID ();
- int superclass_id = ::SuperClassID_From_ClassID (class_id);
- switch (superclass_id) {
- case CLASSID_TERRAIN:
- icon = TERRAIN_ICON;
- break;
- case CLASSID_TILE:
- icon = TILE_ICON;
- break;
- case CLASSID_GAME_OBJECTS:
- case CLASSID_MUNITIONS:
- case CLASSID_DUMMY_OBJECTS:
- if (class_id == CLASSID_GAME_OBJECT_DEF_BUILDING) {
- icon = BUILDING_ICON;
- } else {
- icon = OBJECT_ICON;
- }
- break;
- case CLASSID_LIGHT:
- icon = LIGHT_ICON;
- break;
- case CLASSID_SOUND:
- icon = SOUND_ICON;
- break;
- case CLASSID_WAYPATH:
- icon = WAYPATH_ICON;
- break;
- case CLASSID_ZONE:
- icon = ZONE_ICON;
- break;
- case CLASSID_TRANSITION:
- icon = TRANSITION_ICON;
- break;
- case CLASSID_TWIDDLERS:
- icon = RAND_ICON;
- break;
- case CLASSID_BUILDINGS:
- icon = BUILDING_ICON;
- break;
- case CLASSID_EDITOR_OBJECTS:
- if (class_id == CLASSID_VIS_POINT_DEF) {
- icon = VIS_ICON;
- } else if (class_id == CLASSID_PATHFIND_START_DEF) {
- icon = PATHFIND_ICON;
- }
- break;
- case CLASSID_GLOBAL_SETTINGS:
- icon = FILE_ICON;
- break;
- }
- }
- if (preset->Get_IsTemporary ()) {
- icon = TEMP_ICON;
- }
- return icon;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Insert_Preset
- //
- /////////////////////////////////////////////////////////////////////////////
- HTREEITEM
- PresetsFormClass::Insert_Preset
- (
- HTREEITEM root_item,
- PresetClass * preset
- )
- {
- int icon = Get_Icon (preset);
- //
- // Insert a new node into the tree to represent this item
- //
- HTREEITEM tree_item = m_TreeCtrl.InsertItem (preset->Get_Name (), icon, icon, root_item);
- if (tree_item != NULL) {
- Set_Item_Data (tree_item, preset);
- bool needs_overlay = (preset->Get_Node_List ().Count () > 0);
- TreeView_SetOverlay (m_TreeCtrl, tree_item, needs_overlay);
- }
- return tree_item;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnDeleteitemPresetsTree
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnDeleteitemPresetsTree
- (
- NMHDR * pNMHDR,
- LRESULT *pResult
- )
- {
- NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW *)pNMHDR;
- (*pResult) = 0;
- //
- // Free the wrapper we installed around this item
- //
- ITEM_DATA *item_data = (ITEM_DATA *)m_TreeCtrl.GetItemData (pNMTreeView->itemOld.hItem);
- SAFE_DELETE (item_data);
- m_TreeCtrl.SetItemData (pNMTreeView->itemOld.hItem, 0L);
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnModify
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Modify_Preset (void)
- {
- bool retval = false;
- HTREEITEM current_item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (current_item);
- if (preset != NULL) {
- StringClass old_name = preset->Get_Name ();
- //
- // Show the properties dialog for this preset
- //
- if (preset->Show_Properties ()) {
-
- //
- // Check to see if the user has renamed the preset
- //
- StringClass new_name = preset->Get_Name ();
- if (::lstrcmp (old_name, new_name) != 0) {
-
- //
- // Rename the item in the tree
- //
- m_TreeCtrl.SetRedraw (FALSE);
- m_TreeCtrl.SetItemText (current_item, preset->Get_Name ());
- m_TreeCtrl.SetRedraw (TRUE);
- m_TreeCtrl.InvalidateRect (NULL, TRUE);
- //
- // Log the rename operation
- //
- if (preset->Get_IsTemporary () == false) {
- PresetLoggerClass::Log_Renamed (old_name, new_name);
- }
- }
- retval = true;
- }
- }
- return retval;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnModify
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnModify (void)
- {
- HTREEITEM current_item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (current_item);
- if (preset != NULL) {
- if (preset->Get_IsTemporary () == false) {
- //
- // Check out the definition database
- //
- SelectionCaptureClass sel_capture (this);
- bool undo_on_err = false;
- uint32 class_id = preset->Get_Class_ID ();
- if (PresetMgrClass::Check_Out_Database (class_id, &undo_on_err)) {
- sel_capture.Restore ();
- //
- // Re-get the preset (its pointer has changed, the
- // old one is crap).
- //
- current_item = m_TreeCtrl.GetSelectedItem ();
- preset = Get_Item_Preset (current_item);
- if (preset != NULL) {
- //
- // Show the preset settings
- //
- if (Modify_Preset ()) {
- Save_Global_Presets (class_id);
- PresetMgrClass::Add_Dirty_Preset (preset->Get_ID ());
- } else if (undo_on_err) {
- PresetMgrClass::Undo_Database_Check_Out (class_id);
- }
- }
- }
- } else {
-
- //
- // Show the preset settings
- //
- if (Modify_Preset ()) {
- Save_Temp_Presets ();
- }
- }
- NodeMgrClass::Reload_Nodes (preset);
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Load_Databases
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Load_Databases (void)
- {
- // Start fresh
- PresetMgrClass::Free_Presets ();
- DefinitionMgrClass::Free_Definitions ();
-
- bool retval = false;
- #ifdef PUBLIC_EDITOR_VER
-
- //
- // Reload the presets
- //
- retval = Old_Load_Presets ();
- retval &= Load_Temp_Presets ();
- #else
-
- //
- // Reload the presets
- //
- retval = Load_Preset_Libraries ();
- retval &= Load_Temp_Presets ();
- #endif //PUBLIC_EDITOR_VER
-
- return retval;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Load_Preset_Libraries
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Load_Preset_Libraries (void)
- {
- //
- // Try to load the library for each factory
- //
- DefinitionFactoryClass *factory = NULL;
- for ( factory = DefinitionFactoryMgrClass::Get_First ();
- factory != NULL;
- factory = DefinitionFactoryMgrClass::Get_Next (factory))
- {
- if (factory->Is_Displayed ()) {
- Load_Presets (factory->Get_Class_ID ());
- }
- }
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Load_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Load_Presets (uint32 class_id)
- {
- //
- // Build a filename for the presets library
- //
- CString path;
- ::Get_File_Mgr ()->Get_Preset_Library_Path (class_id, false, path);
- //
- // Open the file
- //
- HANDLE file = ::CreateFile ( path,
- GENERIC_READ,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- 0L,
- NULL);
- if (file != INVALID_HANDLE_VALUE) {
- //
- // Determine how large the file is
- //
- int file_size = ::GetFileSize (file, NULL);
- if (file_size > 0 && file_size < 99999999)
- {
- //
- // Read the file into memory
- //
- unsigned char *buffer = new unsigned char[file_size];
- DWORD bytes_read = 0;
- ::ReadFile (file, buffer, file_size, &bytes_read, NULL);
- //
- // Close the file
- //
- ::CloseHandle (file);
- file = INVALID_HANDLE_VALUE;
- //
- // Use a RAM file for the loading
- //
- RAMFileClass file_obj (buffer, file_size);
- file_obj.Open (FileClass::READ);
- ChunkLoadClass chunk_load (&file_obj);
- //
- // Load the file
- //
- SaveLoadSystemClass::Load (chunk_load);
- //
- // Free the buffer
- //
- delete [] buffer;
- buffer = NULL;
- }
- }
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Old_Load_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Old_Load_Presets (void)
- {
- CString path = ::Get_File_Mgr ()->Make_Full_Path (OBJECTS_DDB_PATH);
- //
- // Open the file
- //
- HANDLE file = ::CreateFile (path,
- GENERIC_READ,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- 0L,
- NULL);
- if (file != INVALID_HANDLE_VALUE) {
- //
- // Determine how large the file is
- //
- int file_size = ::GetFileSize (file, NULL);
- if (file_size > 0 && file_size < 99999999)
- {
- //
- // Read the file into memory
- //
- unsigned char *buffer = new unsigned char[file_size];
- DWORD bytes_read = 0;
- ::ReadFile (file, buffer, file_size, &bytes_read, NULL);
- //
- // Close the file
- //
- ::CloseHandle (file);
- file = INVALID_HANDLE_VALUE;
- //
- // Use a RAM file for the loading
- //
- RAMFileClass file_obj (buffer, file_size);
- file_obj.Open (FileClass::READ);
- ChunkLoadClass chunk_load (&file_obj);
- //
- // Load the file
- //
- SaveLoadSystemClass::Load (chunk_load);
- //
- // Free the buffer
- //
- delete [] buffer;
- buffer = NULL;
- }
- }
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Load_Temp_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Load_Temp_Presets (void)
- {
- CString path = ::Get_File_Mgr ()->Make_Full_Path (TEMP_DB_PATH);
- //
- // Open the file
- //
- HANDLE hfile = ::CreateFile (path,
- GENERIC_READ,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- 0L,
- NULL);
- if (hfile != INVALID_HANDLE_VALUE) {
- RawFileClass file_obj;
- file_obj.Attach (hfile);
- ChunkLoadClass chunk_load (&file_obj);
- //
- // Load the file
- //
- SaveLoadSystemClass::Load (chunk_load);
- }
-
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Save_Temp_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Save_Temp_Presets (void)
- {
- Save_Presets (0, true);
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Save_Global_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Save_Global_Presets (uint32 class_id)
- {
- #ifndef PUBLIC_EDITOR_VER
-
- Save_Presets (class_id, false);
- #endif //PUBLIC_EDITOR_VER
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Build_DDB_File_List
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Build_DDB_File_List
- (
- DynamicVectorClass<CString> & file_list,
- HTREEITEM parent_item
- )
- {
- //
- // Loop over all the immediate children
- //
- for ( HTREEITEM child_item = m_TreeCtrl.GetChildItem (parent_item);
- child_item != NULL;
- child_item = m_TreeCtrl.GetNextSiblingItem (child_item))
- {
- //
- // If this tree item represents a definition factory, then
- // we should have a preset library to match
- //
- DefinitionFactoryClass *factory = Get_Item_Factory (child_item);
- if (factory != NULL) {
- //
- // Build a filename for this preset library
- //
- CString path;
- ::Get_File_Mgr ()->Get_Preset_Library_Path (factory->Get_Class_ID (), false, path);
- //
- // Add this preset library to the list
- //
- file_list.Add (path);
- } else if (m_TreeCtrl.ItemHasChildren (child_item)) {
-
- //
- // Recursively call this method for all sub-folders in this tree
- //
- Build_DDB_File_List (file_list, child_item);
- }
- }
-
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Save_Preset_Libraries
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Save_Preset_Libraries (HTREEITEM parent_item)
- {
- #ifdef PUBLIC_EDITOR_VER
- //
- // Simply save the presets together in one file
- //
- CString path = ::Get_File_Mgr ()->Make_Full_Path (OBJECTS_DDB_PATH);
- Save_Presets (path, 0, false, false);
- #else
- //
- // Loop over all the immediate children
- //
- for ( HTREEITEM child_item = m_TreeCtrl.GetChildItem (parent_item);
- child_item != NULL;
- child_item = m_TreeCtrl.GetNextSiblingItem (child_item))
- {
- //
- // If this tree item represents a definition factory, then save
- // a preset library for all presets of this class ID
- //
- DefinitionFactoryClass *factory = Get_Item_Factory (child_item);
- if (factory != NULL) {
- Save_Global_Presets (factory->Get_Class_ID ());
- } else if (m_TreeCtrl.ItemHasChildren (child_item)) {
-
- //
- // Recursively call this method for all sub-folders in this tree
- //
- Save_Preset_Libraries (child_item);
- }
- }
- #endif //PUBLIC_EDITOR_VER
-
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Save_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Save_Presets
- (
- LPCTSTR path,
- uint32 class_id,
- bool class_id_matters,
- bool temps_only
- )
- {
- ///
- // Delete the file if it already exists
- //
- if (::GetFileAttributes (path) != 0xFFFFFFFF) {
- DWORD attributes = ::GetFileAttributes (path);
- ::SetFileAttributes (path, attributes & (~FILE_ATTRIBUTE_READONLY));
- ::DeleteFile (path);
- }
- //
- // Create the file at the specified location
- //
- HANDLE file = ::CreateFile ( path,
- GENERIC_WRITE,
- 0,
- NULL,
- CREATE_ALWAYS,
- 0L,
- NULL);
- ASSERT (file != INVALID_HANDLE_VALUE);
- if (file != INVALID_HANDLE_VALUE) {
-
- //
- // Now write the presets and definitions out to this file
- //
- Save_Presets (file, class_id, class_id_matters, temps_only);
-
- } else {
-
- //
- // Warn the user
- //
- DWORD last_error = ::GetLastError ();
- CString message;
- message.Format ("Unable to create database file.\nPath:%s\nError Code:%d", path, last_error);
- ::MessageBox (::AfxGetMainWnd ()->m_hWnd, message, "File I/O Error", MB_ICONERROR | MB_OK);
- }
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Save_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Save_Presets (uint32 class_id, bool temps_only)
- {
- //
- // Build a filename for the presets library
- //
- CString path;
- ::Get_File_Mgr ()->Get_Preset_Library_Path (class_id, temps_only, path);
- //
- // Now save the presets to this file
- //
- return Save_Presets (path, class_id, !temps_only, temps_only);
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Save_Presets
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Save_Presets (HANDLE file, uint32 class_id, bool class_id_matters, bool temps_only)
- {
- //
- // Create a chunk IO object that we can use to save our subsystems
- //
- RawFileClass file_obj;
- file_obj.Attach (file);
- ChunkSaveClass chunk_save (&file_obj);
- //
- // Remove all the presets that don't match our criteria
- //
- PRESET_LIST preset_list;
- preset_list.Set_Growth_Step (2000);
- PresetMgrClass::Remove_Non_Matching_Presets (class_id, class_id_matters, temps_only, preset_list);
- //
- // Turn saving off for all definitions
- //
- DefinitionClass *definition = NULL;
- for ( definition = DefinitionMgrClass::Get_First ();
- definition != NULL;
- definition = DefinitionMgrClass::Get_Next (definition))
- {
- definition->Enable_Save (false);
- }
- //
- // Now turn saving on for all definitions that are needed by
- // one of the presets.
- //
- DEFINITION_LIST defs_to_save;
- PresetClass *preset = NULL;
- for ( preset = PresetMgrClass::Get_First ();
- preset != NULL;
- preset = PresetMgrClass::Get_Next (preset))
- {
- //
- // Build a list of definitions this preset depends on
- //
- DEFINITION_LIST curr_defs;
- preset->Collect_Definitions (curr_defs);
- //
- // Turn saving on for all these definitions
- //
- for (int index = 0; index < curr_defs.Count (); index ++) {
- DefinitionClass *definition = curr_defs[index];
- if (definition != NULL) {
- definition->Enable_Save (true);
- }
- }
- }
- //
- // The definition database consists of the definitions (global)
- // and the presets (editor only).
- //
- SaveLoadSystemClass::Save (chunk_save, _TheDefinitionMgr);
- SaveLoadSystemClass::Save (chunk_save, _ThePresetMgr);
- //
- // Turn saving back on for all definitions
- //
- for ( definition = DefinitionMgrClass::Get_First ();
- definition != NULL;
- definition = DefinitionMgrClass::Get_Next (definition))
- {
- definition->Enable_Save (true);
- }
- //
- // Now add back all the presets we removed
- //
- PresetMgrClass::Put_Presets_Back (preset_list);
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Reselect_Item
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Reselect_Item (int id, bool is_factory)
- {
- HTREEITEM tree_item = NULL;
- if (is_factory) {
- tree_item = Find_Factory (TVI_ROOT, id);
- } else {
- tree_item = Find_Preset (TVI_ROOT, id);
- }
- m_TreeCtrl.Select (tree_item, TVGN_FIRSTVISIBLE);
- m_TreeCtrl.SelectItem (tree_item);
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnAddTemp
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnAddTemp (void)
- {
- DefinitionFactoryClass *factory = Get_Selected_Factory ();
- if (factory != NULL) {
- if (Add_New_Preset (NULL, true) != NULL) {
- Save_Temp_Presets ();
- }
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnAdd
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnAdd (void)
- {
- DefinitionFactoryClass *factory = Get_Selected_Factory ();
- if (factory != NULL) {
- //
- // Check out the definition database
- //
- SelectionCaptureClass sel_capture (this);
- bool undo_check_out = false;
- if (PresetMgrClass::Check_Out_Database (factory->Get_Class_ID (), &undo_check_out)) {
- sel_capture.Restore ();
- //
- // Create a new preset
- //
- PresetClass *preset = Add_New_Preset (NULL);
- if (preset != NULL) {
-
- //
- // Log creation
- //
- PresetLoggerClass::Log_Created (preset);
- //
- // Register this new preset for check-in
- //
- Save_Global_Presets (factory->Get_Class_ID ());
- PresetMgrClass::Add_Dirty_Preset (preset->Get_ID ());
- } else if (undo_check_out) {
- PresetMgrClass::Undo_Database_Check_Out (factory->Get_Class_ID ());
- }
- }
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnMake
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnMake (void)
- {
- HTREEITEM current_item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (current_item);
- if (preset != NULL) {
- ::Get_Scene_Editor ()->Create_Node (preset);
- //
- // Repartition the scene if the user placed a terrain
- //
- if (preset->Get_Class_ID () == CLASSID_TERRAIN) {
- ::Get_Scene_Editor ()->Re_Partition_Static_Projectors ();
- ::Get_Scene_Editor ()->Re_Partition_Static_Lights ();
- ::Get_Scene_Editor ()->Re_Partition_Static_Objects ();
- }
- ::Refresh_Main_View ();
- }
- return ;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // Add_New_Preset
- //
- /////////////////////////////////////////////////////////////////////////////
- PresetClass *
- PresetsFormClass::Add_New_Preset (LPCTSTR name, bool is_temp, bool sel_new)
- {
- PresetClass *new_preset = NULL;
- DefinitionFactoryClass *factory = Get_Selected_Factory ();
- if (factory != NULL) {
- HTREEITEM current_item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *parent_preset = Get_Item_Preset (current_item);
- //
- // Create a new preset
- //
- new_preset = PresetMgrClass::Create_Preset (factory->Get_Class_ID (), name, is_temp);
- new_preset->Set_Parent (parent_preset);
- //
- // Give the new preset its parent's values by default
- //
- if (parent_preset != NULL) {
- new_preset->Copy_Properties (*parent_preset);
- }
- //
- // Edit the preset's properties
- //
- if (name != NULL || new_preset->Show_Properties ()) {
-
- //
- // Add this preset to the framework
- //
- HTREEITEM new_item = Insert_Preset (current_item, new_preset);
- PresetMgrClass::Add_Preset (new_preset);
- DefinitionMgrClass::Register_Definition (new_preset->Get_Definition ());
- if (parent_preset != NULL) {
- parent_preset->Add_Child_Preset (new_preset->Get_ID ());
- }
- //
- // Select the new entry
- //
- if (sel_new) {
- m_TreeCtrl.Select (new_item, TVGN_FIRSTVISIBLE);
- m_TreeCtrl.SelectItem (new_item);
- }
- m_TreeCtrl.SortChildren (current_item);
- m_TreeCtrl.InvalidateRect (NULL, TRUE);
- } else {
- DefinitionClass *definition = new_preset->Get_Definition ();
- SAFE_DELETE (definition);
- SAFE_DELETE (new_preset);
- }
- }
- return new_preset;
- }
- /////////////////////////////////////////////////////////////////////////////
- //
- // OnDelete
- //
- /////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnDelete (void)
- {
- HTREEITEM current_item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (current_item);
- if (preset != NULL) {
- //
- // Make sure the user really wants to do this
- //
- if (::Message_Box ( m_hWnd,
- IDS_DELETE_PRESET_MSG,
- IDS_DELETE_PRESET_TITLE,
- MB_ICONQUESTION | MB_YESNO) == IDYES )
- {
- CWaitCursor wait_cursor;
- //
- // Check out the definition database (unless its a temp)
- //
- SelectionCaptureClass sel_capture (this);
- bool undo_on_err = false;
- bool was_temp = preset->Get_IsTemporary ();;
- if (was_temp || PresetMgrClass::Check_Out_Database (preset->Get_Class_ID (), &undo_on_err)) {
- sel_capture.Restore ();
- //
- // Re-get the preset (its pointer has changed, the
- // old one is crap).
- //
- current_item = m_TreeCtrl.GetSelectedItem ();
- preset = Get_Item_Preset (current_item);
- if (preset != NULL) {
- //
- // Log the delete operation
- //
- if (preset->Get_IsTemporary () == false) {
- PresetLoggerClass::Log_Deleted (preset->Get_Name ());
- }
- //
- // Build a list of all the sub-items that are affected by this operation
- //
- DynamicVectorClass<HTREEITEM> tree_item_list;
- tree_item_list.Add (current_item);
- Build_Child_List (current_item, tree_item_list);
- //
- // Determine what class-id's these presets belong to (they all belong
- // to the same class)
- //
- uint32 class_id = 0;
- DefinitionClass *definition = preset->Get_Definition ();
- if (definition != NULL) {
- class_id = definition->Get_Class_ID ();
- }
-
- //
- // Free all the nodes in the scene that use any of these presets.
- // Also unregister the preset and its definition
- //
- bool save_temp_lib = was_temp;
- for (int index = 0; index < tree_item_list.Count (); index ++) {
- PresetClass *preset = Get_Item_Preset (tree_item_list[index]);
- if (preset != NULL) {
- ::Get_Scene_Editor ()->Delete_Nodes (preset);
- PresetMgrClass::Remove_Preset (preset);
-
- //
- // Determine if we need to save the temporary preset
- // library later or not.
- //
- if (preset->Get_IsTemporary ()) {
- save_temp_lib = true;
- }
- //
- // Unlink the definition
- //
- preset->Set_Definition (NULL);
- //
- // Free the definition
- //
- DefinitionClass *definition = preset->Get_Definition ();
- if (definition != NULL) {
- DefinitionMgrClass::Unregister_Definition (definition);
- preset->Set_Definition (NULL);
- SAFE_DELETE (definition);
- }
-
- //
- // Free the preset
- //
- SAFE_DELETE (preset);
- }
- }
- //
- // Save the temporary presets library if necessary.
- //
- if (save_temp_lib) {
- Save_Temp_Presets ();
- }
- //
- // Save the global presets library if necessary
- //
- if (was_temp == false) {
- Save_Global_Presets (class_id);
- if (PresetMgrClass::Get_Immediate_Check_In_Mode ()) {
- PresetMgrClass::Check_In_Presets ();
- } else {
- PresetMgrClass::Set_Presets_Dirty ();
- }
- }
- m_TreeCtrl.DeleteItem (current_item);
- ::Refresh_Main_View ();
- }
- }
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Sort_Nodes
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Sort_Nodes (HTREEITEM root_item, bool recursive)
- {
- for ( HTREEITEM tree_item = m_TreeCtrl.GetChildItem (root_item);
- tree_item != NULL;
- tree_item = m_TreeCtrl.GetNextSiblingItem (tree_item))
- {
- //
- // Sort the children
- //
- m_TreeCtrl.SortChildren (tree_item);
- //
- // Recurse through the hierarchy
- //
- if (recursive && m_TreeCtrl.ItemHasChildren (tree_item)) {
- Sort_Nodes (tree_item);
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Create_Preset
- //
- ////////////////////////////////////////////////////////////////////////////
- PresetClass *
- PresetsFormClass::Create_Preset (DefinitionFactoryClass *factory, bool is_temp)
- {
- //
- // Create a new definition for the preset
- //
- DefinitionClass *definition = factory->Create ();
- //
- // Assign the definition a new ID
- //
- if (is_temp) {
- definition->Set_ID (::Get_Next_Temp_ID ());
- } else {
- definition->Set_ID (DefinitionMgrClass::Get_New_ID (definition->Get_Class_ID ()));
- }
-
- //
- // Create the new preset
- //
- PresetClass *new_preset = new PresetClass;
- new_preset->Set_Definition (definition);
- new_preset->Set_IsTemporary (is_temp);
- return new_preset;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Build_Child_List
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Build_Child_List
- (
- HTREEITEM parent_item,
- DynamicVectorClass<HTREEITEM> & list
- )
- {
- //
- // Loop over all the immediate children
- //
- for ( HTREEITEM child_item = m_TreeCtrl.GetChildItem (parent_item);
- child_item != NULL;
- child_item = m_TreeCtrl.GetNextSiblingItem (child_item))
- {
- list.Add (child_item);
- if (m_TreeCtrl.ItemHasChildren (child_item)) {
-
- //
- // Recursively call this method for all sub-folders in this tree
- //
- Build_Child_List (child_item, list);
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Enable_Button
- //
- ////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Enable_Button (int cmd_id)
- {
- bool retval = false;
- HTREEITEM current_item = m_TreeCtrl.GetSelectedItem ();
- if (current_item != NULL) {
- PresetClass *preset = Get_Item_Preset (current_item);
- DefinitionFactoryClass *factory = Get_Item_Factory (current_item);
- bool read_only = ::Get_File_Mgr()->Is_VSS_Read_Only ();
- bool temp = (preset != NULL && preset->Get_IsTemporary ()) ? true : false;
- bool is_proxy_test_folder = false;
- //
- // Determine if this is the proxy-test folder or not (special rules
- // apply to this folder).
- //
- if (preset != NULL) {
- is_proxy_test_folder = preset->Is_A_Parent (PROXY_TESTS_FOLDER);
- }
- //
- // Change the read_only state depending on the user class
- //
- if (read_only == false && ::Get_File_Mgr ()->Is_Special_User ()) {
- read_only = true;
- if (preset != NULL) {
- if (preset->Is_A_Parent (SPECIAL_USER_FOLDER)) {
- read_only = false;
- //
- // Don't let special users modify the folder itself (just sub-folders)
- //
- if ( ::lstrcmpi (preset->Get_Name (), SPECIAL_USER_FOLDER) == 0 &&
- (cmd_id == IDC_MODIFY || cmd_id == IDC_DELETE))
- {
- read_only = true;
- }
- }
- }
- }
- //
- // What operation is this?
- //
- switch (cmd_id)
- {
- case IDC_ADD:
- retval = ((preset || factory) && !read_only && !temp && !is_proxy_test_folder);
- break;
- case IDC_ADD_TEMP:
- retval = (preset || factory);
- break;
- case IDC_MAKE:
- retval = (preset != NULL);
- break;
- case IDC_MODIFY:
- retval = (preset && (!read_only || temp));
- break;
- case IDC_DELETE:
- retval = (preset && (!read_only || temp));
- break;
- case IDC_PLAY:
- retval = (preset != NULL && preset->Is_Valid_Sound_Preset ()) ? true : false;
- break;
- case IDC_UPDATE_VSS:
- retval = ((preset != NULL) && !read_only);
- break;
- case IDC_INFO:
- retval = (preset != NULL);
- break;
- case IDC_CONVERT:
- retval = ((preset != NULL) && temp && !read_only && !is_proxy_test_folder);
- if ( preset != NULL &&
- preset->Get_Parent () != NULL &&
- preset->Get_Parent ()->Get_IsTemporary ())
- {
- retval = false;
- }
- break;
- case IDM_BATCH_IMPORT_TERRAIN:
- {
- if (preset != NULL && preset->Get_Class_ID () == CLASSID_TERRAIN) {
- retval = true;
- }
- }
- break;
- case IDM_CLEAR_EMBEDDED_NODE_LIST:
- {
- retval = (preset && (!read_only || temp));
- if (preset != NULL && preset->Get_Node_List ().Count () == 0) {
- retval = false;
- }
- }
- break;
- case IDM_UPDATE_EMBEDDED_NODE_LIST:
- retval = (preset && (!read_only || temp));
- //
- // Only allow this option for terrain and tile presets
- //
- if (preset != NULL) {
- if ( preset->Get_Class_ID () != CLASSID_TERRAIN &&
- preset->Get_Class_ID () != CLASSID_TILE)
- {
- retval = false;
- }
- }
- break;
- }
- }
- return retval;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnSelchangedPresetsTree
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnSelchangedPresetsTree (NMHDR *pNMHDR, LRESULT *pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- (*pResult) = 0;
- //
- // Enable/disable the toolbar buttons
- //
- m_Toolbar.Enable_Button (IDC_ADD, Enable_Button (IDC_ADD));
- m_Toolbar.Enable_Button (IDC_ADD_TEMP, Enable_Button (IDC_ADD_TEMP));
- m_Toolbar.Enable_Button (IDC_MAKE, Enable_Button (IDC_MAKE));
- m_Toolbar.Enable_Button (IDC_MODIFY, Enable_Button (IDC_MODIFY));
- m_Toolbar.Enable_Button (IDC_DELETE, Enable_Button (IDC_DELETE));
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Propagate_Changes
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Propagate_Changes
- (
- HTREEITEM modified_item,
- DERIVED_PARAM_LIST & list
- )
- {
- CWaitCursor wait_cursor;
- CLevelEditView::Allow_Repaint (false);
- PresetClass *preset = Get_Item_Preset (modified_item);
- DefinitionClass *definition = preset->Get_Definition ();
- //
- // Loop over the list of derived parameters that need to
- // be updated with the new values.
- //
- for (int index = 0; index < list.Count (); index ++) {
- DERIVED_PARAM_INFO &info = list[index];
- //
- // Copy all the inherited parameter values from the parent preset
- //
- int list_count = info.base_param_list.Count ();
- for (int list_index = 0; list_index < list_count; list_index ++) {
- //int param_index = info.inherited_param_list[list_index];
- ParameterClass *parameter = info.base_param_list[list_index];
- ParameterClass *curr_parameter = info.derived_param_list[list_index];
- ASSERT (parameter != NULL);
- ASSERT (curr_parameter != NULL);
- //
- // Copy the parameter value from the parent.
- //
- curr_parameter->Copy_Value (*parameter);
- //
- // Release the parameter pointers
- //
- //definition->Unlock_Parameter (param_index);
- //curr_definition->Unlock_Parameter (param_index);
- }
- //
- // Now reload any nodes in the scene that refer to the
- // changed preset.
- //
- if (info.preset != NULL) {
- NodeMgrClass::Reload_Nodes (info.preset);
- }
- }
- //
- // Now reload any nodes in the scene that refer to the
- // changed preset.
- //
- NodeMgrClass::Reload_Nodes (preset);
- CLevelEditView::Allow_Repaint (true);
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Compare_Derived_Parameters
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Compare_Derived_Parameters
- (
- PresetClass * curr_preset,
- DefinitionClass * base_def,
- DefinitionClass * derived_def,
- DERIVED_PARAM_LIST & list
- )
- {
- DERIVED_PARAM_INFO info;
- info.preset = curr_preset;
-
- //
- // Compare all the parameters with this derived definition to
- // find any that are not overridden.
- //
- int param_count = base_def->Get_Parameter_Count ();
- for (int param_index = 0; param_index < param_count; param_index ++) {
- ParameterClass *parameter = base_def->Lock_Parameter (param_index);
- ParameterClass *curr_parameter = derived_def->Lock_Parameter (param_index);
- ASSERT (parameter != NULL);
- ASSERT (curr_parameter != NULL);
- //
- // If the parameter values are exactly the same, then
- // we will assume this parameter is derived and not overridden
- //
- if (*curr_parameter == *parameter) {
- info.base_param_list.Add (parameter);
- info.derived_param_list.Add (curr_parameter);
- } else if (parameter->Get_Type () == ParameterClass::TYPE_MODELDEFINITIONID) {
-
- //
- // Lookup the definitions that these parameters reference
- //
- int base_id = ((ModelDefParameterClass *)parameter)->Get_Value ();
- int derived_id = ((ModelDefParameterClass *)curr_parameter)->Get_Value ();
- DefinitionClass *base_model_def = DefinitionMgrClass::Find_Definition (base_id, false);
- DefinitionClass *derived_model_def = DefinitionMgrClass::Find_Definition (derived_id, false);
- //
- // Recursively add parameters from these definitions to the list
- //
- if ( base_model_def != NULL && derived_model_def != NULL &&
- base_model_def->Get_Class_ID () == derived_model_def->Get_Class_ID ())
- {
- Compare_Derived_Parameters (NULL, base_model_def, derived_model_def, list);
- }
- }
- //
- // Release the parameter pointers
- //
- base_def->Unlock_Parameter (param_index);
- derived_def->Unlock_Parameter (param_index);
- }
- //
- // If this preset contains at least one derived (not overridden) value,
- // then add it to the list.
- //
- if (info.base_param_list.Count () > 0) {
- list.Add (info);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Build_Inherited_Param_List
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Build_Inherited_Param_List
- (
- HTREEITEM parent_item,
- DERIVED_PARAM_LIST & list
- )
- {
- PresetClass *preset = Get_Item_Preset (parent_item);
- DefinitionClass *definition = preset->Get_Definition ();
- //
- // Build a list of children (derived presets)
- //
- DynamicVectorClass<HTREEITEM> child_list;
- Build_Child_List (parent_item, child_list);
- //
- // Loop over all the derived presets and build up the list
- // of non-overridden parameter values
- //
- for (int index = 0; index < child_list.Count (); index ++) {
- HTREEITEM tree_item = child_list[index];
- PresetClass *curr_preset = Get_Item_Preset (tree_item);
- DefinitionClass *curr_definition = curr_preset->Get_Definition ();
- ASSERT (curr_definition->Get_Class_ID () == definition->Get_Class_ID ());
- //
- // Build the list of parameters that are the same as the base
- //
- Compare_Derived_Parameters (curr_preset, definition, curr_definition, list);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnPlay
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnPlay (void)
- {
- HTREEITEM tree_item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (tree_item);
- if (preset != NULL && preset->Get_Definition () != NULL) {
- AudibleSoundDefinitionClass *definition = NULL;
- definition = (AudibleSoundDefinitionClass *)preset->Get_Definition ();
- //
- // Make sure we have a local copy of this sound
- //
- CString filename = definition->Get_Filename ();
- if (::Get_File_Mgr ()->Does_File_Exist (filename, true)) {
-
- //
- // Pass the sound filename onto the dialog
- //
- PlaySoundDialogClass dialog (filename, this);
- dialog.DoModal ();
- }
- }
-
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnInfo
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnInfo (void)
- {
- HTREEITEM current_item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (current_item);
- if (preset != NULL) {
- //
- // Show the (read-only) properties dialog for this preset
- //
- preset->Show_Properties (true);
- }
-
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnExtra
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnExtra (void)
- {
- //
- // Determine the screen coords of the toolbar button
- //
- CRect rect;
- m_Toolbar.GetItemRect (m_Toolbar.CommandToIndex (IDC_EXTRA), &rect);
- m_Toolbar.ClientToScreen (&rect);
- //
- // Load the menu we want to display
- //
- HMENU main_menu = ::LoadMenu (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDR_XTRA_POPUP));
- HMENU menu = ::GetSubMenu (main_menu, 0);
- //
- // Make the menu commands owner-draw so we can paint icons next to them
- //
- ::ModifyMenu (menu, IDC_PLAY, MF_BYCOMMAND | MF_OWNERDRAW, IDC_PLAY, NULL);
- ::ModifyMenu (menu, IDC_CONVERT, MF_BYCOMMAND | MF_OWNERDRAW, IDC_CONVERT, NULL);
- ::ModifyMenu (menu, IDC_UPDATE_VSS, MF_BYCOMMAND | MF_OWNERDRAW, IDC_UPDATE_VSS, NULL);
- ::ModifyMenu (menu, IDM_BATCH_IMPORT_TERRAIN, MF_BYCOMMAND | MF_OWNERDRAW, IDM_BATCH_IMPORT_TERRAIN, NULL);
- ::ModifyMenu (menu, IDM_UPDATE_EMBEDDED_NODE_LIST, MF_BYCOMMAND | MF_OWNERDRAW, IDM_UPDATE_EMBEDDED_NODE_LIST, NULL);
- ::ModifyMenu (menu, IDM_CLEAR_EMBEDDED_NODE_LIST, MF_BYCOMMAND | MF_OWNERDRAW, IDM_CLEAR_EMBEDDED_NODE_LIST, NULL);
-
- //
- // Disable any buttons if necessary
- //
- if (Enable_Button (IDC_PLAY) == false) {
- ::EnableMenuItem (menu, IDC_PLAY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
- }
- if (Enable_Button (IDC_CONVERT) == false) {
- ::EnableMenuItem (menu, IDC_CONVERT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
- }
- if (Enable_Button (IDC_UPDATE_VSS) == false) {
- ::EnableMenuItem (menu, IDC_UPDATE_VSS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
- }
- if (Enable_Button (IDM_BATCH_IMPORT_TERRAIN) == false) {
- ::EnableMenuItem (menu, IDM_BATCH_IMPORT_TERRAIN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
- }
- if (Enable_Button (IDM_UPDATE_EMBEDDED_NODE_LIST) == false) {
- ::EnableMenuItem (menu, IDM_UPDATE_EMBEDDED_NODE_LIST, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
- }
- if (Enable_Button (IDM_CLEAR_EMBEDDED_NODE_LIST) == false) {
- ::EnableMenuItem (menu, IDM_CLEAR_EMBEDDED_NODE_LIST, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
- }
- //
- // Display the menu
- //
- ::TrackPopupMenu (menu, TPM_LEFTALIGN | TPM_TOPALIGN, rect.left, rect.bottom, 0, m_hWnd, NULL);
- //
- // Cleanup
- //
- ::DestroyMenu (main_menu);
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnNotify
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL
- PresetsFormClass::OnNotify
- (
- WPARAM wParam,
- LPARAM lParam,
- LRESULT* pResult
- )
- {
- if (((NMHDR *)lParam)->code == TBN_DROPDOWN) {
- OnExtra ();
- (*pResult) = TBDDRET_DEFAULT;
- return TRUE;
- }
-
- return CDialog::OnNotify(wParam, lParam, pResult);
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdateConvert
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnUpdateConvert (CCmdUI *pCmdUI)
- {
- pCmdUI->Enable (Enable_Button (IDC_CONVERT));
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdateInfo
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnUpdateInfo (CCmdUI *pCmdUI)
- {
- pCmdUI->Enable (Enable_Button (IDC_INFO));
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdatePlay
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnUpdatePlay (CCmdUI *pCmdUI)
- {
- pCmdUI->Enable (Enable_Button (IDC_PLAY));
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdateUpdateVss
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnUpdateUpdateVss (CCmdUI *pCmdUI)
- {
- pCmdUI->Enable (Enable_Button (IDC_UPDATE_VSS));
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Get_Menu_Text
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Get_Menu_Text (int menu_id, CString &text)
- {
- switch (menu_id)
- {
- case IDC_PLAY:
- text = "Play...";
- break;
- case IDC_CONVERT:
- text = "Convert Temp...";
- break;
- case IDC_UPDATE_VSS:
- text = "Update VSS...";
- break;
- case IDM_BATCH_IMPORT_TERRAIN:
- text = "Batch Import Terrain...";
- break;
-
- case IDM_CLEAR_EMBEDDED_NODE_LIST:
- text = "Clear Embedded Node List";
- break;
- case IDM_UPDATE_EMBEDDED_NODE_LIST:
- text = "Embed Nodes...";
- break;
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnDrawItem
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnDrawItem
- (
- int nIDCtl,
- LPDRAWITEMSTRUCT lpDrawItemStruct
- )
- {
- HICON icon = NULL;
- CString text;
- Get_Menu_Text (lpDrawItemStruct->itemID, text);
- switch (lpDrawItemStruct->itemID)
- {
- case IDC_PLAY:
- icon = (HICON)::LoadImage (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDI_PLAY), IMAGE_ICON, 16, 16, LR_SHARED);
- break;
- case IDC_CONVERT:
- icon = (HICON)::LoadImage (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDI_CONVERT), IMAGE_ICON, 16, 16, LR_SHARED);
- break;
- case IDC_UPDATE_VSS:
- icon = (HICON)::LoadImage (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDI_UPDATE), IMAGE_ICON, 16, 16, LR_SHARED);
- break;
- case IDM_BATCH_IMPORT_TERRAIN:
- icon = (HICON)::LoadImage (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDI_TERRAIN), IMAGE_ICON, 16, 16, LR_SHARED);
- break;
- case IDM_UPDATE_EMBEDDED_NODE_LIST:
- icon = (HICON)::LoadImage (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDI_OBJECT), IMAGE_ICON, 16, 16, LR_SHARED);
- break;
- case IDM_CLEAR_EMBEDDED_NODE_LIST:
- icon = (HICON)::LoadImage (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDI_DELETE), IMAGE_ICON, 16, 16, LR_SHARED);
- break;
- }
- CRect rect = lpDrawItemStruct->rcItem;
- int dss_state = DSS_NORMAL;
- UINT bk_color = 0;
-
- //
- // Deteremine what background and text color to use
- //
- if (lpDrawItemStruct->itemState & ODS_GRAYED) {
- bk_color = COLOR_MENU;
- ::SetBkColor (lpDrawItemStruct->hDC, ::GetSysColor (COLOR_MENU));
- ::SetTextColor (lpDrawItemStruct->hDC, ::GetSysColor (COLOR_GRAYTEXT));
- dss_state = DSS_DISABLED;
- } else if (lpDrawItemStruct->itemState & ODS_SELECTED) {
- bk_color = COLOR_HIGHLIGHT;
- ::SetBkColor (lpDrawItemStruct->hDC, ::GetSysColor (COLOR_HIGHLIGHT));
- ::SetTextColor (lpDrawItemStruct->hDC, ::GetSysColor (COLOR_HIGHLIGHTTEXT));
- } else {
- bk_color = COLOR_MENU;
- ::SetBkColor (lpDrawItemStruct->hDC, ::GetSysColor (COLOR_MENU));
- ::SetTextColor (lpDrawItemStruct->hDC, ::GetSysColor (COLOR_MENUTEXT));
- }
- //
- // Determine the height of the text
- //
- CSize text_size;
- ::GetTextExtentPoint32 (lpDrawItemStruct->hDC, text, text.GetLength (), &text_size);
-
- //
- // Render the text
- //
- rect.top += 2;
- rect.bottom -= 2;
- ::FillRect (lpDrawItemStruct->hDC, &rect, (HBRUSH) (bk_color+1));
- ::SetBkMode (lpDrawItemStruct->hDC, TRANSPARENT);
- ::DrawState ( lpDrawItemStruct->hDC,
- NULL,
- NULL,
- (LPARAM)(LPCTSTR)text,
- 0,
- rect.left + 24,
- rect.top + (rect.Height () >> 1) - (text_size.cy >> 1),
- 0, 0, DST_TEXT | dss_state);
- //
- // Draw the associated icon (if necessary)
- //
- if (icon != NULL) {
- ::DrawState ( lpDrawItemStruct->hDC, NULL, NULL, (LPARAM)icon, 0, rect.left + 4, rect.top + 4, 16, 16, DST_ICON | dss_state);
- }
-
- CDialog::OnDrawItem (nIDCtl, lpDrawItemStruct);
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnMeasureItem
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnMeasureItem
- (
- int nIDCtl,
- LPMEASUREITEMSTRUCT lpMeasureItemStruct
- )
- {
- CString text;
- Get_Menu_Text (lpMeasureItemStruct->itemID, text);
- NONCLIENTMETRICS metrics = { sizeof (NONCLIENTMETRICS), 0 };
- ::SystemParametersInfo (SPI_GETNONCLIENTMETRICS, 0, &metrics, FALSE);
-
- HDC mem_dc = ::CreateCompatibleDC (NULL);
- HFONT font = ::CreateFontIndirect (&metrics.lfMenuFont);
- HFONT old_font = (HFONT)::SelectObject (mem_dc, font);
- CSize text_size;
- ::GetTextExtentPoint32 (mem_dc, text, text.GetLength (), &text_size);
-
- ::SelectObject (mem_dc, old_font);
- ::DeleteObject (font);
- ::DeleteDC (mem_dc);
- lpMeasureItemStruct->itemWidth = text_size.cx + 24;
- lpMeasureItemStruct->itemHeight = 24;
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnConvert
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnConvert (void)
- {
- HTREEITEM item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (item);
- if (preset != NULL) {
- //
- // Make sure the user really wants to do this...
- //
- CString message;
- message.Format ("Are you sure you wish to convert '%s' from a temporary preset to a shared preset?", preset->Get_Name ());
- if (MessageBox (message, "Preset Convert", MB_ICONQUESTION | MB_YESNO) == IDYES) {
- CWaitCursor wait_cursor;
- //
- // Check out the definition database
- //
- SelectionCaptureClass sel_capture (this);
- bool undo_check_out = false;
- uint32 class_id = preset->Get_Class_ID ();
- if (PresetMgrClass::Check_Out_Database (class_id, &undo_check_out)) {
- sel_capture.Restore ();
- item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (item);
- if (preset != NULL) {
- //
- // Change the preset's ID from temp-range to normal-range
- //
- preset->Set_IsTemporary (false);
- preset->Set_ID (DefinitionMgrClass::Get_New_ID (preset->Get_Class_ID ()));
- //
- // Now change the IDs of any embedded definition objects
- //
- Fix_Embedded_Definition_IDs (preset->Get_Definition ());
- //
- // Now save-out the databases (they have both changed)
- //
- Save_Global_Presets (class_id);
- PresetMgrClass::Add_Dirty_Preset (preset->Get_ID ());
- Save_Temp_Presets ();
- //
- // Finally change the preset's icon
- //
- int icon = Get_Icon (preset);
- m_TreeCtrl.SetItemImage (item, icon, icon);
- //
- // Force a re-paint
- //
- m_TreeCtrl.SelectItem (item);
- m_TreeCtrl.InvalidateRect (NULL, TRUE);
- } else if (undo_check_out) {
- MessageBox ("Unable to find preset.", "Preset Error", MB_ICONERROR | MB_OK);
- PresetMgrClass::Undo_Database_Check_Out (class_id);
- }
- }
- }
- }
-
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdateVss
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnUpdateVss (void)
- {
- HTREEITEM item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (item);
- if (preset != NULL) {
- //
- // Show the update-preset dialog
- //
- UpdatePresetDialogClass dialog (preset, this);
- dialog.DoModal ();
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnClearEmbeddedNodeList
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnClearEmbeddedNodeList (void)
- {
- CWaitCursor wait_cursor;
- //
- // Get the currently selected preset
- //
- HTREEITEM current_item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (current_item);
- if (preset != NULL) {
- if (preset->Get_IsTemporary () == false) {
- //
- // Check out the definition database
- //
- SelectionCaptureClass sel_capture (this);
- bool undo_on_err = false;
- uint32 class_id = preset->Get_Class_ID ();
- if (PresetMgrClass::Check_Out_Database (class_id, &undo_on_err)) {
- sel_capture.Restore ();
- //
- // Re-get the preset (its pointer has changed, the
- // old one is crap).
- //
- current_item = m_TreeCtrl.GetSelectedItem ();
- preset = Get_Item_Preset (current_item);
-
- //
- // Now, free the embedded nodes
- //
- if (preset != NULL) {
- preset->Free_Node_List ();
- Save_Global_Presets (preset->Get_Class_ID ());
- PresetMgrClass::Add_Dirty_Preset (preset->Get_ID ());
- }
- }
- } else {
-
- //
- // Free the embedded nodes
- //
- preset->Free_Node_List ();
- Save_Temp_Presets ();
- }
- Reset_Embedded_Node_Instances (preset);
- NodeMgrClass::Reload_Nodes (preset);
- if (preset != NULL) {
- //
- // Update the overlay icon on the preset
- //
- bool needs_overlay = (preset->Get_Node_List ().Count () > 0);
- TreeView_SetOverlay (m_TreeCtrl, current_item, needs_overlay);
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Reset_Embedded_Node_Instances
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Reset_Embedded_Node_Instances (PresetClass *preset)
- {
- if (preset == NULL) {
- return ;
- }
- //
- // Loop over all the nodes in the scene
- //
- for ( NodeClass *node = NodeMgrClass::Get_First ();
- node != NULL;
- node = NodeMgrClass::Get_Next (node))
- {
- //
- // If this was an embedded node, then convert it to
- // a "normal" node.
- //
- if (node->Get_Container_Preset_ID () == preset->Get_ID ()) {
- node->Set_Is_Proxied (false);
- node->Set_Needs_Save (true);
- node->Set_Container_Preset_ID (0);
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnBuildEmbedNodeList
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnBuildEmbedNodeList (void)
- {
- //
- // Prompt the user
- //
- if (::MessageBox (m_hWnd,
- "This operation will embed a copy of all the nodes in scene into this preset. Are you sure you wish to continue?",
- "Embed Nodes", MB_ICONQUESTION | MB_YESNO) == IDNO)
- {
- return ;
- }
- CWaitCursor wait_cursor;
- //
- // Get the currently selected preset
- //
- HTREEITEM current_item = m_TreeCtrl.GetSelectedItem ();
- PresetClass *preset = Get_Item_Preset (current_item);
- if (preset != NULL) {
- if (preset->Get_IsTemporary () == false) {
- //
- // Check out the definition database
- //
- SelectionCaptureClass sel_capture (this);
- bool undo_on_err = false;
- uint32 class_id = preset->Get_Class_ID ();
- if (PresetMgrClass::Check_Out_Database (class_id, &undo_on_err)) {
- sel_capture.Restore ();
- //
- // Re-get the preset (its pointer has changed, the
- // old one is crap).
- //
- current_item = m_TreeCtrl.GetSelectedItem ();
- preset = Get_Item_Preset (current_item);
-
- //
- // Now, update the embedded node information for this preset
- //
- if (preset != NULL) {
- Update_Embedded_Nodes (preset);
- Save_Global_Presets (preset->Get_Class_ID ());
- PresetMgrClass::Add_Dirty_Preset (preset->Get_ID ());
- }
- }
- } else {
-
- //
- // Update the embedded node information for this preset
- //
- Update_Embedded_Nodes (preset);
- Save_Temp_Presets ();
- }
- NodeMgrClass::Reload_Nodes (preset);
- //
- // Update the overlay icon on the preset
- //
- if (preset != NULL) {
- bool needs_overlay = (preset->Get_Node_List ().Count () > 0);
- TreeView_SetOverlay (m_TreeCtrl, current_item, needs_overlay);
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Update_Embedded_Nodes
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Update_Embedded_Nodes (PresetClass *preset)
- {
- Reset_Embedded_Node_Instances (preset);
- //
- // Loop over all the nodes in the scene
- //
- for ( NodeClass *node = NodeMgrClass::Get_First ();
- node != NULL;
- node = NodeMgrClass::Get_Next (node))
- {
- //
- // Just find the first node that came from this preset
- //
- if (node->Get_Preset () == preset) {
- break;
- }
- }
- //
- // Generate the node list
- //
- if (node != NULL) {
- preset->Build_Node_List (node);
- }
-
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnBatchImportTerrain
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnBatchImportTerrain (void)
- {
- CFileDialog dialog ( TRUE,
- ".w3d",
- NULL,
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT | OFN_EXPLORER,
- "Westwood 3D Files (*.w3d)|*.w3d||",
- this);
- TCHAR filename_list[MAX_PATH*20] = { 0 };
- dialog.m_ofn.lpstrFile = filename_list;
- dialog.m_ofn.nMaxFile = sizeof (filename_list);
- //
- // Ask the user what files they wish to import
- //
- if (dialog.DoModal () == IDOK) {
- //
- // Loop through all the selected files
- //
- POSITION pos = dialog.GetStartPosition ();
- while (pos != NULL) {
- //
- // Add this preset to the tree
- //
- Add_Terrain_Preset (dialog.GetNextPathName (pos));
- }
- //
- // Save the temp presets lib
- //
- Save_Temp_Presets ();
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdateClearEmbeddedNodeList
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnUpdateClearEmbeddedNodeList (CCmdUI *pCmdUI)
- {
- pCmdUI->Enable (Enable_Button (IDM_CLEAR_EMBEDDED_NODE_LIST));
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdateEmbeddedNodeList
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnUpdateEmbeddedNodeList (CCmdUI *pCmdUI)
- {
- pCmdUI->Enable (Enable_Button (IDM_UPDATE_EMBEDDED_NODE_LIST));
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnUpdateBatchImportTerrain
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnUpdateBatchImportTerrain (CCmdUI *pCmdUI)
- {
- pCmdUI->Enable (Enable_Button (IDM_BATCH_IMPORT_TERRAIN));
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Add_Terrain_Preset
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Add_Terrain_Preset (LPCTSTR filename)
- {
- if (::Is_W3D_Filename (filename)) {
- //
- // Make an asset name from the filename
- //
- CString preset_name = ::Asset_Name_From_Filename (filename);
- if (preset_name.GetLength () > 0) {
-
- //
- // Add the new preset
- //
- PresetClass *preset = Add_New_Preset (preset_name, true, false);
- if (preset != NULL && preset->Get_Class_ID () == CLASSID_TERRAIN) {
-
- //
- // Configure the preset
- //
- TerrainDefinitionClass *definition = (TerrainDefinitionClass *)preset->Get_Definition ();
- definition->Set_Model_Name (::Get_File_Mgr ()->Make_Relative_Path (filename));
- }
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnBegindragPresetsTree
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnBegindragPresetsTree
- (
- NMHDR * pNMHDR,
- LRESULT *pResult
- )
- {
- NM_TREEVIEW *tv_info = (NM_TREEVIEW *)pNMHDR;
- (*pResult) = 0;
- if (Is_Drag_OK (tv_info->itemNew.hItem)) {
-
- //
- // Set-up for our drag operation
- //
- m_DragItem = tv_info->itemNew.hItem;
- if (m_DragItem != NULL) {
-
- m_DragImageList = m_TreeCtrl.CreateDragImage (m_DragItem);
- m_DragImageList->BeginDrag (0, CPoint (-20, -20));
- m_IsDragging = true;
- SetCapture ();
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnLButtonUp
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnLButtonUp (UINT nFlags, CPoint point)
- {
- if (m_IsDragging) {
- //
- // Convert the tab mouse-position to the tree's mouse-position
- //
- CPoint tree_pt = point;
- ClientToScreen (&tree_pt);
- m_TreeCtrl.ScreenToClient (&tree_pt);
-
- //
- // Reset the state of the tree
- //
- CImageList::EndDrag ();
- ReleaseCapture ();
- m_TreeCtrl.SelectDropTarget (NULL);
- m_TreeCtrl.SelectItem (m_DragItem);
- //
- // Check to ensure its OK to move the preset
- //
- UINT flags = TVHT_ONITEM;
- HTREEITEM drop_target = m_TreeCtrl.HitTest (tree_pt, &flags);
- if (Is_Drop_OK (drop_target)) {
-
- //
- // Perform the move operation
- //
- m_TreeCtrl.SelectItem (drop_target);
- Do_Drop (m_DragItem, drop_target);
- }
- m_DragItem = NULL;
- m_IsDragging = false;
- }
- CDialog::OnLButtonUp (nFlags, point);
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnMouseMove
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnMouseMove (UINT nFlags, CPoint point)
- {
- if (m_IsDragging) {
-
- //
- // Convert the tab mouse-position to the tree's mouse-position
- //
- CPoint tree_pt = point;
- ClientToScreen (&tree_pt);
- m_TreeCtrl.ScreenToClient (&tree_pt);
-
- //
- // Draw the outline of the drag operation
- //
- CImageList::DragMove (tree_pt);
- m_DragImageList->DragLeave (&m_TreeCtrl);
- //
- // Determine if we should hilight one of the entries in the tree control
- //
- UINT flags = TVHT_ONITEM;
- HTREEITEM drop_target = m_TreeCtrl.HitTest (tree_pt, &flags);
- if (drop_target != NULL) {
- m_TreeCtrl.SelectDropTarget (drop_target);
- }
- m_DragImageList->DragEnter (&m_TreeCtrl, tree_pt);
- //
- // Choose a cursor
- //
- if (drop_target == NULL || Is_Drop_OK (drop_target) == false) {
- SetCursor (::LoadCursor (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDC_NODROP)));
- } else {
- SetCursor (::LoadCursor (NULL, IDC_ARROW));
- }
- }
-
- CDialog::OnMouseMove (nFlags, point);
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Is_Drag_OK
- //
- ////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Is_Drag_OK (HTREEITEM drag_item)
- {
- bool retval = false;
- PresetClass *preset = Get_Item_Preset (drag_item);
- bool read_only = ::Get_File_Mgr()->Is_VSS_Read_Only ();
- bool temp = (preset != NULL && preset->Get_IsTemporary ()) ? true : false;
- //
- // We allow the user to drag a preset if its a temp or they have write
- // access to the database.
- //
- if (preset != NULL && (read_only == false || temp == true)) {
- retval = true;
- }
- return retval;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Is_Drop_OK
- //
- ////////////////////////////////////////////////////////////////////////////
- bool
- PresetsFormClass::Is_Drop_OK (HTREEITEM drop_item)
- {
- bool retval = false;
- if (m_DragItem != NULL && drop_item != NULL) {
-
- PresetClass *drag_preset = Get_Item_Preset (m_DragItem);
- PresetClass *drop_preset = Get_Item_Preset (drop_item);
- DefinitionFactoryClass *factory = Get_Item_Factory (drop_item);
- if (drag_preset != NULL && (drop_preset != NULL || factory != NULL)) {
- //
- // Check to make sure we don't try to move a preset to one of its children
- //
- if (drop_preset == NULL || drop_preset->Is_A_Parent (drag_preset) == false) {
- //
- // Get information about what 'type' of presets these are
- //
- int drag_classid = drag_preset->Get_Class_ID ();
- int drop_classid = 0;
- if (drop_preset != NULL) {
- drop_classid = drop_preset->Get_Class_ID ();
- } else {
- drop_classid = factory->Get_Class_ID ();
- }
- //
- // Are the preset's factories the same?
- //
- if (drag_classid == drop_classid) {
- bool is_drop_temp = (drop_preset != NULL && drop_preset->Get_IsTemporary ()) ? true : false;
- bool is_drag_temp = (drag_preset != NULL && drag_preset->Get_IsTemporary ()) ? true : false;
- //
- // We allow the drop if the target is a factory, or both the drag and drops are non-temp
- //
- if (factory != NULL || is_drag_temp || is_drop_temp == false) {
- retval = true;
- }
- }
- }
- }
- }
- return retval;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Do_Drop
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Do_Drop (HTREEITEM drag_item, HTREEITEM drop_item)
- {
- CWaitCursor wait_cursor;
- PresetClass *drag_preset = Get_Item_Preset (drag_item);
- bool is_drag_temp = (drag_preset != NULL && drag_preset->Get_IsTemporary ()) ? true : false;
- //
- // Does this operation affect only shared presets or only temps?
- //
- if (is_drag_temp == false) {
- uint32 drag_preset_id = drag_preset->Get_Definition ()->Get_ID ();
- //
- // Check out the definition database
- //
- SelectionCaptureClass sel_capture (this);
- bool undo_on_err = false;
- uint32 class_id = drag_preset->Get_Class_ID ();
- if (PresetMgrClass::Check_Out_Database (class_id, &undo_on_err)) {
- sel_capture.Restore ();
- //
- // Look-up the preset tree items
- //
- drag_item = Find_Preset (TVI_ROOT, drag_preset_id);
- drop_item = m_TreeCtrl.GetSelectedItem ();
- drag_preset = Get_Item_Preset (drag_item);
- //
- // Are the drag and drop locations still valid?
- //
- if ( drag_preset != NULL &&
- drag_preset->Get_Definition ()->Get_ID () == drag_preset_id &&
- drag_item != NULL && drop_item != NULL && drag_item != drop_item)
- {
- //
- // Perform the operation and save the presets...
- //
- Move_Preset (drag_item, drop_item);
- Save_Global_Presets (class_id);
- PresetMgrClass::Add_Dirty_Preset (drag_preset->Get_ID ());
- } else {
-
- //
- // Inform the user that something has changed...
- //
- ::MessageBox ( NULL,
- "Either the drag source or the drop target no longer exists, please try again.",
- "Drag/Drop Error",
- MB_OK | MB_ICONERROR);
- if (undo_on_err) {
- PresetMgrClass::Undo_Database_Check_Out (class_id);
- }
- }
- }
- } else {
-
- //
- // Simply move the preset and save the temp library
- //
- Move_Preset (drag_item, drop_item);
- if (drag_preset != NULL) {
- Save_Temp_Presets ();
- }
- }
-
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Move_Preset
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Move_Preset (HTREEITEM preset_item, HTREEITEM parent_item)
- {
- ASSERT (preset_item != NULL);
- ASSERT (parent_item != NULL);
- PresetClass *preset = Get_Item_Preset (preset_item);
- if (preset != NULL) {
-
- //
- // Let the preset know who its new parent is
- //
- PresetClass *parent_preset = Get_Item_Preset (parent_item);
- preset->Set_Parent (parent_preset);
- if (parent_preset != NULL) {
- parent_preset->Add_Child_Preset (preset->Get_ID ());
- }
- //
- // Make a log entry about the new parent
- //
- if (preset->Get_IsTemporary () == false) {
- //
- // Get the name of the new parent
- //
- const char *parent_name = NULL;
- if (parent_preset != NULL) {
- parent_name = parent_preset->Get_Name ();
- }
- //
- // Log the operation
- //
- PresetLoggerClass::Log_Moved (preset, parent_name);
- }
- //
- // Move the tree item (and all its children)
- //
- m_TreeCtrl.SetRedraw (false);
- Copy_Preset_Items (preset_item, parent_item);
- m_TreeCtrl.DeleteItem (preset_item);
- m_TreeCtrl.SetRedraw (true);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Copy_Preset_Items
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Copy_Preset_Items (HTREEITEM preset_item, HTREEITEM parent_item)
- {
- //
- // Copy the preset to its new parent
- //
- PresetClass *preset = Get_Item_Preset (preset_item);
- HTREEITEM new_item = Insert_Preset (parent_item, preset);
- //
- // Recursive copy all child items
- //
- for ( HTREEITEM child_item = m_TreeCtrl.GetChildItem (preset_item);
- child_item != NULL;
- child_item = m_TreeCtrl.GetNextSiblingItem (child_item))
- {
- Copy_Preset_Items (child_item, new_item);
- }
- // Ensure the entries are sorted correctly
- m_TreeCtrl.SortChildren (parent_item);
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // OnDestroy
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::OnDestroy (void)
- {
- ::RemoveProp (m_TreeCtrl, "TRANS_ACCS");
- ::RemoveProp (m_hWnd, "TRANS_ACCS");
- CDialog::OnDestroy ();
- return ;
-
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Export_File_Dependencies
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Export_File_Dependencies (const char *filename)
- {
- //
- // Create the file
- //
- TextFileClass file (filename);
- if (file.Open (RawFileClass::WRITE)) {
- //
- // Build a list of all the entries in the tree
- //
- DynamicVectorClass<HTREEITEM> entry_list;
- Build_Child_List (TVI_ROOT, entry_list);
- //
- // Loop over all the presets in the list
- //
- for (int index = 0; index < entry_list.Count (); index ++) {
- PresetClass *preset = Get_Item_Preset (entry_list[index]);
- if (preset != NULL) {
- DefinitionClass *definition = preset->Get_Definition ();
- if (definition != NULL) {
-
- //
- // Generate the list of file's that this preset is dependent on
- //
- DynamicVectorClass<StringClass> file_list;
- Build_File_Dependencies_For_Definition (file_list, definition);
- //
- // If the list wasn't empty, then export the filenames to the text file.
- //
- if (file_list.Count () > 0) {
-
- //
- // Start the entry off with the name of the preset
- //
- StringClass entry;
- entry.Format ("%s\t", (const char *)definition->Get_Name ());
- //
- // Now, spit out the list of files
- //
- for (int index = 0; index < file_list.Count (); index ++) {
- entry += file_list[index];
- entry += "\t";
- }
- //
- // Add the entry to the text file
- //
- file.Write_Line (entry);
- }
- }
- }
- }
- //
- // Close the file
- //
- file.Close ();
- }
- return ;
-
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Build_File_Dependencies_For_Definition
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Build_File_Dependencies_For_Definition
- (
- DynamicVectorClass<StringClass> & file_list,
- DefinitionClass * definition
- )
- {
- //
- // Loop over all the parameters of this definition
- //
- int count = definition->Get_Parameter_Count ();
- for (int index = 0; index < count; index ++) {
- ParameterClass *parameter = definition->Lock_Parameter (index);
- //
- // Handle the different file types
- //
- if (parameter->Is_Type (ParameterClass::TYPE_FILENAME)) {
- FilenameParameterClass *filename_param = reinterpret_cast<FilenameParameterClass *> (parameter);
-
- //
- // Add the filename to the list if its not empty
- //
- StringClass filename = filename_param->Get_String ();
- if (filename.Get_Length () > 0) {
- file_list.Add (filename);
- }
- } else if (parameter->Get_Type () == ParameterClass::TYPE_MODELDEFINITIONID) {
- int def_id = ((ModelDefParameterClass *)parameter)->Get_Value ();
-
- //
- // Recurse into the model's definition (if necessary)
- //
- DefinitionClass *model_definition = DefinitionMgrClass::Find_Definition (def_id, false);
- if (model_definition != NULL) {
- Build_File_Dependencies_For_Definition (file_list, model_definition);
- }
- } else if (parameter->Get_Type () == ParameterClass::TYPE_PHYSDEFINITIONID) {
- int def_id = ((PhysDefParameterClass *)parameter)->Get_Value ();
- //
- // Recurse into the physic object's definition (if necessary)
- //
- DefinitionClass *phys_definition = DefinitionMgrClass::Find_Definition (def_id, false);
- if (phys_definition != NULL) {
- Build_File_Dependencies_For_Definition (file_list, phys_definition);
- }
- }
- definition->Unlock_Parameter (index);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Add_Preset
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Add_Preset (PresetClass *preset)
- {
- uint32 class_id = preset->Get_Class_ID ();
- //
- // Find the root item
- //
- HTREEITEM root_item = Find_Factory (TVI_ROOT, class_id);
- if (root_item != NULL) {
-
- //
- // Add the preset to the tree
- //
- Insert_Preset (root_item, preset);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Sort_Items
- //
- ////////////////////////////////////////////////////////////////////////////
- void
- PresetsFormClass::Sort_Items (uint32 class_id)
- {
- //
- // Find the root item
- //
- HTREEITEM root_item = Find_Factory (TVI_ROOT, class_id);
- if (root_item != NULL) {
- //
- // Sort all items under this root
- //
- m_TreeCtrl.SetRedraw (FALSE);
- Sort_Nodes (root_item);
- m_TreeCtrl.SetRedraw (TRUE);
- }
- return ;
- }
|