# =============================================================================
# Giga + Age of Wonder Compatibility Patch — megastructure build-menu filter
# Persistent on-screen "mode" button (see interface/zzzz_compat_megatab_bar.gui,
# shown by events/zzzz_compat_megatab_events.txt). Cycles the build-menu filter:
#   All  -> Giga only -> Age of Wonder only -> All ...
#
# State is two per-country flags (MP-safe, each player independent):
#   neither            = All
#   compat_mega_hide_aow  set = Giga only
#   compat_mega_hide_giga set = AoW only
# Megastructures' `potential` checks these (AoW via the shared
# AOW_trigger_mega_potential override; Giga per-structure). The list only rebuilds
# when the build window OPENS, so you set the mode first, then open the menu.
#
# Three buttons share one slot in the bar; the bound button_effect `potential`
# (evaluated live, FROM = the viewing player's country) shows only the one matching
# the current mode, so the button always displays the current mode and clicking it
# advances to the next. ALL THREE also require NOT has_edict = compat_hide_megatab,
# so activating that edict hides the button entirely (live).
# =============================================================================

# Current mode = All  ->  click sets Giga only
compat_megatab_show_all = {
	potential = {
		from = {
			NOT = { has_edict = compat_hide_megatab }
			NOT = { has_country_flag = compat_mega_hide_giga }
			NOT = { has_country_flag = compat_mega_hide_aow }
		}
	}
	allow = { always = yes }
	effect = {
		custom_tooltip = compat_megatab_btn_tt
		hidden_effect = {
			from = {
				set_country_flag = compat_mega_hide_aow
				remove_country_flag = compat_mega_hide_giga
			}
		}
	}
}

# Current mode = Giga only  ->  click sets AoW only
compat_megatab_show_giga = {
	potential = {
		from = {
			NOT = { has_edict = compat_hide_megatab }
			has_country_flag = compat_mega_hide_aow
			NOT = { has_country_flag = compat_mega_hide_giga }
		}
	}
	allow = { always = yes }
	effect = {
		custom_tooltip = compat_megatab_btn_tt
		hidden_effect = {
			from = {
				set_country_flag = compat_mega_hide_giga
				remove_country_flag = compat_mega_hide_aow
			}
		}
	}
}

# Current mode = AoW only  ->  click returns to All
compat_megatab_show_aow = {
	potential = {
		from = {
			NOT = { has_edict = compat_hide_megatab }
			has_country_flag = compat_mega_hide_giga
			NOT = { has_country_flag = compat_mega_hide_aow }
		}
	}
	allow = { always = yes }
	effect = {
		custom_tooltip = compat_megatab_btn_tt
		hidden_effect = {
			from = {
				remove_country_flag = compat_mega_hide_giga
				remove_country_flag = compat_mega_hide_aow
			}
		}
	}
}
