73 lines
1.6 KiB
GDScript
73 lines
1.6 KiB
GDScript
class_name EventGetItem extends "res://scripts/Event/Item/EventItem.gd"
|
|
|
|
const EventConversation = preload("res://scripts/Event/EventConversation.gd")
|
|
|
|
enum GetType {
|
|
FOUND,
|
|
GIVEN,
|
|
}
|
|
|
|
@export var showText: bool = true
|
|
@export var getType:GetType = GetType.FOUND;
|
|
@export var removeNode:Node = null
|
|
|
|
var conversationEvent:EventConversation = null
|
|
var textboxEvent:EventTextbox = null
|
|
|
|
func start() -> void:
|
|
getInventory().addItem(itemType, quantity)
|
|
|
|
# Should show text?
|
|
if !showText:
|
|
super.start()
|
|
return
|
|
|
|
# What text to show?
|
|
var textKey:String
|
|
match getType:
|
|
GetType.FOUND:
|
|
textKey = "event.get_item.found"
|
|
GetType.GIVEN:
|
|
textKey = "event.get_item.given"
|
|
_:
|
|
super.start()
|
|
return
|
|
|
|
# Create translation context
|
|
var ctx = TransContext.new()
|
|
ctx.addInteger("quantity", quantity)
|
|
ctx.addContext("item", ITEM.getItem(itemType).getTransContext())
|
|
|
|
# Create conversation
|
|
conversationEvent = EventConversation.new()
|
|
addChildEvent(conversationEvent)
|
|
|
|
# Create textbox
|
|
textboxEvent = EventTextbox.new()
|
|
textboxEvent.transContext = ctx
|
|
textboxEvent.text = textKey
|
|
textboxEvent.textPlural = textKey + "_plural"
|
|
textboxEvent.count = quantity
|
|
conversationEvent.addChildEvent(textboxEvent)
|
|
|
|
# Begin processing
|
|
super.start()
|
|
startChild(conversationEvent)
|
|
|
|
func isDone() -> bool:
|
|
if !super.isDone():
|
|
return false
|
|
|
|
if !showText:
|
|
return true
|
|
return conversationEvent.isDone()
|
|
|
|
func end() -> void:
|
|
if removeNode:
|
|
var parent = removeNode.get_parent()
|
|
if parent:
|
|
parent.remove_child(removeNode)
|
|
removeNode.queue_free()
|
|
removeNode = null
|
|
super.end()
|