﻿# Leo VI's Mass Vassal Directives - scripted GUIs
#
# These back the configuration panel's toggles and buttons. Each is invoked
# from the panel with the player as root:
#   [GetScriptedGui('name').Execute( GuiScope.SetRoot( GetPlayer.MakeScope ).End )]
#
# Convention used by the panel widgets:
#   is_shown  -> the control's "checked"/"selected" state (IsShown binding)
#   is_valid  -> whether the control is enabled  (IsValid binding)
#   effect    -> runs on click                    (Execute binding)
#
# A control's selected state does not always need a scripted GUI: where it is
# simply "does this variable equal N", the panel reads the variable directly and
# no entry is needed here. That is why the preset radios below define only an
# effect - their selected state comes straight from leo_mvd_preset in the panel.
#
# Settings changes re-run the waterfall immediately only when automation is
# already on, so that auto mode stays live; otherwise the change just updates
# the configuration and the player applies it explicitly.

# Monthly automation. Checked when on; only usable for a landed ruler.
# Turning it on applies the directives once right away for immediate feedback.
leo_mvd_toggle_auto = {
	scope = character

	is_shown = {
		has_variable = leo_mvd_auto
	}
	is_valid = {
		is_ruler = yes
	}
	effect = {
		leo_mvd_init_defaults_effect = yes
		if = {
			limit = { has_variable = leo_mvd_auto }
			remove_variable = leo_mvd_auto
		}
		else = {
			set_variable = leo_mvd_auto
			leo_mvd_run_waterfall_effect = yes
		}
	}
}

# Preset selection. Each loads a built-in rule set, replacing the rules in
# place. leo_mvd_select_preset_effect re-applies when automation is on.
#
# None is the default and does exactly what it says: with no rules the mod
# assigns nothing. It is a real choice rather than an absence of one, so that
# the player can turn the automation off without unpicking anything else.
leo_mvd_preset_0 = {
	scope = character
	effect = {
		leo_mvd_init_defaults_effect = yes
		leo_mvd_select_preset_effect = { N = 0 }
	}
}

leo_mvd_preset_1 = {
	scope = character
	effect = {
		leo_mvd_init_defaults_effect = yes
		leo_mvd_select_preset_effect = { N = 1 }
	}
}

leo_mvd_preset_2 = {
	scope = character
	effect = {
		leo_mvd_init_defaults_effect = yes
		leo_mvd_select_preset_effect = { N = 2 }
	}
}

leo_mvd_preset_3 = {
	scope = character
	effect = {
		leo_mvd_init_defaults_effect = yes
		leo_mvd_select_preset_effect = { N = 3 }
	}
}

leo_mvd_preset_4 = {
	scope = character
	effect = {
		leo_mvd_init_defaults_effect = yes
		leo_mvd_select_preset_effect = { N = 4 }
	}
}

leo_mvd_preset_8 = {
	scope = character
	effect = {
		leo_mvd_init_defaults_effect = yes
		leo_mvd_select_preset_effect = { N = 8 }
	}
}

# The player's own rules. Picking Custom from a preset starts blank; starting
# from a preset is a different gesture - change one of its rules and
# leo_mvd_edit_effect makes the whole thing yours.
leo_mvd_preset_5 = {
	scope = character
	effect = {
		leo_mvd_init_defaults_effect = yes
		leo_mvd_select_preset_effect = { N = 5 }
	}
}

# Apply the priority waterfall across all eligible vassals right now.
# Disabled while there are no rules, so that the button can never be the thing
# that assigns a directive the player never chose.
leo_mvd_apply_now = {
	scope = character

	is_valid = {
		is_ruler = yes
		has_variable = leo_mvd_rule_count
		var:leo_mvd_rule_count >= 1
	}
	effect = {
		leo_mvd_init_defaults_effect = yes
		leo_mvd_run_waterfall_effect = yes
	}
}

# Remove every mod-assigned directive and exemption, and turn automation off.
leo_mvd_remove_all = {
	scope = character

	effect = {
		leo_mvd_remove_all_effect = yes
	}
}
