Skip to content

Commit

Permalink
GUI templates and game commands
Browse files Browse the repository at this point in the history
Progress on refactoring the GI

Progress on working with 9 verbs

First draft of the Sierra GUI implementation

Created the `g.gd` script to test an approach for accessing the commands
defined for the graphic interface.
Moved the Toolbar folder to the popochiu template folder since that
component will be part of that GUI only.
Added a function to "replace" the default cursor. This still needs
improvements or a complete refactor.

GUI template selection in Setup popup

Refactorization of GUI template commands

This fixes a dependency generated when having the commands of the current GUI in the g.gd singleton. Now each GUI has its own commands Resource class.
Selecting the GUI template in the Setup popup is now working without bugs.

Changed Popochiu GUI template name to BASS

Usability improvements in 9 verb interface

Sound settings script moved to BASS' toolbar folder

History popup working again in BASS template

upd: Lines in History to RichTextLabel so one can uses colors to
highlight characters, commands and props.
fea: Improved the way BASS handles mouse positioning to open/close the
inventory and the settings.
upd: Renamed scene and script filenames from Toolbar to SettingsBar.

PopochiuPopup are now used by History, Save and Load and Sound settings.

upd: Updated the Settings popup for the 9 verb interface. Now it allows to
Save, Load, open the History, and update sound volumes.
upd: New appearance for Sound volumes sliders.
upd: Created Sound volumes component, so devs can use the sliders
without having to use a popup.
fea: Created Settings icon for settings button in 9 verb interface.
upd: Created cursor for UI elements in 9 verb interface.
fix: Opening the SaveAndLoad popup when saving no longer requires to
pass a String as a parameter.

upd: new style for 9 verb interface

Now it get closer to the style used in Thimbleweed Park.
fea: created icons for GUI templates in the Setup window.
fea: added option to 9 verb settings popup to choose between classic and
modern sentences.
fea: created sprites and style for CheckButton.

Sierra theme styles updated

This is for PanelContainers and Buttons.
Created inventory popup for Sierra GUI.
Created USE cursor for Sierra GUI.
Created top bar (hover text + score) panel for Sierra GUI.
Fixed some bugs in the Sierra GUI.
Working on making the inventory popup to work properly in Sierra GUI.

SystemText working again.

fix: showing the SystemText blocks interactions until players click
anywhere to close the panel.
upd: `G.display` changed to `G.show_system_text`.
fea: basic inventory functionality working in Sierra GUI. Players can
inspect items and select them for use. Once used, the item disappears
from the inventory grid.

First approach on having varios dialog text types

Devs can choose between Above character, Portrait and Caption.
The implementation is still hardcoded in various parts. Improvements
will come soon.

Fix: cursor behavior in Sierra inventory popup.

fix: the error related to set_name.call_deferred is now solved.
Working on fix for C singleton.

Fallback for commands improved

Code refactor and improvements for DialogText.

upd: Now the now supports the three display modes (Above character, Portrait
and Caption) by itself.
fix: #79 .
fix: Recognizing emotions in dialog lines for `E.queue` was not working.
upd: Added support for avatars with emotions in PopochiuCharacter.
upd: Portrait mode displays the avatar of the talking character (with
its corresponding emotion).

Improved CAPTION text style rendering.

Fixes and minor improvements in DialogText rendering.
Updated properties in scaling and layout for PopochiuInventoryItem.

9 verb inventory scroll working

It takes into account the size of each slot, the size of the gaps
between rows and the number of rows.
This inventory panel adds items to the i_inventory based on what the
scene tree has.
NEXT >> Make this as a component that can work in a popup (i.e. in the
Sierra inventory popup).

Progress on 9 verb inventory functionality

Can trigger commands on inventory items.
Can use inventory items with popochiu clickable and other inventory
items.

fea: Make suggested command to work

This applies for PopochiuClickable and PopochiuInventoryItem (which
suggested verb will be always LOOK AT).
fea: Try calling the left click version of a command before triggering
its fallback (this applies to PopochiuClickable and
PopochiuInventoryItem).

NEXT >> [9 verb] Make inventory container to re-arrange after removing an
inventory item.

fea: can remove items in 9 verb inventory

Removing the item also removes the slot it belongs to, which ensures the
container will re-arrange correctly. A new slot is created after
removing the item.

NEXT >> Allow to replace an item (useful for combining items).

fea: Adds method to replace an inventory item

The new inventory item replaces the one that calls the `replace` method
in the 9 verb interface.
fea: Cursor doesn't leave the screen when the mouse exits the game
window.

