Skip to content

Commit

Permalink
Changed the layerlist on the right side to be a list with checkboxes …
Browse files Browse the repository at this point in the history
…instead. The checkbox determines the visibility while the selection determines the working layer.

Removed the layer combo in the toolbars.
  • Loading branch information
Beliar83 committed Feb 18, 2015
1 parent 3c91ed1 commit 4e35686
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 116 deletions.
52 changes: 2 additions & 50 deletions editor/basic_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,11 @@ class BasicToolbar(ToolbarPage):
def __init__(self, editor):
ToolbarPage.__init__(self, editor, "Basic")
self.is_active = False
x_adjust = 5
pos = self.gui.getPosition()
y_pos = pos.d_y
x_pos = PyCEGUI.UDim(0, x_adjust)
width = PyCEGUI.UDim(0.9, 0.0)
label = self.gui.createChild("TaharezLook/Label",
"LayersLabel")
label.setText(_("Layer"))
label.setWidth(width)
label.setXPosition(x_pos)
label.setProperty("HorzFormatting", "LeftAligned")
self.layers_combo = self.gui.createChild("TaharezLook/Combobox",
"LayerCombo")
self.layers_combo.setReadOnly(True)
y_pos.d_scale = y_pos.d_scale + 0.02
self.layers_combo.setPosition(pos)
self.layers = []
self.layers_combo.setWidth(width)
self.layers_combo.setXPosition(x_pos)
self.editor.add_map_switch_callback(self.cb_map_changed)
self.outliner = BasicToolbarOutliner(self)
mode = self.editor.current_mode
mode.listener.add_callback("mouse_pressed",
self.cb_map_clicked)

@property
def selected_layer(self):
"""Returns the selected layer in the combo box"""
item = self.layers_combo.getSelectedItem()
if item is not None:
return str(item.getText())
return None

def update_contents(self):
"""Update the contents of the toolbar page"""
pass
Expand All @@ -84,26 +56,6 @@ def deactivate(self):
mode.outliner = None
mode.listener.is_outlined = False

def cb_map_changed(self, old_map_name, new_map_name):
"""Called when the map of the editor changed
Args:
old_map_name: Name of the map that was previously loaded
new_map_name: Name of the map that was changed to
"""
game_map = self.editor.maps[new_map_name]
self.layers_combo.resetList()
self.layers = []
self.layers_combo.setText("")
layers = game_map.fife_map.getLayers()
for layer in layers:
item = PyCEGUI.ListboxTextItem(layer.getId())
item.setSelectionBrushImage("TaharezLook/MultiListSelectionBrush")
self.layers_combo.addItem(item)
self.layers.append(item)

