|  |  |  | @tool | 
					
						
							|  |  |  | extends Control | 
					
						
							|  |  |  | class_name CoreItemSub | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @onready var mp_scene: PackedScene = preload("res://scene/ui/item/mp_item.tscn") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @export var is_right: bool: | 
					
						
							|  |  |  | 	set(value): | 
					
						
							|  |  |  | 		is_right = value | 
					
						
							|  |  |  | 		$CoreNameLeft.visible = not value | 
					
						
							|  |  |  | 		$CoreNameRight.visible = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @export var detail_rate: float: | 
					
						
							|  |  |  | 	set(value): | 
					
						
							|  |  |  | 		detail_rate = value | 
					
						
							|  |  |  | 		var panel_left = $CoreNameLeft/CoreNamePanelLeft as TextureRect | 
					
						
							|  |  |  | 		var panel_right = $CoreNameRight/CoreNamePanelRight as TextureRect | 
					
						
							|  |  |  | 		var label_left = $CoreNameLeft/CoreNameLabelLeft as Label | 
					
						
							|  |  |  | 		var label_right = $CoreNameRight/CoreNameLabelRight as Label | 
					
						
							|  |  |  | 		var mp_list_left = $CoreNameLeft/CoreMpCostLeft as HBoxContainer | 
					
						
							|  |  |  | 		var mp_list_right = $CoreNameRight/CoreMpCostRight as HBoxContainer | 
					
						
							|  |  |  | 		panel_left.modulate.a = value | 
					
						
							|  |  |  | 		panel_right.modulate.a = value | 
					
						
							|  |  |  | 		label_left.modulate.a = value | 
					
						
							|  |  |  | 		label_right.modulate.a = value | 
					
						
							|  |  |  | 		mp_list_left.modulate.a = value | 
					
						
							|  |  |  | 		mp_list_right.modulate.a = value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @onready var icon: TextureRect = $CoreIcon as TextureRect | 
					
						
							|  |  |  | @onready var slot: TextureRect = $CoreSlot as TextureRect | 
					
						
							|  |  |  | @onready var icon_empty: Texture2D = load("res://resource/ui/icon/core/empty.png") as Texture2D | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func set_info(cfg: CoreCfg): | 
					
						
							|  |  |  | 	var label_left = $CoreNameLeft/CoreNameLabelLeft as Label | 
					
						
							|  |  |  | 	var label_right = $CoreNameRight/CoreNameLabelRight as Label | 
					
						
							|  |  |  | 	var mp_list_left = $CoreNameLeft/CoreMpCostLeft as HBoxContainer | 
					
						
							|  |  |  | 	var mp_list_right = $CoreNameRight/CoreMpCostRight as HBoxContainer | 
					
						
							|  |  |  | 	if not cfg: | 
					
						
							|  |  |  | 		icon.texture = icon_empty | 
					
						
							|  |  |  | 		label_left.text = "-" | 
					
						
							|  |  |  | 		label_right.text = "-" | 
					
						
							|  |  |  | 		set_mp_cost(mp_list_left, 0) | 
					
						
							|  |  |  | 		set_mp_cost(mp_list_right, 0) | 
					
						
							|  |  |  | 	else: | 
					
						
							|  |  |  | 		icon.texture = cfg.get_icon() | 
					
						
							|  |  |  | 		label_left.text = cfg.name | 
					
						
							|  |  |  | 		label_right.text = cfg.name | 
					
						
							|  |  |  | 		set_mp_cost(mp_list_left, cfg.get_mp_cost()) | 
					
						
							|  |  |  | 		set_mp_cost(mp_list_right, cfg.get_mp_cost()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | func set_mp_cost(mp_list: HBoxContainer, value: int): | 
					
						
							|  |  |  | 	for child in mp_list.get_children(): | 
					
						
							|  |  |  | 		child.queue_free() | 
					
						
							|  |  |  | 	if value == 0: | 
					
						
							|  |  |  | 		var mp_item: MpItemSub = mp_scene.instantiate() as MpItemSub | 
					
						
							|  |  |  | 		mp_list.add_child(mp_item) | 
					
						
							|  |  |  | 		mp_item.set_active(false) | 
					
						
							|  |  |  | 	else: | 
					
						
							|  |  |  | 		for i in range(value): | 
					
						
							|  |  |  | 			var mp_item: MpItemSub = mp_scene.instantiate() as MpItemSub | 
					
						
							|  |  |  | 			mp_list.add_child(mp_item) |