Amélioration de la partie création de personnages, refonte et diverses correction de bug.

This commit is contained in:
osquallo 2018-08-23 16:03:36 +02:00
parent 9770d7f402
commit 98d9df20d4
8 changed files with 117 additions and 109 deletions

View file

@ -5,12 +5,10 @@ signal logout_button_pressed
const WINDOW_TITLE_INPUT = "GUI/Settings/Menus/TabContainer/Test/ScrollContainer/VBoxContainer/TitleBox/Title" const WINDOW_TITLE_INPUT = "GUI/Settings/Menus/TabContainer/Test/ScrollContainer/VBoxContainer/TitleBox/Title"
func _ready(): func _ready():
# change_title()
get_tree().get_root().connect("size_changed", self, "on_window_size_changed") get_tree().get_root().connect("size_changed", self, "on_window_size_changed")
# character.get_node( "MeshInstance" ).get_surface_material(0).set_shader_param( "albedo", global.character_color ) global.get_node("GUI").show()
global.get_node("GUI").visible = true
global.get_node("GUI").play() global.get_node("GUI").play()
func _process(delta): func _process(delta):
@ -26,8 +24,3 @@ func change_title():
title = title_node.text.strip_edges() title = title_node.text.strip_edges()
title += " (" + String(OS.get_window_size().x) + "x" + String(OS.get_window_size().y) + ")" title += " (" + String(OS.get_window_size().x) + "x" + String(OS.get_window_size().y) + ")"
OS.set_window_title( title ) OS.set_window_title( title )
#func _on_GUI_logout_button_pressed():
# emit_signal( "logout_button_pressed" )
# global.goto_scene_loading( "res://login_scene/login_scene.tscn" )

View file

@ -174,19 +174,19 @@ func set_new_scene( scene_resource ):
func _on_login_scene_character_creation_finished(): func _on_login_scene_character_creation_finished():
var config_file = ConfigFile.new() # var config_file = ConfigFile.new()
var err = config_file.load( "user://player.cfg" ) # var err = config_file.load( "user://player.cfg" )
if err: # if err:
print("Error code when loading config file: ", err) # print("Error code when loading config file: ", err)
#
config_file.set_value(str(character.slot), "name", character.pseudo) # config_file.set_value(str(character.slot), "name", character.pseudo)
config_file.set_value(str(character.slot), "color", character.color) # config_file.set_value(str(character.slot), "color", character.color)
config_file.set_value(str(character.size), "size", character.size) # config_file.set_value(str(character.slot), "size", character.size)
#
config_file.save( "user://player.cfg" ) # config_file.save( "user://player.cfg" )
self.change_level( "game", "res://game_scene/game_scene.tscn", null, get_tree().get_root().get_node("login_scene") ) self.change_level( "game", "res://game_scene/game_scene.tscn", null, get_tree().get_root().get_node("login_scene") )
character.show_third_person_camera() character.show_third_person_camera()
# character.get_node( "infos_spatial" ).show() character.get_node( "infos_spatial" ).show()
func _on_logout_button_pressed(): func _on_logout_button_pressed():
self.change_level( "login", "res://login_scene/login_scene.tscn", null, current_map ) self.change_level( "login", "res://login_scene/login_scene.tscn", null, current_map )

View file

@ -74,16 +74,7 @@ func _ready():
popup_node.selected = 1 popup_node.selected = 1
func _on_sex_bar_value_changed( value ): func _on_sex_bar_value_changed( value ):
# if value == 0:
# character.gender = 0
# character.color = Color( 0.0, 0.0, 1.0, 1.0 )
# else:
# character.gender = 1
# character.color = Color( 1.0, 0.25, 0.25, 1.0 )
emit_signal( "sex_bar_changed", value ) emit_signal( "sex_bar_changed", value )
func _on_size_bar_value_changed( value ): func _on_size_bar_value_changed( value ):
# character.size = value
emit_signal( "size_bar_changed", value ) emit_signal( "size_bar_changed", value )

View file

