# Hurry Curry! - a game about cooking
# Copyright (C) 2025 Hurry Curry! contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see .
#
extends Menu
var authors := ["metamuffin", "nokoe", "tpart"]
var contributors := ["sofviic", "BigBrotherNii", "Miner34"]
const cc_by_4 := "CC-BY 4.0"
const cc_by_3 := "CC-BY 3.0"
const cc0 := "CC0"
const AGPL_NOTICE := """This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see ."""
const SOURCE_CODE := "https://codeberg.org/hurrycurry/hurrycurry"
func _ready() -> void:
	super()
	$side/margin/options/first/source.tooltip_text = SOURCE_CODE
var credits := [
	[tr("c.credits.models"), [
		["kenney.nl", "Various Models", cc0],
		["Kay Lousberg", "Kitchen tiles", cc0],
		["Poly by Google", "Strawberry", cc_by_3],
		["Poly by Google", "Fish", cc_by_3],
		["Poly by Google", "Rolling pin", cc_by_3],
		["jeremy", "Propeller hat", cc_by_3]
	]],
	[tr("c.credits.sounds"), [
		["Dryoma", "Footstep sounds", cc_by_4],
		["Koops", "Page_Turn_24.wav", cc_by_4],
		["InspectorJ", "Pencil, Writing, Close, A.wav", cc_by_4],
		["Dillon Becker", "Super Dialogue Audio Pack", cc_by_4],
		["Ellr", "Universal UI/Menu Soundpack", cc_by_4],
		["toyoto", "Woosh Fleuret Escrime B.wav", cc_by_4],
		["deleted_user_877451", "Game_over.wav", cc_by_3],
		["Quaternius", "Someting, dont remember...", cc0],
		["Dillon Becker", "Super Dialogue Audio Pack V1", cc_by_4],
		["Ekrcoaster", "Water steaming on hot surface #2", cc0]
	]],
	[tr("c.credits.translations"), {
		tr("c.settings.ui.language.zh_Hans"): ["Outbreak2096"],
		tr("c.settings.ui.language.zh_Hant"): ["hugoalh"],
		tr("c.settings.ui.language.nl"): ["Vistaus"],
		tr("c.settings.ui.language.it"): ["Miner34", "solemden"],
		tr("c.settings.ui.language.eu"): ["josuigoa"],
		tr("c.settings.ui.language.fr"): ["fnetX", "lejun"],
		tr("c.settings.ui.language.pl"): ["tranzystorekk"],
		tr("c.settings.ui.language.he"): ["RustyStriker"],
		tr("c.settings.ui.language.el"): ["n0toose"],
		tr("c.settings.ui.language.ja"): ["BigBrotherNii"],
		tr("c.settings.ui.language.ar"): ["sofviic"],
		tr("c.settings.ui.language.tr"): ["furkanunsalan", "tekrei"],
		tr("c.settings.ui.language.ru"): ["0ko"],
	}]
]
func _menu_cover(state):
	$side.visible = not state
func credits_text() -> String:
	var text = "[center]"
	authors.shuffle()
	contributors.shuffle()
	
	text += "\n\n\n[b]%s[/b]\n\n%s\n\n[b]%s[/b]\n\n%s\n\n[b]%s[/b]\n\n\n" % [
		tr("c.credits.title"),
		tr("c.credits.developed_by"),
		"\n".join(authors),
		tr("c.credits.contributors"),
		",  ".join(contributors),
	]
	for section in credits:
		text += "[b]%s[/b]\n\n" % section[0]
		if typeof(section[1]) == TYPE_DICTIONARY:
			text += "[table=2]"
			for key in section[1]:
				text += "[cell][right]%s[/right][/cell]" % key
				text += "[cell][left]%s[/left][/cell]" % ", ".join(section[1][key])
			text += "[/table]"
		else:
			text += "[table=3]"
			for entry in section[1]:
				text += "[cell][right]%s[/right][/cell]" % entry[0]
				text += "[cell][left]%s[/left][/cell]" % entry[1]
				text += "[cell][left]%s[/left][/cell]" % entry[2]
			text += "[/table]"
		text += "\n\n\n"
	text += "\n[b]%s[/b]\n\n\n[/center]" % tr("c.credits.thanks")
	return text
func legal_text() -> String:
	var all: Array[String] = []
	var translators: Array[String] = []
	for c in credits[2][1].values():
		translators.append_array(c)
	translators.shuffle()
	authors.shuffle()
	contributors.shuffle()
	all.append_array(authors)
	all.append_array(contributors)
	all.append_array(translators)
	var text := "Hurry Curry! - a game about cooking\n"
	text += "[code]Copyright 2024, 2025 %s\n\n" % ", ".join(dedup_array(all))
	text += "%s[/code]\n\n" % AGPL_NOTICE
	text += tr("c.legal.using_godot")
	text += "\n\n[code]%s[/code]" % Engine.get_license_text()
	return text
func version_text() -> String:
	var text := "[center][b]Hurry Curry![/b]\n\n"
	OS.get_version()
	text += "[table=2]"
	var row = "[cell][right]%s[/right][/cell][cell][left]%s[/left][/cell]"
	text += row % [tr("c.version.game"), Global.VERSION]
	text += row % [tr("c.version.protocol"), "%s.%s" % [Multiplayer.VERSION_MAJOR, Multiplayer.VERSION_MINOR]]
	text += row % [tr("c.version.godot"), Engine.get_version_info().string]
	text += row % [tr("c.version.os"), OS.get_name()]
	text += row % [tr("c.version.arch"), Engine.get_architecture_name()]
	text += row % [tr("c.version.distribution"), Global.DISTRIBUTION]
	text += "[/table]"
	text += "[/center]"
	return text
func _on_credits_pressed() -> void:
	submenu("res://gui/menus/popup_large.tscn", credits_text())
func _on_legal_pressed() -> void:
	submenu("res://gui/menus/popup_large.tscn", legal_text())
func _on_version_pressed() -> void:
	submenu("res://gui/menus/popup_large.tscn", version_text())
func _on_back_pressed() -> void:
	exit()
func _on_source_pressed() -> void:
	OS.shell_open(SOURCE_CODE)
func dedup_array(a: Array) -> Array:
	var b = []
	for x in a: if not b.has(x): b.append(x)
	return b