Skip to content

Commit

Permalink
Added a special property case for Point and Point3D properties.
Browse files Browse the repository at this point in the history
Entities can now be edited in the property editor.
Fixed the property editor not showing all properties.
  • Loading branch information
Beliar83 committed Aug 5, 2014
1 parent 03baf5e commit fecc711
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 17 deletions.
148 changes: 138 additions & 10 deletions editor/property_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import PyCEGUI

""" Contains the property editor
.. module:: object_toolbar
Expand All @@ -22,6 +20,8 @@
.. moduleauthor:: Karsten Bock <[email protected]>
"""

import PyCEGUI


class PropertyEditor(object):

Expand All @@ -40,8 +40,6 @@ def __init__(self, root):
self.properties_area = self.properties_box.createChild(
"TaharezLook/ScrollablePane", "property_container")
self.properties_area.setSize(size)
self.properties_container = self.properties_area.createChild(
"VerticalLayoutContainer", "properties_container")
self.sections = {}
self.__value_changed_callbacks = []
self.__list_items = []
Expand Down Expand Up @@ -102,14 +100,18 @@ def add_property(self, section, property_name, property_data):

def update_widgets(self):
"""Update the editors widgets"""
self.properties_area.destroyChild(self.properties_container)
self.properties_container = self.properties_area.createChild(
"DefaultWindow", "properties_container")
ignored_count = 0
area = self.properties_area
while (area.getContentPane().getChildCount() - ignored_count) > 0:
child = area.getContentPane().getChildAtIdx(ignored_count)
if child.isAutoWindow():
ignored_count += 1
continue
child.destroy()
y_pos = PyCEGUI.UDim(0, 0.0)

container = self.properties_container
for section, properties in self.sections.iteritems():
section_label = container.createChild("TaharezLook/Label", section)
section_label = area.createChild("TaharezLook/Label", section)
section_label.setYPosition(y_pos)
section_label.setText(section)
section_label.setWidth(PyCEGUI.UDim(0.99, 0.0))
Expand All @@ -119,7 +121,7 @@ def update_widgets(self):
y_pos += self.WIDGET_MARGIN
for property_name, property_data in properties.iteritems():
self.__create_property_widget(property_name, section,
property_data, container, y_pos)
property_data, area, y_pos)
y_pos += self.WIDGET_HEIGHT
y_pos += self.WIDGET_MARGIN

Expand Down Expand Up @@ -193,6 +195,71 @@ def __create_property_widget(self, property_name, section, property_data,
lambda args: self.cb_toggle_value_changed(section,
property_name,
args))
elif property_type == "point":
x_pos = unicode(property_data[1][0])
y_pos = unicode(property_data[1][1])
property_input = property_container.createChild(
"TaharezLook/Editbox", "%s_x_input" % (base_text))
property_input.setWidth(PyCEGUI.UDim(0.245, 0))
property_input.setHeight(self.WIDGET_HEIGHT)
property_input.setText(x_pos)
property_input.setTooltipText(x_pos)
property_input.subscribeEvent(
PyCEGUI.Editbox.EventTextAccepted,
lambda args: self.cb_point_value_changed(section,
property_name,
args))
property_input = property_container.createChild(
"TaharezLook/Editbox", "%s_y_input" % (base_text))
property_input.setWidth(PyCEGUI.UDim(0.245, 0))
property_input.setYPosition(PyCEGUI.UDim(0.245, 0))
property_input.setHeight(self.WIDGET_HEIGHT)
property_input.setText(y_pos)
property_input.setTooltipText(y_pos)
property_input.subscribeEvent(
PyCEGUI.Editbox.EventTextAccepted,
lambda args: self.cb_point_value_changed(section,
property_name,
args))
elif property_type == "point3d":
x_pos = unicode(property_data[1][0])
y_pos = unicode(property_data[1][1])
z_pos = unicode(property_data[1][2])
property_input = property_container.createChild(
"TaharezLook/Editbox", "%s_x_input" % (base_text))
property_input.setWidth(PyCEGUI.UDim(0.163, 0))
property_input.setHeight(self.WIDGET_HEIGHT)
property_input.setText((x_pos))
property_input.setTooltipText(x_pos)
property_input.subscribeEvent(
PyCEGUI.Editbox.EventTextAccepted,
lambda args: self.cb_point3d_value_changed(section,
property_name,
args))
property_input = property_container.createChild(
"TaharezLook/Editbox", "%s_y_input" % (base_text))
property_input.setWidth(PyCEGUI.UDim(0.163, 0))
property_input.setYPosition(PyCEGUI.UDim(0.163, 0))
property_input.setHeight(self.WIDGET_HEIGHT)
property_input.setText(y_pos)
property_input.setTooltipText(y_pos)
property_input.subscribeEvent(
PyCEGUI.Editbox.EventTextAccepted,
lambda args: self.cb_point3d_value_changed(section,
property_name,
args))
property_input = property_container.createChild(
"TaharezLook/Editbox", "%s_z_input" % (base_text))
property_input.setWidth(PyCEGUI.UDim(0.163, 0))
property_input.setYPosition(PyCEGUI.UDim(0.326, 0))
property_input.setHeight(self.WIDGET_HEIGHT)
property_input.setText(z_pos)
property_input.setTooltipText(z_pos)
property_input.subscribeEvent(
PyCEGUI.Editbox.EventTextAccepted,
lambda args: self.cb_point3d_value_changed(section,
property_name,
args))
else:
raise RuntimeError("Don't know the property type %s"
% (property_type))
Expand Down Expand Up @@ -230,6 +297,67 @@ def cb_toggle_value_changed(self, section, property_name, args):
property_name,
args.window.isSelected())