@ -7,6 +7,7 @@ var preview_slot = 0
var character_preview = null var character_preview = null
var character_mesh = null var character_mesh = null
var character_box = null
var name_input = null var name_input = null
func update_character_slots(): func update_character_slots():
@ -20,7 +21,7 @@ func update_character_slots():
var last_slot = 0 var last_slot = 0
for section in config_file.get_sections(): for section in config_file.get_sections():
useds_slot.append( int(section) ) useds_slot.append( int(section) )
if not has_node( "h_box_container/character_slots/slot_box_"+section ): if not self.character_box.has_node( "character_slots/slot_box_"+section ):
last_slot = int(section) last_slot = int(section)
var character_name = config_file.get_value( section, "name" ) var character_name = config_file.get_value( section, "name" )
@ -32,35 +33,30 @@ func update_character_slots():
slot_box.size_flags_horizontal = SIZE_FILL slot_box.size_flags_horizontal = SIZE_FILL
slot_box.size_flags_vertical = SIZE_EXPAND slot_box.size_flags_vertical = SIZE_EXPAND
slot_box.set( "custom_constants/separation", 8) slot_box.set( "custom_constants/separation", 8)
$h_box_container/character_slots.add_child( slot_box ) self.character_box.get_node( "character_slots" ).add_child( slot_box )
slot_box.set_owner( $h_box_container/character_slots )
slot_box.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] ) slot_box.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] )
var label_name = Label.new() var label_name = Label.new()
label_name.text = character_name#+ " ("+section+")" label_name.text = character_name#+ " ("+section+")"
label_name.size_flags_horizontal = SIZE_EXPAND
slot_box.add_child( label_name ) slot_box.add_child( label_name )
label_name.set_owner( slot_box )
# label_name.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] ) # label_name.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] )
var choose_button = Button.new() var choose_button = Button.new()
choose_button.text = "Choisir"#+ " ("+section+")" choose_button.text = "Choisir"
# choose_button.mouse_filter = MOUSE_FILTER_PASS
slot_box.add_child( choose_button ) slot_box.add_child( choose_button )
choose_button.set_owner( slot_box )
choose_button.connect( "pressed", self, "_on_choose_pressed", [int(section)] ) choose_button.connect( "pressed", self, "_on_choose_pressed", [int(section)] )
choose_button.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] ) choose_button.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] )
var delete_button = Button.new() var delete_button = Button.new()
delete_button.text = "Supprimer"#+ " ("+section+")" delete_button.text = "Supprimer"
# delete_button.mouse_filter = MOUSE_FILTER_PASS
slot_box.add_child( delete_button ) slot_box.add_child( delete_button )
delete_button.set_owner( slot_box )
delete_button.connect( "pressed", self, "_on_delete_pressed", [int(section), slot_box] ) delete_button.connect( "pressed", self, "_on_delete_pressed", [int(section), slot_box] )
delete_button.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] ) delete_button.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] )
if has_node( "h_box_container/character_slots/creation_button" ): if self.character_box.has_node( "character_slots/creation_button" ):
$h_box_container/character_slots/creation_button.free() self.character_box.get_node( "character_slots/creation_button" ).free()
var index = 0 var index = 0
while index in useds_slot: while index in useds_slot:
@ -68,32 +64,25 @@ func update_character_slots():
var next_slot = index var next_slot = index
var create_new_characer_button = Button.new() var create_new_characer_button = Button.new()
create_new_characer_button.name = "creation_button" create_new_characer_button.name = "creation_button"
create_new_characer_button.text = "Créer"#+" ("+str(next_slot)+")" create_new_characer_button.text = "Créer"
create_new_characer_button.hint_tooltip = "Create a new character" create_new_characer_button.hint_tooltip = "Create a new character"
$h_box_container/character_slots.add_child( create_new_characer_button ) self.character_box.get_node( "character_slots" ).add_child( create_new_characer_button )
create_new_characer_button.set_owner( $h_box_container/character_slots )
create_new_characer_button.connect( "pressed", self, "_on_create_pressed", [next_slot] ) create_new_characer_button.connect( "pressed", self, "_on_create_pressed", [next_slot] )
func _ready(): func _ready():
self.character_preview = $viewport/character self.character_preview = $viewport/character
self.character_mesh = $viewport/character.get_node("MeshInstance") self.character_mesh = $viewport/character.get_node("MeshInstance")
self.name_input = $h_box_container/character_creation_box/margin_container/v_box_container/name_box/line_edit self.character_box = $margin_container/character_box
self.name_input = self.character_box.get_node( "character_creation_box/margin_container/v_box_container/name_box/line_edit" )
self.character_preview.update() self.character_preview.update()
# var parent = character.get_parent()
# parent.remove_child( character )
# $viewport.add_child( character )
update_character_slots() update_character_slots()
func _on_character_slots_return_button_pressed():
emit_signal( "return_button_pressed" )
func _on_create_pressed( slot ): func _on_create_pressed( slot ):
self.character_preview.slot = slot self.character_preview.slot = slot
$h_box_container/character_slots.hide() self.character_box.get_node( "character_slots" ).hide()
$h_box_container/character_creation_box.show() self.character_box.get_node( "character_creation_box" ).show()
self.character_preview.update() self.character_preview.update()
func _on_choose_pressed( slot ): func _on_choose_pressed( slot ):
@ -115,6 +104,7 @@ func _on_delete_pressed( slot, node_to_delete ):
func _on_name_mouse_entered_pressed( slot ): func _on_name_mouse_entered_pressed( slot ):
$viewport/character.show()
preview_slot = slot preview_slot = slot
update_preview() update_preview()
@ -127,30 +117,39 @@ func update_preview():
print("Error code when loading player config file: ", err) print("Error code when loading player config file: ", err)
if config_file.has_section( str(slot) ): if config_file.has_section( str(slot) ):
self.character_preview.slot = slot
# name
var pseudo = config_file.get_value( str(slot), "name", "Player" )
self.character_preview.pseudo = pseudo
# gender
var gender = config_file.get_value( str(slot), "gender", 1 )
self.character_preview.gender = gender
# Color # Color
var color = config_file.get_value( str(slot), "color" ) var color = config_file.get_value( str(slot), "color", Color( 1, 0.25, 0.25, 1 ) )
if not color: self.character_preview.color = color
color = Color( 1, 0.25, 0.25, 1 )
character_mesh.get_surface_material(0).set_shader_param("albedo", color )
# Size # Size
var size = config_file.get_value( str(slot), "size" ) var size = config_file.get_value( str(slot), "size", 1.0 )
if not size: self.character_preview.size = size
size = 1
character_preview.scale = Vector3( size, size, size ) self.character_preview.update()
func _on_character_slots_return_button_pressed():
emit_signal( "return_button_pressed" )
func _on_character_creation_box_return_button_pressed(): func _on_character_creation_box_return_button_pressed():
self.character_box.get_node( "character_slots" ).show()
$h_box_container/character_slots.show() self.character_box.get_node( "character_creation_box" ).hide()
$h_box_container/character_creation_box.hide()
func _on_character_creation_box_creation_button_pressed(): func _on_character_creation_box_creation_button_pressed():
if not self.name_input.text or self.name_input.text == "": if not self.name_input.text or self.name_input.text == "":
$h_box_container/character_creation_box.show_error( "You need to choose a character's name." ) self.character_box.get_node( "character_creation_box" ).show_error( "You need to choose a character's name." )
return return
character_preview.pseudo = self.name_input.text self.character_preview.pseudo = self.name_input.text
# character.color = character_mesh.get_surface_material(0).get_shader_param("albedo") # character.color = character_mesh.get_surface_material(0).get_shader_param("albedo")
# character.size = character_mesh.scale.x # character.size = character_mesh.scale.x
@ -158,19 +157,16 @@ func _on_character_creation_box_creation_button_pressed():
var err = config_file.load( "user://player.cfg" ) var err = config_file.load( "user://player.cfg" )
if err: if err:
print("Error code when loading player config file: ", err) print("Error code when loading player config file: ", err)
config_file.set_value( str(character.slot), "name", character.pseudo) config_file.set_value( str(self.character_preview.slot), "name", self.character_preview.pseudo)
config_file.set_value( str(character.slot), "color", character.color) config_file.set_value( str(self.character_preview.slot), "gender", self.character_preview.gender)
config_file.set_value( str(character.slot), "size", character.size) config_file.set_value( str(self.character_preview.slot), "color", self.character_preview.color)
config_file.set_value( str(self.character_preview.slot), "size", self.character_preview.size)
config_file.save( "user://player.cfg" ) config_file.save( "user://player.cfg" )
$h_box_container/character_slots.show() self.character_box.get_node( "character_slots" ).show()
$h_box_container/character_creation_box.hide() self.character_box.get_node( "character_creation_box" ).hide()
update_character_slots() update_character_slots()
func _on_character_creation_box_character_changed():
self.character_preview.update()
func _on_character_creation_box_sex_bar_changed( value ): func _on_character_creation_box_sex_bar_changed( value ):
if value == 0: if value == 0:
self.character_preview.gender = 0 self.character_preview.gender = 0

