示例#1
0
    def create(self):
        """ Create the basic gui container """
        self.container = pychan.loadXML('gui/regiontool.xml')
        self.wrapper = self.container.findChild(name="regions_wrapper")
        self.remove_region_button = self.container.findChild(name="remove_region_button")
        self.create_region_button = self.container.findChild(name="add_region_button")
        self.edit_region_button = self.container.findChild(name="edit_region_button")

        self.remove_region_button.capture(self.removeSelectedRegion)
        self.remove_region_button.capture(cbwa(self._editor.getStatusBar().showTooltip, self.remove_region_button.helptext), 'mouseEntered')
        self.remove_region_button.capture(self._editor.getStatusBar().hideTooltip, 'mouseExited')

        self.create_region_button.capture(self.showRegionWizard)
        self.create_region_button.capture(cbwa(self._editor.getStatusBar().showTooltip, self.create_region_button.helptext), 'mouseEntered')
        self.create_region_button.capture(self._editor.getStatusBar().hideTooltip, 'mouseExited')

        self.edit_region_button.capture(self.showEditDialog)
        self.edit_region_button.capture(cbwa(self._editor.getStatusBar().showTooltip, self.edit_region_button.helptext), 'mouseEntered')
        self.edit_region_button.capture(self._editor.getStatusBar().hideTooltip, 'mouseExited')

        self.select_layer_drop_down = self.container.findChild(name="layer_select_drop_down")
        self.select_layer_drop_down.capture(self.update_region_layer)

        self.onNewMap(None)

        # overwrite Panel.afterUndock
        self.container.afterUndock = self.on_undock
        self.container.afterDock = self.on_dock
示例#2
0
	def moveInstances(self, instances, moveBy, exact=False, origLoc=None, origFacing=None):
		""" Moves provided instances by moveBy. If exact is false, the instances are
			snapped to closest cell. origLoc and origFacing are only set when an undo/redo
			operation takes place and will have no effect and should not be used under normal
			circumstances.
		
		@type	instances:	list
		@param	instances:	a bunch of selected fife.Instance objects
		@type	moveBy:	fife.Point3D
		@param	moveBy:	diff of last and current exact model coordinate relative to the cursor
		@type	exact:	bool
		@param	exact:	flag to either set exactLayerCoordinates or LayerCoordinates
		@rtype	result:	bool
		@return	result:	flag wether the instances were moved or not (always True if exact=True)
		"""
		result = True
		mname = 'moveInstances'
		if not self._layer:
			if self.debug: print 'No layer assigned in %s' % mname
			return not result

		moveBy = fife.ExactModelCoordinate(float(moveBy.x), float(moveBy.y), float(moveBy.z))

		for i in instances:
			loc = i.getLocation()
			f = i.getFacingLocation()
			
			nloc = fife.Location(self._layer)
			nloc.setMapCoordinates(loc.getMapCoordinates() + moveBy)
			
			if loc.getLayerCoordinates() == nloc.getLayerCoordinates() and not exact:
				result = False
				break
			
			if exact:
				loc.setMapCoordinates(nloc.getMapCoordinates())
				f.setMapCoordinates(loc.getMapCoordinates())
			else:	
				loc.setLayerCoordinates(nloc.getLayerCoordinates())
				f.setLayerCoordinates(loc.getLayerCoordinates())

			if not self._undo:
				undocall = cbwa(self.moveInstances, [i], moveBy, exact, i.getLocation(), i.getFacingLocation())
				redocall = cbwa(self.moveInstances, [i], moveBy, exact, i.getLocation(), i.getFacingLocation())
				undoobject = undomanager.UndoObject(undocall, redocall, "Moved instance")
				self._undomanager.addAction(undoobject)
				i.setLocation(loc)
				i.setFacingLocation(f)
				
			else:
				assert(origLoc)
				assert(origFacing)
				i.setLocation(origLoc)
				i.setFacingLocation(origFacing)
				
		return result
示例#3
0
	def _createGui(self):
		""" Create the basic gui container """
		self._container =  pychan.loadXML('gui/cameradialog.xml')
		
		self._ok_button = self._container.findChild(name="okButton")
		self._cancel_button = self._container.findChild(name="cancelButton")
		
		self._ok_button.capture(self.saveSettings)
		self._ok_button.capture(cbwa(self._editor.getStatusBar().showTooltip, unicode("Save changes to the camera")), 'mouseEntered')
		self._ok_button.capture(self._editor.getStatusBar().hideTooltip, 'mouseExited')

		self._cancel_button.capture(self.toggle)
		self._cancel_button.capture(cbwa(self._editor.getStatusBar().showTooltip, unicode("Discard any changes to the camera")), 'mouseEntered')
		self._cancel_button.capture(self._editor.getStatusBar().hideTooltip, 'mouseExited')
示例#4
0
	def _redirectEvent(self,name,event):
		self.indent += 4
		try:
			event = self.translateEvent(getEventType(name), event)
			if name in self.events:
				if self.debug: print "-"*self.indent, name
				for f in self.events[name].itervalues():
					def delayed_f(timer, f=f): # bind f during loop
						n_timer = timer()
						f( event )
						
						#FIXME: figure out a way to get rid of the dead timer list
						del self._deadtimers[:]
						
						if n_timer in self._timers:
							self._deadtimers.append(n_timer)
							self._timers.remove(n_timer)
						
							
					timer = Timer(repeat=1)
					timer._callback = cbwa(delayed_f, weakref.ref(timer))
					timer.start()
					
					self._timers.append(timer)

		except:
			print name, repr(event)
			traceback.print_exc()
			raise

		finally:
			self.indent -= 4
