| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429 |
- from PandaObject import *
- from PieMenu import *
- from OnscreenText import *
- from whrandom import *
- from Tkinter import *
- from DirectGeometry import *
- from SceneGraphExplorer import *
- from tkSimpleDialog import askstring
- from tkFileDialog import *
- import Pmw
- import Dial
- import Floater
- import EntryScale
- import VectorWidgets
- import string
- class LevelEditor(NodePath, PandaObject):
- def __init__(self,direct,parent = None):
- # Initialize superclass
- NodePath.__init__(self)
- self.assign(hidden.attachNewNode( NamedNode('LevelEditor')))
- # Record handle to direct session
- self.direct = direct
- # Make sure direct is running
- self.direct.enable()
- self.direct.widget.disableHandles(['x-ring', 'x-disc',
- 'y-ring', 'y-disc',
- 'z-post'])
- # Create level editor dictionaries
- # This dictionary stores information about new objects added
- # to the level
- self.levelDictionary = {}
- # This dictionary stores information about module hooks,
- # grouped by level
- self.hooksDictionary = {}
- # This dictionary stores information about the various
- # pie menus in use
- self.pieMenuDictionary = {}
- # This dictionary stores all the different color palettes
- self.colorPaletteDictionary = {}
- # This dictionary stores info about current and possible
- # object attributes
- self.attributeDictionary = {}
- # This dictionary stores pleasing style combinations
- self.styleDictionary = {}
- # This dictionary stores pointers to the various maps
- self.mapDictionary = {}
- self.activeMap = None
- # DNAStorage instance for storing level DNA info
- self.dnaStore = DNAStorage()
- loadDNAFile(self.dnaStore, 'dna/storage.dna',
- getDefaultCoordinateSystem())
- self.dnaOutputDir = 'ToontownCentral'
- self.dnaOutputFile = 'toontown_working.dna'
- # Top level DNA Data Object
- self.levelObjectsDNA = DNAData('LevelObjects')
- # Create top level node
- self.levelObjects = self.attachNewNode(NamedNode('LevelObjects'))
- # Create a top level group
- self.createTopLevelGroup()
- # Set used to iterate over module categories
- self.categorySet = []
- self.selectedLevelObject = None
- self.targetDNAObject = None
- self.activeMenu = None
- # Get a handle to the grid
- self.grid = self.direct.grid
- self.showGrid(0)
- self.levelMap = hidden.attachNewNode(NamedNode('level-map'))
- map = loader.loadModel('level_editor/toontown_central_layout')
- map.getBottomArc().setTransition(TransparencyTransition(1))
- map.setColor(Vec4(1,1,1,.4))
- self.mapDictionary['toontownCentral'] = map
- map = loader.loadModel('level_editor/donalds_dock_layout')
- map.getBottomArc().setTransition(TransparencyTransition(1))
- map.setColor(Vec4(1,1,1,.4))
- self.mapDictionary['donaldsDock'] = map
- map = loader.loadModel('level_editor/minnies_melody_land_layout')
- map.getBottomArc().setTransition(TransparencyTransition(1))
- map.setColor(Vec4(1,1,1,.4))
- self.mapDictionary['minniesMelodyLand'] = map
- map = loader.loadModel('level_editor/the_burrrgh_layout')
- map.getBottomArc().setTransition(TransparencyTransition(1))
- map.setColor(Vec4(1,1,1,.4))
- self.mapDictionary['theBurrrgh'] = map
- self.hitPt = Point3(0)
- self.offset = Point3(0)
- self.crankOrigin = Point3(0)
- self.crankDir = Vec3(0)
- self.hprSnap = 1
- self.snapAngle = 15.0
- self.lastAngle = 0.0
- # Create Level Editor Panel and pie menus
- # Initialize styles
- self.initializeStyleDictionary()
- # Initialize pie Menus (this depends on the style dictionary)
- self.initializePieMenus()
- self.panel = LevelEditorPanel(self, parent)
- base.cam.node().setNear(5.0)
- base.cam.node().setFar(10000)
- self.direct.camera.setPos(0,-10,10)
- # Default is to use the toontown central color palette
- self.editToontownCentral()
- self.enable()
- def initializeAttributeDictionary(self):
- # Retrieve lists of available attributes from DNAStorage object
- # Cornices
- attributeList = self.getCatalogCodesSuffix('cornice', '_ur')
- # Make the first one a null texture
- attributeList[:0] = [None]
- self.attributeDictionary['corniceTextures'] = attributeList
- self.attributeDictionary['corniceTexture'] = attributeList[1]
- self.attributeDictionary['corniceOrienation'] = '_ur'
- # Doors
- attributeList = self.getCatalogCodesSuffix('door', '_ur')
- self.attributeDictionary['doorTextures'] = attributeList
- self.attributeDictionary['doorTexture'] = attributeList[1]
- self.attributeDictionary['doorOrienation'] = '_ur'
- # FlatBuildings
- self.attributeDictionary['buildingHeight'] = 20.0
- # Props
- attributeList = self.getCatalogCodes('prop')
- self.attributeDictionary['propTypes'] = attributeList
- self.attributeDictionary['propType'] = attributeList[1]
- # Walls
- attributeList = self.getCatalogCodesSuffix('wall', '_ur')
- self.attributeDictionary['wallTextures'] = attributeList
- self.attributeDictionary['wallTexture'] = attributeList[1]
- self.attributeDictionary['wallOrienation'] = '_ur'
- self.attributeDictionary['wallWidth'] = 15.0
- # Windows
- attributeList = self.getCatalogCodesSuffix('window', '_ur')
- self.attributeDictionary['windowTextures'] = attributeList
- self.attributeDictionary['windowTexture'] = attributeList[1]
- self.attributeDictionary['windowOrienation'] = '_ur'
- self.attributeDictionary['numWindows'] = 0
- def getActiveColor(self):
- return self.attributeDictionary['activeColor']
- def setActiveColor(self, color):
- self.attributeDictionary['activeColor'] = color
- def getBuildingHeight(self):
- return self.attributeDictionary['buildingHeight']
- def setBuildingHeight(self, height):
- self.attributeDictionary['buildingHeight'] = height
- def getCategorySet(self):
- return self.categorySet
- def getCorniceColor(self):
- return self.attributeDictionary['corniceColor']
- def getCorniceColors(self):
- return self.attributeDictionary['corniceColors']
- def getCorniceTexture(self):
- return self.attributeDictionary['corniceTexture']
- def setCorniceTexture(self, dnaString):
- self.attributeDictionary['corniceTexture'] = dnaString
- def getCorniceTextures(self):
- return self.attributeDictionary['corniceTextures']
- def getDnaStore(self):
- return self.dnaStore
- def getDoorColor(self):
- return self.attributeDictionary['doorColor']
- def getDoorColors(self):
- return self.attributeDictionary['doorColors']
- def getDoorTexture(self):
- return self.attributeDictionary['doorTexture']
- def setDoorTexture(self,dnaString):
- self.attributeDictionary['doorTexture'] = dnaString
- def getDoorTextures(self):
- return self.attributeDictionary['doorTextures']
- def getGrid(self):
- return self.grid
- def getGroupNum(self):
- return self.groupNum
- def setGroupNum(self,num):
- self.groupNum = num
- def setGroupParentToSelected(self):
- if self.direct.selected.last:
- self.setGroupParent(self.direct.selected.last)
-
- def setGroupParent(self,nodePath):
- parentDNA = self.getDNAGroup(nodePath)
- if parentDNA:
- self.groupParent = nodePath
- self.groupParentDNA = parentDNA
- def getHooksDictionary(self):
- return self.hooksDictionary
- def getLevelDictionary(self):
- return self.levelDictionary
- def getLevelMap(self):
- return self.levelMap
-
- def getLevelObjects(self):
- return self.levelObjects
-
- def getLevelObjectsDNA(self):
- return self.levelObjectsDNA
-
- def getNumWindows(self):
- return self.attributeDictionary.get('numWindows', 0)
-
- def setNumWindows(self, numWindows):
- self.attributeDictionary['numWindows'] = numWindows
-
- def printWallStyle(self):
- if self.selectedLevelObject:
- dnaObject = self.selectedLevelObject['DNA']
- objectClass = dnaObject.__class__.getClassType()
- if objectClass.eq(DNAFlatBuilding.getClassType()):
- self.printWallStyleFor(dnaObject)
-
- def printWallStyleFor(self, DNAFlatBuilding):
- wall = self.getLastWall(DNAFlatBuilding)
- cornice = self.getCornice(DNAFlatBuilding)
- self.printWallStyleWith(wall, cornice)
- def printWallStyleWith(self, wall, cornice):
- if wall:
- print 'self.addStyle(styleCount = styleCount + 1)'
- print 'wallTexture: ', self.getDNAString(wall)
- print 'wallColor: #(', wall.getColor(), ')'
- window = self.getWindow(wall,0)
- if window & (window.getWindowCount() > 0):
- print 'windowTexture: ', self.getDNAString(window)
- print 'windowColor: #(', window.getColor(), ')'
- else:
- print 'windowTexture: None'
- print 'windowColor: None'
- if cornice:
- print 'corniceTexture: ', self.getDNAString(cornice)
- print 'corniceColor: #(', cornice.getColor(), ')'
- else:
- print'corniceTexture: None'
- print'corniceColor: None'
- def printWallStyleForBldgWall(self, aDNAFlatBuilding, wallNum):
- if (aDNAFlatBuilding.getClassType().eq(DNAFlatBuilding.getClassType())):
- wall = self.getWall(aDNAFlatBuilding, wallNum)
- cornice = self.getCornice(aDNAFlatBuilding)
- self.printWallStyleWith(wall,cornice)
- def getPropType(self):
- return self.attributeDictionary['propType']
- def setPropType(self,dnaString):
- self.attributeDictionary['propType'] = dnaString
- def getPropTypes(self):
- return self.attributeDictionary['propTypes']
- def getSelectedLevelObject(self):
- return self.selectedLevelObject
- def getSnapAngle(self):
- return self.grid.getSnapAngle()
- def setSnapAngle(self, aFloat):
- self.grid.setSnapAngle(aFloat)
- def getWallColor(self):
- return self.attributeDictionary['wallColor']
- def setWallColor(self,aColor):
- self.attributeDictionary['wallColor'] = aColor
- def getWallColors(self):
- return self.attributeDictionary['wallColors']
- def getWallMenu(self):
- return wallMenu
- def getWallTexture(self):
- return self.attributeDictionary['wallTexture']
- def setWallTexture(self, texture):
- self.attributeDictionary['wallTexture'] = texture
- def getWallTextureDNA(self, dnaString):
- self.attributeDictionary['wallTexture'] = dnaString
- def getWallTextures(self):
- return self.attributeDictionary['wallTextures']
- def getWallWidth(self):
- return self.attributeDictionary['wallWidth']
- def setWallWidthVal(self,aFloat):
- self.attributeDictionary['wallWidth'] = aFloat
- def setWallWidthString(self, width):
- if width == 'fiveFt':
- self.setWallWidthVal(5.0)
- elif width == 'tenFt':
- self.setWallWidthVal(10.0)
- elif width == 'fifteenFt':
- self.setWallWidthVal(10.0)
- elif width == 'twentyFt':
- self.setWallWidthVal(10.0)
- elif width == 'twentyFiveFt':
- self.setWallWidthVal(10.0)
- def getWindowColor(self):
- return self.attributeDictionary['windowColor']
- def getWindowColors(self):
- return self.attributeDictionary['windowColors']
- def getWindowTexture(self):
- return self.attributeDictionary['windowTexture']
- def setWindowTexture(self,dnaString):
- self.attributeDictionary['windowTexture'] = dnaString
- def getWindowTextures(self):
- return self.attributeDictionary['windowTextures']
- def destroy(self):
- self.disable()
- self.removeNode()
- def disable(self):
- self.direct.deselectAll()
- self.reparentTo(hidden)
- self.hide()
- self.grid.ignore('insert')
- self.ignore('selectedNodePath')
- self.ignore('preRemoveNodePath')
- self.ignore('toggleMapViz')
- self.ignore('reparentNodePath')
- self.ignore('createNewLevelGroup')
- self.ignore('setNodePathName')
- self.ignore('manipulateObjectCleanup')
- self.ignore('SGESelectNodePath')
- self.ignore('SGEIsolateNodePath')
- self.ignore('SGEToggle VizNodePath')
- self.ignore('SGESet ParentNodePath')
- self.ignore('SGEAdd GroupNodePath')
- self.ignore('showAll')
- self.ignore('p')
- self.disableManipulation()
- def disableManipulation(self):
- # Disable handling of mouse events
- self.ignore('handleMouse3')
- self.ignore('handleMouse3Up')
- def editToontownCentral(self):
- self.levelMap.setPos(0.0,0.0,0.0)
- self.showMap('toontownCentral')
- self.useToontownCentralColors()
- self.styleDictionary = (
- self.attributeDictionary['toontownCentralStyleDictionary'])
- self.pieMenuDictionary['styleMenu'] = (
- self.pieMenuDictionary['toontownCentralStyleMenu'])
- self.attributeDictionary['streetTexture'] = 'street_street_tex'
- self.attributeDictionary['sidewalkTexture'] = 'street_sidewalk_tex'
- self.dnaOutputDir = 'ToontownCentral'
- self.dnaOutputFile = 'toontown_central_working.dna'
- self.panel.editMenu.selectitem('Toontown Central')
- def editDonaldsDock(self):
- self.levelMap.setPos(0.0,0.0,0.0)
- self.showMap('donaldsDock')
- self.useDonaldsDockColors()
- self.styleDictionary = (
- self.attributeDictionary['donaldsDockStyleDictionary'])
- self.pieMenuDictionary['styleMenu'] = (
- self.pieMenuDictionary['donaldsDockStyleMenu'])
- self.attributeDictionary['streetTexture'] = 'street_street_dock_tex'
- self.attributeDictionary['sidewalkTexture'] = (
- 'street_sidewalk_dock_tex')
- self.dnaOutputDir = 'DonaldsDock'
- self.dnaOutputFile = 'donalds_dock_working.dna'
- self.panel.editMenu.selectitem('Donalds Dock')
- def editMinniesMelodyLand(self):
- self.levelMap.setPos(0.0,0.0,0.0)
- self.showMap('minniesMelodyLand')
- self.useMinniesMelodyLandColors()
- self.styleDictionary = (
- self.attributeDictionary['minniesMelodyLandStyleDictionary'])
- self.pieMenuDictionary['styleMenu'] = (
- self.pieMenuDictionary['minniesMelodyLandStyleMenu'])
- self.attributeDictionary['streetTexture'] = 'street_street_dock_tex'
- self.attributeDictionary['sidewalkTexture'] = (
- 'street_sidewalk_dock_tex')
- self.dnaOutputDir = 'MinniesMelodyLand'
- self.dnaOutputFile = 'minnies_melody_land_working.dna'
- self.panel.editMenu.selectitem('Minnies Melody Land')
- def editTheBurrrgh(self):
- self.levelMap.setPos(0.0,0.0,0.0)
- self.showMap('theBurrrgh')
- self.useTheBurrrghColors()
- self.styleDictionary = (
- self.attributeDictionary['theBurrrghStyleDictionary'])
- self.pieMenuDictionary['styleMenu'] = (
- self.pieMenuDictionary['theBurrrghStyleMenu'])
- self.attributeDictionary['streetTexture'] = 'street_street_dock_tex'
- self.attributeDictionary['sidewalkTexture'] = (
- 'street_sidewalk_dock_tex')
- self.dnaOutputDir = 'TheBurrrgh'
- self.dnaOutputFile = 'the_burrrgh_working.dna'
- self.panel.editMenu.selectitem('The Burrrgh')
- def showMap(self, mapName):
- if self.activeMap:
- self.activeMap.reparentTo(hidden)
- self.activeMap = self.mapDictionary[mapName]
- self.activeMap.reparentTo(self.levelMap)
- def enable(self):
- self.reparentTo(render)
- self.show()
- self.accept('selectedNodePath', self.selectDNARoot)
- self.accept('preRemoveNodePath', self.preRemoveNodePath)
- self.accept('toggleMapViz', self.toggleMapViz)
- self.accept('reparentNodePath', self.reparentNodePath)
- self.accept('createNewLevelGroup', self.createNewLevelGroup)
- self.accept('setNodePathName', self.setNodePathName)
- self.accept('manipulateObjectCleanup', self.updateSelectedPose)
- self.accept('SGESelectNodePath', self.selectNodePath)
- #self.accept('SGESelectNodePath', self.flashNodePath)
- self.accept('SGEFlashNodePath', self.flashNodePath)
- self.accept('SGEIsolateNodePath', self.isolateNodePath)
- self.accept('SGEToggle VizNodePath', self.toggleNodePathViz)
- self.accept('SGESet ParentNodePath', self.setGroupParent)
- self.accept('SGEAdd GroupNodePath', self.addGroupToSelected)
- self.accept('showAll', self.showAll)
- self.accept('p',self.plantSelectedNodePath)
- self.enableManipulation()
- def enableManipulation(self):
- # Enable interactive placement of a nodePath
- # Turn off camera control
- base.disableMouse()
- # Handle mouse events for pie menus
- self.accept('handleMouse3',self.levelHandleMouse3)
- self.accept('handleMouse3Up',self.levelHandleMouse3Up)
- def useDriveMode(self):
- pos = base.camera.getPos()
- pos.setZ(4.0)
- hpr = base.camera.getHpr()
- hpr.set(hpr[0], 0.0, 0.0)
- t = base.camera.lerpPosHpr(pos, hpr, 1.0, blendType = 'easeInOut',
- task = 'manipulateCamera')
- # Note, if this dies an unatural death, this could screw things up
- t.uponDeath = self.switchToDriveMode
- def switchToDriveMode(self,state):
- self.direct.minimumConfiguration()
- self.disableManipulation()
- base.useDrive()
- # Make sure we're where we want to be
- pos = base.camera.getPos()
- pos.setZ(4.0)
- hpr = base.camera.getHpr()
- hpr.set(hpr[0], 0.0, 0.0)
- # Fine tune the drive mode
- base.mouseInterface.getBottomNode().setPos(pos)
- base.mouseInterface.getBottomNode().setHpr(hpr)
- base.mouseInterface.getBottomNode().setForwardSpeed(20.0)
- base.mouseInterface.getBottomNode().setReverseSpeed(20.0)
- def useDirectFly(self):
- base.disableMouse()
- self.enableManipulation()
- self.direct.enable()
- def useToontownCentralColors(self):
- self.attributeDictionary['wallColors'] = (
- self.colorPaletteDictionary['toontownCentralWallColors'])
- self.attributeDictionary['wallColor'] = (
- self.attributeDictionary['wallColors'][1])
- self.pieMenuDictionary['wallColorMenu'] = (
- self.pieMenuDictionary['toontownCentralWallColors'])
- self.attributeDictionary['windowColors'] = (
- self.colorPaletteDictionary['toontownCentralWindowColors'])
- self.attributeDictionary['windowColor'] = (
- self.attributeDictionary['windowColors'][1])
- self.pieMenuDictionary['windowColorMenu'] = (
- self.pieMenuDictionary['toontownCentralWindowColors'])
- self.attributeDictionary['doorColors'] = (
- self.colorPaletteDictionary['toontownCentralDoorColors'])
- self.attributeDictionary['doorColor'] = (
- self.attributeDictionary['doorColors'][1])
- self.pieMenuDictionary['doorColorMenu'] = (
- self.pieMenuDictionary['toontownCentralDoorColors'])
- self.attributeDictionary['corniceColors'] = (
- self.colorPaletteDictionary['toontownCentralCorniceColors'])
- self.attributeDictionary['corniceColor'] = (
- self.attributeDictionary['corniceColors'][1])
- self.pieMenuDictionary['corniceColorMenu'] = (
- self.pieMenuDictionary['toontownCentralCorniceColors'])
- def useDonaldsDockColors(self):
- self.attributeDictionary['wallColors'] = (
- self.colorPaletteDictionary['donaldsDockWallColors'])
- self.attributeDictionary['wallColor'] = (
- self.attributeDictionary['wallColors'][1])
- self.pieMenuDictionary['wallColorMenu'] = (
- self.pieMenuDictionary['donaldsDockWallColors'])
- self.attributeDictionary['windowColors'] = (
- self.colorPaletteDictionary['donaldsDockWindowColors'])
- self.attributeDictionary['windowColor'] = (
- self.attributeDictionary['windowColors'][1])
- self.pieMenuDictionary['windowColorMenu'] = (
- self.pieMenuDictionary['donaldsDockWindowColors'])
- self.attributeDictionary['doorColors'] = (
- self.colorPaletteDictionary['donaldsDockDoorColors'])
- self.attributeDictionary['doorColor'] = (
- self.attributeDictionary['doorColors'][1])
- self.pieMenuDictionary['doorColorMenu'] = (
- self.pieMenuDictionary['donaldsDockDoorColors'])
- self.attributeDictionary['corniceColors'] = (
- self.colorPaletteDictionary['donaldsDockCorniceColors'])
- self.attributeDictionary['corniceColor'] = (
- self.attributeDictionary['corniceColors'][1])
- self.pieMenuDictionary['corniceColorMenu'] = (
- self.pieMenuDictionary['donaldsDockCorniceColors'])
- def useTheBurrrghColors(self):
- self.attributeDictionary['wallColors'] = (
- self.colorPaletteDictionary['theBurrrghWallColors'])
- self.attributeDictionary['wallColor'] = (
- self.attributeDictionary['wallColors'][1])
- self.pieMenuDictionary['wallColorMenu'] = (
- self.pieMenuDictionary['theBurrrghWallColors'])
- self.attributeDictionary['windowColors'] = (
- self.colorPaletteDictionary['theBurrrghWindowColors'])
- self.attributeDictionary['windowColor'] = (
- self.attributeDictionary['windowColors'][1])
- self.pieMenuDictionary['windowColorMenu'] = (
- self.pieMenuDictionary['theBurrrghWindowColors'])
- self.attributeDictionary['doorColors'] = (
- self.colorPaletteDictionary['theBurrrghDoorColors'])
- self.attributeDictionary['doorColor'] = (
- self.attributeDictionary['doorColors'][1])
- self.pieMenuDictionary['doorColorMenu'] = (
- self.pieMenuDictionary['theBurrrghDoorColors'])
- self.attributeDictionary['corniceColors'] = (
- self.colorPaletteDictionary['theBurrrghCorniceColors'])
- self.attributeDictionary['corniceColor'] = (
- self.attributeDictionary['corniceColors'][1])
- self.pieMenuDictionary['corniceColorMenu'] = (
- self.pieMenuDictionary['theBurrrghCorniceColors'])
- def useMinniesMelodyLandColors(self):
- self.attributeDictionary['wallColors'] = (
- self.colorPaletteDictionary['minniesMelodyLandWallColors'])
- self.attributeDictionary['wallColor'] = (
- self.attributeDictionary['wallColors'][1])
- self.pieMenuDictionary['wallColorMenu'] = (
- self.pieMenuDictionary['minniesMelodyLandWallColors'])
- self.attributeDictionary['windowColors'] = (
- self.colorPaletteDictionary['minniesMelodyLandWindowColors'])
- self.attributeDictionary['windowColor'] = (
- self.attributeDictionary['windowColors'][1])
- self.pieMenuDictionary['windowColorMenu'] = (
- self.pieMenuDictionary['minniesMelodyLandWindowColors'])
- self.attributeDictionary['doorColors'] = (
- self.colorPaletteDictionary['minniesMelodyLandDoorColors'])
- self.attributeDictionary['doorColor'] = (
- self.attributeDictionary['doorColors'][1])
- self.pieMenuDictionary['doorColorMenu'] = (
- self.pieMenuDictionary['minniesMelodyLandDoorColors'])
- self.attributeDictionary['corniceColors'] = (
- self.colorPaletteDictionary['minniesMelodyLandCorniceColors'])
- self.attributeDictionary['corniceColor'] = (
- self.attributeDictionary['corniceColors'][1])
- self.pieMenuDictionary['corniceColorMenu'] = (
- self.pieMenuDictionary['minniesMelodyLandCorniceColors'])
- def addCollisionSphere(self):
- sphere = self.vizRegion.attachNewNode(NamedNode('vizSphere'))
- instance = self.vizSphere.instanceTo(sphere)
- instance.setScale(20.0 * math.sqrt(2))
- if (self.vizRegion.getNumChildren() > 1):
- sphere.setPos(vizRegion.getChild(vizRegion.getNumChildren() - 2),
- 40.0,0.0,0.0)
- else:
- sphere.setPos(0,0,0)
- self.selectNodePath(sphere)
- def addVizRegion(self):
- self.vizRegionCount = self.vizRegionCount + 1
- self.vizRegion = self.vizObjects.attachNewNode(
- NamedNode('vizRegion' + `self.vizRegionCount`))
- self.addCollisionSphere()
- # Start with region selected
- self.selectNodePath(vizRegion)
- def setHprSnap(self,flag):
- self.hprSnap = flag
- def isolateSelectedNodePath(self):
- if self.direct.selected.last:
- self.isolateNodePath(self.direct.selected.last)
-
- def isolateNodePath(self,aNodePath):
- # First show everything in level
- self.levelObjects.showAllDescendants()
- render.hideCollisionSolids()
- aNodePath.hideSiblings()
- def selectDNARoot(self, aNodePath):
- # If this isn't a root object see if one exists above it
- if (aNodePath.getName()[-8:] != '_DNARoot'):
- dnaRoot = self.getDNARoot(aNodePath)
- # Is this a DNA object?
- if dnaRoot:
- # Yes! Select root
- self.direct.select(dnaRoot)
- def getDNARoot(self, aNodePath):
- if not aNodePath.hasParent():
- return 0
- name = aNodePath.getName()
- if (name[-8:] == '_DNARoot'):
- return aNodePath
- else:
- return self.getDNARoot(aNodePath.getParent())
- def updateSelectedPose(self):
- # Move grid to line up with object
- for selectedNode in self.direct.selected:
- if self.levelDictionary.has_key(selectedNode.id()):
- # First snap to grid
- pos = selectedNode.getPos(self.grid)
- snapPos = self.grid.computeSnapPoint(pos)
- selectedNode.setPos(self.grid, snapPos[0], snapPos[1], 0)
- # Angle snap
- self.lastAngle = self.grid.computeSnapAngle(
- selectedNode.getH(self.grid))
- selectedNode.setH(self.grid, self.lastAngle)
- # Update DNA
- self.updateDNAPosHpr(selectedNode)
- # If this node is the last selected reposition grid
- if selectedNode == self.direct.selected.last:
- # Position grid for placing next object
- self.autoPositionGrid()
-
- def levelHandleMouse3(self):
- # If nothing selected, just return
- if not self.direct.selected.last:
- return
- # Otherwise, find its dictionary entry
- self.selectedLevelObject = (
- self.getLevelObject(self.direct.selected.last))
- # If not None, determine interaction type
- if self.selectedLevelObject:
- selectedObjectDNA = self.selectedLevelObject['DNA']
- # Default target/menu
- target = None
- menuType = None
- # Interaction type depends on selected object's class
- objClass = selectedObjectDNA.__class__.getClassType()
- if objClass.eq(DNAFlatBuilding.getClassType()):
- # Where are we hitting the building?
- hitPt = self.getWallIntersectionPoint()
- if hitPt:
- xPt = hitPt[0]
- zPt = hitPt[2]
- # Which wall are we pointing at (if any)
- wallNum = self.getWallNum(selectedObjectDNA, zPt)
- # How wide is the selected wall?
- wallWidth = selectedObjectDNA.getWidth()
- # Menu mode depends on where we are pointing
- if (zPt > self.getWallHeights(selectedObjectDNA)[-1:][0]):
- menuMode = 'cornice'
- else:
- if (xPt < 0.0):
- menuMode = 'window'
- elif (xPt > wallWidth):
- menuMode = 'misc'
- elif ((xPt >= 0.0) & (xPt <= wallWidth)):
- menuMode = 'wall'
- if menuMode == 'wall':
- if wallNum != -1:
- selectedWall = (
- self.getWall(selectedObjectDNA, wallNum))
- # Default is wall type menu
- menuType = 'style'
- target = selectedWall
- # If shift, switch wall texture
- if self.direct.fShift:
- menuType = 'wall'
- # If alt, switch to wall orientation menu
- if self.direct.fAlt:
- menuType = 'orientation'
- # If control, switch to wall color menu
- if self.direct.fControl:
- menuType = 'wallColor'
- else:
- target = None
- elif menuMode == 'window':
- if wallNum != -1:
- selectedWall = (
- self.getWall(selectedObjectDNA, wallNum))
- # Default is window type menu
- menuType = 'window'
- target = self.getWindow(selectedWall,0)
- # If alt, switch to window orientation menu
- if self.direct.fAlt:
- menuType = 'upOrientation'
- if self.direct.fShift:
- menuType = 'numWindows'
- target = selectedWall
- if self.direct.fControl:
- menuType = 'windowColor'
- elif menuMode == 'cornice':
- menuType = 'cornice'
- target = self.getCornice(selectedObjectDNA)
- if self.direct.fAlt:
- menuType = 'upOrientation'
- if self.direct.fControl:
- menuType = 'corniceColor'
- elif menuMode == 'misc':
- menuType = 'wallWidth'
- target = selectedObjectDNA
- else:
- target = None
- elif objClass.eq(DNALandmarkBuilding.getClassType()):
- menuType = 'door'
- target = self.getDoor(selectedObjectDNA)
- if self.direct.fAlt:
- menuType = 'upOrientation'
- if self.direct.fControl:
- menuType = 'doorColor'
- elif objClass.eq(DNAProp.getClassType()):
- menuType = 'propType'
- target = selectedObjectDNA
- if self.direct.fControl:
- menuType = 'propColor'
- # Now spawn apropriate menu task
- if ((target != None) | (menuType == 'cornice')):
- self.spawnMenuTask(menuType, target)
- def levelHandleMouse3Up(self):
- if self.activeMenu:
- self.activeMenu.removePieMenuTask()
- def flashNodePath(self, aNodePath):
- taskMgr.removeTasksNamed('flashNodePath')
- t = Task.Task(self.flashNodePathTask)
- t.aNodePath = aNodePath
- t.initState = t.hidden = aNodePath.isHidden()
- t.flashCount = 0
- t.frameCount = 0
- t.uponDeath = self.preSelectDone
- taskMgr.spawnTaskNamed(t, 'flashNodePath')
- def flashNodePathTask(self, state):
- aNodePath = state.aNodePath
- initState = state.initState
- hidden = state.hidden
- flashCount = state.flashCount
- frameCount = state.frameCount
- if (flashCount < 4):
- if (frameCount % 3) == 0:
- if hidden:
- aNodePath.show()
- else:
- aNodePath.hide()
- state.hidden = not state.hidden
- state.flashCount = flashCount + 1
- state.frameCount = frameCount + 1
- return Task.cont
- else:
- return Task.done
- def preSelectDone(self,state):
- if state.initState:
- state.aNodePath.hide()
- else:
- state.aNodePath.show()
- def showAll(self):
- self.levelObjects.showAllDescendants()
- render.hideCollisionSolids()
- def showGrid(self,flag):
- if flag:
- self.grid.enable()
- else:
- self.grid.disable()
-
- def spawnMenuTask(self, menu, aDNAObject):
- # Record the starting window code and targetDNAObject
- # This will be used by pieMenu action selector
- self.targetDNAObject = aDNAObject
- # Update panel's color if appropriate
- if aDNAObject:
- targetClass = self.targetDNAObject.__class__.getClassType()
- if ((targetClass.eq(DNAWall.getClassType())) |
- (targetClass.eq(DNAWindows.getClassType())) |
- (targetClass.eq(DNACornice.getClassType()))):
- self.panel.setCurrentColor(self.targetDNAObject.getColor())
-
- # What kind of menu is it?
- if menu == 'wall':
- self.activeMenu = self.pieMenuDictionary['wallMenu']
- state = self.getDNAString(aDNAObject)
- elif menu == 'window':
- self.activeMenu = self.pieMenuDictionary['windowMenu']
- state = self.getDNAString(aDNAObject)
- elif menu == 'orientation':
- self.activeMenu = self.pieMenuDictionary['orientationMenu']
- dnaString = self.getDNAString(aDNAObject)
- state = dnaString[-3:]
- elif menu == 'upOrientation':
- self.activeMenu = self.pieMenuDictionary['upOrientationMenu']
- if aDNAObject:
- dnaString = self.getDNAString(aDNAObject)
- state = dnaString[-3:]
- else:
- state = None
- elif menu == 'numWindows':
- self.activeMenu = self.pieMenuDictionary['numWindowsMenu']
- state = self.getWindow(aDNAObject, 0).getWindowCount()
- elif menu == 'cornice':
- self.activeMenu = self.pieMenuDictionary['corniceMenu']
- if aDNAObject:
- state = self.getDNAString(aDNAObject)
- else:
- state = None
- elif menu == 'door':
- self.activeMenu = self.pieMenuDictionary['doorMenu']
- state = self.getDNAString(aDNAObject)
- elif menu == 'wallWidth':
- self.activeMenu = self.pieMenuDictionary['wallWidthMenu']
- state = aDNAObject.getWidth()
- elif menu == 'wallColor':
- self.activeMenu = self.pieMenuDictionary['wallColorMenu']
- self.activeColors = self.getWallColors()
- state = aDNAObject.getColor()
- elif menu == 'windowColor':
- self.activeMenu = self.pieMenuDictionary['windowColorMenu']
- self.activeColors = self.getWindowColors()
- state = aDNAObject.getColor()
- elif menu == 'doorColor':
- self.activeMenu = self.pieMenuDictionary['doorColorMenu']
- self.activeColors = self.getDoorColors()
- state = aDNAObject.getColor()
- elif menu == 'corniceColor':
- self.activeMenu = self.pieMenuDictionary['corniceColorMenu']
- self.activeColors = self.getCorniceColors()
- state = aDNAObject.getColor()
- elif menu == 'propColor':
- self.activeMenu = self.pieMenuDictionary['wallColorMenu']
- self.activeColors = self.getWallColors()
- state = aDNAObject.getColor()
- elif menu == 'propType':
- self.activeMenu = self.pieMenuDictionary['propTypesMenu']
- state = self.getDNAString(aDNAObject)
- elif menu == 'style':
- self.activeMenu = self.pieMenuDictionary['styleMenu']
- state = 1
- # Store initial state in case you need to restore it on menu cancel
- self.activeMenu.setInitialState(state)
-
- # Spawn the menu task
- self.activeMenu.spawnPieMenuTask()
- def toggleMapViz(self, flag):
- if flag:
- self.levelMap.reparentTo(self)
- else:
- self.levelMap.reparentTo(hidden)
- def toggleNodePathViz(self, aNodePath):
- # First kill the flashing task
- taskMgr.removeTasksNamed('flashNodePath')
- if aNodePath.isHidden():
- aNodePath.show()
- else:
- aNodePath.hide()
- def setXyzSnap(self, flag):
- self.grid.setXyzSnap(flag)
- if flag:
- self.autoPositionGrid()
- def addStyle(self, dictionary, key, wallTexture, wallColor, windowTexture,
- windowColor, corniceTexture, corniceColor):
- style = {}
- style['wallTexture'] = wallTexture
- color = VBase4(wallColor)
- style['wallColor'] = color
- style['windowTexture'] = windowTexture
- color = VBase4(windowColor)
- style['windowColor'] = color
- style['corniceTexture'] = corniceTexture
- color = None
- if corniceColor:
- color = VBase4(corniceColor)
- style['corniceColor'] = color
- dictionary[key] = style
- def createColorMenu(self, menuName, colorArray):
- # Create the new one
- numberNodes = []
-
- # Add in common grey scale colors
- adjustedColorArray = (
- [VBase4(1,1,1,1)] +
- colorArray +
- [VBase4(0.75, 0.75, 0.75, 1.0 ),
- VBase4(0.5, 0.5, 0.5, 1.0),
- VBase4(0.25, 0.25, 0.25, 1.0)]
- )
- for i in range(len(adjustedColorArray)):
- node = OnscreenText(' ', 0.0, 0.0)
- numberNodes.append(node)
- node.setColor(adjustedColorArray[i])
- numItems = len(numberNodes)
- # Attach it to hidden for now
- newColorMenu = hidden.attachNewNode(NamedNode(menuName + 'Menu'))
- # Attach the color chips to the new menu and adjust sizes
- radius = 0.7
- angle = deg2Rad(360.0/float(numItems))
- for i in range (numItems):
- # Get the node
- node = numberNodes[i]
- node.setScale(node.getScale() * 2.0)
-
- # Reposition it
- node.setXY(radius * math.cos(i * angle),
- (radius *
- (self.direct.chan.width /
- float(self.direct.chan.height)) *
- math.sin(i * angle)))
-
- # Add it to the wallColorMenu
- node.reparentTo(newColorMenu)
- # Scale the whole shebang down by 0.5
- newColorMenu.setScale(0.5)
- # Store menu and colors in appropriate dictionarys
- self.pieMenuDictionary[menuName] = (
- PieMenu(self.direct, newColorMenu, self.updateColorIndex))
- self.colorPaletteDictionary[menuName] = adjustedColorArray
- def createColorMenusFromFile(self, prefix):
- dict = self.createColorDictionaryFromFile(
- 'level_editor/' + prefix + 'Colors.txt')
- self.colorPaletteDictionary[prefix + 'Colors'] = dict
- self.createColorMenu(prefix + 'WallColors', dict['wallColors'])
- self.createColorMenu(prefix + 'WindowColors', dict['windowColors'])
- self.createColorMenu(prefix + 'DoorColors', dict['doorColors'])
- self.createColorMenu(prefix + 'CorniceColors', dict['corniceColors'])
- def createColorDictionaryFromFile(self, filename):
- print 'Loading Color Palettes from: ' + filename
- f = Filename(filename)
- f.resolveFilename(getModelPath())
- f = open(f.toOsSpecific(), 'r')
- rawData = f.readlines()
- f.close()
- dict = {}
- wallColors = []
- windowColors = []
- doorColors = []
- corniceColors = []
- for line in rawData:
- l = string.strip(line)
- if l:
- if l[:4] == 'wall':
- wallColors.append(eval(l[11:]))
- elif l[:4] == 'wind':
- windowColors.append(eval(l[13:]))
- elif l[:4] == 'door':
- doorColors.append(eval(l[11:]))
- elif l[:4] == 'corn':
- corniceColors.append(eval(l[14:]))
- dict['wallColors'] = wallColors
- dict['windowColors'] = windowColors
- dict['doorColors'] = doorColors
- dict['corniceColors'] = corniceColors
- return dict
- def printColorDictionary(self, dict):
- for color in dict['wallColors']:
- print ('wallColor: Vec4(%.2f, %.2f, %.2f, 1.0)' %
- (color[0], color[1], color[2]))
- for color in dict['windowColors']:
- print ('windowColor: Vec4(%.2f, %.2f, %.2f, 1.0)' %
- (color[0], color[1], color[2]))
- for color in dict['doorColors']:
- print ('doorColor: Vec4(%.2f, %.2f, %.2f, 1.0)' %
- (color[0], color[1], color[2]))
- for color in dict['corniceColors']:
- print ('corniceColor: Vec4(%.2f, %.2f, %.2f, 1.0)' %
- (color[0], color[1], color[2]))
- def createColorMenus(self):
- self.createColorMenusFromFile('toontownCentral')
- self.createColorMenusFromFile('donaldsDock')
- self.createColorMenusFromFile('theBurrrgh')
- self.createColorMenusFromFile('minniesMelodyLand')
- # Use the toontown color set
- self.useToontownCentralColors()
- def createCorniceMenu(self):
- # Get the currently available window options
- numItems = len(self.getCorniceTextures())
- newCorniceMenu = hidden.attachNewNode(NamedNode('corniceMenu'))
- # Attach an empty node for first item
- newCorniceMenu.attachNewNode(NamedNode('no cornice'))
- angle = deg2Rad(360.0/numItems)
- # Note: start at 2 to skip first item (none)
- for i in range(1, numItems):
- # Get the node
- node = self.dnaStore.findNode(self.getCorniceTextures()[i])
-
- # Add it to the window menu
- path = node.instanceTo(newCorniceMenu)
- # Place menu nodes in a circle, offset each in X and Z
- # by half node width/height (.5 * path scale)
- path.setPos(0.75 * math.cos(i * angle),
- 0.0,
- (0.75 *
- (self.direct.chan.width /
- float(self.direct.chan.height)) *
- math.sin(i * angle)))
- path.setScale(0.5)
- # Scale the whole shebang down by 0.5
- newCorniceMenu.setScale(0.5)
- return newCorniceMenu
- def createDoorMenu(self):
- # Get the currently available door options
- numItems = len(self.getDoorTextures())
-
- newDoorMenu = hidden.attachNewNode(NamedNode('doorMenu'))
- angle = deg2Rad(360.0/float(numItems))
- for i in range(numItems):
- # Get the node
- node = self.dnaStore.findNode(self.getDoorTextures()[i])
- # Add it to the door menu
- path = node.instanceTo(newDoorMenu)
- # Place menu nodes in a circle, offset each in X and Z
- # by half node width/height (.5 * path scale)
- path.setPos(0.75 * math.cos(i * angle) - 0.025,
- 0.0,
- ((0.75 *
- (self.direct.chan.width/
- float(self.direct.chan.height)) *
- math.sin(i * angle)) - 0.025))
- path.setScale(0.05)
- # Scale the whole shebang down by 0.5
- newDoorMenu.setScale(0.5)
- return newDoorMenu
- def createNumWindowsMenu(self):
-
- numberNodes = []
- for i in range(4):
- node = OnscreenText(`i`, 0.0, 0.0)
- numberNodes.append(node)
- numItems = len(numberNodes)
- newNumWindowsMenu = hidden.attachNewNode(NamedNode('numWindowsMenu'))
- radius = 0.7
- angle = deg2Rad(360.0/numItems)
- for i in range(numItems):
- # Get the node
- node = numberNodes[i]
- node.setScale(node.getScale() * 4.0)
-
- # Reposition it
- node.setXY(radius * math.cos(i * angle),
- (radius *
- (self.direct.chan.width/
- float(self.direct.chan.height)) *
- math.sin(i * angle)))
- # Add it to the numWindowsMenu
- node.reparentTo(newNumWindowsMenu)
- # Scale the whole shebang down by 0.5
- newNumWindowsMenu.setScale(0.5)
- return newNumWindowsMenu
- def createOrientationMenu(self):
- newOrientationMenu = hidden.attachNewNode(NamedNode('orientationMenu'))
-
- radius = 0.5
- node = OnscreenText('UR',radius,radius)
- node.setScale(node.getScale() * 3.0)
- node.reparentTo(newOrientationMenu)
- node = OnscreenText('UL',-radius,radius)
- node.setScale(node.getScale() * 3.0)
- node.reparentTo(newOrientationMenu)
- node = OnscreenText('DL',-radius, -radius)
- node.setScale(node.getScale() * 3.0)
- node.reparentTo(newOrientationMenu)
- node = OnscreenText('DR',radius,-radius)
- node.setScale(node.getScale() * 3.0)
- node.reparentTo(newOrientationMenu)
- # Scale the whole shebang down by radius
- newOrientationMenu.setScale(radius)
-
- return newOrientationMenu
- def createPropTypesMenu(self):
- numItems = len(self.getPropTypes())
- propNodes = []
- for i in range (numItems):
- node = OnscreenText(self.getPropTypes()[i],0,0)
- propNodes.append(node)
- newPropTypeMenu = hidden.attachNewNode(NamedNode('propTypeMenu'))
- radius = 0.7
- angle = deg2Rad(360.0/numItems)
- for i in range (numItems):
- # Get the node
- node = propNodes[i]
- node.setScale(node.getScale())
-
- # Reposition it
- node.setXY(radius * math.cos(i * angle),
- (radius *
- (self.direct.chan.width/
- float(self.direct.chan.height)) *
- math.sin(i * angle)))
- # Add it to the propTypeMenu
- node.reparentTo(newPropTypeMenu)
- # Scale the whole shebang down by 0.5
- newPropTypeMenu.setScale(0.5)
- return newPropTypeMenu
- def createStyleSample(self, style, num):
- # Create a wall
- wall = DNAWall('wall')
- wall.setCode(self.dnaStore.findCode(style['wallTexture']))
- wall.setColor(style['wallColor'])
- wall.setHeight(10.0)
- # Add its windows
- windows = DNAWindows('windows')
- windows.setWindowCount(2)
- windows.setCode(self.dnaStore.findCode(style['windowTexture']))
- windows.setColor(style['windowColor'])
- wall.add(windows)
- # And a cornice if necessary
- corniceTexture = style['corniceTexture']
- if corniceTexture:
- cornice = DNACornice('cornice')
- cornice.setCode(self.getDNACode(corniceTexture))
- cornice.setColor(style['corniceColor'])
- wall.add(cornice)
- # The final building
- bldg = DNAFlatBuilding('style' + `num`)
- bldg.add(wall)
- bldg.setWidth(12.0)
- return bldg.traverse(hidden, self.dnaStore)
- def createStyleMenuWith(self, dictionary):
- numItems = len(dictionary)
- newStyleMenu = hidden.attachNewNode(NamedNode('styleMenu'))
- radius = 0.7
- angle = deg2Rad(360.0/numItems)
- for i in range(numItems):
- # Get the node
- node = self.createStyleSample(dictionary[i], i)
- node.setScale(0.03)
-
- # Reposition it
- node.setPos(radius * math.cos(i * angle),
- 0.0,
- (radius *
- (self.direct.chan.width/
- float(self.direct.chan.height)) *
- math.sin(i * angle)))
- # Add it to the styleMenu
- node.reparentTo(newStyleMenu)
- # Scale the whole shebang down by 0.5
- newStyleMenu.setScale(0.5)
- return newStyleMenu
- def createUpOrientationMenu(self):
- newUpOrientationMenu = (
- hidden.attachNewNode(NamedNode('upOrientationMenu')))
- radius = 0.5
- node = OnscreenText('UR',radius, radius)
- node.setScale(node.getScale() * 3.0)
- node.reparentTo(newUpOrientationMenu)
- node = OnscreenText('UL',-radius, radius)
- node.setScale(node.getScale() * 3.0)
- node.reparentTo(newUpOrientationMenu)
- node = newUpOrientationMenu.attachNewNode(NamedNode('hiddenNode'))
- node.setScale(node.getScale() * 3.0)
- node = newUpOrientationMenu.attachNewNode(NamedNode('hiddenNode'))
- node.setScale(node.getScale() * 3.0)
- # Scale the whole shebang down by radius
- newUpOrientationMenu.setScale(radius)
- return newUpOrientationMenu
- def createWallMenu(self):
- numItems = len(self.getWallTextures())
- newWallMenu = hidden.attachNewNode(NamedNode('wallMenu'))
- angle = deg2Rad(360.0/numItems)
- for i in range(numItems):
- node = self.dnaStore.findNode(self.getWallTextures()[i])
- path = node.instanceTo(newWallMenu)
- # Place menu nodes in a circle, offset each in X and Z by
- # half node width/height (.5 * path scale)
- path.setPos(0.75 * math.cos(i * angle) - 0.15,
- 0.0,
- (0.75 *
- (self.direct.chan.width/
- float(self.direct.chan.height)) *
- math.sin(i * angle) - 0.15))
- path.setScale(0.25)
- # Scale the whole shebang down by 0.5
- newWallMenu.setScale(0.5)
- return newWallMenu
- def createWallWidthMenu(self):
- numberNodes = []
- self.wallWidths = [5, 10, 15, 15.607, 20, 20.706, 25]
- widthsAsText = ['5', '10', '15', '15.6', '20', '20.7', '25']
- for width in widthsAsText:
- node = OnscreenText(width,0,0)
- numberNodes.append(node)
- numItems = len(numberNodes)
- newWallWidthMenu = hidden.attachNewNode(NamedNode('wallWidthMenu'))
- radius = 0.7
- angle = deg2Rad(360.0/numItems)
- for i in range(numItems):
- # Get the node
- node = numberNodes[i]
- node.setScale(node.getScale()* 4.0)
-
- # Reposition it
- node.setXY(radius * math.cos(i * angle),
- (radius *
- (self.direct.chan.width/
- float(self.direct.chan.height)) *
- math.sin(i * angle)))
- # Add it to the wallWidthMenu
- node.reparentTo(newWallWidthMenu)
- # Scale the whole shebang down by 0.5
- newWallWidthMenu.setScale(0.5)
- return newWallWidthMenu
- def createWindowMenu(self):
- # Get the currently available window options
- numItems = len(self.getWindowTextures())
-
- newWindowMenu = hidden.attachNewNode(NamedNode('windowMenu'))
- angle = deg2Rad(360.0/numItems)
- for i in range(numItems):
- # Get the node
- node = self.dnaStore.findNode(self.getWindowTextures()[i])
- # Add it to the window menu
- path = node.instanceTo(newWindowMenu)
- # Place menu nodes in a circle, offset each in X and Z by
- # half node width/height (.5 * path scale)
- path.setPos(0.75 * math.cos(i * angle) - 0.05,
- 0.0,
- (0.75 *
- (self.direct.chan.width/
- float(self.direct.chan.height)) *
- math.sin(i * angle) - 0.05))
- path.setScale(0.1)
- # Scale the whole shebang down by 0.5
- newWindowMenu.setScale(0.5)
- return newWindowMenu
- def createStyleDictionaryFromFile(self, filename):
- print 'Loading style from: ' + filename
- styleData = self.getStyleData(filename)
- styleDictionary = {}
- styleCount = 0
- while styleData:
- style, styleData = self.getStyleFromStyleData(styleData)
- styleDictionary[styleCount] = style
- styleCount = styleCount + 1
- return styleDictionary
- def getStyleData(self, filename):
- f = Filename(filename)
- f.resolveFilename(getModelPath())
- f = open(f.toOsSpecific(), 'r')
- rawData = f.readlines()
- f.close()
- styleData = []
- for line in rawData:
- l = string.strip(line)
- if l:
- styleData.append(l)
- return styleData
- def getStyleFromStyleData(self, styleData):
- style = {}
- # Wall
- style['wallTexture'] = string.strip(styleData[0][12:])
- style['wallColor'] = eval(styleData[1][10:])
- # Window Texture
- texture = string.strip(styleData[2][14:])
- if texture == 'None':
- style['windowTexture'] = None
- else:
- style['windowTexture'] = texture
- # Window Color
- color = string.strip(styleData[3][12:])
- if color == 'None':
- style['windowColor'] = None
- else:
- style['windowColor'] = eval(color,globals())
- # Cornice Texture
- texture = string.strip(styleData[4][15:])
- if texture == 'None':
- style['corniceTexture'] = None
- else:
- style['corniceTexture'] = texture
- # Cornice Color
- color = string.strip(styleData[5][13:])
- if color == 'None':
- style['corniceColor'] = None
- else:
- style['corniceColor'] = eval(color,globals())
- # Result
- return style, styleData[6:]
- def initializePieMenus(self):
- # Clear out any old menus just in case
- for key in self.pieMenuDictionary.keys():
- oldMenu = self.pieMenuDictionary[key]
- oldMenu.reparentTo(hidden)
- oldMenu.removeNode()
- # Get list of available attributes
- self.initializeAttributeDictionary()
- # Create pop-up pie menus
- self.pieMenuDictionary['wallMenu'] = (
- PieMenu(self.direct, self.createWallMenu(),
- self.updateWallTextureNum))
- self.pieMenuDictionary['windowMenu'] = (
- PieMenu(self.direct, self.createWindowMenu(),
- self.updateWindowTextureNum))
- menu = PieMenu(self.direct, self.createOrientationMenu(),
- self.updateOrientationNum)
- # Clear angle offset on this menu
- menu.setItemOffset(0.0)
- self.pieMenuDictionary['orientationMenu'] = menu
- menu = PieMenu(self.direct, self.createUpOrientationMenu(),
- self.updateOrientationNum)
- # Clear angle offset on this menu
- menu.setItemOffset(0.0)
- self.pieMenuDictionary['upOrientationMenu'] = menu
- self.pieMenuDictionary['numWindowsMenu'] = (
- PieMenu(self.direct, self.createNumWindowsMenu(),
- self.updateNumWindows))
- self.pieMenuDictionary['corniceMenu'] = (
- PieMenu(self.direct,self.createCorniceMenu(),
- self.updateCorniceTextureNum))
- self.pieMenuDictionary['doorMenu'] = (
- PieMenu(self.direct,self.createDoorMenu(),
- self.updateDoorTextureNum))
- self.pieMenuDictionary['wallWidthMenu'] = (
- PieMenu(self.direct,self.createWallWidthMenu(),
- self.updateWallWidthSF))
- self.pieMenuDictionary['propTypesMenu'] = (
- PieMenu(self.direct,self.createPropTypesMenu(),
- self.updatePropNum))
- self.pieMenuDictionary['toontownCentralStyleMenu'] = (
- PieMenu(self.direct,self.createStyleMenuWith(
- self.attributeDictionary['toontownCentralStyleDictionary']),
- self.updateWallStyleNum))
- self.pieMenuDictionary['donaldsDockStyleMenu'] = (
- PieMenu(self.direct,self.createStyleMenuWith(
- self.attributeDictionary['donaldsDockStyleDictionary']),
- self.updateWallStyleNum))
- self.pieMenuDictionary['theBurrrghStyleMenu'] = (
- PieMenu(self.direct,self.createStyleMenuWith(
- self.attributeDictionary['theBurrrghStyleDictionary']),
- self.updateWallStyleNum))
- self.pieMenuDictionary['minniesMelodyLandStyleMenu'] = (
- PieMenu(self.direct,self.createStyleMenuWith(
- self.attributeDictionary['minniesMelodyLandStyleDictionary']),
- self.updateWallStyleNum))
- self.pieMenuDictionary['styleMenu'] = (
- self.pieMenuDictionary['toontownCentralStyleMenu'])
- # Create several differnt color palette menus
- self.createColorMenus()
- def initializeStyleDictionary(self):
- # Create a dictionary for toontownCentral
- dictionary = self.createStyleDictionaryFromFile(
- 'level_editor/toontownCentralStyles.txt')
- # Store this dictionary in the self.attributeDictionary
- self.attributeDictionary['toontownCentralStyleDictionary'] = dictionary
-
- # Create a dictionary for donaldsDock
- dictionary = self.createStyleDictionaryFromFile(
- 'level_editor/donaldsDockStyles.txt')
- # Store this dictionary in the self.attributeDictionary
- self.attributeDictionary['donaldsDockStyleDictionary'] = dictionary
-
- # Create a dictionary for theBurrrgh
- dictionary = self.createStyleDictionaryFromFile(
- 'level_editor/theBurrrghStyles.txt')
- # Store this dictionary in the self.attributeDictionary
- self.attributeDictionary['theBurrrghStyleDictionary'] = dictionary
-
- # Create a dictionary for minniesMelodyLand
- dictionary = self.createStyleDictionaryFromFile(
- 'level_editor/minniesMelodyLandStyles.txt')
- # Store this dictionary in the self.attributeDictionary
- self.attributeDictionary['minniesMelodyLandStyleDictionary'] = (
- dictionary)
-
- # Record active style dictionary
- self.styleDictionary = (
- self.attributeDictionary['toontownCentralStyleDictionary'])
- def initializeTheBurrrghStyleDictionary(self):
- dictionary = {}
- styleCount = 0
- self.addStyle(dictionary, styleCount,
- 'wall_md_blank_ur',
- Vec4(0.417323, 0.15711, 0.15711, 1.0),
- 'window_sm_square_ur',
- Vec4(0.874016, 0.654655, 0.329041, 1.0),
- 'cornice_marble_ur',
- Vec4(0.76378, 0.572086, 0.287541, 1.0))
-
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_sm_wood_ur',
- Vec4(0.874016, 0.610097, 0.610097, 1.0),
- 'window_sm_shuttered_ur',
- Vec4(0.874016, 0.548402, 0.329041, 1.0),
- None,
- None)
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_sm_wood_ur',
- Vec4(0.913386, 0.540868, 0.540868, 1.0),
- 'window_porthole_ur',
- Vec4(0.0778138, 0.472441, 0.314961, 1.0),
- 'cornice_horizontal_ur',
- Vec4(1.0, 0.501961, 0.376471, 1.0))
-
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_sm_wood_ur',
- Vec4(0.913386, 0.540868, 0.540868, 1.0),
- 'window_porthole_ur',
- Vec4(0.0778138, 0.472441, 0.314961, 1.0),
- 'cornice_shingles_ur',
- Vec4(0.732283, 0.511163, 0.511163, 1.0))
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_md_blank_ur',
- Vec4(0.384314, 0.305635, 0.187618, 1.0),
- 'window_sm_round_ur',
- Vec4(0.779528, 0.489115, 0.293469, 1.0),
- 'cornice_dental_ur',
- Vec4(0.574803, 0.38771, 0.340374, 1.0))
-
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_bricks_dr',
- Vec4(0.629921, 0.471823, 0.237147, 1.0),
- 'window_sm_shuttered_ur',
- Vec4(1.0, 0.627451, 0.376471, 1.0),
- None,
- None)
-
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_md_board_ur',
- Vec4(0.929134, 0.153034, 0.153034, 1.0),
- 'window_porthole_ur',
- Vec4(0.0, 0.532747, 0.317894, 1.0),
- 'cornice_shingles_ur',
- Vec4(0.944882, 0.715146, 0.659565, 1.0))
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_lg_brick_ur',
- Vec4(0.166003, 0.440945, 0.276671, 1.0),
- 'window_md_curtains_ur',
- Vec4(0.17258, 0.637795, 0.450208, 1.0),
- None,
- None)
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_md_board_ur',
- Vec4(0.929134, 0.153034, 0.153034, 1.0),
- 'window_porthole_ur',
- Vec4(0.0, 0.532747, 0.317894, 1.0),
- None,
- None)
- # Store this dictionary in the self.attributeDictionary
- self.attributeDictionary['theBurrrghStyleDictionary'] = dictionary
- def initializeMinniesMelodyLandStyleDictionary(self):
- dictionary = {}
- styleCount = 0
- self.addStyle(dictionary, styleCount,
- 'wall_md_blank_ur',
- Vec4(0.417323, 0.15711, 0.15711, 1.0),
- 'window_sm_square_ur',
- Vec4(0.874016, 0.654655, 0.329041, 1.0),
- 'cornice_marble_ur',
- Vec4(0.76378, 0.572086, 0.287541, 1.0))
-
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_sm_wood_ur',
- Vec4(0.874016, 0.610097, 0.610097, 1.0),
- 'window_sm_shuttered_ur',
- Vec4(0.874016, 0.548402, 0.329041, 1.0),
- None,
- None)
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_sm_wood_ur',
- Vec4(0.913386, 0.540868, 0.540868, 1.0),
- 'window_porthole_ur',
- Vec4(0.0778138, 0.472441, 0.314961, 1.0),
- 'cornice_horizontal_ur',
- Vec4(1.0, 0.501961, 0.376471, 1.0))
-
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_sm_wood_ur',
- Vec4(0.913386, 0.540868, 0.540868, 1.0),
- 'window_porthole_ur',
- Vec4(0.0778138, 0.472441, 0.314961, 1.0),
- 'cornice_shingles_ur',
- Vec4(0.732283, 0.511163, 0.511163, 1.0))
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_md_blank_ur',
- Vec4(0.384314, 0.305635, 0.187618, 1.0),
- 'window_sm_round_ur',
- Vec4(0.779528, 0.489115, 0.293469, 1.0),
- 'cornice_dental_ur',
- Vec4(0.574803, 0.38771, 0.340374, 1.0))
-
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_bricks_dr',
- Vec4(0.629921, 0.471823, 0.237147, 1.0),
- 'window_sm_shuttered_ur',
- Vec4(1.0, 0.627451, 0.376471, 1.0),
- None,
- None)
-
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_md_board_ur',
- Vec4(0.929134, 0.153034, 0.153034, 1.0),
- 'window_porthole_ur',
- Vec4(0.0, 0.532747, 0.317894, 1.0),
- 'cornice_shingles_ur',
- Vec4(0.944882, 0.715146, 0.659565, 1.0))
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_lg_brick_ur',
- Vec4(0.166003, 0.440945, 0.276671, 1.0),
- 'window_md_curtains_ur',
- Vec4(0.17258, 0.637795, 0.450208, 1.0),
- None,
- None)
- styleCount = styleCount + 1
- self.addStyle(dictionary, styleCount,
- 'wall_md_board_ur',
- Vec4(0.929134, 0.153034, 0.153034, 1.0),
- 'window_porthole_ur',
- Vec4(0.0, 0.532747, 0.317894, 1.0),
- None,
- None)
- # Store this dictionary in the self.attributeDictionary
- self.attributeDictionary['minniesMelodyLandStyleDictionary'] = dictionary
- def addDNAGroup(self,dnaGroup):
- # Add hook to allow placement of a new dna Group of this type
- # by simply hitting the space bar
- # First clear out old hooks just to be safe
- self.ignore('insert')
- # Now add new hook
- self.accept('insert', self.initNewDNAGroupWithParent,
- [dnaGroup, self.groupParent])
- # Now add the first copy of this Group
- self.initDNAGroupWithParent(dnaGroup,self.groupParent)
- def addDNAGroupType(self, dnaGroup, type):
- # Add hook to allow placement of a new dna Group of this type
- # by simply hitting the space bar
- # First clear out old hooks just to be safe
- self.ignore('insert')
- # Now add new hook
- self.accept('insert',
- self.addFlatBuilding,
- [type])
- # First clear out old hooks just to be safe
- self.ignore('space')
- self.accept('space',
- initNewDNAGroupWithParentType,
- [dnaGroup, self.groupParent, type])
- # Now add the first copy of this Group
- self.initDNAGroupWithParentType(dnaGroup, self.groupParent, type)
- def addDNAGroupTypeMethod(self, dnaGroup, type, method):
- # Add hook to allow placement of a new dna Group of this type
- # by simply hitting the space bar
- # First clear out old hooks just to be safe
- self.ignore('insert')
- # Now add new hooks
- # Insert key generates random version
- self.accept('insert', method, [type])
- # Space bar creates a copy
- self.ignore('space')
- self.accept('space', self.initNewDNAGroupWithParentType,
- [dnaGroup, self.groupParent, type])
- # Now add the first copy of this Group
- self.initDNAGroupWithParentType(dnaGroup, self.groupParent, type)
- def addFlatBuilding(self, buildingType):
- # Create new building
- newDNAFlatBuilding = DNAFlatBuilding(buildingType + '_DNARoot')
- # Select walls
- if buildingType == 'random20':
- selectedType = self.selectBuildingType('twenty')
- elif buildingType == 'random30':
- selectedType = self.selectBuildingType('thirty')
- else:
- selectedType = buildingType
- if selectedType == 'toonTenTen':
- self.setBuildingHeight(20.0)
- newDNAFlatBuilding.add(self.createWall(10.0))
- newDNAFlatBuilding.add(self.createWall(10.0))
- elif selectedType == 'toonTwenty':
- self.setBuildingHeight(20.0)
- newDNAFlatBuilding.add(self.createWall(20.0))
- elif selectedType == 'toonTenTwenty':
- self.setBuildingHeight(30.0)
- newDNAFlatBuilding.add(self.createWall(10.0))
- newDNAFlatBuilding.add(self.createWall(20.0))
- elif selectedType == 'toonTwentyTen':
- self.setBuildingHeight(30.0)
- newDNAFlatBuilding.add(self.createWall(20.0))
- newDNAFlatBuilding.add(self.createWall(10.0))
- elif selectedType == 'toonTenTenTen':
- self.setBuildingHeight(30.0)
- newDNAFlatBuilding.add(self.createWall(10.0))
- newDNAFlatBuilding.add(self.createWall(10.0))
- newDNAFlatBuilding.add(self.createWall(10.0))
- elif selectedType == 'toonTenTwenty':
- newDNAFlatBuilding.add(self.createWall(10.0))
- newDNAFlatBuilding.add(self.createWall(20.0))
- elif selectedType == 'toonTwentyTen':
- newDNAFlatBuilding.add(self.createWall(20.0))
- newDNAFlatBuilding.add(self.createWall(10.0))
- elif selectedType == 'toonThirty':
- newDNAFlatBuilding.add(self.createWall(30.0))
- # Pick a style for this building
- self.setRandomBuildingStyle(newDNAFlatBuilding)
- # Initialize its position and hpr
- newDNAFlatBuilding.setPos(VBase3(0))
- newDNAFlatBuilding.setHpr(VBase3(0))
- # Now place new building in the world
- self.addDNAGroupTypeMethod(newDNAFlatBuilding,buildingType,
- self.addFlatBuilding)
- def addLandmark(self, landmarkType):
- newDNALandmarkBuilding = DNALandmarkBuilding(landmarkType + '_DNARoot')
- newDNALandmarkBuilding.setCode(self.getDNACode(landmarkType))
- newDNALandmarkBuilding.setPos(VBase3(0))
- newDNALandmarkBuilding.setHpr(VBase3(0))
- newDNADoor = self.createDoor(self.getDoorTexture())
- newDNALandmarkBuilding.add(newDNADoor)
- # Now place new building in the world
- self.addDNAGroup(newDNALandmarkBuilding)
- def addObject(self, aNodePath, dnaGroup):
- # Add specified node path to the scene dictionary
- objectDictionary = {}
- objectDictionary['nodePath'] = aNodePath
- objectDictionary['DNA'] = dnaGroup
- self.levelDictionary[aNodePath.id()] = objectDictionary
- return objectDictionary
- def addProp(self, newPropType):
- newDNAProp = DNAProp(newPropType + '_DNARoot')
- newDNAProp.setCode(self.getDNACode(newPropType))
- newDNAProp.setPos(VBase3(0))
- newDNAProp.setHpr(VBase3(0))
- # Now place new building in the world
- self.addDNAGroup(newDNAProp)
- self.setPropType(newPropType)
- def addStreetModule(self, streetType):
- newDNAStreet = DNAStreet(streetType + '_DNARoot')
- newDNAStreet.setCode(self.getDNACode(streetType))
- newDNAStreet.setPos(VBase3(0))
- newDNAStreet.setHpr(VBase3(0))
- newDNAStreet.setStreetTexture(
- self.getDNACode(self.attributeDictionary['streetTexture']))
- newDNAStreet.setSidewalkTexture(
- self.getDNACode(self.attributeDictionary['sidewalkTexture']))
- # Now place new building in the world
- self.addDNAGroup(newDNAStreet)
- def addWall(self, dnaString, height):
- # Create the DNA for this wall
- newDNAWall = self.createWallWithDNA(dnaString, height)
- # Pick a default window
- newDNAWindows = DNAWindows()
- self.setWindowTexture(self.getRandomWindowTexture())
- newDNAWindows.setCode(self.getDNACode(self.getWindowTexture()))
- newDNAWindows.setWindowCount(self.getRandomNumWindows(height))
- colors = self.getWallColors()
- newDNAWindows.setColor(colors[randint(0,len(colors) - 1)])
- newDNAWall.add(newDNAWindows)
- return newDNAWall
- def createCornice(self,dnaString):
- newDNACornice = DNACornice()
- newDNACornice.setCode(self.getDNACode(dnaString))
- colors = self.getCorniceColors()
- newDNACornice.setColor(colors[randint(0,len(colors) - 1)])
- return newDNACornice
- def createDoor(self, dnaString):
- newDNADoor = DNADoor()
- newDNADoor.setCode(self.getDNACode(dnaString))
- colors = self.getDoorColors()
- newDNADoor.setColor(colors[randint(0,len(colors) - 1)])
- return newDNADoor
- def addGroupToSelected(self, aNodePath):
- self.setGroupParent(aNodePath)
- self.createNewLevelGroup()
- def createNewLevelGroup(self):
- newGroupParentDNA = DNAGroup('group=' + `self.groupNum`)
- # Add it to the level objects
- self.groupParentDNA.add(newGroupParentDNA)
- # Make the new one be the current one
- self.groupParentDNA = newGroupParentDNA
- newGroupParent = self.groupParentDNA.traverse(
- self.groupParent, self.dnaStore)
- self.groupParent = newGroupParent
- self.groupNum = self.groupNum + 1
- # Add it to the level dictionary
- self.addObject(self.groupParent, self.groupParentDNA)
- def createTopLevelGroup(self):
- # Create a new top level group
- self.groupParentDNA = DNAGroup('rootNode')
- self.groupNum = 0
- # Add it to the level objects
- self.levelObjectsDNA.add(self.groupParentDNA)
- self.groupParent = self.groupParentDNA.traverse(
- self.levelObjects, self.dnaStore)
- # Add it to the level dictionary
- self.addObject(self.groupParent, self.groupParentDNA)
- def createWall(self, height):
- return self.createWallWithDNA(self.getWallTexture(), height)
- def createWallWithDNA(self, dnaString, height):
- # Create a new DNAWall using default attributes
- # Create the DNA for this wall
- newDNAWall = DNAWall()
- newDNAWall.setCode(self.getDNACode(dnaString))
- newDNAWall.setHeight(height)
- newDNAWall.setColor(self.getWallColor())
-
- # Pick a default window
- newDNAWindows = DNAWindows()
- newDNAWindows.setCode(self.getDNACode(self.getWindowTexture()))
- newDNAWindows.setWindowCount(1)
- newDNAWindows.setColor(self.getWindowColor())
- newDNAWall.add(newDNAWindows)
-
- return newDNAWall
- def createWindows(self, numWindows):
- newDNAWindows = DNAWindows()
- newDNAWindows.setCode(self.getDNACode(self.getWindowTexture()))
- newDNAWindows.setWindowCount(numWindows)
- newDNAWindows.setColor(self.getWindowColor())
- return newDNAWindows
- def getCatalogCode(self, category, i):
- return self.dnaStore.getCatalogCode(category, i)
-
- def getCatalogCodes(self, category):
- numCodes = self.dnaStore.getNumCatalogCodes(category)
- codes = []
- for i in range(numCodes):
- codes.append(self.dnaStore.getCatalogCode(category, i))
- return codes
- def getCatalogCodesSuffix(self, category, suffix):
- codes = self.getCatalogCodes(category)
- orientedCodes = []
- for code in codes:
- if code[-3:] == suffix:
- orientedCodes.append(code)
- return orientedCodes
- def getCornice(self, aDNAFlatBuilding):
- lastWall = self.getLastWall(aDNAFlatBuilding)
- if lastWall:
- for i in range(lastWall.getNumChildren()):
- child = lastWall.at(i)
- if child.__class__.getClassType().eq(DNACornice.getClassType()):
- return child
- # Not found
- return None
- def getDNACode(self, dnaString):
- dnaCode = self.dnaStore.findCode(dnaString)
- if dnaCode == 0:
- print 'getDNACode Error!'
- return dnaCode
- def getDNAGroup(self, aNodePath):
- dict = self.getLevelObject(aNodePath)
- if dict:
- return dict['DNA']
- else:
- return None
- def getDNAString(self, aDNAObject):
- return (self.dnaStore.findStringFromCode(aDNAObject.getCode()))
- def getDoor(self, aDNAGroup):
- for i in range(aDNAGroup.getNumChildren()):
- child = aDNAGroup.at(i)
- if child.__class__.getClassType().eq(DNADoor.getClassType()):
- return child
- # Not found
- return None
- def getLastWall(self, aDNAFlatBuilding):
- lastWall = None
- for i in range(aDNAFlatBuilding.getNumChildren()):
- child = aDNAFlatBuilding.at(i)
- if child.__class__.getClassType().eq(DNAWall.getClassType()):
- lastWall = child
- return lastWall
- def getLevelObject(self, aNodePath):
- # Given a node path, find the corresponding level object
- # in the levelDictionary, if none exists, return 0
- return self.levelDictionary.get(aNodePath.id(), None)
- def getRandomCorniceTexture(self):
- chance = 100 * random()
- if (chance < 20):
- textures = self.getCorniceTextures()
- len = len(textures)
- index = randint(0,len)
- return textures[index]
- else:
- return None
- def rounded(self,val):
- return int(round(val))
-
- def getRandomNumWindows(self, height):
- h = self.rounded(height)
- if h == 10:
- # Only return 0 25% of the time
- if self.rounded(self.getWallWidth()) == 5:
- return randint(1,3)
- else:
- return randint(0,3)
- elif h == 20:
- if self.rounded(self.getWallWidth()) == 5:
- return randint(1,3)
- else:
- return randint(0,4)
- elif h == 30:
- if self.rounded(self.getWallWidth()) == 5:
- return randint(1,3)
- else:
- return randint(0,4)
- def getRandomDictionaryEntry(self,dict):
- numKeys = len(dict)
- if numKeys > 0:
- keys = dict.keys()
- key = keys[randint(0,numKeys - 1)]
- return dict[key]
- else:
- return None
-
- def getRandomStyle(self):
- return self.getRandomDictionaryEntry(self.styleDictionary)
- def getRandomWallTexture(self):
- return self.getWallTextures()[
- randint(0, len(self.getWallTextures()) - 1)]
- def getRandomWallWidth(self):
- chance = randint(0,100)
- if chance <= 15:
- return 5.0
- elif (chance > 15) & (chance <= 30):
- return 10.0
- elif (chance > 30) & (chance <= 65):
- return 15.0
- elif (chance > 65) & (chance <= 85):
- return 20.0
- elif (chance > 85):
- return 25.0
- def getRandomWindowTexture(self):
- wt = self.getWindowTextures()
- return wt[randint(9, len(wt) -1 )]
- def getWall(self, aDNAGroup, wallNum):
- wallCount = 0
- for i in range(aDNAGroup.getNumChildren()):
- child = aDNAGroup.at(i)
- if child.__class__.getClassType().eq(DNAWall.getClassType()):
- if wallCount == wallNum:
- return child
- wallCount = wallCount + 1
- # Not found
- return None
- def getWallHeights(self, aDNAFlatBuilding):
- heightList = []
- heightTotal = 0.0
- # Compute wall heights
- for i in range(aDNAFlatBuilding.getNumChildren()):
- child = aDNAFlatBuilding.at(i)
- if child.__class__.getClassType().eq(DNAWall.getClassType()):
- heightTotal = heightTotal + child.getHeight()
- heightList.append(heightTotal)
- return heightList
- def getWallNum(self, aDNAFlatBuilding, zPt):
- if zPt < 0:
- return -1
- heightList = self.getWallHeights(aDNAFlatBuilding)
- wallNum = 0
- for height in heightList:
- if zPt < height:
- return wallNum
- wallNum = wallNum + 1
- return -1
- def getWindow(self, aDNAGroup, windowNum):
- windowCount = 0
- for i in range(aDNAGroup.getNumChildren()):
- child = aDNAGroup.at(i)
- if child.__class__.getClassType().eq(DNAWindows.getClassType()):
- if windowCount == windowNum:
- return child
- windowCount = windowCount + 1
- # Not found
- return None
- def initDNAGroupWithParent(self, dnaGroup, parent):
- # Create the geometry
- # If it is a flat building, update building DNA to current wall width
- if (dnaGroup.__class__.getClassType().eq(DNAFlatBuilding.getClassType())):
- dnaGroup.setWidth(self.getWallWidth())
- newNodePath = dnaGroup.traverse(parent,self.dnaStore)
- #newNodePath.node().setName(newNodePath.node().getName() + '_DNARoot')
-
- # Add it to the level dictionary
- self.addObject(newNodePath, dnaGroup)
- # Add it to the top level DNA Group
- self.groupParentDNA.add(dnaGroup)
- # Place the new node path at the current grid origin
- newNodePath.setPos(self.grid,0,0,0)
- # Initialize angle to match last object
- newNodePath.setH(self.grid, self.lastAngle)
- # Select the instance
- self.selectNodePath(newNodePath)
- # Now move the grid to get ready for the next group
- self.autoPositionGrid()
- # Update dictionary
- dnaGroup.setPos(newNodePath.getPos())
- dnaGroup.setHpr(newNodePath.getHpr())
- def initDNAGroupWithParentType(self, dnaGroup, parent, type):
- # Create the geometry
- # If it is a flat building, update building DNA to current wall width
- if dnaGroup.__class__.getClassType().eq(DNAFlatBuilding.getClassType()):
- dnaGroup.setWidth(self.getWallWidth())
- newNodePath = dnaGroup.traverse(parent, self.dnaStore)
- #newNodePath.node().setName(newNodePath.node().getName() + '_DNARoot')
- # Add it to the level dictionary
- self.addObject(newNodePath, dnaGroup)
-
- # Add it to the top level DNA Group
- self.groupParentDNA.add(dnaGroup)
- # Place the new node path at the current grid origin
- newNodePath.setPos(self.grid,0,0,0)
- # Initialize angle to match last object
- newNodePath.setH(self.grid, self.lastAngle)
- # Select the instance
- self.selectNodePath(newNodePath)
- # Now move the grid to get ready for the next group
- self.autoPositionGrid()
- # Update dictionary
- dnaGroup.setPos(newNodePath.getPos())
- dnaGroup.setHpr(newNodePath.getHpr())
- def initNewDNAGroupWithParent(self, dnaGroup, rootNode):
- # Reflect currently selected prop type
- if dnaGroup.__class__.getClassType().eq(DNAProp.getClassType()):
- self.updatePropType(dnaGroup,self.getPropType())
- # Create a new copy of dnaGroup's class
- # Extract group's class using __class__
- # Call that class's constructor passing in dnaGroup to make a copy
- self.initDNAGroupWithParent(dnaGroup.__class__(dnaGroup), self.groupParent)
- # Initialize
- if dnaGroup.__class__.getClassType().eq(DNAProp.getClassType()):
- objectType = self.getDNAString(dnaGroup)
- if objectType != 'prop_sphere':
- # Update props placement to reflect current mouse position
- # Where is the mouse relative to the grid?
- hitPt = self.getGridIntersectionPoint()
- self.direct.selected.last.setPos(self.grid, self.hitPt)
- dnaGroup.setPos(self.direct.selected.last.getPos())
- def initNewDNAGroupWithParentType(self, dnaGroup, rootNode, type):
- # Create a new dna Group of the same type a dnaGroup
- newDNAGroup = dnaGroup.__class__(dnaGroup)
- if dnaGroup.__class__.getClassType().eq(DNAProp.getClassType()):
- self.updatePropType(newDNAGroup,self.getPropType())
- self.initDNAGroupWithParentType(newDNAGroup, self.groupParent, type)
- def loadSpecifiedDNAFile(self):
- f = Filename('/alpha/DIRECT/LevelEditor/DNAFiles')
- path = os.path.join(f.toOsSpecific(), self.dnaOutputDir)
- #f = Filename('dna')
- #f.resolveFilename(getModelPath())
- #path = f.toOsSpecific()
- if not os.path.isdir(path):
- print 'LevelEditor Warning: Invalid default DNA directory!'
- print 'Using: C:\\'
- path = 'C:\\'
- dnaFilename = askopenfilename(
- defaultextension = '.dna',
- filetypes = (('DNA Files', '*.dna'),('All files', '*')),
- initialdir = path,
- title = 'Load DNA File',
- parent = self.panel.component('hull'))
- if dnaFilename:
- self.loadDNAFromFile(dnaFilename)
- def saveToSpecifiedDNAFile(self):
- f = Filename('/alpha/DIRECT/LevelEditor/DNAFiles')
- path = os.path.join(f.toOsSpecific(), self.dnaOutputDir)
- if not os.path.isdir(path):
- print 'LevelEditor Warning: Invalid DNA save directory!'
- print 'Using: C:\\'
- path = 'C:\\'
- dnaFilename = asksaveasfilename(
- defaultextension = '.dna',
- filetypes = (('DNA Files', '*.dna'),('All files', '*')),
- initialdir = path,
- title = 'Save DNA File as',
- parent = self.panel.component('hull'))
- if dnaFilename:
- self.outputDNA(dnaFilename)
- def loadDNAFromFile(self, filename):
- # Out with the old, in with the new
- self.resetLevel()
- # Get rid of default group and root node
- self.preRemoveNodePath(self.groupParent)
- self.removeNodePath(self.groupParent)
- # Clear self.dnaStore
- self.dnaStore.resetDNAGroups()
- # Reset DNA VIS Groups
- self.dnaStore.resetDNAVisGroups()
- # Now load in new file
- self.groupParent = loadDNAFile(self.dnaStore, filename,
- getDefaultCoordinateSystem())
- # Make sure the topmost level object gets put under level objects dna
- self.groupParentDNA = self.dnaStore.findDNAGroup(
- self.groupParent.getBottomArc())
- self.levelObjectsDNA.add(self.groupParentDNA)
- # No level objects node found, just add the whole thing
- self.groupParent.reparentTo(self.levelObjects)
- if 0:
- newLevelObjects = nodePath.find('**/LevelObjects')
- if newLevelObjects.isEmpty():
- # No level objects node found, just add the whole thing
- nodePath.reparentTo(self.levelObjects)
- else:
- # There is a LevelObjects node, add its children
- # Before reparenting children, try to set groupNum to
- # something reasonable
- self.groupNum = newLevelObjects.getNumChildren()
- # Go ahead and get rid of the default parent
- # (since there is probably one in the dnafile
- self.preRemoveNodePath(self.groupParent)
- self.removeNodePath(self.groupParent)
- # Now add the children from the DNA File
- children = newLevelObjects.getChildren()
- for i in range(children.getNumPaths()):
- children.getPath(i).reparentTo(self.levelObjects)
- # Now create a new top level group with next group number
- self.createTopLevelGroup()
- # Add these objects to the levelDictionary
- numPaths = self.dnaStore.getNumNodeRelations()
- for pathNum in range(numPaths):
- relation = self.dnaStore.getNodeRelationAt(pathNum)
- if relation:
- if (relation.getChild() and relation.getParent()):
- newNodePath = NodePath(relation)
- group = self.dnaStore.findDNAGroup(relation)
- if newNodePath.isSingleton():
- print 'Singleton!!'
- else:
- self.addObject(newNodePath, group)
- else:
- print'blah'
- self.createNewLevelGroup()
- def outputDNADefaultFile(self):
- f = Filename('/alpha/DIRECT/LevelEditor/DNAFiles')
- file = os.path.join(f.toOsSpecific(), self.dnaOutputDir,
- self.dnaOutputFile)
- self.outputDNA(file)
-
- def outputDNA(self,filename):
- print 'Saving DNA to: ', filename
- self.levelObjectsDNA.writeDna(Filename(filename),
- Notify.out(),self.dnaStore)
- def preRemoveNodePath(self, aNodePath):
- # Remove nodePath's DNA from its parent
- dnaGroup = self.getDNAGroup(aNodePath)
- if dnaGroup:
- parentDNAGroup = self.getDNAGroup((aNodePath.getParent()))
- if parentDNAGroup:
- parentDNAGroup.remove(dnaGroup)
- def printVizRegions(self):
- if self.direct.selected.last:
- self.printVizRegionsOf(self.direct.selected.last)
- def printVizRegionsOf(self, aNodePath):
- # Print out commands to create viz regions
- print 'To Be Supplied'
- def removeCornices(self, aDNAGroup):
- while self.removeDNAObjectOfClass(
- DNACornice,self.getLastWall(aDNAGroup)):
- pass
- def removeDNAObjectOfClass(self, objectClass, aDNAGroup):
- # Remove the first object of that type you come across
- for i in range(aDNAGroup.getNumChildren()):
- child = aDNAGroup.at(i)
- if child.__class__.getClassType().eq(objectClass.getClassType()):
- aDNAGroup.remove(child)
- return 1
- # None found
- return 0
- def removeNodePath(self, aNodePath):
- # Remove specified node path from the scene dictionary
- nodePathHandle = aNodePath.id()
- del(self.levelDictionary[nodePathHandle])
- # Get rid of its visible representation
- aNodePath.removeNode()
- def removeWindows(self, aDNAGroup):
- while self.removeDNAObjectOfClass(DNAWindows, aDNAGroup):
- pass
- def reparentNodePath(self, aNodePath):
- selectedDNAObject = self.getDNAGroup(aNodePath)
- if not selectedDNAObject:
- return 0
- parent = aNodePath.getParent()
- if not parent:
- return 0
- parentDNAObject = self.getDNAGroup(parent)
- if not parentDNAObject:
- return 0
- if self.groupParent & self.groupParentDNA:
- # Everybody seems happy, move it
- aNodePath.reparentTo(self.groupParent)
- parentDNAObject.remove(selectedDNAObject)
- self.groupParentDNA.add(selectedDNAObject)
- return 1
- def reparentSelectedNodePath(self):
- selectedNodePath = self.direct.selected.last
- if not selectedNodePath:
- return 0
- return self.reparentNodePath(selectedNodePath)
- def replaceLevelObject(self, levelObject):
- # Get the DNA for this object
- dnaGroup = levelObject['DNA']
- # Get to current node path and its parent
- oldNodePath = levelObject['nodePath']
- parent = oldNodePath.getParent()
- # Traverse the dna to create the new node path
- newNodePath = dnaGroup.traverse(parent, self.dnaStore)
- #newNodePath.node().setName(newNodePath.node().getName() + '_DNARoot')
- self.selectNodePath(newNodePath)
- # Add it to the levelObjects dictionary
- self.selectedLevelObject = self.addObject(newNodePath, dnaGroup)
- # Now get rid of the old level object
- self.removeNodePath(oldNodePath)
- def replaceLevelObjectNodePath(self, levelObject):
- # Get and reuse the DNA for this object
- dnaGroup = levelObject['DNA']
- # Get to current node path and its parent
- oldNodePath = levelObject['nodePath']
- parent = oldNodePath.getParent()
- # Traverse the dna to create the new node path
- newNodePath = dnaGroup.traverse(parent, self.dnaStore)
- #newNodePath.node().setName(newNodePath.node().getName() + '_DNARoot')
- self.selectNodePath(newNodePath)
- # Add it to the levelObjects dictionary
- self.selectedLevelObject = self.addObject(newNodePath, dnaGroup)
- # Now get rid of the old level object
- self.removeNodePath(oldNodePath)
- def selectBuildingType(self, heightType):
- chance = randint(0,100)
- if heightType == 'twenty':
- if chance <= 65:
- return 'toonTenTen'
- else:
- return 'toonTwenty'
- else:
- if chance <= 40:
- return 'toonTenTwenty'
- elif (chance > 40) & (chance <= 70):
- return 'toonTwentyTen'
- elif (chance > 70) & (chance <= 90):
- return 'toonTenTenTen'
- else:
- return 'toonThirty'
- def setGroupName(self, aNodePath, aName):
- aDNAGroup = self.getDNAGroup(aNodePath)
- if aDNAGroup:
- aNodePath.setName(aName)
- aDNAGroup.setName(aName)
- def setNodePathName(self, aNodePath, aName):
- levelObject = self.getLevelObject(aNodePath)
- if levelObject:
- levelObjectDNA = levelObject['DNA']
- aNodePath.setName(aName)
- levelObjectDNA.setName(aName)
- self.replaceLevelObject(levelObject)
- def setRandomBuildingStyle(self, aDNAFlatBuilding):
- self.setWallWidthVal(self.getRandomWallWidth())
- aDNAFlatBuilding.setWidth(self.getWallWidth())
- style = self.getRandomStyle()
- for i in range(aDNAFlatBuilding.getNumChildren()):
- # Set style of each child
- child = aDNAFlatBuilding.at(i)
- if child.__class__.getClassType().eq(DNAWall.getClassType()):
- if randint(0,100) < 40:
- style = self.getRandomStyle()
- self.setWallStyle(child, style)
- # Using the style of the last wall:
- if not style['corniceTexture']:
- self.removeCornices(aDNAFlatBuilding)
- else:
- aDNACornice = self.getCornice(aDNAFlatBuilding)
- if not aDNACornice:
- aDNACornice = DNACornice()
- aDNACornice.setCode(
- self.dnaStore.findCode(style['corniceTexture']))
- aDNACornice.setColor(style['corniceColor'])
- lastWall = self.getLastWall(aDNAFlatBuilding)
- lastWall.add(aDNACornice)
- def setRandomNumWindows(self, aDNAWall, numWindows):
- window = self.getWindow(aDNAWall, 0)
- window.setWindowCount(numWindows)
- def setWallStyle(self, aDNAWall, style):
- aDNAWall.setCode(self.dnaStore.findCode(style['wallTexture']))
- aDNAWall.setColor(style['wallColor'])
- aDNAWindows = self.getWindow(aDNAWall, 0)
- # If the wall has windows:
- if aDNAWindows:
- aDNAWindows.setWindowCount(
- self.getRandomNumWindows(aDNAWall.getHeight()))
- aDNAWindows.setCode(self.dnaStore.findCode(style['windowTexture']))
- aDNAWindows.setColor(style['windowColor'])
- def setWallStyleNum(self, aDNAWall, styleNum):
- # What about cornices
- self.setWallStyle(aDNAWall, self.styleDictionary[styleNum])
- def updateColorIndex(self, colorIndex):
- if colorIndex < 0:
- self.updateObjColor(
- self.targetDNAObject,self.activeMenu.getInitialState())
- else:
- self.updateObjColor(
- self.targetDNAObject,self.activeColors[colorIndex])
- def updateObjColor(self, aDNAObject, color):
- aDNAObject.setColor(color)
- # Replace object in levelObjects dictionary and scene graph
- self.replaceLevelObjectNodePath(self.selectedLevelObject)
- self.setActiveColor(color)
- def updateCorniceTextureNum(self, corniceNumber):
- self.updateObjCorniceTexture(self.targetDNAObject, corniceNumber)
- def updateObjCorniceTexture(self, aDNACornice, corniceTextureNumber):
- # Which wall texture was picked by the user?
- if (corniceTextureNumber < 0):
- dnaString = self.activeMenu.getInitialState()
- else:
- dnaString = self.getCorniceTextures()[corniceTextureNumber]
- # Now update the texture on the cornice with that texture
- self.updateCorniceTextureDNA(aDNACornice, dnaString)
- def updateCorniceTextureDNA(self, aDNACornice, dnaString):
- # Get the currently selected DNA Group
- aDNAGroup = self.selectedLevelObject['DNA']
- if dnaString == None:
- # Remove any existing cornices
- self.removeCornices(aDNAGroup)
- # Clear out target DNA Object
- self.targetDNAObject = None
- else:
- # Change the cornice type
- if aDNACornice:
- # Change existing one
- aDNACornice.setCode(self.dnaStore.findCode(dnaString))
- else:
- lastWall = self.getLastWall(aDNAGroup)
- if lastWall:
- # No cornice exists, add a new one
- newDNACornice = self.createCornice(dnaString)
- lastWall.add(newDNACornice)
- # Update target DNA Object
- self.targetDNAObject = newDNACornice
- # Replace object in levelObjects dictionary and scene graph
- self.replaceLevelObjectNodePath(self.selectedLevelObject)
- self.setCorniceTexture(dnaString)
- def updateDNAPosHpr(self, aNodePath):
- if aNodePath:
- dnaGroup = self.getDNAGroup(aNodePath)
- if dnaGroup:
- groupClass = dnaGroup.__class__.getClassType()
- if not(groupClass.eq(DNAGroup.getClassType())):
- dnaGroup.setPos(aNodePath.getPos())
- dnaGroup.setHpr(aNodePath.getHpr())
- if (groupClass.eq(DNAProp.getClassType())):
- dnaGroup.setScale(aNodePath.getScale())
- def updateDoorTextureNum(self, doorTextureNumber):
- self.updateObjDoorTexture(self.targetDNAObject, doorTextureNumber)
- def updateObjDoorTexture(self, aDNADoor, doorTextureNumber):
- # Which door texture was picked by the user?
- if doorTextureNumber < 0:
- dnaString = self.activeMenu.getInitialState()
- else:
- dnaString = self.getDoorTextures()[doorTextureNumber]
- # Now update the texture on the door with that texture
- self.updateDoorTextureDNA(aDNADoor, dnaString)
- def updateDoorTextureDNA(self, aDNADoor ,dnaString):
- aDNADoor.setCode(self.dnaStore.findCode(dnaString))
- # Replace object in levelObjects dictionary and scene graph
- self.replaceLevelObjectNodePath(self.selectedLevelObject)
- self.setDoorTexture(dnaString)
- def updateNumWindows(self, numWindows):
- if numWindows < 0:
- self.updateObjNumWindows(self.targetDNAObject,
- self.activeMenu.getInitialState())
- else:
- self.updateObjNumWindows(self.targetDNAObject,numWindows)
- def updateObjNumWindows(self, aDNAWall, numWindows):
- # remove any existing windows
- self.removeWindows(aDNAWall)
- # Add the newly specified number of windows
- newDNAWindows = self.createWindows(numWindows)
- aDNAWall.add(newDNAWindows)
- # Replace object in levelObjects dictionary and scene graph
- self.replaceLevelObjectNodePath(self.selectedLevelObject)
- self.setNumWindows(numWindows)
- def updateOrientationNum(self, orientationNumber):
- remappedOrientationNumber = orientationNumber
- # Remap lower menu values for Door's and Cornices'
- # (only have upper orientations)
- targetClass = self.targetDNAObject.__class__.getClassType()
- if (targetClass.eq(DNADoor.getClassType()) |
- targetClass.eq(DNAWindows.getClassType()) |
- targetClass.eq(DNACornice.getClassType())):
- if (orientationNumber == 2):
- remappedOrientationNumber = 1
- elif (orientationNumber == 3):
- remappedOrientationNumber = 0
- self.updateOrientation(self.targetDNAObject, remappedOrientationNumber)
- def updateOrientation(self, aDNAObject, orientationNumber):
- if self.activeMenu.getInitialState() == None:
- return None
- currString = self.getDNAString(aDNAObject)
- # Strip off current suffix
- newString = currString[:-3]
- if orientationNumber == 0:
- dnaString = newString + '_ur'
- elif orientationNumber == 1:
- dnaString = newString + '_ul'
- elif orientationNumber == 2:
- dnaString = newString + '_dl'
- elif orientationNumber == 3:
- dnaString = newString + '_dr'
- else:
- dnaString = self.activeMenu.getInitialState()
- if dnaString != currString:
- objClass = aDNAObject.__class__.getClassType()
- if objClass.eq(DNAWall.getClassType()):
- self.updateWallTextureDNA(aDNAObject, dnaString)
- elif objClass.eq(DNACornice.getClassType()):
- self.updateCorniceTextureDNA(aDNAObject, dnaString)
- elif objClass.eq(DNADoor.getClassType()):
- self.updateDoorTextureDNA(aDNAObject, dnaString)
- elif objClass.eq(DNAWindows.getClassType()):
- self.updateWindowTextureDNA(aDNAObject, dnaString)
- def updatePropNum(self,propNumber):
- self.updatePropType(self.targetDNAObject, propNumber)
- def updatePropType(self, aDNAProp, propNumber):
- # Which propType was picked by the user?
- if (propNumber < 0):
- dnaString = self.activeMenu.getInitialState()
- else:
- dnaString = self.getPropTypes()[propNumber]
- # Now update the texture on the wall with that texture
- self.updatePropDNA(aDNAProp,dnaString)
- def updatePropDNA(self, aDNAProp, dnaString):
- aDNAProp.setCode(self.dnaStore.findCode(dnaString))
- # Replace object in levelObjects dictionary and scene graph
- self.replaceLevelObjectNodePath(self.selectedLevelObject)
- self.setPropType(dnaString)
- def updateRandomNumWindows(self, aDNAFlatBuilding):
- for i in range(aDNAFlatBuilding.getNumChildren()):
- child = aDNAFlatBuilding.at(i)
- if child.__class__.getClassType().eq(DNAWall.getClassType()):
- self.setRandomNumWindows(
- child,
- self.getRandomNumWindows(child.getHeight()))
- def updateWallColor(self, aDNAWall, color):
- aDNAWall.setColor(color)
- # Replace object in levelObjects dictionary and scene graph
- self.replaceLevelObject(self.selectedLevelObject)
- def updateWallOrientationNum(self, wallOrientationNumber):
- self.updateWallOrientation(self.targetDNAObject, wallOrientationNumber)
- def updateWallOrientation(self, aDNAWall, wallOrientationNumber):
- currString = self.getDNAString(aDNAWall)
- # Strip off current suffix
- newString = currString[:-3]
- if wallOrientationNumber == 0:
- dnaString = newString + '_ur'
- elif wallOrientationNumber == 1:
- dnaString = newString + '_ul'
- elif wallOrientationNumber == 2:
- dnaString = newString + '_dr'
- elif wallOrientationNumber == 3:
- dnaString = newString + '_dl'
- else:
- dnaString = self.activeMenu.getInitialState()
- if dnaString != currString:
- self.updateWallTextureDNA(aDNAWall, dnaString)
- def updateWallStyleNum(self, styleNum):
- if styleNum < 0:
- self.setWallStyleNum(self.targetDNAObject, 0)
- else:
- self.setWallStyleNum(self.targetDNAObject, styleNum)
- self.replaceLevelObjectNodePath(self.selectedLevelObject)
- def updateWallTextureNum(self, wallTextureNumber):
- self.updateObjWallTextureNum(self.targetDNAObject, wallTextureNumber)
- def updateObjWallTextureNum(self, aDNAWall, wallTextureNumber):
- # Which wall texture was picked by the user?
- if wallTextureNumber < 0:
- dnaString = self.activeMenu.getInitialState()
- else:
- dnaString = self.getWallTextures()[wallTextureNumber]
- # Now update the texture on the wall with that texture
- self.updateWallTextureDNA(aDNAWall, dnaString)
- def updateWallTextureDNA(self, aDNAWall, dnaString):
- aDNAWall.setCode(self.dnaStore.findCode(dnaString))
- # Replace object in levelObjects dictionary and scene graph
- self.replaceLevelObjectNodePath(self.selectedLevelObject)
- self.setWallTexture(dnaString)
- def updateWallWidthSF(self, scaleFactor):
- if (scaleFactor < 0):
- self.updateWallWidth(self.targetDNAObject,
- (self.activeMenu.getInitialState()))
- else:
- self.updateWallWidth(self.targetDNAObject,
- self.wallWidths[scaleFactor])
- def updateSelectedWallWidth(self, width):
- if self.targetDNAObject:
- if self.targetDNAObject.__class__.getClassType().eq(
- DNAFlatBuilding.getClassType()):
- self.updateWallWidth(self.targetDNAObject,width)
- def updateWallWidth(self, aDNAWall, width):
- aDNAWall.setWidth(width)
- # Replace object in levelObjects dictionary and scene graph
- self.replaceLevelObjectNodePath(self.selectedLevelObject)
- self.setWallWidthVal(width)
- self.autoPositionGrid()
- def updateWindowTextureNum(self, windowTextureNumber):
- self.updateObjWindowTexture(self.targetDNAObject,
- windowTextureNumber)
- def updateObjWindowTexture(self, aDNAWindow, windowTextureNumber):
- # Which window texture was picked by the user?
- if windowTextureNumber < 0:
- dnaString = self.activeMenu.getInitialState()
- else:
- dnaString = self.getWindowTextures()[windowTextureNumber]
- # Now update the texture on the window with that texture
- self.updateWindowTextureDNA(aDNAWindow, dnaString)
- def updateWindowTextureDNA(self, aDNAWindow, dnaString):
- aDNAWindow.setCode(self.dnaStore.findCode(dnaString))
- # Replace object in levelObjects dictionary and scene graph
- self.replaceLevelObjectNodePath(self.selectedLevelObject)
- self.setWindowTexture(dnaString)
- def roundTo(self, value, divisor):
- return round(value/float(divisor)) * divisor
- def autoPositionGrid(self):
- # Move grid to prepare for placement of next object
- selectedNode = self.direct.selected.last
- if selectedNode:
- dnaGroup = self.getDNAGroup(selectedNode)
- groupClass = dnaGroup.__class__.getClassType()
- deltaPos = Point3(20,0,0)
- deltaHpr = VBase3(0)
- if groupClass.eq(DNAFlatBuilding.getClassType()):
- deltaPos.setX(self.getWallWidth())
- elif groupClass.eq(DNAStreet.getClassType()):
- objectType = self.getDNAString(dnaGroup)
- if objectType == 'street_5x20':
- deltaPos.setX(5.0)
- elif objectType == 'street_10x20':
- deltaPos.setX(10.0)
- elif objectType == 'street_20x20':
- deltaPos.setX(20.0)
- elif objectType == 'street_40x20':
- deltaPos.setX(40.0)
- elif objectType == 'street_80x20':
- deltaPos.setX(80.0)
- elif objectType == 'street_5x40':
- deltaPos.setX(5.0)
- elif objectType == 'street_10x40':
- deltaPos.setX(10.0)
- elif objectType == 'street_20x40':
- deltaPos.setX(20.0)
- elif objectType == 'street_30x40':
- deltaPos.setX(30.0)
- elif objectType == 'street_40x40':
- deltaPos.setX(40.0)
- elif objectType == 'street_80x40':
- deltaPos.setX(80.0)
- elif objectType == 'street_angle_30':
- deltaPos.setX(0.0)
- elif objectType == 'street_angle_45':
- deltaPos.setX(0.0)
- elif objectType == 'street_angle_60':
- deltaPos.setX(0.0)
- elif objectType == 'street_inner_corner':
- deltaPos.setX(20.0)
- elif objectType == 'street_outer_corner':
- deltaPos.setX(20.0)
- elif objectType == 'street_full_corner':
- deltaPos.setX(40.0)
- elif objectType == 'street_t_intersection':
- deltaPos.setX(40.0)
- elif objectType == 'street_y_intersection':
- deltaPos.setX(30.0)
- elif objectType == 'street_street_20x20':
- deltaPos.setX(20.0)
- elif objectType == 'street_street_40x40':
- deltaPos.setX(40.0)
- elif objectType == 'street_sidewalk_20x20':
- deltaPos.setX(20.0)
- elif objectType == 'street_sidewalk_40x40':
- deltaPos.setX(40.0)
- elif objectType == 'street_divided_transition':
- deltaPos.setX(40.0)
- elif objectType == 'street_divided_40x70':
- deltaPos.setX(40.0)
- elif objectType == 'street_stairs_40x10x5':
- deltaPos.setX(40.0)
- elif objectType == 'street_4way_intersection':
- deltaPos.setX(40.0)
- elif objectType == 'street_incline_40x40x5':
- deltaPos.setX(40.0)
- elif objectType == 'street_courtyard_70':
- deltaPos.setX(0.0)
- elif objectType == 'street_courtyard_70_exit':
- deltaPos.setX(0.0)
- elif objectType == 'street_courtyard_90':
- deltaPos.setX(0.0)
- elif objectType == 'street_courtyard_90_exit':
- deltaPos.setX(0.0)
- elif objectType == 'street_50_transition':
- deltaPos.setX(10.0)
- elif objectType == 'street_20x50':
- deltaPos.setX(20.0)
- elif objectType == 'street_40x50':
- deltaPos.setX(40.0)
- elif groupClass.eq(DNALandmarkBuilding.getClassType()):
- objectType = self.getDNAString(dnaGroup)
- if objectType[:-1] == 'toon_landmark_building_0':
- deltaPos.setX(25.0)
- elif objectType[:-1] == 'toon_landmark_building_2':
- deltaPos.setX(15.0)
- elif objectType[:-1] == 'toon_landmark_building_3':
- deltaPos.setX(20.0)
- elif groupClass.eq(DNAProp.getClassType()):
- objectType = self.getDNAString(dnaGroup)
- if objectType == 'prop_sphere':
- deltaPos.setX(40.0)
- # Position grid for placing next object
- # Eventually we need to setHpr too
- taskMgr.removeTasksNamed('autoPositionGrid')
- t = self.grid.lerpPos(deltaPos, 0.25,
- other = selectedNode,
- blendType = 'easeInOut',
- task = 'autoPositionGrid')
- t.deltaPos = deltaPos
- t.selectedNode = selectedNode
- t.uponDeath = self.autoPositionCleanup
-
- # Also move the camera
- taskMgr.removeTasksNamed('autoMoveDelay')
- handlesToCam = self.direct.widget.getPos(self.direct.camera)
- handlesToCam = handlesToCam * ( self.direct.chan.near/handlesToCam[1])
- if ((abs(handlesToCam[0]) > (self.direct.chan.nearWidth * 0.4)) |
- (abs(handlesToCam[2]) > (self.direct.chan.nearHeight * 0.4))):
- taskMgr.removeTasksNamed('manipulateCamera')
- self.direct.cameraControl.centerCamIn(self.direct.chan, 0.5)
- def autoPositionCleanup(self,state):
- self.grid.setPos(state.selectedNode, state.deltaPos)
- if self.grid.getXyzSnap():
- # Tighten up grid position
- pos = self.grid.getPos()
- roundVal = self.roundTo(self.grid.getGridSpacing(), 1)
- x = self.roundTo(pos[0], roundVal)
- y = self.roundTo(pos[1], roundVal)
- z = self.roundTo(pos[2], roundVal)
- self.grid.setPos(x,y,z)
- def plantSelectedNodePath(self):
- # Move grid to prepare for placement of next object
- selectedNode = self.direct.selected.last
- if selectedNode:
- # Where is the mouse relative to the grid?
- hitPt = self.getGridIntersectionPoint()
- selectedNode.setPos(self.grid, self.hitPt)
- dnaGroup = self.getDNAGroup(selectedNode)
- if dnaGroup:
- # Update props placement to reflect current mouse position
- dnaGroup.setPos(self.direct.selected.last.getPos())
- def resetLevel(self):
- # Clear out all objects
- self.direct.deselectAll()
- children = self.levelObjects.getChildren()
- for i in range(children.getNumPaths()):
- path = children.getPath(i)
- path.reparentTo(hidden)
- path.remove()
- # Create fresh DNA Object
- self.levelObjectsDNA = DNAData('LevelObjects')
- # Create new levelDictionary
- self.levelDictionary = {}
- # Create root node
- self.createTopLevelGroup()
- self.grid.setPosHpr(0,0,0,0,0,0)
- def selectNodePath(self, aNodePath):
- # Select new node path
- self.direct.select(aNodePath)
- # Update selectedLevelObject
- self.selectedLevelObject = self.getLevelObject(aNodePath)
- def getWallIntersectionPoint(self):
- """
- Return point of intersection between building's wall and line from cam
- through mouse. Return false, if nothing selected
- """
- selectedNode = self.direct.selected.last
- if not selectedNode:
- return 0
- # Find mouse point on near plane
- chan = self.direct.chan
- mouseX = chan.mouseX
- mouseY = chan.mouseY
- nearX = math.tan(deg2Rad(chan.fovH)/2.0) * mouseX * chan.near
- nearZ = math.tan(deg2Rad(chan.fovV)/2.0) * mouseY * chan.near
- # Initialize points
- mCam2Wall = chan.camera.getMat(selectedNode)
- mouseOrigin = Point3(0)
- mouseOrigin.assign(mCam2Wall.getRow3(3))
- mouseDir = Vec3(0)
- mouseDir.set(nearX, chan.near, nearZ)
- mouseDir.assign(mCam2Wall.xformVec(mouseDir))
- # Calc intersection point
- return planeIntersect(mouseOrigin, mouseDir, ZERO_POINT, NEG_Y_AXIS)
- def getGridIntersectionPoint(self):
- """
- Return point of intersection between ground plane and line from cam
- through mouse. Return false, if nothing selected
- """
- # Find mouse point on near plane
- chan = self.direct.chan
- mouseX = chan.mouseX
- mouseY = chan.mouseY
- nearX = math.tan(deg2Rad(chan.fovH)/2.0) * mouseX * chan.near
- nearZ = math.tan(deg2Rad(chan.fovV)/2.0) * mouseY * chan.near
- # Initialize points
- mCam2Grid = chan.camera.getMat(self.direct.grid)
- mouseOrigin = Point3(0)
- mouseOrigin.assign(mCam2Grid.getRow3(3))
- mouseDir = Vec3(0)
- mouseDir.set(nearX, chan.near, nearZ)
- mouseDir.assign(mCam2Grid.xformVec(mouseDir))
- # Calc intersection point
- return planeIntersect(mouseOrigin, mouseDir, ZERO_POINT, Z_AXIS)
- class LevelEditorPanel(Pmw.MegaToplevel):
- def __init__(self, levelEditor, parent = None, **kw):
- INITOPT = Pmw.INITOPT
- optiondefs = (
- ('title', 'Toontown Level Editor', None),
- )
- self.defineoptions(kw, optiondefs)
- Pmw.MegaToplevel.__init__(self, parent, title = self['title'])
- self.levelEditor = levelEditor
- self.direct = levelEditor.direct
- # Handle to the toplevels hull
- hull = self.component('hull')
- balloon = self.balloon = Pmw.Balloon(hull)
- # Start with balloon help disabled
- self.balloon.configure(state = 'none')
-
- menuFrame = Frame(hull, relief = GROOVE, bd = 2)
- menuFrame.pack(fill = X, expand = 1)
- menuBar = Pmw.MenuBar(menuFrame, hotkeys = 1, balloon = balloon)
- menuBar.pack(side = LEFT, expand = 1, fill = X)
- menuBar.addmenu('Level Editor', 'Level Editor Operations')
- menuBar.addmenuitem('Level Editor', 'command',
- 'Load DNA from specified file',
- label = 'Load DNA...',
- command = self.levelEditor.loadSpecifiedDNAFile)
- menuBar.addmenuitem('Level Editor', 'command',
- 'Save DNA data to specified file',
- label = 'Save DNA As...',
- command = self.levelEditor.saveToSpecifiedDNAFile)
- menuBar.addmenuitem('Level Editor', 'command',
- 'Save DNA File',
- label = 'Save DNA',
- command = self.levelEditor.outputDNADefaultFile)
- menuBar.addmenuitem('Level Editor', 'command',
- 'Exit Level Editor Panel',
- label = 'Exit',
- command = self.destroy)
- menuBar.addmenu('Help', 'Level Editor Help Operations')
- self.toggleBalloonVar = IntVar()
- self.toggleBalloonVar.set(0)
- menuBar.addmenuitem('Help', 'checkbutton',
- 'Toggle balloon help',
- label = 'Balloon Help',
- variable = self.toggleBalloonVar,
- command = self.toggleBalloon)
- self.editMenu = Pmw.ComboBox(
- menuFrame, labelpos = W,
- label_text = 'Edit Mode:', entry_width = 12,
- selectioncommand = self.chooseNeighborhood, history = 0,
- scrolledlist_items = ['Toontown Central', 'Donalds Dock',
- 'The Burrrgh', 'Minnies Melody Land'])
- self.editMenu.selectitem('Toontown Central')
- self.editMenu.pack(side = 'left', expand = 0)
-
- # Create the notebook pages
- notebook = Pmw.NoteBook(hull)
- notebook.pack(fill = BOTH, expand = 1)
- streetsPage = notebook.add('Streets')
- toonBuildingsPage = notebook.add('Toon Bldgs')
- landmarkBuildingsPage = notebook.add('Landmark Bldgs')
- # suitBuildingsPage = notebook.add('Suit Buildings')
- propsPage = notebook.add('Props')
- sceneGraphPage = notebook.add('SceneGraph')
- self.addStreetButton = Button(
- streetsPage,
- text = 'ADD STREET',
- command = self.addStreetModule)
- self.addStreetButton.pack(fill = 'x')
- self.streetSelector = Pmw.ComboBox(
- streetsPage,
- dropdown = 0,
- listheight = 200,
- labelpos = W,
- label_text = 'Street type:',
- label_width = 12,
- label_anchor = W,
- entry_width = 30,
- selectioncommand = self.setStreetModuleType,
- scrolledlist_items = map(lambda s: s[7:],
- levelEditor.getCatalogCodes(
- 'street'))
- )
- self.streetModuleType = levelEditor.getCatalogCode('street',0)
- self.streetSelector.selectitem(self.streetModuleType[7:])
- self.streetSelector.pack(expand = 1, fill = 'both')
- self.addToonBuildingButton = Button(
- toonBuildingsPage,
- text = 'ADD TOON BUILDING',
- command = self.addFlatBuilding)
- self.addToonBuildingButton.pack(fill = 'x')
- self.toonBuildingSelector = Pmw.ComboBox(
- toonBuildingsPage,
- dropdown = 0,
- listheight = 200,
- labelpos = W,
- label_width = 12,
- label_anchor = W,
- label_text = 'Toon bldg type:',
- entry_width = 30,
- selectioncommand = self.setFlatBuildingType,
- scrolledlist_items = ('random20', 'random30',
- 'toonTenTen', 'toonTwenty',
- 'toonTenTwenty', 'toonTwentyTen',
- 'toonTenTenTen', 'toonThirty')
- )
- self.toonBuildingType = 'random20'
- self.toonBuildingSelector.selectitem(self.toonBuildingType)
- self.toonBuildingSelector.pack(expand = 1, fill = 'both')
-
- self.toonBuildingWidthScale = EntryScale.EntryScale(
- toonBuildingsPage, min = 1.0, max = 30.0,
- resolution = 0.01, text = 'Wall Width',
- command = self.updateSelectedWallWidth)
- self.toonBuildingWidthScale.pack(fill = 'x')
-
- self.addLandmarkBuildingButton = Button(
- landmarkBuildingsPage,
- text = 'ADD LANDMARK BUILDING',
- command = self.addLandmark)
- self.addLandmarkBuildingButton.pack(fill = 'x')
- self.landmarkBuildingSelector = Pmw.ComboBox(
- landmarkBuildingsPage,
- dropdown = 0,
- listheight = 200,
- labelpos = W,
- label_width = 12,
- label_anchor = W,
- label_text = 'Landmark Building type:',
- entry_width = 30,
- selectioncommand = self.setLandmarkType,
- scrolledlist_items = map(lambda s: s[14:],
- levelEditor.getCatalogCodes(
- 'toon_landmark'))
- )
- self.landmarkType = levelEditor.getCatalogCode(
- 'toon_landmark',0)
- self.landmarkBuildingSelector.selectitem(
- levelEditor.getCatalogCode('toon_landmark',0)[14:])
- self.landmarkBuildingSelector.pack(expand = 1, fill = 'both')
- self.addPropsButton = Button(
- propsPage,
- text = 'ADD PROP',
- command = self.addProp)
- self.addPropsButton.pack(fill = 'x')
- self.propSelector = Pmw.ComboBox(
- propsPage,
- dropdown = 0,
- listheight = 200,
- labelpos = W,
- label_width = 12,
- label_anchor = W,
- label_text = 'Prop type:',
- entry_width = 30,
- selectioncommand = self.setPropType,
- scrolledlist_items = map(lambda s: s[5:],
- levelEditor.getCatalogCodes('prop'))
- )
- self.propType = levelEditor.getCatalogCode('prop',0)
- self.propSelector.selectitem(
- levelEditor.getCatalogCode('prop',0)[5:])
- self.propSelector.pack(expand = 1, fill = 'both')
- # Compact down notebook
- notebook.setnaturalsize()
- self.colorEntry = VectorWidgets.ColorEntry(
- hull, text = 'Select Color',
- command = self.updateSelectedObjColor)
- self.colorEntry.pack(fill = 'x')
- buttonFrame = Frame(hull)
- self.fMapViz = IntVar()
- self.fMapViz.set(0)
- self.mapSnapButton = Checkbutton(buttonFrame,
- text = 'Map Viz',
- width = 6,
- variable = self.fMapViz,
- command = self.toggleMapViz)
- self.mapSnapButton.pack(side = 'left', expand = 1, fill = 'x')
- self.fXyzSnap = IntVar()
- self.fXyzSnap.set(1)
- self.xyzSnapButton = Checkbutton(buttonFrame,
- text = 'XyzSnap',
- width = 6,
- variable = self.fXyzSnap,
- command = self.toggleXyzSnap)
- self.xyzSnapButton.pack(side = 'left', expand = 1, fill = 'x')
- self.fHprSnap = IntVar()
- self.fHprSnap.set(1)
- self.hprSnapButton = Checkbutton(buttonFrame,
- text = 'HprSnap',
- width = 6,
- variable = self.fHprSnap,
- command = self.toggleHprSnap)
- self.hprSnapButton.pack(side = 'left', expand = 1, fill = 'x')
- self.fGrid = IntVar()
- self.fGrid.set(0)
- self.gridButton = Checkbutton(buttonFrame,
- text = 'Show Grid',
- width = 6,
- variable = self.fGrid,
- command = self.toggleGrid)
- self.gridButton.pack(side = 'left', expand = 1, fill = 'x')
- buttonFrame.pack(expand = 1, fill = 'x')
- buttonFrame2 = Frame(hull)
- self.groupButton = Button(
- buttonFrame2,
- text = 'New group',
- command = self.levelEditor.createNewLevelGroup)
- self.groupButton.pack(side = 'left', expand = 1, fill = 'x')
-
- self.saveButton = Button(
- buttonFrame2,
- text = 'Set Parent',
- command = self.levelEditor.setGroupParentToSelected)
- self.saveButton.pack(side = 'left', expand = 1, fill = 'x')
- self.isolateButton = Button(
- buttonFrame2,
- text = 'Isolate Selected',
- command = self.levelEditor.isolateSelectedNodePath)
- self.isolateButton.pack(side = 'left', expand = 1, fill = 'x')
- self.showAllButton = Button(
- buttonFrame2,
- text = 'Show All',
- command = self.levelEditor.showAll)
- self.showAllButton.pack(side = 'left', expand = 1, fill = 'x')
- buttonFrame2.pack(fill = 'x')
- buttonFrame3 = Frame(hull)
- self.driveMode = IntVar()
- self.driveMode.set(1)
- self.driveModeButton = Radiobutton(
- buttonFrame3,
- text = 'Drive Mode',
- value = 0,
- variable = self.driveMode,
- command = self.levelEditor.useDriveMode)
- self.driveModeButton.pack(side = 'left', expand = 1, fill = 'x')
- self.directModeButton = Radiobutton(
- buttonFrame3,
- text = 'DIRECT Fly',
- value = 1,
- variable = self.driveMode,
- command = self.levelEditor.useDirectFly)
- self.directModeButton.pack(side = 'left', expand = 1, fill = 'x')
- buttonFrame3.pack(fill = 'x')
- self.sceneGraphExplorer = SceneGraphExplorer(
- parent = sceneGraphPage,
- root = self.levelEditor.getLevelObjects(),
- menuItems = ['Select', 'Isolate', 'Flash',
- 'Toggle Viz', 'Set Parent', 'Add Group'])
- self.sceneGraphExplorer.pack(expand = 1, fill = 'both')
-
- def toggleGrid(self):
- if self.fGrid.get():
- self.direct.grid.enable()
- else:
- self.direct.grid.disable()
- def toggleXyzSnap(self):
- self.direct.grid.setXyzSnap(self.fXyzSnap.get())
- def toggleHprSnap(self):
- self.direct.grid.setHprSnap(self.fXyzSnap.get())
-
- def toggleMapViz(self):
- self.levelEditor.toggleMapViz(self.fMapViz.get())
-
- def setStreetModuleType(self,name):
- self.streetModuleType = 'street_' + name
- def addStreetModule(self):
- self.levelEditor.addStreetModule(self.streetModuleType)
- def setFlatBuildingType(self,name):
- self.toonBuildingType = name
-
- def addFlatBuilding(self):
- self.levelEditor.addFlatBuilding(self.toonBuildingType)
- def setLandmarkType(self,name):
- self.landmarkType = 'toon_landmark_' + name
- def addLandmark(self):
- self.levelEditor.addLandmark(self.landmarkType)
- def setPropType(self,name):
- import pdb
- pdb.set_trace()
- self.propType = 'prop_' + name
-
- def addProp(self):
- self.levelEditor.addProp(self.propType)
- def chooseNeighborhood(self, neighborhood):
- if neighborhood == "Toontown Central":
- self.levelEditor.editToontownCentral()
- elif neighborhood == "Donalds Dock":
- self.levelEditor.editDonaldsDock()
- elif neighborhood == "The Burrrgh":
- self.levelEditor.editTheBurrrgh()
- elif neighborhood == "Minnies Melody Land":
- self.levelEditor.editMinniesMelodyLand()
- def updateSelectedWallWidth(self, strVal):
- self.levelEditor.updateSelectedWallWidth(string.atof(strVal))
- def setCurrentColor(self, colorVec):
- self.colorEntry.set([int(colorVec[0] * 255.0),
- int(colorVec[1] * 255.0),
- int(colorVec[2] * 255.0),
- 255])
- self.colorEntry['resetValue'] = (
- [int(colorVec[0] * 255.0),
- int(colorVec[1] * 255.0),
- int(colorVec[2] * 255.0),
- 255])
- def updateSelectedObjColor(self, color):
- obj = self.levelEditor.targetDNAObject
- if obj:
- objClass = obj.__class__.getClassType()
- if ((objClass.eq(DNAWall.getClassType())) |
- (objClass.eq(DNAWindows.getClassType())) |
- (objClass.eq(DNADoor.getClassType())) |
- (objClass.eq(DNACornice.getClassType()))):
- self.levelEditor.updateObjColor(
- self.levelEditor.targetDNAObject,
- VBase4((color[0]/255.0),
- (color[1]/255.0),
- (color[2]/255.0),
- 1.0))
- def toggleBalloon(self):
- if self.toggleBalloonVar.get():
- self.balloon.configure(state = 'balloon')
- else:
- self.balloon.configure(state = 'none')
- """
- !Level methodsFor: 'object operations' stamp: 'panda 00/00/0000 00:00'!
- keyboardRotateNodePath: aNodePath key: arrowDirection
- | pos hpr scale |
- pos = aNodePath getPos.
- scale = aNodePath getScale.
- self.lastAngle = self.lastAngle + (arrowDirection caseOf: { [#left]->[ 90.0 ] .
- [#right]->[ -90.0 ] .
- [#up]->[ 90.0 ] .
- [#down]->[ -90.0 ] }).
- (self.lastAngle < -180.0) ifTrue: [ self.lastAngle = self.lastAngle + 360.0 ].
- (self.lastAngle > 180.0) ifTrue: [ self.lastAngle = self.lastAngle - 360.0 ].
- hpr = VBase3 new: self.lastAngle y: 0.0 z: 0.0.
- aNodePath setPosHprScale: pos hpr: hpr scale: scale.
- # Refresh DNA
- self.updateDNAPosHpr: aNodePath.
- # Position grid for placing next object
- self.autoPositionGrid.
- ! !
- !Level methodsFor: 'object operations' stamp: 'panda 00/00/0000 00:00'!
- keyboardTranslateNodePath: aNodePath key: arrowDirection
- | pos deltaMove gridToCamera xAxis zAxis camXAxis xxDot xzDot |
- gridToCamera = self.grid getMat: chanCenter camera.
- xAxis = Vec3 right.
- zAxis = Vec3 up.
- camXAxis = gridToCamera xformVec: xAxis.
- xxDot = camXAxis dot: xAxis.
- xzDot = camXAxis dot: zAxis.
-
- # get current object position
- pos = aNodePath getPos: self.grid.
- # what is the current grid spacing?
- deltaMove = self.grid gridSpacing.
- # Add or subtract the specified delta
- (xxDot abs > xzDot abs) ifTrue: [
- (xxDot < 0.0) ifTrue: [ deltaMove = deltaMove negated. ].
- arrowDirection caseOf: { [#left]->[ pos setX: ((pos at: 0) - deltaMove) ] .
- [#right]->[ pos setX: ((pos at: 0) + deltaMove) ] .
- [#up]->[ pos setY: ((pos at: 1) + deltaMove) ] .
- [#down]->[ pos setY: ((pos at: 1) - deltaMove) ] }
- ]
- ifFalse: [
- (xzDot < 0.0) ifTrue: [ deltaMove = deltaMove negated. ].
- arrowDirection caseOf: { [#left]->[ pos setY: ((pos at: 1) + deltaMove) ] .
- [#right]->[ pos setY: ((pos at: 1) - deltaMove) ] .
- [#up]->[ pos setX: ((pos at: 0) + deltaMove) ] .
- [#down]->[ pos setX: ((pos at: 0) - deltaMove) ] }
- ].
- # Move it
- aNodePath setPos: self.grid pos: pos.
-
- # Refresh DNA
- self.updateDNAPosHpr: aNodePath.
- # Position grid for placing next object
- self.autoPositionGrid.
- ! !
- !Level methodsFor: 'object operations' stamp: 'panda 00/00/0000 00:00'!
- keyboardXformNodePath: arrowDirection
- (direct fControl) ifTrue: [
- direct selectedNodePaths
- valuesDo: [ :np | self.keyboardRotateNodePath: np key: arrowDirection ].
- ]
- ifFalse: [
- direct selectedNodePaths
- valuesDo: [ :np | self.keyboardTranslateNodePath: np key: arrowDirection ].
- ].
- ! !
- !Level methodsFor: 'object operations' stamp: 'panda 00/00/0000 00:00'!
- mouseCrank: aNodePath
- # Rotate object about its origin, based upon current mouse position
- # Positive X axis of object is rotated to line up with current Crank Dir
- (or closest snapAngle degree angle if HPR Snap is on
- (self.grid getMouseIntersectionPoint: self.hitPt )
- ifTrue: [self.crankDir = self.hitPt - self.crankOrigin.
- ((self.crankDir length) > 1.0)
- ifTrue: [ | deltaAngle newH |
- deltaAngle = (self.getCrankAngle - startAngle).
- newH = startH + deltaAngle.
- self.hprSnap ifTrue: [ newH = newH roundTo: self.snapAngle. ].
- aNodePath setH: newH.
- # record angle (used for placing new instance)
- self.lastAngle = newH.
- ].
- ].
- ! !
- def acceptArrowKeys(self):
- # Accept arrow key events for swinging piece around
- self.accept('left', self.keyboardXformNodePath, ['left'])
- self.accept('right', self.keyboardXformNodePath, ['right'])
- self.accept('up', self.keyboardXformNodePath, ['up'])
- self.accept('down', self.keyboardXformNodePath, ['down'])
- def keyboardXformNodePath(self,x):
- pass
- def ignoreArrowKeys(self):
- # Accept arrow key events for swinging piece around
- self.ignore('left')
- self.ignore('right')
- self.ignore('up')
- self.ignore('down')
- """
|