upd: Adjust styles and layout of 9 verb interface

upd: Inventory container component for Sierra GPI

Uses the component created for the 9 verb interface in the Inventory
popup of the Sierra template.

upd: Create scroll buttons for Sierra inventory.

upd: Work in Sierra inventory popup

Now players can select an inventory item (with the INTERACT command
active), close the popup, and use such item with clickables.

Create Settings popup for Sierra template.

Can change dialog style in Text options popup in Sierra template.
Can change dialog text speed with a slider in Text options popup in
Sierra template.
Create Sound options popup.

Create Sierra settings option to toggle auto-continue

Update style of text continue icon for Sierra template.
Create texture for QUIT button in Sierra template.
Sierra template now has buttons to quit the game.
Improvements in dialog_text component behavior and anchors setup.

Add function to E for registering commands

The 9 verb and Sierra commands' scripts now register their commands
using the created method.
PopochiuClickable and PopochiuInventoryItem now store the mouse button
index used in the last click.
Started to prepare everything to freeze the development of the 9 verb and Sierra templates.

NEXT >> Cursor refactor or Verb coin template creation.

Dialog menu working in 9 verb and Sierra templates

Change G.freed to G.unblocked.
DialogText no longer affects the Cursor. Now it triggers a signal so the
graphic interface decides what to do while a dialog line is played.
Create signal in D to know when a dialog starts.

Refactors Dialog menu

Now it works in 9 verb and Sierra templates.
It is a bit easier to modify the appearance of the Dialog menu.
Added more signals to PopochiuGraphicInterface in order to allow devs to
customize how to handle more interactions.

Remove G.continue_clicked

Connect to G.dialog_line_finished in PopochiuCharacter.say()
Create signal for listening when the system text is hidden.
Behavior improvements in 9 verb GUI.

Update in BASS GUI for setting the cursor

Set "popochiu_gui_component" group to GI components in order to start
building the UI tab in the dock.

Rename methods

Create InventoryGrid component

This is the type of inventory used by 9 verbs and Sierra templates.
upd: change `Cursor.set_cursor(int)` by `Cursor.show_cursor(String)`.

Create inventory grid component for 9 Verb template

Ready to start freezing development for PR creation.

Updated command handling

Both in PopochiuClickable and PopochiuInventoryItem. They will call
`_on_click` if not custom method is present in the object. Method
fallback should be manually called with `E.command_fallback()`.
Added script_name property to PopochiuCommands class. This can be used
to know which set of commands is the current one.

BASS template working with new commands approach

Fix various issues in the BASS template regarding cursor animations and
behavior with PopochiuClickable and PopochiuInventoryItem.
The reference to the current commands class is now in E.
Updated InventoryBar so it can react to the I.item_replaced signal.

Restore cursor property

Both in PopochiuClickable and PopochiuInventory Item.
Now variations for voices are defined by an array of AudioCueSound.

Fix and update in Setup popup

Now it shows a description of the selected template so devs can know a
bit more about each one.
If the selected template is the same that is currently active after
closing the Setup popup, no action is performed.
Add Popsy as a character to test a bug reported related to z-index.
Add GUI cursor to BASS cursors.

Improve GUI template change with confirmation popup

Created templates for GUI commands types.

Create script copies when selecting GUI template

A copy of the template scripts for the graphic interface and the
commands linked to it is created and placed in
res://popochiu/graphic_interface.
This makes sure devs can play with those scripts instead of modifying
those in the addons folder.

fea: Create a commands template script for the Empty template.

First draft of UI tab working.

It allows to add GUI components to the graphic interface scene.
Buttons in the UI panel show enable when the component they represent is
deleted from the graphic interface scene.

Change to Godot 4.1.2 and removed game scenes

Add buttons to open graphic interface script and commands script

upd: use PopochiuGroup for base components and popups in UI tab.

Change BASS template to SimpleClick template

Fix "Start with it" for inventory items.

fix: Devs can select items to start with in the Main tab.
fix: Setting an inventory item as active with `add_as_active` makes the
cursor take the appearance of the item.
fix: Text color changes when character talks in the Caption dialog
style.
fix: PopochiuInventoryItem.add was not showing InventoryBar.
fea: Added `is_pixel_art_game` property to ProjectSettings.
upd: When selecting Pixel in Game type (setup popup) the default texture
filter is set to TEXTURE_FILTER_NEAREST for props, characters and
inventory items.

Progress on improving code before merge

