Skip to content

Commit

Permalink
fix colors of selected entities (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbrain committed Oct 24, 2023
1 parent 04097e9 commit d5dad10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions addons/pandora/ui/components/entity_picker/entity_picker.gd
Expand Up @@ -51,6 +51,9 @@ func set_data(entities:Array[PandoraEntity]) -> void:
option_button.get_popup().clear()
for entity in _entities:
option_button.get_popup().add_icon_item(load(entity.get_icon_path()), entity.get_entity_name(), id_counter)
# Godot 4.1+
if option_button.get_popup().has_method("set_item_icon_modulate"):
option_button.get_popup().set_item_icon_modulate(id_counter, entity.get_icon_color())
_ids_to_entities[id_counter] = entity
_entity_ids_to_ids[entity.get_entity_id()] = id_counter
id_counter += 1
Expand All @@ -59,6 +62,7 @@ func set_data(entities:Array[PandoraEntity]) -> void:
func select(entity:PandoraEntity) -> void:
var id = _entity_ids_to_ids[entity.get_entity_id()]
option_button.select(id)
option_button.modulate = entity.get_icon_color()


func _on_id_selected(id:int) -> void:
Expand Down
Expand Up @@ -17,15 +17,17 @@ func _init(class_data:Dictionary) -> void:

for entity in all_entities:
property_control.get_popup().add_icon_item(load(entity.get_icon_path()), entity.get_entity_name(), id_counter)
property_control.get_popup().set_item_icon_modulate(id_counter, entity.get_icon_color())
# Godot 4.1+
if property_control.get_popup().has_method("set_item_icon_modulate"):
property_control.get_popup().set_item_icon_modulate(id_counter, entity.get_icon_color())
ids_to_entities[id_counter] = entity
id_counter += 1


func _on_id_selected(id:int) -> void:
var entity = ids_to_entities[id] as PandoraEntity
var current_entity = get_edited_object()[get_edited_property()] as PandoraEntity

property_control.modulate = current_entity.get_icon_color() if current_entity != null else Color.WHITE
if current_entity != null and entity.get_entity_id() == current_entity.get_entity_id():
# skip current entities
return
Expand All @@ -44,6 +46,7 @@ func _update_deferred() -> void:
for id in ids_to_entities.keys():
if ids_to_entities[id].get_entity_id() == current_entity.get_entity_id():
property_control.select(id)
property_control.modulate = current_entity.get_icon_color()
break


Expand Down

0 comments on commit d5dad10

Please sign in to comment.