2018-08-09 14:09:55 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
signal character_selected( slot )
|
|
|
|
signal return_button_pressed
|
|
|
|
|
|
|
|
var preview_slot = 0
|
|
|
|
|
2018-08-22 15:00:33 +00:00
|
|
|
var character_preview = null
|
2018-08-09 14:09:55 +00:00
|
|
|
var character_mesh = null
|
2018-08-23 15:50:34 +00:00
|
|
|
var character_face_camera = null
|
2018-08-23 14:03:36 +00:00
|
|
|
var character_box = null
|
2018-09-15 09:00:55 +00:00
|
|
|
var character_creation_box = null
|
2018-08-09 14:09:55 +00:00
|
|
|
var name_input = null
|
|
|
|
|
2018-08-23 15:50:34 +00:00
|
|
|
var turn_direction = null
|
|
|
|
var zoom_direction = null
|
|
|
|
|
|
|
|
|
2018-09-15 09:00:55 +00:00
|
|
|
func _ready():
|
|
|
|
|
|
|
|
# $viewport/character/face_camera.make_current()
|
|
|
|
|
|
|
|
|
|
|
|
self.character_preview = $viewport/character
|
|
|
|
self.character_preview.set_default_values()
|
|
|
|
# self.character_preview.get_node( "Camera_rotation_helper/face_camera" ).make_current()
|
|
|
|
self.character_preview.get_node( "face_camera" ).make_current()
|
|
|
|
|
|
|
|
self.character_mesh = $viewport/character.get_node("suzanne/mesh")
|
|
|
|
# self.character_face_camera = $viewport/character/Camera_rotation_helper/face_camera
|
|
|
|
self.character_box = $margin_container/character_box
|
|
|
|
self.character_creation_box = $margin_container/character_box/character_creation_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()
|
|
|
|
|
|
|
|
update_character_slots()
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-09 14:09:55 +00:00
|
|
|
func update_character_slots():
|
|
|
|
|
|
|
|
var config_file = ConfigFile.new()
|
|
|
|
var err = config_file.load( "user://player.cfg" )
|
|
|
|
if err:
|
|
|
|
print("Error code when loading player config file: ", err)
|
|
|
|
|
|
|
|
var useds_slot = []
|
|
|
|
var last_slot = 0
|
|
|
|
for section in config_file.get_sections():
|
|
|
|
useds_slot.append( int(section) )
|
2018-10-11 15:00:50 +00:00
|
|
|
if not self.character_box.has_node( "character_slots/slots_box/slot_box_"+section ):
|
2018-08-09 14:09:55 +00:00
|
|
|
last_slot = int(section)
|
|
|
|
|
2018-08-22 15:00:33 +00:00
|
|
|
var character_name = config_file.get_value( section, "name" )
|
|
|
|
if not character_name:
|
|
|
|
character_name = "NameNotFound"
|
|
|
|
|
2018-08-09 14:09:55 +00:00
|
|
|
var slot_box = HBoxContainer.new()
|
|
|
|
slot_box.name = "slot_box_"+section
|
|
|
|
slot_box.size_flags_horizontal = SIZE_FILL
|
|
|
|
slot_box.size_flags_vertical = SIZE_EXPAND
|
|
|
|
slot_box.set( "custom_constants/separation", 8)
|
2018-10-11 15:00:50 +00:00
|
|
|
self.character_box.get_node( "character_slots/slots_box/" ).add_child( slot_box )
|
2018-08-09 14:09:55 +00:00
|
|
|
slot_box.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] )
|
|
|
|
|
|
|
|
var label_name = Label.new()
|
2018-09-15 09:00:55 +00:00
|
|
|
label_name.text = character_name
|
2018-08-23 14:03:36 +00:00
|
|
|
label_name.size_flags_horizontal = SIZE_EXPAND
|
2018-08-09 14:09:55 +00:00
|
|
|
slot_box.add_child( label_name )
|
|
|
|
|
|
|
|
var choose_button = Button.new()
|
2018-08-23 14:03:36 +00:00
|
|
|
choose_button.text = "Choisir"
|
2018-08-09 14:09:55 +00:00
|
|
|
slot_box.add_child( choose_button )
|
|
|
|
choose_button.connect( "pressed", self, "_on_choose_pressed", [int(section)] )
|
|
|
|
choose_button.connect( "mouse_entered", self, "_on_name_mouse_entered_pressed", [int(section)] )
|
|
|
|
|
|
|
|
var delete_button = Button.new()
|
2018-08-23 14:03:36 +00:00
|
|
|
delete_button.text = "Supprimer"
|
2018-08-09 14:09:55 +00:00
|
|
|
slot_box.add_child( delete_button )
|
|
|
|
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)] )
|
|
|
|
|
|
|
|
|
2018-08-23 14:03:36 +00:00
|
|
|
if self.character_box.has_node( "character_slots/creation_button" ):
|
|
|
|
self.character_box.get_node( "character_slots/creation_button" ).free()
|
2018-08-09 14:09:55 +00:00
|
|
|
|
|
|
|
var index = 0
|
|
|
|
while index in useds_slot:
|
|
|
|
index += 1
|
|
|
|
var next_slot = index
|
|
|
|
var create_new_characer_button = Button.new()
|
|
|
|
create_new_characer_button.name = "creation_button"
|
2018-08-23 14:03:36 +00:00
|
|
|
create_new_characer_button.text = "Créer"
|
2018-08-09 14:09:55 +00:00
|
|
|
create_new_characer_button.hint_tooltip = "Create a new character"
|
2018-10-11 15:00:50 +00:00
|
|
|
self.character_box.get_node( "character_slots/slots_box/" ).add_child( create_new_characer_button )
|
2018-08-09 14:09:55 +00:00
|
|
|
create_new_characer_button.connect( "pressed", self, "_on_create_pressed", [next_slot] )
|
|
|
|
|
|
|
|
func _on_create_pressed( slot ):
|
2018-08-22 15:00:33 +00:00
|
|
|
self.character_preview.slot = slot
|
2018-08-23 14:03:36 +00:00
|
|
|
self.character_box.get_node( "character_slots" ).hide()
|
|
|
|
self.character_box.get_node( "character_creation_box" ).show()
|
2018-08-22 15:00:33 +00:00
|
|
|
self.character_preview.update()
|
|
|
|
|
2018-08-09 14:09:55 +00:00
|
|
|
func _on_choose_pressed( slot ):
|
|
|
|
emit_signal( "character_selected", slot )
|
|
|
|
|
|
|
|
|
|
|
|
func _on_delete_pressed( slot, node_to_delete ):
|
|
|
|
var config_file = ConfigFile.new()
|
|
|
|
var err = config_file.load( "user://player.cfg" )
|
|
|
|
if err:
|
|
|
|
print("Error code when loading player config file: ", err)
|
|
|
|
config_file.erase_section( str(slot) )
|
|
|
|
config_file.save( "user://player.cfg" )
|
|
|
|
|
|
|
|
var parent = node_to_delete.get_parent()
|
|
|
|
parent.remove_child( node_to_delete )
|
|
|
|
|
|
|
|
update_character_slots()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_name_mouse_entered_pressed( slot ):
|
2018-08-23 14:03:36 +00:00
|
|
|
$viewport/character.show()
|
2018-08-09 14:09:55 +00:00
|
|
|
preview_slot = slot
|
|
|
|
update_preview()
|
|
|
|
|
|
|
|
func update_preview():
|
|
|
|
var slot = preview_slot
|
|
|
|
|
|
|
|
var config_file = ConfigFile.new()
|
|
|
|
var err = config_file.load( "user://player.cfg" )
|
|
|
|
if err:
|
|
|
|
print("Error code when loading player config file: ", err)
|
|
|
|
if config_file.has_section( str(slot) ):
|
2018-08-23 14:03:36 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-08-22 15:00:33 +00:00
|
|
|
# Color
|
2018-08-23 14:03:36 +00:00
|
|
|
var color = config_file.get_value( str(slot), "color", Color( 1, 0.25, 0.25, 1 ) )
|
|
|
|
self.character_preview.color = color
|
2018-08-09 14:09:55 +00:00
|
|
|
|
2018-08-22 15:00:33 +00:00
|
|
|
# Size
|
2018-08-23 14:03:36 +00:00
|
|
|
var size = config_file.get_value( str(slot), "size", 1.0 )
|
|
|
|
self.character_preview.size = size
|
|
|
|
|
2018-08-29 08:13:37 +00:00
|
|
|
# Ears size
|
2018-08-27 08:22:15 +00:00
|
|
|
var ears_size = config_file.get_value( str(slot), "ears_size", 0.0 )
|
|
|
|
self.character_preview.ears_size = ears_size
|
|
|
|
|
2018-08-29 08:13:37 +00:00
|
|
|
# Eyes color
|
|
|
|
var eyes_color = config_file.get_value( str(slot), "eyes_color", Color( 0.0, 1.0, 0.0, 1.0 ) )
|
|
|
|
self.character_preview.eyes_color = eyes_color
|
|
|
|
|
2018-08-23 14:03:36 +00:00
|
|
|
self.character_preview.update()
|
2018-08-09 14:09:55 +00:00
|
|
|
|
|
|
|
|
2018-08-23 14:03:36 +00:00
|
|
|
func _on_character_slots_return_button_pressed():
|
|
|
|
emit_signal( "return_button_pressed" )
|
2018-08-09 14:09:55 +00:00
|
|
|
|
2018-08-23 14:03:36 +00:00
|
|
|
func _on_character_creation_box_return_button_pressed():
|
|
|
|
self.character_box.get_node( "character_slots" ).show()
|
|
|
|
self.character_box.get_node( "character_creation_box" ).hide()
|
2018-08-09 14:09:55 +00:00
|
|
|
|
|
|
|
func _on_character_creation_box_creation_button_pressed():
|
2018-08-22 15:00:33 +00:00
|
|
|
if not self.name_input.text or self.name_input.text == "":
|
2018-08-23 14:03:36 +00:00
|
|
|
self.character_box.get_node( "character_creation_box" ).show_error( "You need to choose a character's name." )
|
2018-08-09 14:09:55 +00:00
|
|
|
return
|
2018-08-23 14:03:36 +00:00
|
|
|
self.character_preview.pseudo = self.name_input.text
|
2018-08-09 14:09:55 +00:00
|
|
|
|
|
|
|
var config_file = ConfigFile.new()
|
|
|
|
var err = config_file.load( "user://player.cfg" )
|
|
|
|
if err:
|
|
|
|
print("Error code when loading player config file: ", err)
|
2018-08-23 14:03:36 +00:00
|
|
|
config_file.set_value( str(self.character_preview.slot), "name", self.character_preview.pseudo)
|
|
|
|
config_file.set_value( str(self.character_preview.slot), "gender", self.character_preview.gender)
|
|
|
|
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)
|
2018-08-27 08:22:15 +00:00
|
|
|
config_file.set_value( str(self.character_preview.slot), "ears_size", self.character_preview.ears_size)
|
2018-08-29 08:13:37 +00:00
|
|
|
config_file.set_value( str(self.character_preview.slot), "eyes_color", self.character_preview.eyes_color)
|
2018-08-27 08:22:15 +00:00
|
|
|
|
2018-08-09 14:09:55 +00:00
|
|
|
config_file.save( "user://player.cfg" )
|
|
|
|
|
2018-08-23 14:03:36 +00:00
|
|
|
self.character_box.get_node( "character_slots" ).show()
|
|
|
|
self.character_box.get_node( "character_creation_box" ).hide()
|
2018-08-09 14:09:55 +00:00
|
|
|
update_character_slots()
|
|
|
|
|
2018-09-15 09:00:55 +00:00
|
|
|
func _on_character_creation_box_character_preview_need_update():
|
|
|
|
self.character_preview.pseudo = self.character_creation_box.get_node( "margin_container/v_box_container/name_box/line_edit" ).text
|
|
|
|
self.character_preview.gender = self.character_creation_box.get_node( "margin_container/v_box_container/sexe_box/h_box_container/sex_bar" ).value
|
|
|
|
if self.character_preview.gender == 1:
|
|
|
|
self.character_preview.color = Color( 1.0, 0.25, 0.25, 1.0 )
|
|
|
|
else:
|
|
|
|
self.character_preview.color = Color( 0.0, 0.0, 1.0, 1.0 )
|
|
|
|
self.character_preview.size = self.character_creation_box.get_node( "margin_container/v_box_container/size_box/h_box_container/size_bar" ).value
|
|
|
|
self.character_preview.ears_size = self.character_creation_box.get_node( "margin_container/v_box_container/ears_size_box/ears_size" ).value
|
|
|
|
self.character_preview.eyes_color = self.character_creation_box.get_node( "margin_container/v_box_container/eyes_color_box/eyes_color" ).color
|
|
|
|
self.character_preview.update()
|
|
|
|
|
|
|
|
|
2018-08-22 15:00:33 +00:00
|
|
|
func _on_character_creation_box_sex_bar_changed( value ):
|
|
|
|
if value == 0:
|
|
|
|
self.character_preview.gender = 0
|
|
|
|
self.character_preview.color = Color( 0.0, 0.0, 1.0, 1.0 )
|
|
|
|
else:
|
|
|
|
self.character_preview.gender = 1
|
|
|
|
self.character_preview.color = Color( 1.0, 0.25, 0.25, 1.0 )
|
|
|
|
self.character_preview.update()
|
2018-08-09 14:09:55 +00:00
|
|
|
|
2018-08-22 15:00:33 +00:00
|
|
|
func _on_character_creation_box_size_bar_changed( value ):
|
|
|
|
self.character_preview.size = value
|
|
|
|
self.character_preview.update()
|
2018-08-23 15:50:34 +00:00
|
|
|
|
2018-08-27 08:22:15 +00:00
|
|
|
func _on_character_creation_box_ears_size_bar_changed( value ):
|
|
|
|
self.character_preview.ears_size = value
|
|
|
|
self.character_preview.update()
|
|
|
|
|
2018-09-15 09:00:55 +00:00
|
|
|
func _on_character_creation_box_eyes_color_changed(value):
|
|
|
|
self.character_preview.eyes_color = value
|
|
|
|
self.character_preview.update()
|
2018-08-27 08:22:15 +00:00
|
|
|
|
2018-08-23 15:50:34 +00:00
|
|
|
func _process( delta ):
|
|
|
|
|
|
|
|
if turn_direction == "left":
|
|
|
|
self.character_mesh.rotation.y -= delta
|
|
|
|
elif turn_direction == "right":
|
|
|
|
self.character_mesh.rotation.y += delta
|
2018-08-25 06:36:37 +00:00
|
|
|
|
2018-08-23 15:50:34 +00:00
|
|
|
if zoom_direction == "front":
|
2018-08-24 09:17:57 +00:00
|
|
|
$viewport/character/face_camera.size += delta
|
2018-08-23 15:50:34 +00:00
|
|
|
elif zoom_direction == "back":
|
2018-08-24 09:17:57 +00:00
|
|
|
$viewport/character/face_camera.size -= delta
|
2018-08-23 15:50:34 +00:00
|
|
|
|
|
|
|
func _on_turn_left_button_down():
|
|
|
|
turn_direction = "left"
|
|
|
|
func _on_turn_left_button_up():
|
|
|
|
turn_direction = null
|
|
|
|
|
|
|
|
func _on_turn_right_button_down():
|
|
|
|
turn_direction = "right"
|
|
|
|
func _on_turn_right_button_up():
|
|
|
|
turn_direction = null
|
|
|
|
|
|
|
|
func _on_zoom_out_button_down():
|
|
|
|
zoom_direction = "front"
|
|
|
|
func _on_zoom_out_button_up():
|
|
|
|
zoom_direction = null
|
|
|
|
|
|
|
|
func _on_zoom_in_button_down():
|
|
|
|
zoom_direction = "back"
|
|
|
|
func _on_zoom_in_button_up():
|
|
|
|
zoom_direction = null
|
2018-08-24 09:17:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_lights_button_up():
|
|
|
|
$viewport/character/face_lights.hide()
|
|
|
|
func _on_lights_button_down():
|
|
|
|
$viewport/character/face_lights.show()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_lights_toggled(button_pressed):
|
|
|
|
if button_pressed:
|
|
|
|
$viewport/character/face_lights.show()
|
|
|
|
else:
|
|
|
|
$viewport/character/face_lights.hide()
|
|
|
|
|
2018-08-25 06:36:37 +00:00
|
|
|
func _on_character_preview_image_resized():
|
|
|
|
$viewport.size = $margin_container/character_box/v_box_container/character_preview_image.rect_size
|