#5 - adding menu language & quit

This commit is contained in:
AleaJactaEst 2022-02-12 20:45:44 +01:00
parent b937f2bcdf
commit e9a17934e7
14 changed files with 324 additions and 18 deletions

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=3] [gd_scene load_steps=4 format=3 uid="uid://cfld6w0cve6gw"]
[ext_resource type="Texture2D" path="res://UI/textures/marker.png" id="1_2jmfe"] [ext_resource type="Texture2D" uid="uid://buv7yoovo0sw" path="res://UI/textures/marker.png" id="1_2jmfe"]
[ext_resource type="Script" path="res://UI/labels.gd" id="1_4t0l0"] [ext_resource type="Script" path="res://UI/labels.gd" id="1_4t0l0"]
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_4fvmj"] [sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_4fvmj"]

31
locales/en.po Normal file
View file

@ -0,0 +1,31 @@
# Don't remove the two lines below, they're required for gettext to work correctly.
msgid ""
msgstr ""
"Project-Id-Version: khanat-client 1\n"
"PO-Revision-Date: 1\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
msgid "Echap = Menu"
msgstr "Echap to show menu"
msgid "Keys"
msgstr "Control"
msgid "Languages"
msgstr "Languages"
msgid "Language"
msgstr "Language"
msgid "Select Language"
msgstr "Select your language"
msgid "Quit"
msgstr "Exit"

31
locales/fr.po Normal file
View file

@ -0,0 +1,31 @@
# Don't remove the two lines below, they're required for gettext to work correctly.
msgid ""
msgstr ""
"Project-Id-Version: khanat-client 1\n"
"PO-Revision-Date: 1\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
msgid "Echap = Menu"
msgstr "Appuyer sur Echap pour faire appaître le menu"
msgid "Keys"
msgstr "Contrôles"
msgid "Languages"
msgstr "Langues"
msgid "Language"
msgstr "Langue"
msgid "Select language"
msgstr "Sélectionner votre langue"
msgid "Quit"
msgstr "Sortir"

27
locales/locale.sh Executable file
View file

@ -0,0 +1,27 @@
*#!/bin/bash
WORKDIR="$(dirname $(readlink -f $0))"
function generate_locale()
{
echo "--- Begin : $1"
if [ -f $1.po ]
then
msgmerge --update --backup=none $1.po messages.pot
else
msginit --no-translator --input=messages.pot --locale=$1
fi
echo "--- Check : $1"
msgfmt $1.po --check
echo "--- End : $1"
}
ORIGIN=$PWD
cd $WORKDIR
#######################
# LIST LANGUAGE : START
#######################
generate_locale fr
generate_locale en
######################
# LIST LANGUAGE : END
######################
cd $ORIGIN

BIN
locales/messages.mo Normal file

Binary file not shown.

21
locales/messages.pot Normal file
View file

@ -0,0 +1,21 @@
# Don't remove the two lines below, they're required for gettext to work correctly.
msgid ""
msgstr ""
msgid "Echap = Menu"
msgstr ""
msgid "Keys"
msgstr ""
msgid "Languages"
msgstr ""
msgid "Language"
msgstr ""
msgid "Select language"
msgstr ""
msgid "Quit"
msgstr ""

View file

@ -1,11 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://cem7wppuuoabv"]
[ext_resource type="PackedScene" uid="uid://cvdmfc2hi172g" path="res://maps/basic_setup.tscn" id="1_s50i7"]
[ext_resource type="PackedScene" uid="uid://dwxrvijqyym70" path="res://player/player.tscn" id="2_bge2k"]
[node name="main_scene" type="Node3D"]
[node name="player" parent="." instance=ExtResource( "2_bge2k" )]
transform = Transform3D(0.750872, 0, -0.660447, 0, 1, 0, 0.660447, 0, 0.750872, -3.68624, 0, -17.6199)
[node name="terrain_basic_setup" parent="." instance=ExtResource( "1_s50i7" )]

View file