def cb_point_value_changed(self, section, property_name, args):
"""Called when the value of a point was changed
Args:
section: The section the edit box belongs to
property: The property the editbox belongs to
args: PyCEGUI event args
"""
area = self.properties_area
base_text = "/".join((section, property_name))
property_container = area.getChildRecursive("%s_container" %
(base_text))
x_pos_edit = property_container.getChildRecursive("%s_x_input" %
(base_text))
y_pos_edit = property_container.getChildRecursive("%s_y_input" %
(base_text))
try:
x_pos = float(x_pos_edit.getText())
y_pos = float(y_pos_edit.getText())
pos = (x_pos, y_pos)
self.__send_value_changed(section,
property_name,
pos)
except ValueError:
self.update_widgets()

def cb_point3d_value_changed(self, section, property_name, args):
"""Called when the value of a point3d was changed
Args:
section: The section the edit box belongs to
property: The property the editbox belongs to
args: PyCEGUI event args
"""
area = self.properties_area
base_text = "/".join((section, property_name))
property_container = area.getChildRecursive("%s_container" %
(base_text))
x_pos_edit = property_container.getChildRecursive("%s_x_input" %
(base_text))
y_pos_edit = property_container.getChildRecursive("%s_y_input" %
(base_text))
z_pos_edit = property_container.getChildRecursive("%s_z_input" %
(base_text))
try:
x_pos = float(x_pos_edit.getText())
y_pos = float(y_pos_edit.getText())
z_pos = float(z_pos_edit.getText())
pos = (x_pos, y_pos, z_pos)
self.__send_value_changed(section,
property_name,
pos)
except ValueError:
self.update_widgets()

def add_value_changed_callback(self, function):
"""Adds a function to be called when a value has changed
Expand Down
11 changes: 6 additions & 5 deletions fife-rpg-editor.project
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project CEGUIDefaultResolution="1024x768" CEGUIVersion="1.0" baseDirectory="." fontsPath="gui/fonts" imagesetsPath="gui/imagesets" layoutsPath="gui/layouts" looknfeelsPath="gui/looksnfeels" schemesPath="gui/schemes" version="CEED Project 1" xmlSchemasPath="gui/xml_schemas">
<Items>
<Item path="gui/fonts/DejaVuSans-10.font" type="file" />
<Item path="gui/fonts/DejaVuSans-12.font" type="file" />
<Item path="gui/fonts/DejaVuSans-14.font" type="file" />
<Item path="gui/layouts/editor_window.layout" type="file" />
<Item path="gui/layouts/filebrowser.layout" type="file" />
<Item path="gui/layouts/toolbar_page.layout" type="file" />
<Item path="gui/layouts/filebrowser.layout" type="file" />
<Item path="gui/layouts/editor_window.layout" type="file" />
<Item path="gui/fonts/DejaVuSans-14.font" type="file" />
<Item path="gui/fonts/DejaVuSans-12.font" type="file" />
<Item path="gui/fonts/DejaVuSans-10.font" type="file" />
<Item path="gui/layouts/list_editor.layout" type="file" />
</Items>
</Project>
35 changes: 33 additions & 2 deletions fife_rpg_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
import yaml

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Expand Down Expand Up @@ -31,6 +32,7 @@
from fife_rpg.systems import SystemManager
from fife_rpg.behaviours import BehaviourManager
from fife_rpg.game_scene import GameSceneView
from fife_rpg.helpers import DoublePointYaml, DoublePoint3DYaml
# pylint: disable=unused-import
from PyCEGUIOpenGLRenderer import PyCEGUIOpenGLRenderer # @UnusedImport
# pylint: enable=unused-import
Expand Down Expand Up @@ -355,8 +357,29 @@ def update_property_editor(self):
property_editor.clear_properties()
identifier = self.selected_object.getId()
world = self.world
components = ComponentManager.get_components()
if world.is_identifier_used(identifier):
print ""
entity = world.get_entity(identifier)
for comp_name, component in components.iteritems():
com_data = getattr(entity, comp_name)
if com_data:
for field in component.saveable_fields:
value = getattr(com_data, field)
if isinstance(value, DoublePointYaml):
pos = (value.x, value.y)
property_editor.add_property(
comp_name, field,
("point", pos))
elif isinstance(value, DoublePoint3DYaml):
pos = (value.x, value.y, value.z)
property_editor.add_property(
comp_name, field,
("point3d", pos))
else:
str_val = yaml.dump(value).split('\n')[0]
property_editor.add_property(
comp_name, field,
("text", str_val))
else:
property_editor.add_property(
"Instance", "Identifier",
Expand Down Expand Up @@ -402,7 +425,15 @@ def cb_value_changed(self, section, property_name, value):
identifier = self.selected_object.getId()
world = self.world
if world.is_identifier_used(identifier):
pass
entity = world.get_entity(identifier)
com_data = getattr(entity, section)
try:
if isinstance(value, basestring):
value = yaml.load(value)
setattr(com_data, property_name, value)
self.update_agents(self.current_map)
except ValueError:
pass
else:
if section != "Instance":
return
Expand Down

0 comments on commit fecc711

Please sign in to comment.