# Scripted GUI Pie Chart example by Yard1
# Feel free to use in your mods, but give credits to Yard1 (both in code, with comments; and on your download page)

# this creates a pie chart of popularities - can be easily adapted to show anything that adds up to 100%
create_pie_chart = {
	clear_array = pie_chart
	resize_array = {
		array = pie_chart
		value = 1 # 1 is value for neutrality frame, so we don't have to make a loop for it
		size = 100 # 100 pieces, each percent is one piece
	}
	set_temp_variable = { militarists_pop = var:militarists_influence }
	round_temp_variable = militarists_pop

	set_temp_variable = { party_pop = var:party_influence }
	round_temp_variable = party_pop 
	set_variable = { ROOT.last_idx = militarists_pop }
	add_to_temp_variable = { party_pop = ROOT.last_idx }
	for_loop_effect = {
		start = ROOT.last_idx
		end = party_pop
		set_variable = { pie_chart^v = 2 }
		add_to_variable = { ROOT.last_idx = 1 }
	}

	set_temp_variable = { science_pop = var:science_influence }
	round_temp_variable = science_pop
	add_to_temp_variable = { science_pop = ROOT.last_idx }
	for_loop_effect = {
		start = ROOT.last_idx
		end = science_pop
		set_variable = { pie_chart^v = 3 }
		add_to_variable = { ROOT.last_idx = 1 }
	}

	set_temp_variable = { industrialists_pop = var:industrialists_influence }
	round_temp_variable = industrialists_pop 
	add_to_temp_variable = { industrialists_pop = ROOT.last_idx }
	for_loop_effect = {
		start = ROOT.last_idx
		end = industrialists_pop
		set_variable = { pie_chart^v = 4 }
	}

	clear_variable = ROOT.last_idx
	add_to_variable = { pie_chart_dirty = 1 }
}