Custom data tooltip, Tooltip manager, Gymkhana autoload

This commit is contained in:
2024-03-17 19:48:58 +01:00
parent 559cb294f2
commit 19ef4704d4
35 changed files with 379 additions and 185 deletions

View 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

View File

@@ -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

View File

@@ -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 ""

View File

@@ -64,4 +64,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)

View File

@@ -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 ""

View File

@@ -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()

View File

@@ -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 = ""