示例#5
0
	def start(self):
		""" 
		load XML file and setup callbacks
		"""
		
		self.widget = pychan.loadXML(self.xmlFile)
		
		self.widget.mapEvents({
			'closeButton'	:	self.stop,
			
			'example_move'	:	cbwa(self._start_anim, type=ACTION_MOVE),
			'example_color'	:	cbwa(self._start_anim, type=ACTION_COLOR),
			'example_resize':	cbwa(self._start_anim, type=ACTION_RESIZE),
			'example_all'	: 	self._anim_all,			
			'delay'			:	self._set_delay_display,
		})
		
		self.move_example_widget = self.widget.findChild(name="move")
		self.mew = self.move_example_widget

		self.resize_example_widget = self.widget.findChild(name="resize")
		self.rew = self.resize_example_widget		

		self.color_example_widget = self.widget.findChild(name="color")
		self.cew = self.color_example_widget
		
		self.delay_slider = self.widget.findChild(name="delay")
		self.delay_slider.value = float(DEFAULT_DELAY)
		
		self.delay_display = self.widget.findChild(name="delay_label")
		self.delay_display.text = unicode(str(DEFAULT_DELAY))
		
		self.progressbar = self.widget.findChild(name="progressbar")
#		self.progressbar2 = self.widget.findChild(name="progressbar2")
		
		self.little_matrix = []
		for x in range(1,4):
			for y in range(1,4):
				name = "color_%s_%s" % (x, y)
				widget = self.widget.findChild(name=name)
				self.little_matrix.append(widget)
		
		self.widget.adaptLayout(True)
		self.widget.show()
示例#6
0
	def placeInstance(self, position, object, layer=None):
		""" Places an instance of object at position. Any existing instances on position are removed. """
		mname = 'placeInstance'
		if not object:
			if self.debug: print 'No object assigned in %s' % mname
			return
		if not position:
			if self.debug: print 'No position assigned in %s' % mname
			return
		if not self._layer:
			if self.debug: print 'No layer assigned in %s' % mname
			return

		if self.debug: print 'Placing instance of ' + object.getId() + ' at ' + str(position)
		
		# Remove instances from target position
		if not self._undo:
			instances = self.getInstancesFromPosition(position)
			if len(instances) == 1:
				# Check if the only instance at position has the same object
				objectId = instances[0].getObject().getId()
				objectNs = instances[0].getObject().getNamespace()
				if objectId == object.getId() and objectNs == object.getNamespace():
					if self.debug: print "Tried to place duplicate instance"
					return
					
			self._undomanager.startGroup("Placed instance")
			self.removeInstances(instances)

		if layer:
			inst = layer.createInstance(object, position)
		else:
			inst = self._layer.createInstance(object, position)
		fife.InstanceVisual.create(inst)
		
		# update reference count in import list for object
		self.incrementReferenceCountForObject(object)
		
		if not self._undo:
			redocall = cbwa(self.placeInstance, position, object, inst.getLocation().getLayer())
			undocall = cbwa(self.removeInstanceOfObjectAt, position, object, inst.getLocation().getLayer())
			undoobject = undomanager.UndoObject(undocall, redocall, "Placed instance")
			self._undomanager.addAction(undoobject)
			self._undomanager.endGroup()
示例#7
0
	def _createGui(self):
		""" Create the basic gui container """
		self._container =  pychan.loadXML('gui/layertool.xml')
		self._wrapper = self._container.findChild(name="layers_wrapper")
		self._remove_layer_button = self._container.findChild(name="remove_layer_button")
		self._create_layer_button = self._container.findChild(name="add_layer_button")
		self._edit_layer_button = self._container.findChild(name="edit_layer_button")
		
		self._remove_layer_button.capture(self.removeSelectedLayer)
		self._remove_layer_button.capture(cbwa(self._editor.getStatusBar().showTooltip, self._remove_layer_button.helptext), 'mouseEntered')
		self._remove_layer_button.capture(self._editor.getStatusBar().hideTooltip, 'mouseExited')
		
		self._create_layer_button.capture(self.showLayerWizard)
		self._create_layer_button.capture(cbwa(self._editor.getStatusBar().showTooltip, self._create_layer_button.helptext), 'mouseEntered')
		self._create_layer_button.capture(self._editor.getStatusBar().hideTooltip, 'mouseExited')
		
		self._edit_layer_button.capture(self.showEditDialog)
		self._edit_layer_button.capture(cbwa(self._editor.getStatusBar().showTooltip, self._edit_layer_button.helptext), 'mouseEntered')
		self._edit_layer_button.capture(self._editor.getStatusBar().hideTooltip, 'mouseExited')
		
		self.update(None)
示例#8
0
    def initializeEvents(self):
        """Intialize Hud events
           @return: None"""
        events_to_map = {}

        # when we click the toggle button don't change the image
        events_to_map["inventoryButton"] = cbwa(self.toggleInventory, False)
        events_to_map["saveButton"] = self.saveGame
        events_to_map["loadButton"] = self.loadGame

        hud_ready_buttons = ["hudReady1", "hudReady2", \
                             "hudReady3", "hudReady4"]

        for item in hud_ready_buttons:
            events_to_map[item] = cbwa(self.readyAction, item)

        self.hud.mapEvents(events_to_map)

        menu_events = {}
        menu_events["newButton"] = self.newGame
        menu_events["quitButton"] = self.quitGame
        menu_events["saveButton"] = self.saveGame
        menu_events["loadButton"] = self.loadGame
        self.main_menu.mapEvents(menu_events)
