view clients/editor/run.py @ 182:bcc93e17f978

- added new plugin to FIFedit (Layertool) FEATURES: - layers now can be toogled visible / invisible - tool also allows layer selection (better workflow IMO) - just click on the layer name - demo screencapture can be found here: http://zero-projekt.net/files/screencaptures/1280x_zero_fifedit_layertool.ogg Please let me know if this plugin causes any trouble for you.
author chewie@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 11 Feb 2009 19:27:18 +0000
parents 28532ae6f9f6
children 51cc05d862f2
line wrap: on
line source

#!/usr/bin/env python
# coding: utf-8
# This is the editor client for FIFE.

import sys, os, re

def _jp(path):
	return os.path.sep.join(path.split('/'))

_paths = ('.', '../../engine/swigwrappers/python', '../../engine/extensions')
for p in _paths:
	if p not in sys.path:
		sys.path.append(_jp(p))

import fife
import fifelog
import basicapplication
import pychan
import pychan.widgets as widgets
import sys

from listener import EditorListener

from plugins.plugin import Plugin
from plugins.maploader import MapLoader
from plugins.maploader import MapSaver
from plugins.importer import Importer
from plugins.mapeditor import MapEditor
from plugins.mapwizard import MapWizard
from fifedit import Fifedit

# zero-projekt plugins
from plugins.objectedit import ObjectEdit
from plugins.layertool import LayerTool


# Help display
class Help(Plugin):
	def __init__(self):
		self._helpWidget = None	
		self.menu_items = { 'Help' : self.showHelp }

	def showHelp(self):
		if self._helpWidget:
			self._helpWidget.show()
			return
		self._helpWidget = pychan.loadXML('gui/help.xml')
		self._helpWidget.mapEvents({ 'closeButton' : self._helpWidget.hide })
		self._helpWidget.distributeData({ 'helpText' : open("misc/infotext.txt").read() })
		self._helpWidget.show()

class Editor(basicapplication.ApplicationBase):
	def __init__(self, params):
		super(Editor,self).__init__()

		# embed Fifedit tools
		self.fifedit = Fifedit(self.engine)

		# Create this client's modules
		self.mapedit = MapEditor(self.engine)
		self.maploader = MapLoader(self.engine)
		self.mapsaver = MapSaver(self.engine)
		self.mapwizard = MapWizard(self.engine)
		self.importer = Importer(self.engine)

		# zero-projekt plugins
		self.objectedit = ObjectEdit(self.engine, self.mapedit)
		self.layertool = LayerTool(self.engine, self.mapedit)

		# Register plugins with Fifedit.
		self.fifedit.registerPlugin(Help())
		self.fifedit.registerPlugin(self.maploader)
		self.fifedit.registerPlugin(self.mapsaver)
		self.fifedit.registerPlugin(self.mapedit)
		self.fifedit.registerPlugin(self.mapwizard)
		self.fifedit.registerPlugin(self.importer)

		# zero-projekt plugins
		self.fifedit.registerPlugin(self.objectedit)
		self.fifedit.registerPlugin(self.layertool)
			
		self.params = params

	def createListener(self):
		# override default event listener
		return EditorListener(self)

	def _pump(self):
		self.mapedit.pump()
		if self.maploader.newMap:
			self.mapedit.editMap(self.maploader.newMap.getId())	
			self.importer.addDirs(self.maploader.newMap.importDirs)
			self.maploader.newMap = None
		if self.mapwizard.newMap:
			self.mapedit.editMap(self.mapwizard.map.getId())
			self.mapwizard.newMap = False
		if self.mapsaver.saveRequested:
			if self.mapedit._map:
				self.mapsaver.saveMap(self.mapedit._map,self.importer.importList)
			else:
				print "Cannot save, map doesn't exist"
			self.mapsaver.saveRequested = False
		if not self.fifedit.active: 
			self.quitRequested = True
		if self.params:
			s = os.path.sep
			parts = self.params.split(s)
			self.maploader.loadFile(s.join(parts[0:-1]), parts[-1])
			self.params = None

		# zero-projekt plugins
		if self.mapedit._instances is not None:
			self.objectedit.input()


if __name__ == '__main__':
	print sys.argv
	params = None
	if len(sys.argv) > 1:
		params = sys.argv[1]
	app = Editor(params)
	app.run()