Better positioning of avatars in Portrait dialog style

Adressed all comments and sugestions made by @stickgrinder

Fix scene validation on Editor2D.

Created House, Goddiu, Popsy and Key for testing.

Sierra template fixes

Improve on copying the selected GUI template.

Fix on opening Sierra popups.

Warning for GUI template change when graphic_interface.tscn is open

DialogText is no longer an editable children in 9_verb_gi.tscn and
sierra_gi.tscn.
Add method to print normal messages in PopochiuUtils.

Add customization properties to InventoryGrid

Devs can define the number of columns, the visible rows, the scene to
use for slots, the horizontal and vertical gap sizes, if the UP and DOWN
buttons should be visible, if the component will scroll with the mouse
wheel.
Update Sierra and 9 verb inventory grids so they use the new
customization properties.
upd: refactor in Setup popup script for better code reading.

Post Alpha 5 rebase

Add button to create popochiu popups

This allows the creation of the scene and script for devs to make their
own popups. The created popup is added to the Popups node in the
graphic_interface scene.
upd: Change name of Empty template to Custom.
upd: Set groups for missing popochiu components and popups scenes.

Add ignored files

Create script to handle gui template operations

Copy dependencies to res://game/graphic_interface based on GUI template selection (#139)

* Progress on copying components when choosing GUI template

* Separate GUI copy operations into methods

Now the game is placed in `res://game` instead of `res://popochiu`.
=== Ready to work on moving components based on source scene dependencies ===

* Graphic interface dependencies point to game folder

Scene dependencies in `res://game/graphic_interface/graphic_interface.tscn` now point to the corresponding scene of the component in the `res://game/graphic_interface/components` folder.
When changing the GUI template, previous components are removed from the FileSystem.

* GUI components determined by group instead of scene path

Assign corresponding groups to all the components in the Sierra template.
Add .png files as part of copying components from the addon to the graphic interface folder in the game.
The .png files will need an extra validation to work properly. Same will apply to .theme files.

* GUI template change copies everything

Components and their scripts and dependencies are correclty moved to res://game/graphic_interface/
=== Ready to test updating the dependencies in each .tscn file ===

* Change dependency source check

Now dependencies are searched in the already copied files of res://game/graphic_interface instead of relying on the source files in res://addons/popochiu...

* Fix untracked files

* Copy components working

Ready to make more tests.

* Add progress window to GUI template change

The copy process ignores resources that were already copied.
Update reference to cursor PNG in SimpleClick template.

* Fix on shared resources when copying components

Fix double call on Setup close in Linux/MacOS

Update minimum size of Setup popup.
[fix] Use EditorInterface scale to update minimum and maximum size of Setup popup.
  • Loading branch information
mapedorr committed Dec 28, 2023
1 parent 87c52d8 commit f742d45
Show file tree
Hide file tree
Showing 228 changed files with 8,923 additions and 1,515 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ data_*/