示例#9
0
	def newMapView(self, map):
		""" Creates a new map view """
		mapview = MapView(map)

		self._mapviewlist.append(mapview)

		map_action = Action(unicode(map.getId()))
		action.activated.connect(cbwa(self.showMapView, mapview), sender=map_action, weak=False)
		self._mapgroup.addAction(map_action)

		self.showMapView(mapview)

		events.mapAdded.send(sender=self, map=map)

		return mapview
示例#10
0
	def removeInstances(self, instances, layer=None):
		""" Removes all provided instances """
		mname = 'removeInstances'
		if not instances:
			if self.debug: print 'No instances assigned in %s' % mname
			return
			
		for i in instances:
			if self.debug: print 'Deleting instance ' + i.getObject().getId() + ' at ' + str(i.getLocation().getExactLayerCoordinates())
			
			if not self._undo:
				object = i.getObject()
				position = i.getLocation().getExactLayerCoordinates()
				undocall = cbwa(self.placeInstance, position, object, i.getLocation().getLayer())
				redocall = cbwa(self.removeInstanceOfObjectAt, position, object, i.getLocation().getLayer())
				undoobject = undomanager.UndoObject(undocall, redocall, "Removed instance")
				self._undomanager.addAction(undoobject)
			
			if layer:
				layer.deleteInstance(i)
			else:
				self._layer.deleteInstance(i)
							
			self.decrementReferenceCountForObject(i.getObject())
示例#11
0
	def _buildGui(self):
		if self.gui is not None:
			self.removeChild(self.gui)
			self._buttonlist = []
			
		self.gui = widgets.HBox()
		for i, menu in enumerate(self.menulist):
			button = widgets.Button(name=menu.name, text=menu.name)
			button.hexpand = 0
			button.capture(cbwa(self._showMenu, i))
			self._buttonlist.append(button)
			self.gui.addChild(button)
			
		self.gui.addSpacer(widgets.Spacer())
		
		self.addChild(self.gui)
    def showContainer(self):
        """Show the container
           @return: None"""
        # Prepare slots 1 through 9
        empty_image = "gui/inv_images/inv_backpack.png"
        slot_count = 9
        for counter in range(1, slot_count+1):
            slot_name = "Slot%i" % counter
            self.empty_images[slot_name] = empty_image
            widget = self.gui.findChild(name=slot_name)
            widget.item = self.container.items.get(counter-1)
            widget.index = counter-1
            self.updateImage(widget)
            self.events_to_map[slot_name] = cbwa(self.dragDrop, slot_name)
            self.events_to_map[slot_name + "/mouseReleased"] = \
                                            self.showContextMenu

        self.gui.mapEvents(self.events_to_map)
        self.gui.show()
示例#13
0
	def addTab(self, widget, title):
		for tab in self.tabs:
			if tab[1] == widget:
				return
	
		widget.max_size = (5000, 5000)
		widget.hexpand = 1
		widget.vexpand = 1
	
		button = widgets.ToggleButton(text=title, group="faketab_"+str(id(self)))
		self.buttonbox.addChild(button)
		
		tab = (title, widget, button)
		self.tabs.append( tab )

		button.capture(cbwa(self.showTab, tab))
		self.showTab(tab)
		
		return tab
