scripted_gui = {

	cat_main_container = {
	
		context_type = selected_country_context
		
		window_name = "cat_main_container"
		
		visible = {
			ROOT = {
				is_ai = no
				has_global_flag = cat_enabled
				OR = {
					has_country_flag = tp_is_host
					NOT = {
						has_global_flag = tp_is_multiplayer
					}
				}
			}
		}
		
		effects = {
			cat_army_button_on_click = {
				set_global_flag = cat_army
			}
			cat_army_button_off_click = {
				clr_global_flag = cat_army
			}
			cat_navy_button_on_click = {
				set_global_flag = cat_navy
			}
			cat_navy_button_off_click = {
				clr_global_flag = cat_navy
			}
			cat_characters_button_on_click = {
				set_global_flag = cat_characters
			}
			cat_characters_button_off_click = {
				clr_global_flag = cat_characters
			}
			cat_coring_button_on_click = {
				set_global_flag = cat_coring
			}
			cat_coring_button_off_click = {
				clr_global_flag = cat_coring
			}
			cat_annexing_button_on_click = {
				set_global_flag = cat_annexing
			}
			cat_annexing_button_off_click = {
				clr_global_flag = cat_army
				clr_global_flag = cat_annexing
				clr_global_flag = cat_army_annexing
			}
			cat_marker_click = {
				set_temp_variable = { ROOT.annexee = this }
				var:annexee = {
					set_country_flag = cat_annexee
				}
			}
			cat_unmarker_click = {
				set_temp_variable = { ROOT.annexee = this }
				var:annexee = {
					clr_country_flag = cat_annexee
				}
			}
			cat_annex_click = {
				
				set_temp_variable = { annexer = this }
				every_country = {
					limit = { has_country_flag = cat_annexee }

					#CORING
					if = {
						limit = { has_global_flag = cat_coring }
						every_owned_state = {
							add_core_of = var:annexer
						}
					}

					#CHARACTERS
					if = {
						limit = {
							has_global_flag = cat_characters
						}
						every_character = {
							set_nationality = FROM
						}
					}

					#LOG
					if = {
						limit = {
							has_global_flag = cat_annexing
						}
						toolpack_cycle_action_log_variables = yes
						add_to_array = { global.toolpack_mp_action_array_targets = THIS }
						add_to_array = { global.toolpack_mp_action_array = 2 }
					}

					#ARMY ONLY NON-ANNEXATION
					if = {
						limit = {
							has_global_flag = cat_army
							NOT = {
								has_global_flag = cat_annexing
							}
						}
						transfer_units_fraction= {
							target = FROM
							size = 1
							navy_ratio = 0
							air_ratio = 0
							keep_unit_leaders_trigger = {
								always = yes
							}
						}
						every_army_leader = { set_nationality = FROM }
					}

					#ARMY ONLY ANNEXATION
					else_if = {
						limit = {
							NOT = { has_global_flag = cat_navy }
							has_global_flag = cat_army
							has_global_flag = cat_annexing
						}
						destroy_ships = {
							type = ship_hull_light
							count = all
						}
						destroy_ships = {
							type = ship_hull_cruiser
							count = all
						}
						destroy_ships = {
							type = ship_hull_heavy
							count = all
						}
						destroy_ships = {
							type = ship_hull_carrier
							count = all
						}
						destroy_ships = {
							type = ship_hull_submarine
							count = all
						}
						every_army_leader = { set_nationality = FROM }
						var:annexer = {
							annex_country = {
								target = PREV
								transfer_troops = yes
							}
						}
					}

					#NAVY ONLY
					if = {
						limit = {
							has_global_flag = cat_navy
							NOT = { has_global_flag = cat_army }
						}
						every_navy_leader = { set_nationality = FROM }
						transfer_navy = { target = FROM }
					}

					#ARMY AND NAVY
					else_if = {
						limit = {
							has_global_flag = cat_navy
							has_global_flag = cat_army
						}
						every_unit_leader = { set_nationality = FROM }
						var:annexer = {
							annex_country = {
								target = PREV
								transfer_troops = yes
							}
						}
					}

					#ARMY NOR NAVY - OR ANNEXING AFTER NAVY ONLY
					if = {
						limit = { has_global_flag = cat_annexing }
						var:annexer = {
							annex_country = {
								target = PREV
								transfer_troops = no
							}
						}
					}
				}
				
				every_country = {
					limit = { has_country_flag = cat_annexee }
					clr_country_flag = cat_annexee
				}
				bst_count_civf = yes
			}
			cat_unmark_all_click = {
				every_country = {
					limit = { has_country_flag = cat_annexee }
					clr_country_flag = cat_annexee
				}
			}
		}
		
		triggers = {

			cat_army_button_on_visible = {
				NOT = { has_global_flag = cat_army }
			}
			cat_army_button_off_visible = {
				has_global_flag = cat_army
			}
			cat_navy_button_on_visible = {
				NOT = { has_global_flag = cat_navy}
			}
			cat_navy_button_off_visible = {
				has_global_flag = cat_navy
			}
			cat_characters_button_on_visible = {
				NOT = { has_global_flag = cat_characters}
			}
			cat_characters_button_off_visible = {
				has_global_flag = cat_characters
			}
			cat_coring_button_on_visible = {
				NOT = { has_global_flag = cat_coring }
			}
			cat_coring_button_off_visible = {
				has_global_flag = cat_coring
			}
			cat_annexing_button_on_visible = {
				NOT = { has_global_flag = cat_annexing }
			}
			cat_annexing_button_off_visible = {
				has_global_flag = cat_annexing
			}
			cat_marker_enabled = {
				NOT = {
					has_country_flag = cat_annexee
				}
			}
			cat_marker_visible = {
				NOT = {
					has_country_flag = cat_annexee
				}
			}
			cat_unmarker_visible = {
				has_country_flag = cat_annexee
			}
			cat_annex_click_enabled = {
				NOT = {
					has_country_flag = cat_annexee
				}
				any_country = {
					has_country_flag = cat_annexee
				}
				OR = {
					has_global_flag = cat_annexing
					has_global_flag = cat_army_annexing
					has_global_flag = cat_army
					has_global_flag = cat_navy
					has_global_flag = cat_coring
				}
			}
			cat_unmark_all_click_enabled = {
				any_country = {
					has_country_flag = cat_annexee
				}
			}
		}
		
	}
}