# Project-specific ignores
popochiu
popochiu/**
popochiu/**
game
game/**
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func create(obj_name: String) -> int:
new_obj.script_name = _pascal_name
new_obj.description = _pascal_name.capitalize()
new_obj.cursor = Constants.CURSOR_TYPE.TALK

if PopochiuResources.get_settings().is_pixel_art_game:
new_obj.get_node("Sprite2D").texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST


# ▓▓▓ END OF LOCAL CODE ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

# Save the scene (.tscn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func create(obj_name: String) -> int:
new_obj.description = _pascal_name.capitalize()
new_obj.cursor = Constants.CURSOR_TYPE.USE
new_obj.size_flags_vertical = new_obj.SIZE_SHRINK_CENTER

if PopochiuResources.get_settings().is_pixel_art_game:
new_obj.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST

# ▓▓▓ END OF LOCAL CODE ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

# Save the scene (.tscn)
Expand Down
3 changes: 3 additions & 0 deletions addons/popochiu/editor/factories/factory_popochiu_prop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func create(
new_obj.cursor = Constants.CURSOR_TYPE.ACTIVE
new_obj.clickable = is_interactive
new_obj.visible = is_visible

if PopochiuResources.get_settings().is_pixel_art_game:
new_obj.get_node("Sprite2D").texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST

if _snake_name in ['bg', 'background']:
new_obj.baseline =\
Expand Down
1 change: 1 addition & 0 deletions addons/popochiu/editor/helpers/popochiu_editor_helper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extends Resource
static var ei: EditorInterface = null
static var undo_redo: EditorUndoRedoManager = null


static func select_node(node: Node) -> void:
ei.get_selection().clear()
ei.get_selection().add_node(node)
324 changes: 324 additions & 0 deletions addons/popochiu/editor/helpers/popochiu_gui_templates_helper.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
@tool
extends Resource
## Helper class for operations related to the GUI templates

static var _template_id := ""
static var _progress_window: Window
static var _progress_lines := ["|", "/", "-", "\\", "-"]
static var _progress_idx := 0

## Create a copy of the selected template, including its components.
## Also, generate the necessary scripts to define custom logic for the graphical
## interface and its commands.
static func copy_gui_template(template_name: String) -> void:
if template_name == PopochiuResources.get_data_value("ui", "template", ""):
PopochiuUtils.print_normal("No changes in GUI tempalte.")
return

_create_progress_window()

var scene_path := PopochiuResources.GUI_CUSTOM_SCENE
var commands_template_path := PopochiuResources.GUI_CUSTOM_TEMPLATE

_template_id = template_name.to_snake_case()

match _template_id:
PopochiuResources.GUI_SIMPLE_CLICK:
scene_path = PopochiuResources.GUI_SIMPLE_CLICK_SCENE
commands_template_path = PopochiuResources.GUI_SIMPLE_CLICK_TEMPLATE
PopochiuResources.GUI_9_VERB:
scene_path = PopochiuResources.GUI_9_VERB_SCENE
commands_template_path = PopochiuResources.GUI_9_VERB_TEMPLATE
PopochiuResources.GUI_SIERRA:
scene_path = PopochiuResources.GUI_SIERRA_SCENE
commands_template_path = PopochiuResources.GUI_SIERRA_TEMPLATE

var script_path := PopochiuResources.GUI_GAME_SCENE.replace(".tscn", ".gd")
var commands_path := PopochiuResources.GUI_GAME_SCENE.replace(
"graphic_interface.tscn", "commands.gd"
)

# ---- Make a copy of the selected GUI template ------------------------------------------------
if _create_scene(scene_path) != OK:
# TODO: Delete the graphic_interface folder and all its contents?
PopochiuUtils.print_error(
"[Popochiu] Couldn't create %s file" % PopochiuResources.GUI_GAME_SCENE
)

return

# Copy the components used by the GUI template to the res://game/graphic_interface/components
# folder so devs can play with them freely -----------------------------------------------------
await _copy_components(scene_path, true)

# Create a copy of the corresponding commands template -----------------------------------------
_copy_scripts(commands_template_path, commands_path, script_path, scene_path)

# Create a copy of the GUI template resources --------------------------------------------------
# TODO: Create res://game/graphic_interface/resources
# Move files (and directories) in the GUI template resources folder
# to the created folder.

# Update the script of the created graphic_interface.tscn so it uses the
# copy created above ---------------------------------------------------------------------------
if _update_scene_script(script_path) != OK:
PopochiuUtils.print_error(
"[Popochiu] Couldn't update graphic_interface.tscn script"
)

return

# Save the GUI template in Settings and popochiu_data.cfg --------------------------------------
_update_settings_and_config(template_name, commands_path)

_progress_window.queue_free()


## Create the **graphic_interface.tscn** file as a copy of the selected GUI template scene.
## If a template change is being made, all components of the previous template are removed along
## with the **.tscn** file before copying the new one.
static func _create_scene(scene_path: String) -> int:
# Create the res://game/graphic_interface/ folder
if not FileAccess.file_exists(PopochiuResources.GUI_GAME_SCENE):
DirAccess.make_dir_recursive_absolute(PopochiuResources.GUI_GAME_FOLDER)
else:
# Remove the graphic_interface.tscn file
DirAccess.remove_absolute(PopochiuResources.GUI_GAME_SCENE)
EditorInterface.get_resource_filesystem().scan()

for dir_name: String in DirAccess.get_directories_at(PopochiuResources.GUI_GAME_FOLDER):
_remove_components(PopochiuResources.GUI_GAME_FOLDER + dir_name)

# Make a copy of the selected GUI template (.tscn) and save it in
# res://game/graphic_interface/graphic_interface.tscn ------------------------------------------
var gi_scene := load(scene_path).duplicate(true)

return ResourceSaver.save(gi_scene, PopochiuResources.GUI_GAME_SCENE)


static func _create_progress_window() -> void:
_progress_window = Window.new()
_progress_window.borderless = true
_progress_window.popup_window = true
_progress_window.exclusive = true
EditorInterface.get_base_control().add_child(_progress_window)

var label := Label.new()
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
label.add_theme_color_override("font_color", Color.WHITE)

_animate_progress_text(label)

var margin_container := MarginContainer.new()
margin_container.add_child(label)
margin_container.add_theme_constant_override("margin_top", 12)
margin_container.add_theme_constant_override("margin_left", 12)
margin_container.add_theme_constant_override("margin_bottom", 12)
margin_container.add_theme_constant_override("margin_right", 12)

var panel_container := PanelContainer.new()
panel_container.add_child(margin_container)

var style_box_flat := StyleBoxFlat.new()
style_box_flat.bg_color = Color("2e2c9b")
style_box_flat.border_color = Color("edf171")
style_box_flat.set_border_width_all(4)
style_box_flat.shadow_color = Color(Color.BLACK, 0.8)
style_box_flat.shadow_offset = Vector2(0.0, 4.0)
style_box_flat.shadow_size = 2

panel_container.add_theme_stylebox_override("panel", style_box_flat)

_progress_window.add_child(panel_container)
_progress_window.popup_centered(_progress_window.get_contents_minimum_size())


static func _animate_progress_text(label: Label) -> void:
if not is_instance_valid(label): return

label.text = "Copying files to graphic interface folder... %s" % _progress_lines[_progress_idx]
await EditorInterface.get_base_control().get_tree().create_timer(0.1).timeout

_progress_idx = posmod(_progress_idx + 1, _progress_lines.size())
_animate_progress_text(label)


static func _remove_components(dir_path: String) -> void:
for file_name: String in DirAccess.get_files_at(dir_path):
DirAccess.remove_absolute(dir_path + "/" + file_name)
EditorInterface.get_resource_filesystem().scan()

for dir_name: String in DirAccess.get_directories_at(dir_path):
var sub_dir_path := dir_path + "/" + dir_name
_remove_components(sub_dir_path)

# Once the directory is empty, remove it
DirAccess.remove_absolute(dir_path)
EditorInterface.get_resource_filesystem().scan()


## Makes a copy of the components used by the original GUI template to the
## **res://game/graphic_interface/components/** folder so devs can play with those scenes without
## affecting the ones in the plugin's folder.
static func _copy_components(source_scene_path: String, is_gui_game_scene := false) -> void:
var dependencies_to_update: Array[Dictionary] = []

# Make a copy of the dependencies of the graphic interface
for dep: String in ResourceLoader.get_dependencies(source_scene_path):
var source_file_path := dep.get_slice("::", 2)

if is_gui_game_scene and source_file_path.get_extension() == "gd"\
and source_scene_path.get_base_dir() == source_file_path.get_base_dir():
# Ignore the script of the GUI template scene file
continue

var source_file_uid := ResourceUID.id_to_text(
ResourceLoader.get_resource_uid(source_file_path)
)
var dependency_data := {
source_path = source_file_path,
source_uid = source_file_uid,
target_path = "",
}

# ---- Create the folder of the file -------------------------------------------------------
var file_name := source_file_path.get_file()
var source_folder := source_file_path.get_base_dir()

var target_folder := source_folder.replace(PopochiuResources.GUI_ADDON_FOLDER, "")
target_folder = target_folder.replace("templates/%s/" % _template_id, "")
target_folder = PopochiuResources.GUI_GAME_FOLDER + target_folder

dependency_data.target_path = "%s/%s" % [target_folder, file_name]
dependencies_to_update.append(dependency_data)

if FileAccess.file_exists(dependency_data.target_path):
# Ignore any file that has already been copied
continue

if not DirAccess.dir_exists_absolute(target_folder):
DirAccess.make_dir_recursive_absolute(target_folder)

# --- Make a copy of the original file -----------------------------------------------------
if source_file_path.get_extension() == "gd":
_copy_script(source_file_path, target_folder, dependency_data.target_path)
else:
_copy_file(source_file_path, target_folder, dependency_data.target_path)

EditorInterface.get_resource_filesystem().scan()
await EditorInterface.get_resource_filesystem().filesystem_changed

# Repeat the process for each of the dependencies of the .tscn resources
if source_file_path.get_extension() == "tscn":
await _copy_components(source_file_path)

if is_gui_game_scene:
_update_dependencies(PopochiuResources.GUI_GAME_SCENE, dependencies_to_update)
else:
var game_scene_path := source_scene_path.replace(PopochiuResources.GUI_ADDON_FOLDER, "")
game_scene_path = game_scene_path.replace("templates/%s/" % _template_id, "")
game_scene_path = PopochiuResources.GUI_GAME_FOLDER + game_scene_path

_update_dependencies(game_scene_path, dependencies_to_update)

EditorInterface.get_resource_filesystem().scan()
await EditorInterface.get_resource_filesystem().filesystem_changed


static func _copy_script(
source_file_path: String, _target_folder: String, target_file_path: String
) -> void:
var file_write = FileAccess.open(target_file_path, FileAccess.WRITE)
file_write.store_string('extends "%s"' % source_file_path)
file_write.close()


static func _copy_file(
source_file_path: String, target_folder: String, target_file_path: String
) -> void:
# ---- Create a copy of the scene file -----------------------------------------------------
if source_file_path.get_extension() in ["tscn", "tres"]:
var file_resource := load(source_file_path).duplicate(true)

if ResourceSaver.save(file_resource, target_file_path) != OK:
DirAccess.remove_absolute(target_folder)
else:
DirAccess.copy_absolute(source_file_path, target_file_path)


## Replace the UID and paths of the components in the graphic interface scene
static func _update_dependencies(scene_path: String, dependencies_to_update: Array) -> void:
if dependencies_to_update.is_empty():
return

# ---- Update the UID and paths of the copied components ---------------------------------------
var file_read = FileAccess.open(scene_path, FileAccess.READ)
var text := file_read.get_as_text()
file_read.close()

for dic: Dictionary in dependencies_to_update:
text = text.replace(dic.source_path, dic.target_path)

var target_uid := ResourceUID.id_to_text(
ResourceLoader.get_resource_uid(dic.target_path)
)

if "invalid" in target_uid: continue

text = text.replace(dic.source_uid, target_uid)

var file_write = FileAccess.open(scene_path, FileAccess.WRITE)
file_write.store_string(text)
file_write.close()


## Copy the commands and graphic interface scripts of the chosen GUI template. The new graphic
## interface scripts inherits from the one originally assigned to the .tscn file of the selected
## template.
static func _copy_scripts(
commands_template_path: String, commands_path: String, script_path: String, scene_path: String
) -> void:
DirAccess.copy_absolute(commands_template_path, commands_path)

# Create a copy of the graphic interface script template ---------------------------------------
var template_path := PopochiuResources.GUI_TEMPLATES_FOLDER + "graphic_interface_template.gd"
var script_file := FileAccess.open(template_path, FileAccess.READ)
var source_code := script_file.get_as_text()
script_file.close()
source_code = source_code.replace(
"extends PopochiuGraphicInterface",
'extends "%s"' % scene_path.replace(".tscn", ".gd")
)
script_file = FileAccess.open(script_path, FileAccess.WRITE)
script_file.store_string(source_code)
script_file.close()


## Updates the script of the created **res://game/graphic_interface/graphic_interface.tscn** file so
## it uses the one created in `_copy_scripts(...)`.
static func _update_scene_script(script_path: String) -> int:
# Update the script of the GUI -----------------------------------------------------------------
var scene := (load(
PopochiuResources.GUI_GAME_SCENE
) as PackedScene).instantiate()
scene.set_script(load(script_path))

# Set the name of the root node
scene.name = "GraphicInterface"

var packed_scene: PackedScene = PackedScene.new()
packed_scene.pack(scene)

return ResourceSaver.save(packed_scene, PopochiuResources.GUI_GAME_SCENE)


static func _update_settings_and_config(template_name: String, commands_path: String) -> void:
var settings := PopochiuResources.get_settings()
settings.graphic_interface = load(PopochiuResources.GUI_GAME_SCENE)
PopochiuResources.save_settings(settings)

# Update the info related to the GUI template and the GUI commands script
# in the popochiu_data.cfg file ----------------------------------------------------------------
PopochiuResources.set_data_value("ui", "template", template_name)
PopochiuResources.set_data_value("ui", "commands", commands_path)
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func _remove_object() -> void:

# Verify if the object to delete is a Prop, a Hotspot or a Region.
if type in Constants.ROOM_TYPES:
# res://popochiu/rooms/???/props/??/ > [res:, popochiu, rooms, ???, props, ??]
# res://game/rooms/???/props/??/ > [res:, popochiu, rooms, ???, props, ??]
location = "Room%s" % (path.split('/', false)[3]).to_pascal_case()

# Look into the Object's folder for audio files and AudioCues to show the
Expand Down
Loading

0 comments on commit f742d45

Please sign in to comment.