Added status readout, confirm to save when reset

This commit is contained in:
Gyedo Jeon 2010-02-25 22:21:57 +00:00
parent d3e12cde87
commit 29d6242dff
4 changed files with 91 additions and 8 deletions

View File

@ -34,6 +34,8 @@ class FileMgr:
f.write(data)
f.write('\n')
f.close()
self.editor.updateStatusReadout('Sucessfully saved to %s'%fileName)
self.editor.fNeedToSave = False
except IOError:
print 'failed to save %s'%fileName
if f:
@ -46,5 +48,7 @@ class FileMgr:
file, pathname, description = imp.find_module(moduleName, [dirname])
try:
module = imp.load_module(moduleName, file, pathname, description)
self.editor.updateStatusReadout('Sucessfully opened file %s'%fileName)
self.editor.fNeedToSave = False
except:
print 'failed to load %s'%fileName

View File

@ -9,6 +9,8 @@ from pandac.PandaModules import *
from direct.showbase.ShowBase import *
from direct.showbase.DirectObject import *
from direct.directtools.DirectGlobals import *
from direct.directtools.DirectUtil import *
from direct.gui.DirectGui import *
base = ShowBase(False)
@ -22,6 +24,7 @@ class LevelEditorBase(DirectObject):
def __init__(self):
#loadPrcFileData('startup', 'window-type none')
self.currentFile = None
self.fNeedToSave = False
self.actionEvents = []
self.objectMgr = ObjectMgr(self)
self.fileMgr = FileMgr(self)
@ -136,6 +139,18 @@ class LevelEditorBase(DirectObject):
else:
self.accept(event[0], event[1])
# editor state text display such as edit mode
self.statusReadout = OnscreenText(
pos = (-1.2, 0.9), bg=Vec4(1,1,1,1),
scale = 0.05, align = TextNode.ALeft,
mayChange = 1, font = TextNode.getDefaultFont())
self.statusReadout.setText("")
# Make sure readout is never lit or drawn in wireframe
useDirectRenderStyle(self.statusReadout)
self.statusReadout.reparentTo(hidden)
self.statusLines = []
taskMgr.doMethodLater(5, self.updateStatusReadoutTimeouts, 'updateStatus')
self.loadSettings()
def removeNodePathHook(self, nodePath):
@ -229,6 +244,12 @@ class LevelEditorBase(DirectObject):
self.objectMgr.deselectAll()
def reset(self):
if self.fNeedToSave:
reply = wx.MessageBox("Do you want to save current scene?", "Save?",
wx.YES_NO | wx.ICON_QUESTION)
if reply == wx.YES:
self.ui.onSave()
base.direct.deselectAll()
self.objectMgr.reset()
self.actionMgr.reset()
@ -239,6 +260,7 @@ class LevelEditorBase(DirectObject):
self.resetOrthoCam(self.ui.topView)
self.resetOrthoCam(self.ui.frontView)
self.resetOrthoCam(self.ui.leftView)
self.fNeedToSave = False
def resetOrthoCam(self, view):
base.direct.drList[base.camList.index(NodePath(view.camNode))].orthoFactor = 0.1
@ -324,3 +346,45 @@ class LevelEditorBase(DirectObject):
else:
mayaConverter = MayaConverter(self.ui, self, modelname, None, False)
mayaConverter.Show()
def updateStatusReadout(self, status, color=None):
if status:
# add new status line, first check to see if it already exists
alreadyExists = False
for currLine in self.statusLines:
if (status == currLine[1]):
alreadyExists = True
break
if (alreadyExists == False):
time = globalClock.getRealTime() + 15
self.statusLines.append([time,status,color])
# update display of new status lines
self.statusReadout.reparentTo(aspect2d)
statusText = ""
lastColor = None
for currLine in self.statusLines:
statusText += currLine[1] + '\n'
lastColor = currLine[2]
self.statusReadout.setText(statusText)
if (lastColor):
self.statusReadout.textNode.setCardColor(
lastColor[0], lastColor[1], lastColor[2], lastColor[3])
self.statusReadout.textNode.setCardAsMargin(0.1, 0.1, 0.1, 0.1)
else:
self.statusReadout.textNode.setCardColor(1,1,1,1)
self.statusReadout.textNode.setCardAsMargin(0.1, 0.1, 0.1, 0.1)
def updateStatusReadoutTimeouts(self,task=None):
removalList = []
for currLine in self.statusLines:
if (globalClock.getRealTime() >= currLine[0]):
removalList.append(currLine)
for currRemoval in removalList:
self.statusLines.remove(currRemoval)
self.updateStatusReadout(None)
# perform doMethodLater again after delay
# This crashes when CTRL-C'ing, so this is a cheap hack.
#return 2
from direct.task import Task
return Task.again

