generated from sakkaku-dev/godot-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix gacha showcase + show collection
- Loading branch information
Showing
16 changed files
with
333 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class_name TweenCreator | ||
|
||
var node: Node | ||
var tw: Tween | ||
var default_duration := 0.5 | ||
var block = true | ||
var trans = Tween.TRANS_CUBIC | ||
var ease = Tween.EASE_IN_OUT | ||
|
||
static func create(n): | ||
return TweenCreator.new(n) | ||
|
||
func _init(n: Node): | ||
node = n | ||
|
||
func new_tween(on_finish = null): | ||
if tw and tw.is_running(): | ||
if block: | ||
return false | ||
else: | ||
tw.kill() | ||
|
||
tw = node.create_tween() | ||
tw.set_parallel() | ||
tw.set_trans(trans) | ||
tw.set_ease(ease) | ||
if on_finish: | ||
tw.finished.connect(on_finish) | ||
return true | ||
|
||
func fade_out(node, duration = default_duration): | ||
return tw.tween_property(node, "modulate", Color.TRANSPARENT, duration).from(Color.WHITE).set_ease(Tween.EASE_IN) | ||
|
||
func fade_in(node, duration = default_duration): | ||
return tw.tween_property(node, "modulate", Color.WHITE, duration).from(Color.TRANSPARENT).set_ease(Tween.EASE_OUT) | ||
|
||
func slide_in(node, dir: Vector2, pos = Vector2.ZERO, dist = node.size, duration = default_duration): | ||
return tw.tween_property(node, "position", pos, duration).from(pos - dir * dist).set_ease(Tween.EASE_OUT) | ||
|
||
func slide_out(node, dir: Vector2, dist = node.size, duration = default_duration): | ||
return tw.tween_property(node, "position", node.position + dir * dist, duration).from(node.position).set_ease(Tween.EASE_IN) | ||
|
||
func scale_in(node, target_scale = Vector2(1, 1), duration = default_duration): | ||
if node is Control: | ||
node.pivot_offset = node.size / 2 | ||
return tw.tween_property(node, "scale", target_scale, duration).from(Vector2.ZERO).set_ease(Tween.EASE_OUT) | ||
|
||
func scale_out(node, init_scale = Vector2(1, 1), duration = default_duration): | ||
if node is Control: | ||
node.pivot_offset = node.size / 2 | ||
return tw.tween_property(node, "scale", Vector2.ZERO, duration).from(init_scale).set_ease(Tween.EASE_IN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
shader_type canvas_item; | ||
|
||
uniform vec2 center = vec2(0.5, 0.5); | ||
uniform float scale: hint_range(0.0, 2.0, 0.01) = 1.0; | ||
|
||
uniform sampler2D mask; | ||
|
||
vec2 scale_uv(vec2 uv, vec2 origin, vec2 scale_factor) | ||
{ | ||
vec2 scaled_coord = uv - origin; | ||
mat2 s = mat2(vec2(scale_factor.x, 0.0), vec2(0.0, scale_factor.y)); | ||
scaled_coord *= s; | ||
scaled_coord += origin; | ||
return scaled_coord; | ||
} | ||
|
||
void fragment() { | ||
vec2 uv = scale_uv(UV, center, vec2(scale, scale)); | ||
vec4 color = texture(mask, uv); | ||
if (uv.x > 1.0 || uv.y > 1.0 || uv.x < 0.0 || uv.y < 0.0) { | ||
color = vec4(0.0); | ||
} | ||
|
||
COLOR=vec4(step(1.0, color.r) * color.a * step(0.0, UV.y)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
extends CenterContainer | ||
|
||
signal close | ||
|
||
@export var grid: GridContainer | ||
|
||
func _ready(): | ||
_update() | ||
visibility_changed.connect(_update) | ||
|
||
func _update(): | ||
for child in grid.get_children(): | ||
grid.remove_child(child) | ||
|
||
for p in Piece.Type.values(): | ||
if p in GameManager.default_pieces: | ||
continue | ||
|
||
var l = Label.new() | ||
l.text = Piece.Type.keys()[p] | ||
l.modulate = Color.WHITE if p in GameManager.unlocked_pieces else Color(0.3, 0.3, 0.3, 1.0) | ||
grid.add_child(l) | ||
|
||
func _on_texture_button_pressed(): | ||
close.emit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
extends Overlay | ||
|
||
const PIECE_TEX = { | ||
Piece.Type.GURA: preload("res://assets/gacha/Myth_Gura.png") | ||
} | ||
|
||
@export var tex: TextureRect | ||
@export var overlay: ColorRect | ||
@export var shine: ColorRect | ||
|
||
var tw: TweenCreator | ||
|
||
func _ready(): | ||
tw = TweenCreator.create(self) | ||
|
||
hide() | ||
on_hide.connect(func(): | ||
if tw.new_tween(func(): hide()): | ||
tw.fade_out(overlay) | ||
tw.fade_out(shine).set_ease(Tween.EASE_OUT) | ||
tw.scale_out(tex) | ||
) | ||
|
||
func show_piece(piece): | ||
if tw.new_tween(): | ||
if piece in PIECE_TEX: | ||
tex.texture = PIECE_TEX[piece] | ||
|
||
tw.fade_in(overlay) | ||
tw.fade_in(shine).set_ease(Tween.EASE_IN) | ||
tw.scale_in(tex) | ||
show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
[gd_scene load_steps=5 format=3 uid="uid://pgikighgyjyb"] | ||
|
||
[ext_resource type="Script" path="res://src/menu/Collection.gd" id="1_ex6bl"] | ||
[ext_resource type="StyleBox" uid="uid://bd0c76q5d7ocf" path="res://theme/dialog.tres" id="2_6nmk1"] | ||
[ext_resource type="Texture2D" uid="uid://bdotu11c1jmm" path="res://assets/ui/close.svg" id="3_bkctx"] | ||
[ext_resource type="Script" path="res://src/menu/UIButton.gd" id="4_nk2lk"] | ||
|
||
[node name="Collection" type="CenterContainer" node_paths=PackedStringArray("grid")] | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
script = ExtResource("1_ex6bl") | ||
grid = NodePath("PanelContainer/MarginContainer/GridContainer") | ||
|
||
[node name="PanelContainer" type="PanelContainer" parent="."] | ||
layout_mode = 2 | ||
theme_override_styles/panel = ExtResource("2_6nmk1") | ||
|
||
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] | ||
layout_mode = 2 | ||
theme_override_constants/margin_left = 30 | ||
theme_override_constants/margin_top = 30 | ||
theme_override_constants/margin_right = 30 | ||
theme_override_constants/margin_bottom = 30 | ||
|
||
[node name="GridContainer" type="GridContainer" parent="PanelContainer/MarginContainer"] | ||
layout_mode = 2 | ||
theme_override_constants/h_separation = 30 | ||
theme_override_constants/v_separation = 30 | ||
columns = 5 | ||
|
||
[node name="MarginContainer2" type="MarginContainer" parent="PanelContainer"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 8 | ||
size_flags_vertical = 0 | ||
theme_override_constants/margin_top = -25 | ||
theme_override_constants/margin_right = -25 | ||
|
||
[node name="TextureButton" type="TextureButton" parent="PanelContainer/MarginContainer2"] | ||
custom_minimum_size = Vector2(50, 50) | ||
layout_mode = 2 | ||
texture_normal = ExtResource("3_bkctx") | ||
ignore_texture_size = true | ||
stretch_mode = 5 | ||
script = ExtResource("4_nk2lk") | ||
|
||
[connection signal="pressed" from="PanelContainer/MarginContainer2/TextureButton" to="." method="_on_texture_button_pressed"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class_name Overlay | ||
extends Control | ||
|
||
signal on_hide() | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.