Merge branch 'custom-data-components'
This commit is contained in:
16
addons/escoria-ui-return-monkey-island/GymkhanaAutoload.gd
Normal file
16
addons/escoria-ui-return-monkey-island/GymkhanaAutoload.gd
Normal file
@@ -0,0 +1,16 @@
|
||||
extends Node
|
||||
|
||||
var item_count_manager: ESCItemCountManager
|
||||
|
||||
var tooltip_manager: ESCTootltipManager
|
||||
|
||||
func get_item(global_id: String) -> ESCItem:
|
||||
var node = escoria.object_manager.get_object(global_id).node
|
||||
if not node is ESCItem:
|
||||
escoria.logger.error(
|
||||
"set_tootltip: invalid object",
|
||||
["Object is not an ESCItem"]
|
||||
)
|
||||
return null
|
||||
|
||||
return node
|
||||
@@ -40,8 +40,7 @@ func validate(arguments: Array):
|
||||
|
||||
# Run the command
|
||||
func run(command_params: Array) -> int:
|
||||
(escoria.object_manager.get_object(command_params[0]).node as ESCItemWithTooltip)\
|
||||
.set_tooltip(command_params[1],command_params[2])
|
||||
gymkhana.tooltip_manager.setTooltip(command_params[0],command_params[1],command_params[2])
|
||||
return ESCExecution.RC_OK
|
||||
|
||||
|
||||
|
||||
@@ -342,10 +342,8 @@ func has_actions(current_target_object):
|
||||
return false
|
||||
|
||||
func get_tooltip_from_current_target(verb,current_target_object):
|
||||
var tooltips = current_target_object.get('tooltips')
|
||||
if(tooltips.has(verb)):
|
||||
return tooltips.get(verb)
|
||||
return ""
|
||||
return gymkhana.tooltip_manager.getTooltip(current_target_object.global_id, verb)
|
||||
|
||||
func get_action_target_text(action_target_texts: Dictionary):
|
||||
var action_target_text = action_target_texts.get(escoria.action_manager.current_tool.global_id)
|
||||
return action_target_text if action_target_text else ""
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# A manager for inventory objects
|
||||
extends Resource
|
||||
class_name ESCTootltipManager
|
||||
|
||||
func setTooltip(global_id: String, verb: String, text: String) -> void:
|
||||
var item = gymkhana.get_item(global_id)
|
||||
item.custom_data["tooltips"][verb] = text
|
||||
|
||||
func getTooltip(global_id, verb):
|
||||
var item = gymkhana.get_item(global_id)
|
||||
if(!item.custom_data.has("tooltips")):
|
||||
return ""
|
||||
|
||||
var tooltips = item.custom_data["tooltips"]
|
||||
if(tooltips.has(verb)):
|
||||
return tooltips.get(verb)
|
||||
return ""
|
||||
@@ -2,26 +2,6 @@ tool
|
||||
extends ESCItem
|
||||
class_name ESCItemWithTooltip, "res://addons/escoria-core/design/esc_item.svg"
|
||||
|
||||
# Action 1 Label text
|
||||
export(String) var action1_text = ""
|
||||
|
||||
# Action 2 Label text
|
||||
export(String) var action2_text = ""
|
||||
|
||||
# Action 3 tooltip text if item in inventory
|
||||
export(String) var action3_text = ""
|
||||
|
||||
# Action 4 tooltip text if item in inventory
|
||||
export(String) var action4_text = ""
|
||||
|
||||
export(Dictionary) var tooltips = {}
|
||||
|
||||
# Action 3 tooltip texts if item is target. Dictionary with tool's global id as key.
|
||||
export(Dictionary) var action3_target_texts = {}
|
||||
|
||||
# Action 4 tooltip texts if item is target. Dictionary with tool's global id as key
|
||||
export(Dictionary) var action4_target_texts = {}
|
||||
|
||||
# If action used by player is in this list, this is a valid target (second item in combination)
|
||||
export(Array) var target_when_selected_action_is_in = []
|
||||
|
||||
@@ -33,10 +13,6 @@ func _ready():
|
||||
register_components()
|
||||
|
||||
|
||||
func set_tooltip(action: String, text: String):
|
||||
tooltips[action] = text
|
||||
|
||||
|
||||
func has_component(key: String)->bool:
|
||||
return components.has(key)
|
||||
|
||||
@@ -64,4 +40,4 @@ func autoload_components():
|
||||
func set_custom_data(data: Dictionary) -> void:
|
||||
.set_custom_data(data)
|
||||
if custom_data.has("count"):
|
||||
ESCItemCountManager.new().updateSprite(self)
|
||||
ESCItemCountManager.new().updateSprite(self)
|
||||
@@ -172,10 +172,8 @@ func update_tooltip_text():
|
||||
$tooltip2.visible = !hidden and action2_text != "";
|
||||
|
||||
func get_tooltip_from_current_target(verb):
|
||||
var tooltips = current_target_object.get('tooltips')
|
||||
if(tooltips.has(verb)):
|
||||
return tooltips.get(verb)
|
||||
return ""
|
||||
return gymkhana.tooltip_manager.getTooltip(current_target_object.global_id, verb)
|
||||
|
||||
func get_action_target_text(action_target_texts: Dictionary):
|
||||
var action_target_text = action_target_texts.get(escoria.action_manager.current_tool.global_id)
|
||||
return action_target_text if action_target_text else ""
|
||||
|
||||
@@ -84,6 +84,11 @@ var last_target: Object
|
||||
|
||||
var video_player: Object
|
||||
|
||||
|
||||
func _init():
|
||||
gymkhana.tooltip_manager = ESCTootltipManager.new()
|
||||
gymkhana.item_count_manager = ESCItemCountManager.new()
|
||||
|
||||
func _ready():
|
||||
# We need a slightly modified version of Action Manager to combine items with different actions.
|
||||
escoria.action_manager = ESCActionManagerMonkey.new()
|
||||
@@ -350,7 +355,7 @@ func right_click_on_inventory_item(inventory_item_global_id: String, event: Inpu
|
||||
func inventory_item_focused(inventory_item_global_id: String) -> void:
|
||||
var target_obj = escoria.object_manager.get_object(inventory_item_global_id).node
|
||||
if target_obj is ESCItemWithTooltip:
|
||||
$tooltip_layer/tooltip.set_target(target_obj.action3_text)
|
||||
#$tooltip_layer/tooltip.set_target(target_obj.action3_text)
|
||||
$tooltip_layer/tooltip.set_target_object(target_obj)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# Basic information about an inventory item
|
||||
class_name ESCInventoryItem
|
||||
|
||||
|
||||
# Global ID of the ESCItem that uses this ESCInventoryItem
|
||||
var global_id: String = ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user