# mod_setting

!'Mod system 1.0 by illume'
gs 'obj_din', 'settingtabs'
cla

if settingmode = 1:
	!value= 2, call from Character creation
	act '<center><b>Return to character creation</b></center>': killvar 'menu_page' & gt 'begin', 'start'
else
	!call from Menu - Game settings
	act 'Exit the menu': killvar 'menu_page' & gt 'obj_din', 'menu_exit'
end

*nl '<center><h1>MODs</h1></center>'
'<center>'
'<b>WARNING</b>: Game slowdown may occur when installing too many mods, or mods with bad structure.'
*nl
'You may find information on available Mods as well as instructions on installing Mods on this thread:'
'<a href="https://tfgames.site/phpbb3/viewtopic.php?f=70&t=11793&sid=08ee13168a1ea71fa2348f20815b8380">https://tfgames.site/phpbb3/viewtopic.php?f=70&t=11793&sid=08ee13168a1ea71fa2348f20815b8380</a>'
*nl
if mod_list > 0:

	'<table border=1><tr><td>id</td><td>Name</td><td>Version</td><td>Author</td><td>Description</td><td>Options</td></tr>'
	mod_i=1
	:mod_alllist
	if $mod_name[mod_i] ! '':
		!name
		*p '<tr><td><<mod_i>></td><td><<$mod_name[mod_i]>></td>'
		!version
		*p '<td><<val($mod_version[mod_i])/10000>>.<<(val($mod_version[mod_i]) mod 10000)/100>> <<iif(val($mod_version[mod_i]) mod 100 > 0, ''fix <<val($mod_version[mod_i]) mod 100>> '', '' '')>></td>'
		!author
		*p '<td><<$mod_author[mod_i]>></td>'
		!description and readme
		*p '<td><a href="exec:gs ''mod_<<$mod_name[mod_i]>>_readme''"><img src="images/system/icons/anptekainfo.jpg"></a> <<$mod_desc[mod_i]>></td>'
		!mod options page
		*p '<td>'+iif($mod_opt[mod_i] ! '','<a href="exec:gs ''mod_<<$mod_name[mod_i]>>_options''"><<$mod_opt[mod_i]>></a>','')+'</td></tr>'
	else
		'ERROR loading mod id <<mod_i>>, no mod name available'
	end

	if mod_list > mod_i:
		mod_i+=1
		jump 'mod_alllist'
	end
	killvar '$mod_info'
	'</table>'
else
	'<br>You have no Mods activated.'
end
'</center>'
act ''+iif(settingmode = 1, '<center><b>Install new mod</b></center>','Install new mod')+'':
	killvar '$mod_info'
	$mod_temp=input('input mod name (as for the example image above, input <B>isample</B>)')
	if $mod_temp='':exit
	addqst 'mod/<<$mod_temp>>.qsp'
	gs 'mod_<<$mod_temp>>_setup'
	if $mod_info[0] = '':
		msg '<b><<$mod_temp>>.qsp</b> is not a Girl life ECV mod, please contract its author for help'
		exit
	end
	mod_list += 1
	$mod_name[mod_list] = $mod_info[0]
	$mod_version[mod_list] = $mod_info[1]
	$mod_author[mod_list] = $mod_info[2]
	$mod_desc[mod_list] = $mod_info[3]
	$mod_opt[mod_list] = $mod_info[4]
	gt 'mod_setting'
end

if mod_list > 0:
	act ''+iif(settingmode = 1, '<center><b>Disable all mods</b></center>','Disable all mods')+'':
		if input('Are you sure? ALL mod will be disabled!<br>please input <b>qqq</B> to confirm') = 'qqq':
			if mod_list > 0:
				mod_i=mod_list
				:mod_data_remover
				if $mod_name[mod_i] ! '':
					$mod_su_name = 'mod_<<$mod_name[mod_i]>>_onremove'
					if LOC($mod_su_name): gs $mod_su_name
				end
				if mod_i > 0:
					mod_i-=1
					jump 'mod_data_remover'
				end
				killvar '$mod_su_name'
				killvar 'mod_i'
			end

			killqst
			set mod_list=0
			killvar '$mod_name'
			killvar '$mod_version'
			killvar '$mod_author'
			killvar '$mod_desc'
			killvar '$mod_opt'
			msg 'All mod disabled. You can re-install them later.'
			gt 'mod_setting'
		end
	end
	! Delete single mod
	act ''+iif(settingmode = 1, '<center><b>Uninstall mod</b></center>','Uninstall mod')+'':
		$mod_temp = input('Input mod name to uninstall (Case Sensetive)')
		mod_removed_temp = 0
		if $mod_temp ! '':
			mod_i = mod_list
			:mod_data_remover
			if $mod_name[mod_i] = $mod_temp:
				$mod_su_name = 'mod_<<$mod_name[mod_i]>>_onremove'
				if LOC($mod_su_name): gs $mod_su_name
				mod_removed_temp += 1
				$mod_name_temp[mod_i] = ''
			else
				$mod_name_temp[mod_i] = $mod_name[mod_i]
				$mod_version_temp[mod_i] = $mod_version[mod_i]
				$mod_author_temp[mod_i] = $mod_author[mod_i]
				$mod_desc_temp[mod_i] = $mod_desc[mod_i]
				$mod_opt_temp[mod_i] = $mod_opt[mod_i]
			end
			if mod_i > 1:
				mod_i -= 1
				jump 'mod_data_remover'
			end
			killvar '$mod_su_name'
			killvar 'mod_i'
		end

		if mod_removed_temp > 0:

			killqst
			killvar '$mod_name'
			killvar '$mod_version'
			killvar '$mod_author'
			killvar '$mod_desc'
			killvar '$mod_opt'

			mod_i = 1
			mod_restored_i = 1
			:mod_data_restore
			if $mod_name_temp[mod_i] ! '':
				$mod_name_add_temp = $mod_name_temp[mod_i]
				addqst 'mod/<<$mod_name_add_temp>>.qsp'
				killvar '$mod_name_add_temp'

				$mod_name[mod_restored_i] = $mod_name_temp[mod_i]
				$mod_version[mod_restored_i] = $mod_version_temp[mod_i]
				$mod_author[mod_restored_i] = $mod_author_temp[mod_i]
				$mod_desc[mod_restored_i] = $mod_desc_temp[mod_i]
				$mod_opt[mod_restored_i] = $mod_opt_temp[mod_i]
				mod_restored_i += 1      
			end
			if mod_i < mod_list:
				mod_i += 1
				jump 'mod_data_restore'
			end

			mod_list = mod_restored_i - 1

			killvar '$mod_name_temp'
			killvar '$mod_version_temp'
			killvar '$mod_author_temp'
			killvar '$mod_desc_temp'
			killvar '$mod_opt_temp'
			killvar 'mod_i'
			killvar 'mod_restored_i'

			if mod_removed_temp > 0:
				msg 'Mod <<$mod_temp>> was disabled.'
			end
		else
			msg 'Mod <<$mod_temp>> was not installed.'
		end

		killvar 'mod_removed_temp'
		killvar 'mod_temp'

		gt 'mod_setting'
	end
end


--- mod_setting ---------------------------------