示例#14
0
 def create(self, engine, application):
     self._application = application
     self._engine = engine
     self._running = False
     
     self._controlsPanel = pychan.loadXML('data/gui/widget_events_controls.xml')
     self._controlsPanel.position = (0, 0)
     self._controlsPanel.mapEvents({
         "controlBtn" : self._toggleWindow,
     })
     
     self._outputBox = self._controlsPanel.findChild(name="outputBox")
     
     self._window = pychan.loadXML('data/gui/widget_events_window.xml')
     self._window.capture(event_name="widgetHidden", callback=cbwa(self._widgetHiddenCallback, self._window.name))
     self._window.capture(event_name="widgetShown", callback=cbwa(self._widgetShownCallback, self._window.name))
     self._window.capture(event_name="widgetMoved", callback=cbwa(self._widgetMovedCallback, self._window.name))
     self._window.mapEvents({
         "testButtonHide/ancestorHidden" : cbwa(self._widgetHiddenCallback, self._window.findChild(name="testButtonHide").name),
         "testButtonShow/ancestorShown" : cbwa(self._widgetShownCallback, self._window.findChild(name="testButtonShow").name),
         "testButtonMove/ancestorMoved" : cbwa(self._widgetMovedCallback, self._window.findChild(name="testButtonMove").name)
     })
    def __init__(self, controller, inventory, callbacks):
        """Initialise the instance.
           @param controller: Current Controller
           @type controller: Class derived from ControllerBase
           @type inventory: Inventory
           @param inventory: An inventory object to be displayed and manipulated
           @type callbacks: dict
           @param callbacks: a dict of callbacks
               refreshReadyImages:
                   Function that will make the ready slots on the HUD
                   reflect those within the inventory
               toggleInventoryButton:
                   Function that will toggle the state of the inventory button
           @return: None"""
        super(InventoryGUI, self).__init__(controller, "gui/inventory.xml")
        self.engine = controller.engine
        self.readyCallback = callbacks['refreshReadyImages']
        self.toggleInventoryButtonCallback = callbacks['toggleInventoryButton']
        self.original_cursor_id = self.engine.getCursor().getId()

        self.inventory_shown = False
        events_to_map = {}
        self.inventory_storage = inventory
        
        # Buttons of inventory arranged by slots

        self.slot_buttons = {'head': ('Head',), 'chest': ('Body',),
                             'left_arm': ('LeftHand',),
                             'right_arm': ('RightHand',),
                             'hips' : ('Belt',), 'left_leg': ('LeftFoot',),
                             'right_leg': ('RightFoot',),
                             'left_hand': ('LeftHeld',),
                             'right_hand': ('RightHeld',),
                             'backpack': ('A1', 'A2', 'A3', 'A4', 'A5',
                                          'B1', 'B2', 'B3', 'B4', 'B5',
                                          'C1', 'C2', 'C3', 'C4', 'C5',
                                          'D1', 'D2', 'D3', 'D4', 'D5'),
                             'ready': ('Ready1', 'Ready2', 'Ready3', 'Ready4')
        }
        # the images that should be used for the buttons when they are "empty"
        self.slot_empty_images = {'head':'gui/inv_images/inv_head.png',
                                  'chest':'gui/inv_images/inv_torso.png',
                                  'left_arm':'gui/inv_images/inv_lhand.png',
                                  'right_arm':'gui/inv_images/inv_rhand.png',
                                  'hips':'gui/inv_images/inv_belt.png',
                                  'left_leg':'gui/inv_images/inv_lfoot.png',
                                  'right_leg':'gui/inv_images/inv_rfoot.png',
                                  'left_hand':'gui/inv_images/inv_litem.png',
                                  'right_hand':'gui/inv_images/inv_ritem.png',
                                  'backpack':'gui/inv_images/inv_backpack.png',
                                  'ready':'gui/inv_images/inv_belt_pouches.png',
                                  }
        self.updateInventoryButtons()

        for slot in self.slot_buttons:
            for _, button in enumerate(self.slot_buttons[slot]):
                events_to_map[button] = cbwa(self.dragDrop, button)
                events_to_map[button + "/mouseReleased"] = \
                                                self.showContextMenu
        events_to_map['close_button'] = self.closeInventoryAndToggle
        self.gui.mapEvents(events_to_map)