@ -418,10 +418,10 @@ func _physics_process_walk(delta):
var collided = move_and_slide() var collided = move_and_slide()
if is_on_floor(): # if is_on_floor():
print("is_on_floor") # print("iZs_on_floor")
else: # else:
print("not is_on_floor") # print("not is_on_floor")
if collided and is_on_floor() and (input_x != 0.0 or input_y != 0.0) and $RayCastGround.is_colliding() and !$RayCastStep.is_colliding(): if collided and is_on_floor() and (input_x != 0.0 or input_y != 0.0) and $RayCastGround.is_colliding() and !$RayCastStep.is_colliding():
var delta_1:Vector3 = get_position_delta() var delta_1:Vector3 = get_position_delta()
var areawalk = delta_1.x * delta_1.x + delta_1.z * delta_1.z var areawalk = delta_1.x * delta_1.x + delta_1.z * delta_1.z

View file

@ -11,7 +11,7 @@ config_version=5
[application] [application]
config/name="Third Person basic scene" config/name="Third Person basic scene"
run/main_scene="res://main.tscn" run/main_scene="res://scenes/main/main.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
config/features=PackedStringArray("4.0", "Vulkan Clustered") config/features=PackedStringArray("4.0", "Vulkan Clustered")
@ -45,6 +45,12 @@ ui_down={
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"unicode":0,"echo":false,"script":null)
] ]
} }
ui_menu={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":16777262,"physical_keycode":0,"unicode":16777262,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":16777217,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
]
}
ui_strafe={ ui_strafe={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null)
@ -80,3 +86,7 @@ switch_state_player={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":67,"physical_keycode":0,"unicode":99,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":67,"physical_keycode":0,"unicode":99,"echo":false,"script":null)
] ]
} }
[internationalization]
locale/translations=PackedStringArray("res://locales/en.po", "res://locales/fr.po")

27
scenes/hud/hud.gd Normal file
View file

@ -0,0 +1,27 @@
extends Control
func _input(event):
if Input.is_action_pressed("ui_menu"):
$Menu.visible = ! $Menu.visible
func _on_timer_timeout():
print("fin")
$Message/Label.visible = false
func _on_quit_pressed():
#get_tree().quit()
$ConfirmQuit.popup_centered()
$ConfirmQuit.visible = true
pass
func _on_confirmation_dialog_confirmed():
get_tree().quit()
func _on_languages_pressed():
$MenuOption/Window.popup_centered()
$MenuOption/Window.visible = true

75
scenes/hud/hud.tscn Normal file
View file

@ -0,0 +1,75 @@
[gd_scene load_steps=3 format=3 uid="uid://cdyi1a858p7em"]
[ext_resource type="Script" path="res://scenes/hud/hud.gd" id="1_s6f6d"]
[ext_resource type="PackedScene" uid="uid://dpvequp5fv27k" path="res://scenes/languages/languages.tscn" id="2_um8fw"]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( "1_s6f6d" )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Message" type="HBoxContainer" parent="."]
anchor_right = 1.0
size_flags_horizontal = 0
size_flags_vertical = 0
alignment = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="Message"]
offset_left = 917.0
offset_right = 1024.0
offset_bottom = 26.0
size_flags_vertical = 1
text = "Echap = Menu"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Menu" type="HBoxContainer" parent="."]
visible = false
anchor_right = 1.0
offset_right = 40.0
offset_bottom = 40.0
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Keys" type="Button" parent="Menu"]
offset_left = 444.0
offset_right = 488.0
offset_bottom = 40.0
text = "Keys"
[node name="Languages" type="Button" parent="Menu"]
offset_left = 492.0
offset_right = 574.0
offset_bottom = 40.0
text = "Languages"
[node name="Quit" type="Button" parent="Menu"]
offset_left = 578.0
offset_right = 619.0
offset_bottom = 40.0
text = "Quit"
[node name="Timer" type="Timer" parent="."]
wait_time = 10.0
one_shot = true
autostart = true
[node name="ConfirmQuit" type="ConfirmationDialog" parent="."]
dialog_text = "Do you want quit?"
[node name="MenuOption" parent="." instance=ExtResource( "2_um8fw" )]
visible = false
[connection signal="pressed" from="Menu/Languages" to="." method="_on_languages_pressed"]
[connection signal="pressed" from="Menu/Quit" to="." method="_on_quit_pressed"]
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
[connection signal="confirmed" from="ConfirmQuit" to="." method="_on_confirmation_dialog_confirmed"]

