Skip to content

Commit

Permalink
Castagne v0.54.20
Browse files Browse the repository at this point in the history
  • Loading branch information
panthavma committed Aug 24, 2024
1 parent e45909c commit 3aa3a45
Show file tree
Hide file tree
Showing 70 changed files with 2,566 additions and 433 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ export_presets.cfg
# Mono-specific ignores
.mono/
data_*/

# ------------------
# Castagne specific

# We don't want the raw assets in this repo to not make it huge -- they will be added properly by the build script
assets
# This one is also added by the build script so it's more release specific, as compared to relying on the state of the code
castagne-version.json
6 changes: 5 additions & 1 deletion Castagne.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]

[ext_resource path="res://castagne/engine/CastagneGlobal.gd" type="Script" id=1]
[ext_resource path="res://castagne/engine/CastagneParser.gd" type="Script" id=2]
[ext_resource path="res://castagne/engine/CastagneNet.gd" type="Script" id=3]
[ext_resource path="res://castagne/engine/CastagneLoader.gd" type="Script" id=4]
[ext_resource path="res://castagne/menus/CastagneMenus.gd" type="Script" id=5]

[node name="Castagne" type="Node"]
script = ExtResource( 1 )
Expand All @@ -16,3 +17,6 @@ script = ExtResource( 3 )

[node name="Loader" type="Node" parent="."]
script = ExtResource( 4 )

[node name="Menus" type="Node" parent="."]
script = ExtResource( 5 )
62 changes: 62 additions & 0 deletions docs/intermediate/ui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: User Interface
order: 350
todo: 54
lastver: 54
---


# User Interface

Castagne's User Interface system allows you to display in-game information to the player, through bars, numbers, and other widgets. This system interfaces with Godot engine more than others as it relies more on its features, and as such some intermediate operations are meant to be done from Godot's editor proper.

The main concept of the system is ***Widgets***. A widget is an interface element displaying one or several values from the current state of the game. They can be added in two ways:
- From CASP, by filling in the UI Specblock.
- Manually, by adding the widget to the UI root scene.

## Widgets

Widgets are updated during the graphics update step. They can be added from CASP, which will try to add them at a hook point defined in the root. You are able to specify the variables and assets to use, but their actual use is defined by the widget itself.

The type of widget can be either "custom" to load any scene, or one of the other default types to load the default associated widget, which can be changed from the Castagne config.

### Default Widgets

Default widgets are meant as an easy way to add information during prototyping or for simple widgets. The

| Type | Description | Variables | Assets |
| --: | -- | -- | -- | -- |
| Bar | A fillable bar that can show two values | Main: Main value to show<br/>Sub: Shown behind the Main value<br/>Max: The full bar capacity needed for ratios | A1: Main bar texture<br/>A2: Sub bar texture<br/>A3: Background texture |
| Icons | Adds icons one after the other | Main: Number of icons | A1: Icon |
| Icon Switch | Shows one icon from a list | Main: Icon ID to show | A1: Icon for 0-<br/>A2: Icon for 1<br/>A3: Icon for 2+ |
| Text | Shows a simple label | Main: Text | / |

### Custom Widgets

You can use any scene as a widget as long as it implements the interface of `res://castagne/helpers/ui/CUIWidget.gd`.

The easiest way is reusing one of the widget scripts from the default section, in `res://castagne/helpers/ui/widgets`. Here are a few additional remarks on each:

- Bar: The widget code actually handles all the values given by godot, meaning you can do rotational filling bars and have them mirror properly.
- Icons: You can change the appearance of icons easily, by adding the nodes as children yourself beforehand. The code will only create new icons once at the end.
- IconSwitch: Again, any node can be used if added as children, so you can actually change the visibility of a lot of stuff
- Text: Straightforward

Save your scene and give the path to CASP to use it with the Custom type, and it should add it to the hook point you want.

### Creating new widgets

Sometimes, you need something complex. You can create new widget types by inheriting `res://castagne/helpers/ui/CUIWidget.gd`. There are helper functions to validate data and gather them.

If you create a new widget, you'll also need to handle mirroring properly through the `isMirrored` value.

## Roots

Before adding widgets to the UI, it needs to create the hooking points. It does this by spawning it the UI Root. There are two:

- Global root: Added at the start, holds general widgets and the root for the player ui roots.
- Player root: Added with as many players as needed, can be mirrored. Can be changed per player in the BID.

You can visualize the current hook points by using the "Visualize UI" Debug switch from the debug tool. Every node can be a hook point.

Widgets already present in the global or player root are detected and updates automatically.
8 changes: 7 additions & 1 deletion editor/CastagneEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func _ready():

EnterMenu()

# Update version name
$MainMenu/Header/CastagneTitle.set_text(Castagne.versionInfo["version-name"])

if(tutorialPath != null):
$TutorialSystem.StartTutorial(tutorialPath)

Expand Down Expand Up @@ -227,7 +230,10 @@ func _on_Characters_item_activated(_index):

# Just copied from the started, a bit of a code smell lol
func _on_StartGame_pressed():
call_deferred("LoadLevel", configData.Get("PathMainMenu"))
var menu = Castagne.Menus.InstanceMenu("MainMenu")
get_tree().get_root().add_child(menu)
queue_free()
#call_deferred("LoadLevel", configData.Get("PathMainMenu"))
func _on_StartGameMatch_pressed():
pass # Replace with function body.
func _on_StartGameTraining_pressed():
Expand Down
7 changes: 1 addition & 6 deletions editor/CastagneEditor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ margin_left = 8.0
margin_top = 8.0
margin_right = -8.0
margin_bottom = -8.0
__meta__ = {
"_edit_use_anchors_": false
}
alignment = 1

[node name="GameIcon" type="TextureRect" parent="MainMenu/Header"]
margin_right = 128.0
Expand Down Expand Up @@ -128,9 +126,6 @@ margin_top = 8.0
margin_right = -12.0
margin_bottom = -8.0
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Label" type="Label" parent="MainMenu/Menu"]
margin_top = 103.0
Expand Down
Loading

0 comments on commit 3aa3a45

Please sign in to comment.