def cb_map_clicked(self, click_point, button):
"""Called when a position on the screen was clicked
Expand All @@ -114,7 +66,7 @@ def cb_map_clicked(self, click_point, button):
button: The button that was clicked
"""
if self.selected_layer is None or not self.is_active:
if self.editor.selected_layer is None or not self.is_active:
return
game_map = self.editor.current_map
if game_map:
Expand Down Expand Up @@ -145,7 +97,7 @@ def get_outlines(self, world, instances):
"""
for instance in instances:
inst_layer = instance.getLocationRef().getLayer().getId()
if self.toolbar.selected_layer == inst_layer:
if self.toolbar.editor.selected_layer == inst_layer:
self.last_instance = instance
return ((instance, (255, 255, 255, 1)),)
self.last_instance = None
Expand Down
49 changes: 6 additions & 43 deletions editor/object_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,10 @@ def __init__(self, editor):
y_pos = pos.d_y
x_pos = PyCEGUI.UDim(0, x_adjust)
width = PyCEGUI.UDim(0.9, 0.0)
label = self.gui.createChild("TaharezLook/Label",
"LayersLabel")
label.setText(_("Layer"))
label.setWidth(width)
label.setXPosition(x_pos)
label.setProperty("HorzFormatting", "LeftAligned")
self.layers_combo = self.gui.createChild("TaharezLook/Combobox",
"LayerCombo")
self.layers_combo.setReadOnly(True)
y_pos.d_scale = y_pos.d_scale + 0.02
self.layers_combo.setPosition(pos)
self.layers = []
self.layers_combo.setWidth(width)
self.layers_combo.setXPosition(x_pos)
label = self.gui.createChild("TaharezLook/Label",
"ObjectsLabel")
label.setText(_("Objects"))
label.setWidth(width)
y_pos.d_scale = y_pos.d_scale + 0.04
label.setYPosition(y_pos)
label.setXPosition(x_pos)
label.setProperty("HorzFormatting", "LeftAligned")
items_panel = self.gui.createChild("TaharezLook/ScrollablePane",
Expand Down Expand Up @@ -311,14 +295,6 @@ def __init__(self, editor):
self.editor.add_project_clear_callback(self.cb_project_closed)
self.editor.add_objects_imported_callback(self.cb_objects_imported)

@property
def selected_layer(self):
"""Returns the selected layer in the combo box"""
item = self.layers_combo.getSelectedItem()
if item is not None:
return str(item.getText())
return None

def image_clicked(self, args):
"""Called when the user clicked on an image
Expand Down Expand Up @@ -578,16 +554,6 @@ def cb_map_changed(self, old_map_name, new_map_name):
new_map_name: Name of the map that was changed to
"""
self.have_objects_changed = True
game_map = self.editor.maps[new_map_name]
self.layers_combo.resetList()
self.layers = []
layers = game_map.fife_map.getLayers()
self.layers_combo.setText("")
for layer in layers:
item = PyCEGUI.ListboxTextItem(layer.getId())
item.setSelectionBrushImage("TaharezLook/MultiListSelectionBrush")
self.layers_combo.addItem(item)
self.layers.append(item)

def cb_map_clicked(self, click_point, button):
"""Called when a position on the screen was clicked
Expand All @@ -600,16 +566,16 @@ def cb_map_clicked(self, click_point, button):
button: The button that was clicked
"""
self.clean_mouse_instance()
if self.selected_layer is None or not self.is_active:
if self.editor.selected_layer is None or not self.is_active:
return
if button == fife.MouseEvent.MIDDLE:
return
namespace, name = self.selected_object
if namespace is None and button == fife.MouseEvent.LEFT:
return
layer = self.editor.current_map.get_layer(self.selected_layer)
layer = self.editor.current_map.get_layer(self.editor.selected_layer)
location = self.editor.screen_coords_to_map_coords(
click_point, self.selected_layer
click_point, self.editor.selected_layer
)
world = self.editor.world
for instance in layer.getInstancesAt(location):
Expand Down Expand Up @@ -655,14 +621,14 @@ def cb_map_moved(self, click_point):
if not self.is_active:
return
self.clean_mouse_instance()
if self.selected_layer is None or not self.is_active:
if self.editor.selected_layer is None or not self.is_active:
return
namespace, name = self.selected_object
if namespace is None:
return
layer = self.editor.current_map.get_layer(self.selected_layer)
layer = self.editor.current_map.get_layer(self.editor.selected_layer)
location = self.editor.screen_coords_to_map_coords(
click_point, self.selected_layer
click_point, self.editor.selected_layer
)
coords = location.getLayerCoordinates()
self.last_mouse_pos = location
Expand Down Expand Up @@ -692,9 +658,6 @@ def cb_project_closed(self):
self.namespaces = {}
self.images = {}
self.selected_object = [None, None]
self.layers = None
self.layers_combo.resetList()
self.layers_combo.setText("")
if self.items:
self.items_panel.destroyChild(self.items)
self.items = self.items_panel.createChild("VerticalLayoutContainer",
Expand Down
59 changes: 43 additions & 16 deletions fife_rpg_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,11 @@ def __init__(self, setting):
layer_box.setHeight(PyCEGUI.UDim(0.175, 0.0))
layer_box.setWidth(PyCEGUI.UDim(1.0, 0.0))

self.listbox = layer_box.createChild("TaharezLook/Listbox", "Listbox")
self.listbox = layer_box.createChild("TaharezLook/ItemListbox",
"Listbox")

self.listbox.setHeight(PyCEGUI.UDim(0.99, 0.0))
self.listbox.setWidth(PyCEGUI.UDim(0.99, 0.0))
self.listbox.setMultiselectEnabled(True)
self.listbox.subscribeEvent(PyCEGUI.Listbox.EventSelectionChanged,
self.cb_layer_selection_changed)
self.show_agents_check = right_area_container.createChild("TaharezLook"
"/Checkbox",
"show_agents"
Expand Down Expand Up @@ -169,6 +168,14 @@ def __loadData(self): # pylint: disable=no-self-use, invalid-name
PyCEGUI.FontManager.getSingleton().createFromFile("DejaVuSans-12.font")
PyCEGUI.FontManager.getSingleton().createFromFile("DejaVuSans-14.font")

@property
def selected_layer(self):
"""Returns the currently selected layer"""
selected = self.listbox.getFirstSelectedItem()
if selected is not None:
return selected.getText().encode()
return None

def setup(self):
"""Actions that should to be done with an active mode"""
self.create_menu()
Expand Down Expand Up @@ -841,13 +848,26 @@ def cb_map_switch(self, args):
if self.current_map:
layers = self.current_map.fife_map.getLayers()
for layer in layers:
item = PyCEGUI.ListboxTextItem(layer.getId())
item.setSelectionBrushImage("TaharezLook/"
"MultiListSelectionBrush")
self.listbox.addItem(item)
item.setSelected(True)
layer_name = layer.getId()
item = self.listbox.createChild(
"TaharezLook/CheckListboxItem",
"layer_%s" % layer_name)
checkbox = item.getChild(0)

checkbox.setSelected(True)
checkbox.subscribeEvent(
PyCEGUI.ToggleButton.EventSelectStateChanged,
# pylint:disable=cell-var-from-loop
lambda args, layer=layer_name:
# pylint:enable=cell-var-from-loop
self.cb_layer_checkbox_changed(
args, layer)
)
item.setText(layer_name)

if not self.show_agents_check.isSelected():
self.hide_map_entities(self.current_map.name)
self.listbox.performChildWindowLayout()
except Exception as error:
print error
raise
Expand All @@ -864,13 +884,15 @@ def cb_tb_page_changed(self, args):
new_toolbar.activate()
self.old_toolbar_index = index

def cb_layer_selection_changed(self, args):
"""Called when the layer selection in the listbox changed"""
layers = self.current_map.fife_map.getLayers()
for layer in layers:
listitem = self.listbox.findItemWithText(layer.getId(), None)
is_selected = listitem.isSelected()
layer.setInstancesVisible(is_selected)
def cb_layer_checkbox_changed(self, args, layer_name):
"""Called when a layer checkbox state was changed
Args:
layer_name: Name of the layer the checkbox is for
"""
layer = self.current_map.fife_map.getLayer(layer_name)
is_selected = args.window.isSelected()
layer.setInstancesVisible(is_selected)

def update_property_editor(self):
"""Update the property editor"""
Expand Down Expand Up @@ -1071,6 +1093,11 @@ def cb_import_objects(self, args):
for callback in self._objects_imported_callbacks:
callback()

def cb_layerbox_item_click(self, args):
"""Callback when an item was clicked in the layerbox"""
pass
args.window.setSelected(True)


def update_settings(project, settings, values):
"""Update the fife-rpg settings of a project
Expand Down
Loading

0 comments on commit 4e35686

Please sign in to comment.