示例#16
0
	def create_gui(self):
		"""
			- creates the gui skeleton by loading the xml file
			
		FIXME:
			- move all dynamic widgets to dict
		"""
		self.container = pychan.loadXML('gui/lightedit.xml')
		self.container.mapEvents({
			"reset"				:	self.reset_light,
			"use"				:	self.use_light,
			"simple_but"		:	self.toggle_simple_gui,
			"image_but"			:	self.toggle_image_gui,
			"animation_but" 	:	self.toggle_animation_gui,
			"global_but" 		:	self.toggle_global_gui,
			"selec_image"		:	self.change_image,
			"selec_animation"	:	self.change_animation,

			"stencil_up" 		: cbwa(self.change_light, value=1, option="stencil"),
			"stencil_dn" 		: cbwa(self.change_light, value=-1, option="stencil"),
			"stencil/mouseWheelMovedUp"			:	cbwa(self.change_light, value=10, option="stencil"),
			"stencil/mouseWheelMovedDown" : cbwa(self.change_light, value=-10, option="stencil"),		

			"intensity_up" 		: cbwa(self.change_light, value=1, option="intensity"),
			"intensity_dn" 		: cbwa(self.change_light, value=-1, option="intensity"),
			"intensity/mouseWheelMovedUp"			:	cbwa(self.change_light, value=10, option="intensity"),
			"intensity/mouseWheelMovedDown" : cbwa(self.change_light, value=-10, option="intensity"),

			"radius_up" 		: cbwa(self.change_light, value= 1, option="radius"),
			"radius_dn" 		: cbwa(self.change_light, value=-1, option="radius"),
			"radius/mouseWheelMovedUp"      : cbwa(self.change_light, value= 10, option="radius"),
			"radius/mouseWheelMovedDown"    : cbwa(self.change_light, value=-10, option="radius"),

			"subdivisions_up" 		: cbwa(self.change_light, value= 1, option="subdivisions"),
			"subdivisions_dn" 		: cbwa(self.change_light, value=-1, option="subdivisions"),
			"subdivisions/mouseWheelMovedUp"      : cbwa(self.change_light, value= 1, option="subdivisions"),
			"subdivisions/mouseWheelMovedDown"    : cbwa(self.change_light, value=-1, option="subdivisions"),

			"xstretch_up" 		: cbwa(self.change_light, value= 0.01, option="xstretch"),
			"xstretch_dn" 		: cbwa(self.change_light, value=-0.01, option="xstretch"),
			"xstretch/mouseWheelMovedUp"      : cbwa(self.change_light, value= 0.1, option="xstretch"),
			"xstretch/mouseWheelMovedDown"    : cbwa(self.change_light, value=-0.1, option="xstretch"),

			"ystretch_up" 		: cbwa(self.change_light, value= 0.01, option="ystretch"),
			"ystretch_dn" 		: cbwa(self.change_light, value=-0.01, option="ystretch"),
			"ystretch/mouseWheelMovedUp"      : cbwa(self.change_light, value= 0.1, option="ystretch"),
			"ystretch/mouseWheelMovedDown"    : cbwa(self.change_light, value=-0.1, option="ystretch"),

			"red_up" 		: cbwa(self.change_light, value= 1, option="red"),
			"red_dn" 		: cbwa(self.change_light, value=-1, option="red"),
			"red/mouseWheelMovedUp"         : cbwa(self.change_light, value= 10, option="red"),
			"red/mouseWheelMovedDown"       : cbwa(self.change_light, value=-10, option="red"),

			"green_up" 		: cbwa(self.change_light, value= 1, option="green"),
			"green_dn" 		: cbwa(self.change_light, value=-1, option="green"),
			"green/mouseWheelMovedUp"       : cbwa(self.change_light, value= 10, option="green"),
			"green/mouseWheelMovedDown"     : cbwa(self.change_light, value=-10, option="green"),

			"blue_up" 		: cbwa(self.change_light, value= 1, option="blue"),
			"blue_dn" 		: cbwa(self.change_light, value=-1, option="blue"),
			"blue/mouseWheelMovedUp"        : cbwa(self.change_light, value= 10, option="blue"),
			"blue/mouseWheelMovedDown"      : cbwa(self.change_light, value=-10, option="blue"),

			"src_up" 		: cbwa(self.change_light, value= 1, option="src"),
			"src_dn" 		: cbwa(self.change_light, value=-1, option="src"),
			"src/mouseWheelMovedUp"      : cbwa(self.change_light, value= 1, option="src"),
			"src/mouseWheelMovedDown"    : cbwa(self.change_light, value=-1, option="src"),

			"dst_up" 		: cbwa(self.change_light, value= 1, option="dst"),
			"dst_dn" 		: cbwa(self.change_light, value=-1, option="dst"),
			"dst/mouseWheelMovedUp"      : cbwa(self.change_light, value= 1, option="dst"),
			"dst/mouseWheelMovedDown"    : cbwa(self.change_light, value=-1, option="dst"),

			"random_global_light"	:	self.random_color,
			"reset_global_light"	:	self.reset_global_light,
			
			"increase_R"			:	cbwa(self.increase_color, r=True),
			"decrease_R"			:	cbwa(self.decrease_color, r=True),
			"value_R/mouseWheelMovedUp"			:	cbwa(self.increase_color, step=0.1, r=True),
			"value_R/mouseWheelMovedDown"		:	cbwa(self.decrease_color, step=0.1, r=True),
			
			"increase_G"			:	cbwa(self.increase_color, g=True),
			"decrease_G"			:	cbwa(self.decrease_color, g=True),
			"value_G/mouseWheelMovedUp"			:	cbwa(self.increase_color, step=0.1, g=True),
			"value_G/mouseWheelMovedDown"		:	cbwa(self.decrease_color, step=0.1, g=True),
			
			"increase_B"			:	cbwa(self.increase_color, b=True),
			"decrease_B"			:	cbwa(self.decrease_color, b=True),
			"value_B/mouseWheelMovedUp"			:	cbwa(self.increase_color, step=0.1, b=True),
			"value_B/mouseWheelMovedDown"		:	cbwa(self.decrease_color, step=0.1, b=True)			
		})

		self._widgets = {
			"group"				:	self.container.findChild(name="group"),
			"ins_id"			:	self.container.findChild(name="ins_id"),
			"obj_id"			:	self.container.findChild(name="obj_id"),
			"stencil"			:	self.container.findChild(name="stencil"),
			
			"intensity"			:	self.container.findChild(name="intensity"),
			"red"                           :       self.container.findChild(name="red"),
			"green"                         :       self.container.findChild(name="green"),
			"blue"                          :       self.container.findChild(name="blue"),
			"radius"                        :       self.container.findChild(name="radius"),
			"subdivisions"                  :       self.container.findChild(name="subdivisions"),
			"xstretch"                      :       self.container.findChild(name="xstretch"),
			"ystretch"                      :       self.container.findChild(name="ystretch"),
			"src"	                        :       self.container.findChild(name="src"),
			"dst"	                        :       self.container.findChild(name="dst"),

			"image"	                        :       self.container.findChild(name="image"),
			"animation"						:       self.container.findChild(name="animation"),

			"value_R"				:	self.container.findChild(name="value_R"),
			"value_G"				:	self.container.findChild(name="value_G"),
			"value_B"				:	self.container.findChild(name="value_B")		
		}

		self._gui_simple_panel_wrapper = self.container.findChild(name="simple_panel_wrapper")
		self._gui_simple_panel = self._gui_simple_panel_wrapper.findChild(name="simple_panel")
		self._gui_image_panel_wrapper = self.container.findChild(name="image_panel_wrapper")
		self._gui_image_panel = self._gui_image_panel_wrapper.findChild(name="image_panel")
		self._gui_animation_panel_wrapper = self.container.findChild(name="animation_panel_wrapper")
		self._gui_animation_panel = self._gui_animation_panel_wrapper.findChild(name="animation_panel")
		self._gui_global_panel_wrapper = self.container.findChild(name="global_panel_wrapper")
		self._gui_global_panel = self._gui_global_panel_wrapper.findChild(name="global_panel")
示例#17
0
	def showEditDialog(self):
		""" Show layerdialog for active layer """
		if not self._mapview: return
		layer = self.getActiveLayer()
		if not layer: return
		
		if self._layer_wizard: self._layer_wizard._widget.hide()
		self._layer_wizard = LayerDialog(self._editor.getEngine(), self._mapview.getMap(), layer=layer, callback=cbwa(self.update, self._mapview))
