Skip to content

Commit

Permalink
It is now possible to rotate objects before placing them by pressing …
Browse files Browse the repository at this point in the history
…"r". This will rotate to the next available direction.
  • Loading branch information
Beliar83 committed Feb 12, 2015
1 parent 828fb07 commit cb66156
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions editor/editor_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, engine, gamecontroller=None):
self.callbacks["mouse_pressed"] = []
self.callbacks["mouse_dragged"] = []
self.callbacks["mouse_moved"] = []
self.callbacks["key_pressed"] = []
self.middle_container = None
self.old_mouse_pos = None

Expand Down Expand Up @@ -124,6 +125,9 @@ def keyPressed(self, event): # pylint: disable=C0103,W0221
event: The key event
"""
for callback_data in self.callbacks["key_pressed"]:
func = callback_data["func"]
func(event)
if event.getKey().getValue() == fife.Key.SPACE:
application = self.gamecontroller.application
if application.current_map is None:
Expand Down
26 changes: 26 additions & 0 deletions editor/object_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ def __init__(self, editor):

self.namespaces = {}
self.images = {}
self.image_directions = {}
self.selected_object = [None, None]
self.is_active = False
self.cur_rotation = 0
x_adjust = 5
pos = self.gui.getPosition()
y_pos = pos.d_y
Expand Down Expand Up @@ -304,6 +306,8 @@ def __init__(self, editor):
self.cb_map_clicked)
mode.listener.add_callback("mouse_moved",
self.cb_map_moved)
mode.listener.add_callback("key_pressed",
self.cb_key_pressed)
self.editor.add_project_clear_callback(self.cb_project_closed)

@property
Expand Down Expand Up @@ -331,6 +335,7 @@ def image_clicked(self, args):
self.images[old_identifier].setAlpha(self.DEFAULT_ALPHA)
self.images[identifier].setAlpha(self.HIGHLIGHT_ALPHA)
self.selected_object = obj_data
self.cur_rotation = self.image_directions[identifier][0]

def update_contents(self):
"""Update the contents of the toolbar page"""
Expand Down Expand Up @@ -516,22 +521,26 @@ def update_images(self):
image = wmgr.createWindow(
"TaharezLook/StaticImage", name)
image.setTooltipText(name)
directions = None
if int(obj["static"]) == 0:
f_action = obj["actions"].keys()[0]
f_action_def = obj["actions"][f_action]
f_dir = f_action_def.keys()[0]
directions = f_action_def.keys()
img_name = ".".join([name,
f_action,
str(f_dir),
str(0)])
image.setProperty("Image", img_name)
elif int(obj["static"]) == 1:
f_dir = obj["directions"][0]
directions = obj["directions"]
img_name = ".".join([name,
str(f_dir)])
image.setProperty("Image", img_name)
self.items.addChild(image)
self.images[name] = image
self.image_directions[name] = sorted(directions)
image.setAlpha(self.DEFAULT_ALPHA)
image.user_data = [namespace, identifier]
image.subscribeEvent(PyCEGUI.Window.EventMouseClick,
Expand Down Expand Up @@ -619,6 +628,7 @@ def cb_map_clicked(self, click_point, button):
map_object = fife_model.getObject(name, namespace)
coords = location.getLayerCoordinates()
instance = layer.createInstance(map_object, coords)
instance.setRotation(self.cur_rotation)
filename = instance.getObject().getFilename()
self.editor.increase_refcount(filename)
fife.InstanceVisual.create(instance)
Expand Down Expand Up @@ -659,6 +669,22 @@ def cb_map_moved(self, click_point):
map_object = fife_model.getObject(name, namespace)
self.last_instance = layer.createInstance(map_object, coords)
fife.InstanceVisual.create(self.last_instance)
self.last_instance.setRotation(self.cur_rotation)

def cb_key_pressed(self, event):
"""Called when a key was pressed"""
if event.getKey().getValue() == fife.Key.R:
namespace, name = self.selected_object
if namespace is not None:
identifier = ".".join((namespace, name))
directions = self.image_directions[identifier]
new_index = directions.index(self.cur_rotation) + 1
if new_index < len(directions):
self.cur_rotation = directions[new_index]
else:
self.cur_rotation = directions[0]
if self.last_instance is not None:
self.last_instance.setRotation(self.cur_rotation)

def cb_project_closed(self):
"""Called when the current project was closed"""
Expand Down

0 comments on commit cb66156

Please sign in to comment.