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
				set_global_flag = cat_army_annexing
			}
			cat_army_button_off_click = {
				clr_global_flag = cat_army
				clr_global_flag = cat_army_annexing
			}
			cat_navy_button_on_click = {
				set_global_flag = cat_navy
			}
			cat_navy_button_off_click = {
				clr_global_flag = cat_navy
			}
			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
						}
					}

					#ARMY ONLY
					if = {
						limit = {
							NOT = { has_global_flag = cat_navy }
							has_global_flag = cat_army
						}
						every_country = {
							limit = { has_country_flag = cat_annexee }
							destroy_ships = {
								type = carrier
								count = all
							}
							destroy_ships = {
								type = helicopter_operator
								count = all
							}
							destroy_ships = {
								type = battleship
								count = all
							}
							destroy_ships = {
								type = battle_cruiser
								count = all
							}
							destroy_ships = {
								type = cruiser
								count = all
							}
							destroy_ships = {
								type = stealth_destroyer
								count = all
							}
							destroy_ships = {
								type = destroyer
								count = all
							}
							destroy_ships = {
								type = frigate
								count = all
							}
							destroy_ships = {
								type = corvette
								count = all
							}
							destroy_ships = {
								type = missile_submarine
								count = all
							}
							destroy_ships = {
								type = attack_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_country = {
							limit = { has_country_flag = cat_annexee }
							every_navy_leader = { set_nationality = FROM }
							transfer_navy = { target = FROM }
						}
					}

					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 AND NAVY
					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_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_army_annexing }
				NOT = { has_global_flag = cat_annexing }
			}
			cat_annexing_button_off_visible = {
				OR = {
					has_global_flag = cat_annexing
					has_global_flag = cat_army_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
				}
			}
		}
		
	}
}