示例#18
0
    def __init__(self, engine, map, callback=None, onCancel=None, layer=None):
        self.engine = engine
        self.model = engine.getModel()
        self.map = map
        self.layer = layer
        self.callback = callback
        self.onCancel = onCancel
        self.selected_interact_layer = 0
        self._widget = pychan.loadXML("gui/layerdialog.xml")
        self._editor = scripts.editor.getEditor()

        # wrapper for layers
        self.wrapper = self._widget.findChild(name="layers_wrapper")

        # TODO: Add access method for adopted grid types?
        self._widget.findChild(name="gridBox").items = ["square", "hexagonal"]

        # TODO: Ditto for pather?
        self._widget.findChild(name="pathingBox").items = ["cell_edges_only", "cell_edges_and_diagonals"]

        self._widget.findChild(name="sortingBox").items = ["camera", "location", "camera_and_location"]

        if layer:
            cg = layer.getCellGrid()
            cgtype = 0
            if cg.getType() == "hexagonal":
                cgtype = 1

            self._widget.distributeData(
                {
                    "layerBox": unicode(layer.getId()),
                    "xScaleBox": unicode(cg.getXScale()),
                    "yScaleBox": unicode(cg.getYScale()),
                    "zScaleBox": unicode(cg.getZScale()),
                    "rotBox": unicode(cg.getRotation()),
                    "xOffsetBox": unicode(cg.getXShift()),
                    "yOffsetBox": unicode(cg.getYShift()),
                    "zOffsetBox": unicode(cg.getZShift()),
                    "transBox": unicode(layer.getLayerTransparency()),
                    "is_walkable": bool(layer.isWalkable()),
                    "is_interact": bool(layer.isInteract()),
                }
            )

            self._widget.findChild(name="pathingBox").selected = int(layer.getPathingStrategy())
            self._widget.findChild(name="sortingBox").selected = int(layer.getSortingStrategy())
            self._widget.findChild(name="gridBox").selected = int(cgtype)

            # fill layer list
            layers = self.map.getLayers()
            if len(layers) <= 0:
                layerid = "No layers"
                subwrapper = pychan.widgets.HBox()

                layerLabel = pychan.widgets.Label()
                layerLabel.text = unicode(layerid)
                layerLabel.name = LayerDialog.LABEL_NAME_PREFIX + layerid
                subwrapper.addChild(layerLabel)
                self.wrapper.addChild(subwrapper)

            interact_layers = self.layer.getInteractLayers()
            for l in reversed(layers):
                layerid = l.getId()
                if layerid == self.layer.getId():
                    continue

                subwrapper = pychan.widgets.HBox()
                layerLabel = pychan.widgets.Label()
                layerLabel.text = unicode(layerid)
                layerLabel.name = LayerDialog.LABEL_NAME_PREFIX + layerid
                layerLabel.capture(cbwa(self.selectInteractLayer, l, layerLabel), "mousePressed")

                for i in interact_layers:
                    if i.getId() == layerid:
                        layerLabel.background_color = LayerDialog.COLORED_DEFAULT_BACKGROUND_COLOR
                        layerLabel.foreground_color = LayerDialog.COLORED_DEFAULT_BACKGROUND_COLOR
                        layerLabel.base_color = LayerDialog.COLORED_DEFAULT_BACKGROUND_COLOR
                        break

                subwrapper.addChild(layerLabel)
                self.wrapper.addChild(subwrapper)

                # button callbacks
            wdgt = self._widget.findChild(name="interact_add")
            wdgt.capture(self.addInteractLayer, "mousePressed")
            wdgt.capture(cbwa(self._editor.getStatusBar().showTooltip, wdgt.helptext), "mouseEntered")
            wdgt.capture(self._editor.getStatusBar().hideTooltip, "mouseExited")

            wdgt = self._widget.findChild(name="interact_remove")
            wdgt.capture(self.removeInteractLayer, "mousePressed")
            wdgt.capture(cbwa(self._editor.getStatusBar().showTooltip, wdgt.helptext), "mouseEntered")
            wdgt.capture(self._editor.getStatusBar().hideTooltip, "mouseExited")

            wdgt = self._widget.findChild(name="is_interact")
            wdgt.capture(self.updateCheckBox, "mousePressed")
        else:
            self._widget.findChild(name="pathingBox").selected = 0
            self._widget.findChild(name="sortingBox").selected = 0
            self._widget.findChild(name="gridBox").selected = 0

        self._widget.mapEvents({"okButton": self._finished, "cancelButton": self._cancelled})

        self._widget.show()
