Mercurial > fife-parpg
changeset 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 | 56ac89189bc4 |
children | fcef34d67ad9 |
files | clients/editor/gui/layertool.xml clients/editor/icons/is_visible.png clients/editor/plugins/layertool.py clients/editor/plugins/mapeditor.py clients/editor/run.py |
diffstat | 5 files changed, 180 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/editor/gui/layertool.xml Wed Feb 11 19:27:18 2009 +0000 @@ -0,0 +1,5 @@ +<Window title="Layertool" position="10,200"> + <VBox name="layers_wrapper"> + + </VBox> +</Window>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/editor/plugins/layertool.py Wed Feb 11 19:27:18 2009 +0000 @@ -0,0 +1,156 @@ +#!/usr/bin/env python +# coding: utf-8 +# ################################################### +# Copyright (C) 2008 The Zero-Projekt team +# http://zero-projekt.net +# info@zero-projekt.net +# This file is part of Zero "Was vom Morgen blieb" +# +# The Zero-Projekt codebase is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# ################################################### + +""" an advanced layer tool for FIFedit """ + +import fife +import plugin +import pychan +import pychan.widgets as widgets +from pychan.tools import callbackWithArguments as cbwa + +import settings as Settings + +class LayerTool(plugin.Plugin): + """ The B{LayerTool} is an advanced method to view + and change layer informations. + + While the original FIFedit tool only allows to select + layers, this one will provide the following functionality: + + - toggle layer visibility + - select layer + - list layers + + The plugin has to register itself in the mapeditor module + to get actual content when a new map is loaded. + """ + def __init__(self, engine, mapedit): + # Fifedit plugin data + self.menu_items = { 'LayerTool' : self.toggle } + self._mapedit = mapedit + self.data = False + + # "register" at mapeditor module + self._mapedit.layertool = self + + self.subwrappers = [] + self.__create_gui() + + def __create_gui(self): + """ create the basic gui container """ + self.container = pychan.loadXML('gui/layertool.xml') + self.wrapper = self.container.findChild(name="layers_wrapper") + + def _adjust_position(self): + """ adjusts the position of the container - we don't want to + let the window appear at the center of the screen. + (new default position: left, beneath the tools window) + """ + self.container.position = (10, 200) + + def clear(self): + """ remove all subwrappers """ + if self.subwrappers is []: return + + for subwrapper in self.subwrappers: + self.wrapper.removeChild(subwrapper) + + self.subwrappers = [] + + def update(self): + """ dump new layer informations into the wrapper + + We group one ToggleButton and one Lable into a HBox, the main wrapper + itself is a VBox and we also capture both the Button and the Label to listen + for mouse actions + """ + layers = self._mapedit._map.getLayers() + + self.clear() + + for layer in layers: + layerid = layer.getId() + subwrapper = pychan.widgets.HBox() + + visibility_widget = pychan.widgets.ToggleButton(up_image="icons/is_visible.png",down_image="icons/quit.png") + visibility_widget.name = "toggle_" + layerid + visibility_widget.capture(self.toggle_layer_visibility,"mousePressed") + + layer_name_widget = pychan.widgets.Label() + layer_name_widget.text = layerid + layer_name_widget.name = "select_" + layerid + layer_name_widget.capture(self.select_active_layer,"mousePressed") + + subwrapper.addChild(visibility_widget) + subwrapper.addChild(layer_name_widget) + + self.wrapper.addChild(subwrapper) + self.subwrappers.append(subwrapper) + + self.container.adaptLayout() + self.data = True + + def toggle(self): + """ toggle visibility of the main gui container """ + if self.container.isVisible(): + self.container.hide() + else: + self.container.show() + self._adjust_position() + + def toggle_layer_visibility(self, event, widget): + """ callback for ToggleButtons + + @type event: object + @param event: pychan mouse event + @type widget: object + @param widget: the pychan widget where the event occurs, transports the layer id in it's name + """ + if not self.data: return + + layerid = widget.name[7:] + + layer = self._mapedit._map.getLayer(layerid) + if layer.areInstancesVisible(): + layer.setInstancesVisible(False) + else: + layer.setInstancesVisible(True) + + + def select_active_layer(self, event, widget): + """ callback for Labels + + We hand the layerid over to the mapeditor module to select a + new active layer + + @type event: object + @param event: pychan mouse event + @type widget: object + @param widget: the pychan widget where the event occurs, transports the layer id in it's name + """ + if not self.data: return + + layerid = widget.name[7:] + self._mapedit._editLayer(layerid)
--- a/clients/editor/plugins/mapeditor.py Sat Jan 31 04:15:43 2009 +0000 +++ b/clients/editor/plugins/mapeditor.py Wed Feb 11 19:27:18 2009 +0000 @@ -243,6 +243,10 @@ self._setMode(VIEWING) self._mapselector.show(self._map) + + # zero-projekt plugin + if self.layertool is not None: + self.layertool.update() def _selectLayer(self): Selection([layer.getId() for layer in self._map.getLayers()], self._editLayer)
--- a/clients/editor/run.py Sat Jan 31 04:15:43 2009 +0000 +++ b/clients/editor/run.py Wed Feb 11 19:27:18 2009 +0000 @@ -28,9 +28,11 @@ from plugins.mapeditor import MapEditor from plugins.mapwizard import MapWizard from fifedit import Fifedit -# by c 09/11/08 + +# zero-projekt plugins from plugins.objectedit import ObjectEdit -# end edit c +from plugins.layertool import LayerTool + # Help display class Help(Plugin): @@ -60,9 +62,11 @@ self.mapsaver = MapSaver(self.engine) self.mapwizard = MapWizard(self.engine) self.importer = Importer(self.engine) -# by c 09/11/08 + + # zero-projekt plugins self.objectedit = ObjectEdit(self.engine, self.mapedit) -# end edit c + self.layertool = LayerTool(self.engine, self.mapedit) + # Register plugins with Fifedit. self.fifedit.registerPlugin(Help()) self.fifedit.registerPlugin(self.maploader) @@ -70,9 +74,11 @@ self.fifedit.registerPlugin(self.mapedit) self.fifedit.registerPlugin(self.mapwizard) self.fifedit.registerPlugin(self.importer) -# by c 09/11/08 + + # zero-projekt plugins self.fifedit.registerPlugin(self.objectedit) -# end edit c + self.fifedit.registerPlugin(self.layertool) + self.params = params def createListener(self): @@ -101,10 +107,11 @@ parts = self.params.split(s) self.maploader.loadFile(s.join(parts[0:-1]), parts[-1]) self.params = None -# edit by c 11/09 + + # zero-projekt plugins if self.mapedit._instances is not None: self.objectedit.input() -# end edit c + if __name__ == '__main__': print sys.argv