Skip to content

Commit

Permalink
feat: fix gacha showcase + show collection
Browse files Browse the repository at this point in the history
  • Loading branch information
myin142 committed Aug 27, 2023
1 parent 566253c commit a2d2714
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 164 deletions.
51 changes: 51 additions & 0 deletions godot/shared/TweenCreator.gd
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)
7 changes: 7 additions & 0 deletions godot/src/StartMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends MenuSystem

@export var settings: Control
@export var store: Control
@export var collection: Control

func _ready():
super._ready()
Expand All @@ -10,9 +11,15 @@ func _ready():

store.hide()
store.close.connect(func(): _hide_node(store))

collection.hide()
collection.close.connect(func(): _hide_node(collection))

func _on_store_pressed():
_show_node(store)

func _on_settings_pressed():
_show_node(settings)

func _on_collection_pressed():
_show_node(collection)
22 changes: 4 additions & 18 deletions godot/src/clip_texture.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,20 @@ uniform sampler2D clip_texture;
uniform vec2 clip_texture_size;
uniform vec2 clip_texture_offset;

void fragment(){
COLOR=COLOR;


void fragment() {
vec2 texture_size = (1.0 / TEXTURE_PIXEL_SIZE);
vec2 texture_ratio = texture_size / clip_texture_size;
vec2 clip_UV = UV * texture_ratio + clip_texture_offset;

vec4 color = COLOR;
vec4 tex = texture(clip_texture, clip_UV);
if (clip_UV.x > 1.0 || clip_UV.x < 0.0 || clip_UV.y > 1.0 || clip_UV.y < 0.0) {
tex = vec4(0.0, 0.0, 0.0, 0.0);
}
float mix_tex = 1.0 - step(color.r, 1.0-tex.a);
if (mix_tex == 0.0 && color.b > 0.0) {
mix_tex = 1.0;
mix_tex = color.a;
}
COLOR=vec4(mix(tex.rgb, color.rgb, mix_tex), color.a);

// vec4 color;
// if (clip_UV.x > 1.0 || clip_UV.x < 0.0 || clip_UV.y > 1.0 || clip_UV.y < 0.0) {
// color = vec4(0.0, 0.0, 0.0, 0.0);
// }
// else {
// color = texture(clip_texture, clip_UV);
// }
//
// if(color.a == 0.0)
// COLOR=vec4(0.0, 0.0, 0.0, 0.0);
// else
// COLOR=color;
}
41 changes: 0 additions & 41 deletions godot/src/electric_bg.gdshader

This file was deleted.

25 changes: 25 additions & 0 deletions godot/src/fade_wave.gdshader
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));
}
23 changes: 13 additions & 10 deletions godot/src/game_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ var default_pieces = [

var unlocked_pieces = []
var selected_pieces = []
var selected_piece = null

func _ready():
_load_game()
energy.restore()

if selected_pieces.size() > 0:
selected_pieces = []

if selected_pieces.size() == 0:
selected_pieces.append_array(default_pieces)

Expand Down Expand Up @@ -77,10 +77,11 @@ func back_to_start():
func _save_game():
save_manager.save_to_slot(SAVE_SLOT, {
"energy": energy.energy,
"energyUsedTime": energy.get_last_used_time(),
"energy_used_time": energy.get_last_used_time(),
"points": points.get_points(),
"unlockedPieces": unlocked_pieces,
"selectedPieces": selected_pieces,
"unlocked_pieces": unlocked_pieces,
"selected_piece": selected_piece,
#"selectedPieces": selected_pieces,
})

func _load_game():
Expand All @@ -90,11 +91,13 @@ func _load_game():

if "energy" in data:
energy.energy = data.energy
if "energyUsedTime" in data:
energy.set_last_used_time(data.energyUsedTime)
if "energy_used_time" in data:
energy.set_last_used_time(data.energy_used_time)
if "points" in data:
points.set_points(data.points)
if "unlockedPieces" in data:
unlocked_pieces = data.unlockedPieces
if "selectedPieces" in data:
selected_pieces = data.selectedPieces
if "unlocked_pieces" in data:
unlocked_pieces = data.unlocked_pieces
if "selected_piece" in data:
selected_piece = data.selected_piece
#if "selectedPieces" in data:
# selected_pieces = data.selectedPieces
25 changes: 25 additions & 0 deletions godot/src/menu/Collection.gd
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()
32 changes: 32 additions & 0 deletions godot/src/menu/Showcase.gd
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()
49 changes: 49 additions & 0 deletions godot/src/menu/collection.tscn
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"]
1 change: 1 addition & 0 deletions godot/src/menu/overlay.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name Overlay
extends Control

signal on_hide()
Expand Down
6 changes: 0 additions & 6 deletions godot/src/menu/store.gd

This file was deleted.

7 changes: 4 additions & 3 deletions godot/src/menu/store.tscn
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[gd_scene load_steps=6 format=3 uid="uid://dx3pmih1fkpfe"]

[ext_resource type="Script" path="res://src/menu/store/Store.gd" id="1_7cxv8"]
[ext_resource type="StyleBox" uid="uid://bd0c76q5d7ocf" path="res://theme/dialog.tres" id="1_16mmg"]
[ext_resource type="Script" path="res://src/menu/store.gd" id="1_oiq8j"]
[ext_resource type="PackedScene" uid="uid://hbh72ag1wvh" path="res://src/menu/store/gacha_pack.tscn" id="2_2e1y3"]
[ext_resource type="Texture2D" uid="uid://bdotu11c1jmm" path="res://assets/ui/close.svg" id="3_wepua"]
[ext_resource type="Script" path="res://src/menu/UIButton.gd" id="4_3mes3"]

[node name="Store" type="CenterContainer"]
[node name="Store" type="CenterContainer" node_paths=PackedStringArray("pack_container")]
offset_right = 1080.0
offset_bottom = 1920.0
script = ExtResource("1_oiq8j")
script = ExtResource("1_7cxv8")
pack_container = NodePath("PanelContainer/MarginContainer/VBoxContainer")

[node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 2
Expand Down
Loading

0 comments on commit a2d2714

Please sign in to comment.