示例#19
0
	def __init__(self):
		from fife import fife
		self.editor = scripts.editor.getEditor()
		self.engine = self.editor.getEngine()
		self._map = None
		self._layer = None
		self._mapdlg = None
		self._layerdlg = None
		self._cameradlg = None
		
		self._filebrowser = None
		self._importbrowser = None
		self._savebrowser = None

		self.obj_loader = XMLObjectLoader(
			self.engine.getImagePool(),
			self.engine.getAnimationPool(),
			self.engine.getModel(),
			self.engine.getVFS()
		)		

		newAction = Action(u"New map", "gui/icons/new_map.png")
		loadAction = Action(u"Open", "gui/icons/load_map.png")
		closeAction = Action(u"Close", "gui/icons/close_map.png")
		saveAction = Action(u"Save", "gui/icons/save_map.png")
		saveAsAction = Action(u"Save as", "gui/icons/save_mapas.png")
		saveAllAction = Action(u"Save all", "gui/icons/save_allmaps.png")
		importFileAction = Action(u"Import file", "gui/icons/import_file.png")
		importDirAction = Action(u"Import directory", "gui/icons/import_dir.png")
		
		newAction.helptext = u"Create new map"
		loadAction.helptext = u"Open existing map"
		closeAction.helptext = u"Close map"
		saveAction.helptext = u"Save map"
		saveAsAction.helptext = u"Save map as"
		saveAllAction.helptext = u"Save all opened maps"
		importFileAction.helptext = u"Imports an object file"
		importDirAction.helptext = u"Recursively imports all objects from a directory"
		
		action.activated.connect(self.showMapWizard, sender=newAction)
		action.activated.connect(self.showLoadDialog, sender=loadAction)
		action.activated.connect(self.closeCurrentMap, sender=closeAction)
		action.activated.connect(self.save, sender=saveAction)
		action.activated.connect(self.saveAs, sender=saveAsAction)
		action.activated.connect(self.editor.saveAll, sender=saveAllAction)
		
		self._importFileCallback = cbwa(self.showImportDialog, self.importFile, False)
		self._importDirCallback = cbwa(self.showImportDialog, self.importDir, True)
		action.activated.connect(self._importFileCallback, sender=importFileAction)
		action.activated.connect(self._importDirCallback, sender=importDirAction)
		
		eventlistener = self.editor.getEventListener()
		
		eventlistener.getKeySequenceSignal(fife.Key.N, ["ctrl"]).connect(self.showMapWizard)
		eventlistener.getKeySequenceSignal(fife.Key.O, ["ctrl"]).connect(self.showLoadDialog)
		eventlistener.getKeySequenceSignal(fife.Key.W, ["ctrl"]).connect(self.closeCurrentMap)
		eventlistener.getKeySequenceSignal(fife.Key.S, ["ctrl"]).connect(self.save)
		eventlistener.getKeySequenceSignal(fife.Key.S, ["ctrl", "shift"]).connect(self.editor.saveAll)
		
		fileGroup = ActionGroup()
		fileGroup.addAction(newAction)
		fileGroup.addAction(loadAction)
		fileGroup.addSeparator()
		fileGroup.addAction(closeAction)
		fileGroup.addSeparator()
		fileGroup.addAction(saveAction)
		fileGroup.addAction(saveAsAction)
		fileGroup.addAction(saveAllAction)
		fileGroup.addSeparator()
		fileGroup.addAction(importFileAction)
		fileGroup.addAction(importDirAction)
		
		self.editor.getToolBar().insertAction(fileGroup, 0)
		self.editor.getToolBar().insertSeparator(None, 1)
		self.editor._file_menu.insertAction(fileGroup, 0)
		self.editor._file_menu.insertSeparator(None, 1)