View file

@ -9,7 +9,7 @@
[sub_resource type="ViewportTexture" id=1] [sub_resource type="ViewportTexture" id=1]
resource_local_to_scene = true resource_local_to_scene = true
flags = 0 flags = 12
viewport_path = NodePath("viewport") viewport_path = NodePath("viewport")
[node name="character_selection_menu" type="Control" index="0"] [node name="character_selection_menu" type="Control" index="0"]
@ -29,7 +29,7 @@ script = ExtResource( 1 )
[node name="viewport" type="Viewport" parent="." index="0"] [node name="viewport" type="Viewport" parent="." index="0"]
arvr = false arvr = false
size = Vector2( 256, 256 ) size = Vector2( 512, 512 )
own_world = false own_world = false
world = null world = null
transparent_bg = false transparent_bg = false
@ -72,7 +72,7 @@ expand = true
stretch_mode = 7 stretch_mode = 7
_sections_unfolded = [ "Size Flags" ] _sections_unfolded = [ "Size Flags" ]
[node name="h_box_container" type="HBoxContainer" parent="." index="2"] [node name="margin_container" type="MarginContainer" parent="." index="2"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -80,16 +80,40 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_constants/margin_left = 8
_sections_unfolded = [ "Size Flags", "custom_constants" ]
[node name="character_box" type="HBoxContainer" parent="margin_container" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 8.0
margin_right = 1024.0
margin_bottom = 600.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1 mouse_filter = 1
mouse_default_cursor_shape = 0 mouse_default_cursor_shape = 0
size_flags_horizontal = 2 size_flags_horizontal = 3
size_flags_vertical = 2 size_flags_vertical = 3
alignment = 0 alignment = 0
_sections_unfolded = [ "Size Flags", "custom_constants" ] _sections_unfolded = [ "Size Flags", "custom_constants" ]
[node name="character_slots" parent="h_box_container" index="0" instance=ExtResource( 4 )] [node name="character_slots" parent="margin_container/character_box" index="0" instance=ExtResource( 4 )]
[node name="character_creation_box" parent="h_box_container" index="1" instance=ExtResource( 5 )] margin_top = 290.0
margin_bottom = 310.0
size_flags_vertical = 6
custom_constants/separation = 8
_sections_unfolded = [ "Size Flags", "custom_constants" ]
[node name="character_creation_box" parent="margin_container/character_box" index="1" instance=ExtResource( 5 )]
visible = false visible = false
margin_left = 58.0 margin_left = 58.0
@ -97,17 +121,17 @@ margin_top = 191.0
margin_right = 600.0 margin_right = 600.0
margin_bottom = 409.0 margin_bottom = 409.0
[node name="nine_patch_rect" type="NinePatchRect" parent="h_box_container" index="2"] [node name="nine_patch_rect" type="NinePatchRect" parent="margin_container/character_box" index="2"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_left = 413.0 margin_left = 281.0
margin_top = 172.0 margin_top = 44.0
margin_right = 669.0 margin_right = 793.0
margin_bottom = 428.0 margin_bottom = 556.0
rect_min_size = Vector2( 256, 256 ) rect_min_size = Vector2( 512, 512 )
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false rect_clip_content = false
mouse_filter = 2 mouse_filter = 2
@ -115,16 +139,16 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 6 size_flags_horizontal = 6
size_flags_vertical = 6 size_flags_vertical = 6
texture = SubResource( 1 ) texture = SubResource( 1 )
_sections_unfolded = [ "Axis Stretch", "Margin", "Rect", "Size Flags" ] _sections_unfolded = [ "Axis Stretch", "Grow Direction", "Margin", "Rect", "Size Flags" ]
[connection signal="return_button_pressed" from="h_box_container/character_slots" to="." method="_on_character_slots_return_button_pressed"] [connection signal="return_button_pressed" from="margin_container/character_box/character_slots" to="." method="_on_character_slots_return_button_pressed"]
[connection signal="creation_button_pressed" from="h_box_container/character_creation_box" to="." method="_on_character_creation_box_creation_button_pressed"] [connection signal="creation_button_pressed" from="margin_container/character_box/character_creation_box" to="." method="_on_character_creation_box_creation_button_pressed"]
[connection signal="return_button_pressed" from="h_box_container/character_creation_box" to="." method="_on_character_creation_box_return_button_pressed"] [connection signal="return_button_pressed" from="margin_container/character_box/character_creation_box" to="." method="_on_character_creation_box_return_button_pressed"]
[connection signal="sex_bar_changed" from="h_box_container/character_creation_box" to="." method="_on_character_creation_box_sex_bar_changed"] [connection signal="sex_bar_changed" from="margin_container/character_box/character_creation_box" to="." method="_on_character_creation_box_sex_bar_changed"]
[connection signal="size_bar_changed" from="h_box_container/character_creation_box" to="." method="_on_character_creation_box_size_bar_changed"] [connection signal="size_bar_changed" from="margin_container/character_box/character_creation_box" to="." method="_on_character_creation_box_size_bar_changed"]

View file

@ -21,9 +21,12 @@ func _on_character_selection_menu_character_selected(slot):
var err = config_file.load( "user://player.cfg" ) var err = config_file.load( "user://player.cfg" )
if err: if err:
print("Error code when loading player config file: ", err) print("Error code when loading player config file: ", err)
character.slot = slot character.slot = slot
character.pseudo = config_file.get_value( str(slot), "name", "player") character.pseudo = config_file.get_value( str(slot), "name", "player")
character.color = config_file.get_value( str(slot), "color", Color(1.0, 63.0, 63.0, 1.0) ) character.gender = config_file.get_value( str(slot), "gender", 1)
character.color = config_file.get_value( str(slot), "color", Color(1.0, 0.25, 0.25, 1.0) )
character.size = config_file.get_value( str(slot), "size", 1.0 )
character.update()
emit_signal( "character_creation_finished" ) emit_signal( "character_creation_finished" )

View file

@ -5,7 +5,7 @@ extends KinematicBody
var pseudo = "" var pseudo = ""
var color = Color( 1.0, 0.25, 0.25, 1.0 ) var color = Color( 1.0, 0.25, 0.25, 1.0 )
var gender = 1 var gender = 1
var size = 1 var size = 1.0
var slot = 0 var slot = 0
var dir = Vector3() var dir = Vector3()
@ -54,8 +54,10 @@ func update( start_position = null ):
self.translation = start_position.translation self.translation = start_position.translation
self.rotation = start_position.rotation self.rotation = start_position.rotation
self.scale = Vector3( self.size, self.size, self.size ) self.player_mesh.scale = Vector3( self.size, self.size, self.size )
$MeshInstance.get_surface_material(0).set_shader_param( "albedo", self.color ) print( "size: "+ str(size) )
print( "scale: "+ str(self.player_mesh.scale) )
self.player_mesh.get_surface_material(0).set_shader_param( "albedo", self.color )
func _process(delta): func _process(delta):
process_input(delta) process_input(delta)
@ -180,11 +182,9 @@ func _input(event):
else: else:
self.show() self.show()
func hide(): func hide_infos():
self.visible = false
$infos_spatial/character_infos_billboard.hide() $infos_spatial/character_infos_billboard.hide()
func show(): func show_infos():
self.visible = true
$infos_spatial/character_infos_billboard.show() $infos_spatial/character_infos_billboard.show()
######## ########

View file

@ -70,6 +70,7 @@ radius = 0.520354
[node name="Character" type="KinematicBody"] [node name="Character" type="KinematicBody"]
transform = Transform( 0.371345, 0, 0, 0, 0.218854, 0, 0, 0, 0.371345, -0.00167466, -0.475751, 6.02408 ) transform = Transform( 0.371345, 0, 0, 0, 0.218854, 0, 0, 0, 0.371345, -0.00167466, -0.475751, 6.02408 )
visible = false
input_ray_pickable = true input_ray_pickable = true
input_capture_on_drag = false input_capture_on_drag = false
collision_layer = 1 collision_layer = 1