View file

@ -0,0 +1,44 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
$Window/VBoxContainer/Select.clear()
var id = 0
var selected = -1
var near_selected = -1
var current_locale = TranslationServer.get_locale()
var root_language = current_locale.split('_')[0]
for key in TranslationServer.get_loaded_locales():
if key == TranslationServer.get_locale():
selected = id
else:
var tmp = key.split("_")
# print("tmp:" + tmp[0])
if tmp[0] == root_language:
if tmp.size() == 1:
near_selected = id
elif near_selected == -1:
near_selected = id
$Window/VBoxContainer/Select.add_item(TranslationServer.get_locale_name(key) + " [" + key + "]", id)
id += 1
if selected == -1 and near_selected != -1:
selected = near_selected
if selected == -1:
# Your language not exist, create it just for the form
var key = TranslationServer.get_locale()
$Window/VBoxContainer/Select.add_item(TranslationServer.get_locale_name(key) + " (" + key + " !)", id)
selected = id
$Window/VBoxContainer/Select.select(selected)
func _on_select_item_selected(index):
var pos = 0
for key in TranslationServer.get_loaded_locales():
if pos == $Window/VBoxContainer/Select.get_selected():
TranslationServer.set_locale(key)
return
pos += 1
func _on_quit_pressed():
$Window.visible = false

View file

@ -0,0 +1,37 @@
[gd_scene load_steps=2 format=3 uid="uid://dpvequp5fv27k"]
[ext_resource type="Script" path="res://scenes/languages/languages.gd" id="1_qc7c5"]
[node name="Control" type="Control"]
script = ExtResource( "1_qc7c5" )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Window" type="Window" parent="."]
title = "Language"
visible = false
[node name="VBoxContainer" type="VBoxContainer" parent="Window"]
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = 40.0
offset_bottom = 40.0
[node name="Label" type="Label" parent="Window/VBoxContainer"]
offset_right = 40.0
offset_bottom = 23.0
text = "Select language"
[node name="Select" type="OptionButton" parent="Window/VBoxContainer"]
offset_right = 43.0
offset_bottom = 31.0
[node name="Quit" type="Button" parent="Window/VBoxContainer"]
offset_top = 35.0
offset_right = 43.0
offset_bottom = 66.0
text = "Quit"
[connection signal="item_selected" from="Window/VBoxContainer/Select" to="." method="_on_select_item_selected"]
[connection signal="pressed" from="Window/VBoxContainer/Quit" to="." method="_on_quit_pressed"]

14
scenes/main/main.tscn Normal file
View file

@ -0,0 +1,14 @@
[gd_scene load_steps=4 format=3 uid="uid://cem7wppuuoabv"]
[ext_resource type="PackedScene" uid="uid://dwxrvijqyym70" path="res://player/player.tscn" id="1_btdsd"]
[ext_resource type="PackedScene" uid="uid://cvdmfc2hi172g" path="res://maps/basic_setup.tscn" id="2_jj4oa"]
[ext_resource type="PackedScene" uid="uid://cdyi1a858p7em" path="res://scenes/hud/hud.tscn" id="3_5vcj4"]
[node name="main_scene" type="Node3D"]
[node name="player" parent="." instance=ExtResource( "1_btdsd" )]
transform = Transform3D(0.750872, 0, -0.660447, 0, 1, 0, 0.660447, 0, 0.750872, -3.68624, 0, -17.6199)
[node name="terrain_basic_setup" parent="." instance=ExtResource( "2_jj4oa" )]
[node name="Control" parent="." instance=ExtResource( "3_5vcj4" )]