示例#20
0
	def create(self):
		""" create gui sceleton """
		if self.container: return
		self.container = pychan.loadXML('gui/cellview.xml')
		self.wrapper = self.container.findChild(name="cell_instance_wrapper")
		
		btn = self.container.findChild(name="show_help")
		btn.capture(self._show_help, 'mousePressed')
		
		# create callbacks for section hiding
		for wdgt_name in _SECTION_TO_WRAPPER.keys():
			wdgt = self.container.findChild(name=wdgt_name)
			wdgt.capture(self.cb_toggle_section, "mousePressed")
		
		# create callbacks for cell blocking policy manipulation
		for name in _WDGT_NAME_TO_CELL_TYPE:
			value = _WDGT_NAME_TO_CELL_TYPE[name]
			wdgt = self.container.findChild(name=name)
			if not wdgt: continue
			wdgt.capture(cbwa(self.set_cell_blocking_policy, value), "mousePressed")
			
		# create callback for setting the expert mode
		wdgt = self.container.findChild(name='expert_mode')
		wdgt.capture(self.updateMode, "mousePressed")
		
		# create callback for setting the speed multiplier
		wdgt = self.container.findChild(name='apply_speed_multiplier')
		wdgt.capture(self.set_cell_speed_multiplier, "mousePressed")
		
		# create callback for setting the default cost_multiplier
		wdgt = self.container.findChild(name='apply_cost_multiplier')
		wdgt.capture(self.set_cell_default_cost_multiplier, "mousePressed")
		
		# create callbacks for mini editor
		wdgt = self.container.findChild(name="mini_editor_cost_save")
		wdgt.capture(self.mini_editor_create_cost, "mousePressed")
		# hide mini editor for cost entries
		self.minieditor = self.container.findChild(name='cost_mini_editor')
		self.minieditor.hide()
		# create callback to control the mini editor
		wdgt = self.container.findChild(name='add_cost_entry')
		wdgt.capture(self.minieditor.show, 'mousePressed')
		wdgt = self.container.findChild(name="edit_current_cost_entry")
		wdgt.capture(self.mini_editor_edit_cost, 'mousePressed')		
		wdgt = self.container.findChild(name="remove_current_cost_entry")
		wdgt.capture(self.mini_editor_remove_cost, 'mousePressed')
		# create fancy callbacks for mouse actions on the listbox
		listbox = self.container.findChild(name="cost_entries")
		listbox.capture(self.mini_editor_edit_cost, 'mousePressed')
		
		# transition
		wdgt = self.container.findChild(name="transition_start")
		wdgt.capture(cbwa(self.transition_set, start=1), 'mousePressed')
		wdgt = self.container.findChild(name="transition_end")
		wdgt.capture(cbwa(self.transition_set, end=1), 'mousePressed')
		wdgt.hide()
		wdgt = self.container.findChild(name="transition_create")
		wdgt.capture(cbwa(self.transition_set, create=1), 'mousePressed')
		wdgt.hide()
		wdgt = self.container.findChild(name="transition_immediate")
		wdgt.hide()
		
		
		self.container.hide()
	def playClip(self, clip):
		"""
		Plays a sound clip.

		This function does not use the L{fife.SoundEmitter}
		"looping" property to loop a sound.  Instead it registers
		a new timer and uses the duration of the clip as the timer length.

		If the SoundEmitter is invalid (no fifeemitter) then it attempts
		to load it before playing it.

		@note: This will stop any clips that use the same L{fife.SoundEmitter}.
		You cannot play the same sound more than once at a time unless you create
		the SoundEmitter with the forceUnique paramater set to True.

		@param clip: The L{SoundEmitter} to be played
		@type clip: L{SoundEmitter}
		"""
		if clip.fifeemitter:
			if clip.callback:
				if clip.timer:
					clip.timer.stop()
					timer = None

				if clip.looping:
					repeat = 0
					def real_callback(clip):
						clip.callback()
						clip.fifeemitter.stop()
						clip.fifeemitter.setGain(float(clip.gain)/255.0)
						if self.listenerposition and clip.position:
							# Use 1 as z coordinate, no need to specify it
							clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1)
							clip.fifeemitter.setRolloff(clip.rolloff)
						elif self.listenerposition and not clip.position:
							clip.fifeemitter.setPosition(self._listenerposition[0], self._listenerposition[1], 1)
							clip.fifeemitter.setRolloff(self.rolloff)
			
						clip.fifeemitter.play()

					clip.callback = cbwa(real_callback, clip)

				else:
					repeat = 1

				clip.timer = fife_timer.Timer(clip.duration, clip.callback, repeat)

			else:
				if clip.looping:
					def real_callback(clip):
						clip.fifeemitter.stop()
						clip.fifeemitter.setGain(float(clip.gain)/255.0)
						if self.listenerposition and clip.position:
							# Use 1 as z coordinate, no need to specify it
							clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1)
							clip.fifeemitter.setRolloff(clip.rolloff)
						elif self.listenerposition and not clip.position:
							clip.fifeemitter.setPosition(self._listenerposition[0], self._listenerposition[1], 1)
							clip.fifeemitter.setRolloff(self.rolloff)
							
						clip.fifeemitter.play()

					clip.callback = cbwa(real_callback, clip)
					clip.timer = fife_timer.Timer(clip.duration, clip.callback, 0)

			clip.fifeemitter.setGain(float(clip.gain)/255.0)

			if self.listenerposition and clip.position:
				# Use 1 as z coordinate, no need to specify it
				clip.fifeemitter.setPosition(clip.position[0], clip.position[1], 1)
				clip.fifeemitter.setRolloff(clip.rolloff)
			elif self.listenerposition and not clip.position:
				clip.fifeemitter.setPosition(self._listenerposition[0], self._listenerposition[1], 1)
				clip.fifeemitter.setRolloff(self.rolloff)

			clip.fifeemitter.play()
			if clip.timer:
				clip.timer.start()

		else:
			clip = self.createSoundEmitter(clip.name)
			self.playClip(clip)
    def moveInstances(self,
                      instances,
                      moveBy,
                      exact=False,
                      origLoc=None,
                      origFacing=None):
        """ Moves provided instances by moveBy. If exact is false, the instances are
			snapped to closest cell. origLoc and origFacing are only set when an undo/redo
			operation takes place and will have no effect and should not be used under normal
			circumstances.
		
		@type	instances:	list
		@param	instances:	a bunch of selected fife.Instance objects
		@type	moveBy:	fife.Point3D
		@param	moveBy:	diff of last and current exact model coordinate relative to the cursor
		@type	exact:	bool
		@param	exact:	flag to either set exactLayerCoordinates or LayerCoordinates
		@rtype	result:	bool
		@return	result:	flag wether the instances were moved or not (always True if exact=True)
		"""
        result = True
        mname = 'moveInstances'
        if not self._layer:
            if self.debug: print 'No layer assigned in %s' % mname
            return not result

        moveBy = fife.ExactModelCoordinate(float(moveBy.x), float(moveBy.y),
                                           float(moveBy.z))

        for i in instances:
            loc = i.getLocation()
            f = i.getFacingLocation()

            nloc = fife.Location(self._layer)
            nloc.setMapCoordinates(loc.getMapCoordinates() + moveBy)

            if loc.getLayerCoordinates() == nloc.getLayerCoordinates(
            ) and not exact:
                result = False
                break

            if exact:
                loc.setMapCoordinates(nloc.getMapCoordinates())
                f.setMapCoordinates(loc.getMapCoordinates())
            else:
                loc.setLayerCoordinates(nloc.getLayerCoordinates())
                f.setLayerCoordinates(loc.getLayerCoordinates())

            if not self._undo:
                undocall = cbwa(self.moveInstances, [i], moveBy, exact,
                                i.getLocation(), i.getFacingLocation())
                redocall = cbwa(self.moveInstances, [i], moveBy, exact,
                                i.getLocation(), i.getFacingLocation())
                undoobject = undomanager.UndoObject(undocall, redocall,
                                                    "Moved instance")
                self._undomanager.addAction(undoobject)
                i.setLocation(loc)
                i.setFacingLocation(f)

            else:
                assert (origLoc)
                assert (origFacing)
                i.setLocation(origLoc)
                i.setFacingLocation(origFacing)

        return result