extends CanvasLayer

func openmenu():
#	get_tree().paused = true
	$Control2.show()
	$Control/VSeparator/Label.text = 'Choose a power:'
	$Control/VSeparator/ItemList.clear()
	var array = []
	var text = Powerups.menbros.keys() + Powerups.corpo.keys() + Powerups.apendice.keys()
	for x in 5:
		while text.has('null'): text.erase('null')
		text.shuffle()
		array.append(text[0])
		text.remove(0)
	for x in array:
		$Control/VSeparator/ItemList.add_item(x)
	
	for x in 5:
		$Control2/VSeparator/buttons.get_child(x).id = x
		$Control2/VSeparator/buttons.get_child(x).text = array[x]
		var buff = 0
		if Powerups.menbros.has(array[x]): buff = 4
		if Powerups.corpo.has(array[x]): buff = 8
		$Control2/VSeparator/buttons.get_child(x).collayer = buff
		$Control2/VSeparator/buttons.get_child(x).col()
		$Control2/VSeparator/buttons.get_child(x).posswitch = true

func _on_bacteria_level_up():
	openmenu()
	pass # Replace with function body.

var power = ''
var dict = ''

func _on_ItemList_item_activated(index):
	if $Control/VSeparator/Label.text == 'Choose a power:':
		print(index)
		power = $Control/VSeparator/ItemList.get_item_text(index)
		if Powerups.menbros.has(power): dict = 'menbros'
		if Powerups.corpo.has(power): dict = 'corpo'
		if Powerups.apendice.has(power): dict = 'apendice'
		$Control/VSeparator/ItemList.clear()
		for x in Powerups.dictslots[dict]:
			$Control/VSeparator/ItemList.add_item(Powerups.dict[dict + str(x)].name)
		$Control/VSeparator/Label.text = 'put on slot:'
	elif $Control/VSeparator/Label.text == 'put on slot:':
		print(index)
		var dict2 = dict + str(index)
		if Powerups.dict[dict2] == Powerups[dict][power]:
			print('upgrading power')
			for x in Powerups[dict][power]['upgrade'].keys():
				 Powerups[dict][power][x] += Powerups[dict][power]['upgrade'][x]
		Powerups.dict[dict2] = Powerups[dict][power]
		get_parent().get_node("bacteria")._ready()
		print(dict2)
		print(power)
#		get_tree().paused = false
		$Control2.hide()
	pass # Replace with function body.

var buff1 = 0
var buff2 = 0

var lock = []

func _physics_process(delta):
	print(lock)

func _on_Button_button_down():
	_on_ItemList_item_activated(buff1)
	_on_ItemList_item_activated(buff2)
	pass # Replace with function body.