View File

@ -374,6 +374,7 @@ class LevelEditorUIBase(WxAppShell):
def onDestroy(self, evt):
self.editor.protoPalette.saveToFile()
self.editor.saveSettings()
self.editor.reset()
def updateGrids(self, newSize, newSpacing):
self.perspView.grid.gridSize = newSize

View File

@ -147,7 +147,7 @@ class ObjectMgr:
if fSelectObject:
self.editor.select(newobj, fUndo=0)
self.editor.ui.sceneGraphUI.add(newobj)
self.editor.fNeedToSave = True
return newobj
def removeObjectByNodePath(self, nodePath):
@ -160,6 +160,7 @@ class ObjectMgr:
for child in nodePath.getChildren():
if child.hasTag('OBJRoot'):
self.removeObjectByNodePath(child)
self.editor.fNeedToSave = True
def findObjectById(self, uid):
return self.objects.get(uid)
@ -195,13 +196,16 @@ class ObjectMgr:
objDef = obj[OG.OBJ_DEF]
objProp = obj[OG.OBJ_PROP]
self.editor.ui.objectPropertyUI.updateProps(obj)
self.editor.fNeedToSave = True
def onEnterObjectPropUI(self, event):
taskMgr.remove('_le_updateObjectUITask')
self.editor.ui.wxApp.Unbind(wx.EVT_CHAR)
def onLeaveObjectPropUI(self, event):
self.spawnUpdateObjectUITask()
self.editor.ui.wxApp.Bind(wx.EVT_CHAR, self.editor.ui.onKeyEvent)
def spawnUpdateObjectUITask(self):
if self.currNodePath is None:
return
@ -290,11 +294,13 @@ class ObjectMgr:
self.editor.actionMgr.push(action)
np.remove()
action()
self.editor.fNeedToSave = True
def setObjectTransform(self, uid, xformMat):
obj = self.findObjectById(uid)
if obj:
obj[OG.OBJ_NP].setMat(xformMat)
self.editor.fNeedToSave = True
def updateObjectColor(self, r, g, b, a, np=None):
if np is None:
@ -309,7 +315,8 @@ class ObjectMgr:
child.getName() != 'bboxLines':
child.setTransparency(1)
child.setColorScale(r, g, b, a)
self.editor.fNeedToSave = True
def updateObjectModel(self, model, obj, fSelectObject=True):
""" replace object's model """
if obj[OG.OBJ_MODEL] != model:
@ -348,6 +355,8 @@ class ObjectMgr:
if fSelectObject:
base.direct.select(newobj, fUndo=0)
self.editor.fNeedToSave = True
def updateObjectAnim(self, anim, obj, fSelectObject=True):
""" replace object's anim """
if obj[OG.OBJ_ANIM] != anim:
@ -362,6 +371,8 @@ class ObjectMgr:
if fSelectObject:
base.direct.select(objNP, fUndo=0)
self.editor.fNeedToSave = True
def updateObjectModelFromUI(self, event, obj):
""" replace object's model with one selected from UI """
model = event.GetString()
@ -488,8 +499,10 @@ class ObjectMgr:
self.editor.actionMgr.push(action)
action()
if self.editor and fSelectObject:
base.direct.select(obj[OG.OBJ_NP], fUndo=0)
if self.editor:
self.editor.fNeedToSave = True
if fSelectObject:
base.direct.select(obj[OG.OBJ_NP], fUndo=0)
def updateObjectProperties(self, nodePath, propValues):
"""
@ -582,7 +595,6 @@ class ObjectMgr:
# copy other properties
for key in obj[OG.OBJ_PROP]:
self.updateObjectPropValue(newObj, key, obj[OG.OBJ_PROP][key])
return newObjNP
def duplicateChild(self, nodePath, parent):
@ -605,6 +617,8 @@ class ObjectMgr:
for newNodePath in duplicatedNPs:
base.direct.select(newNodePath, fMultiSelect = 1, fUndo=0)
self.editor.fNeedToSave = True
def makeSelectedLive(self):
obj = self.findObjectByNodePath(base.direct.selected.last)
if obj: