Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
666Savior committed Apr 26, 2021
2 parents 847e64b + d055ecd commit 8d5dd66
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 10 deletions.
60 changes: 58 additions & 2 deletions environment/props/ResearchTable.gd
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
extends Area2D

const PROGRESS_TIME: float = 4.0

onready var panel: Panel = $CanvasLayer/ResearchPanel
onready var confirm_button: Button = $CanvasLayer/ResearchPanel/ConfirmButton
onready var done_button: Button = $CanvasLayer/ResearchPanel/DoneButton
onready var progress_bar: ProgressBar = $CanvasLayer/ResearchPanel/ProgressBar

onready var inventory_buttons = $CanvasLayer/ResearchPanel/InventoryButtons.get_children()

var character: Node2D = null
var inv_item_types: Dictionary
var current_item_type = Item.ItemType.NONE
var animate_progress_bar: bool = false

var researched_types: Array

func _ready() -> void:
connect("body_entered", self, "on_body_entered")
connect("body_exited", self, "on_body_exited")
panel.hide()
confirm_button.connect("pressed", self, "on_confirm")
done_button.connect("pressed", self, "done_interacting")
for i in range(inventory_buttons.size()):
inventory_buttons[i].connect("pressed", self, "on_inventory_button_pressed", [i])

func _process(delta: float) -> void:
if animate_progress_bar:

progress_bar.value += (delta / PROGRESS_TIME) * progress_bar.max_value

func on_body_entered(body):
if body.has_method("entered_interactive_range"):
Expand All @@ -30,6 +49,32 @@ func interact():
character.set_physics_process(false)
panel.show()
update_inventory_view()
current_item_type = Item.ItemType.NONE
$CanvasLayer/ResearchPanel/ChosenItemIconRect.texture = (
Item.ICONS[current_item_type])
progress_bar.value = 0.0
confirm_button.disabled = false

func on_confirm():
if !character || !is_instance_valid(character):
character = null
return
if !character.inventory.has(current_item_type) || character.inventory[current_item_type] < 1:
return
confirm_button.disabled = true
done_button.disabled = true
for btn in inventory_buttons:
btn.disabled = true
progress_bar.value = 0.0
animate_progress_bar = true
yield(get_tree().create_timer(PROGRESS_TIME), "timeout")
animate_progress_bar = false
if character && is_instance_valid(character):
character.inventory[current_item_type] -= 1
researched_types.append(current_item_type)
current_item_type = Item.ItemType.NONE
update_inventory_view()
done_button.disabled = false

func done_interacting():
panel.hide()
Expand All @@ -43,16 +88,27 @@ func update_inventory_view():
if !character || !is_instance_valid(character):
character = null
return
var inventory_buttons = $CanvasLayer/ResearchPanel/InventoryButtons.get_children()
print_debug(inventory_buttons)

inv_item_types.clear()
var button_idx = 0
for item_type in character.inventory:
if button_idx >= inventory_buttons.size():
break
if character.inventory[item_type] <= 0:
continue
inventory_buttons[button_idx].icon = Item.ICONS[item_type]
inv_item_types[button_idx] = item_type
inventory_buttons[button_idx].disabled = item_type in researched_types
button_idx += 1
while button_idx < inventory_buttons.size():
inventory_buttons[button_idx].icon = Item.ICONS[Item.ItemType.NONE]
inv_item_types[button_idx] = Item.ItemType.NONE
inventory_buttons[button_idx].disabled = true
button_idx += 1

func on_inventory_button_pressed(idx):
current_item_type = inv_item_types[idx]
$CanvasLayer/ResearchPanel/ChosenItemIconRect.texture = (
Item.ICONS[current_item_type])
progress_bar.value = 0.0
confirm_button.disabled = false
34 changes: 31 additions & 3 deletions environment/props/TableWide2.tscn
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=10 format=2]

[ext_resource path="res://environment/props/table.png" type="Texture" id=1]
[ext_resource path="res://environment/props/ResearchTable.gd" type="Script" id=2]
[ext_resource path="res://game/ui-theme/ui_theme.tres" type="Theme" id=3]
[ext_resource path="res://game/menu/InventoryButton.tscn" type="PackedScene" id=4]
[ext_resource path="res://game/ui-theme/panel_style_transparent.tres" type="StyleBox" id=5]
[ext_resource path="res://game/ui-theme/font_large.tres" type="DynamicFont" id=6]
[ext_resource path="res://game/ui-theme/oinventoryitembackground.png" type="Texture" id=7]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 30, 5 )
[sub_resource type="CircleShape2D" id=1]
radius = 40.0

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 30, 5 )
Expand Down Expand Up @@ -128,12 +129,39 @@ margin_top = 200.0
margin_right = 250.0
margin_bottom = 240.0

[node name="NinePatchRect" type="NinePatchRect" parent="CanvasLayer/ResearchPanel"]
margin_left = 380.0
margin_top = 80.0
margin_right = 432.0
margin_bottom = 132.0
texture = ExtResource( 7 )
patch_margin_left = 12
patch_margin_top = 12
patch_margin_right = 12
patch_margin_bottom = 12
__meta__ = {
"_edit_use_anchors_": false
}

[node name="ChosenItemIconRect" type="TextureRect" parent="CanvasLayer/ResearchPanel"]
margin_left = 390.0
margin_top = 90.0
margin_right = 422.0
margin_bottom = 122.0
expand = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="ProgressBar" type="ProgressBar" parent="CanvasLayer/ResearchPanel"]
margin_left = 320.0
margin_top = 260.0
margin_right = 490.0
margin_bottom = 272.0
percent_visible = false
__meta__ = {
"_edit_use_anchors_": false
}

[node name="ConfirmButton" type="Button" parent="CanvasLayer/ResearchPanel"]
margin_left = 200.0
Expand Down
8 changes: 8 additions & 0 deletions game/ui-theme/font_tiny.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="DynamicFont" load_steps=2 format=2]

[ext_resource path="res://font/Silver.ttf" type="DynamicFontData" id=1]

[resource]
size = 10
extra_spacing_bottom = -8
font_data = ExtResource( 1 )
15 changes: 15 additions & 0 deletions game/ui-theme/progress_bar_bg.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[gd_resource type="StyleBoxTexture" load_steps=2 format=2]

[ext_resource path="res://game/ui-theme/progressbar.png" type="Texture" id=1]

[resource]
texture = ExtResource( 1 )
region_rect = Rect2( 4, 2, 19, 20 )
margin_left = 5.0
margin_right = 5.0
margin_top = 5.0
margin_bottom = 7.0
expand_margin_left = 5.0
expand_margin_right = 5.0
expand_margin_top = 5.0
expand_margin_bottom = 7.0
8 changes: 8 additions & 0 deletions game/ui-theme/progress_bar_fg.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="StyleBoxTexture" load_steps=2 format=2]

[ext_resource path="res://game/ui-theme/progressbar.png" type="Texture" id=1]

[resource]
texture = ExtResource( 1 )
region_rect = Rect2( 24, 7, 9, 8 )
axis_stretch_horizontal = 1
Binary file added game/ui-theme/progressbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions game/ui-theme/progressbar.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/progressbar.png-4695f3dcd478080b88372bf38b460dd3.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://game/ui-theme/progressbar.png"
dest_files=[ "res://.import/progressbar.png-4695f3dcd478080b88372bf38b460dd3.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
13 changes: 8 additions & 5 deletions game/ui-theme/ui_theme.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[gd_resource type="Theme" load_steps=7 format=2]
[gd_resource type="Theme" load_steps=10 format=2]

[ext_resource path="res://game/ui-theme/button_style_empty.tres" type="StyleBox" id=1]
[ext_resource path="res://game/ui-theme/button_style_pressed.tres" type="StyleBox" id=2]
[ext_resource path="res://game/ui-theme/font_default.tres" type="DynamicFont" id=3]
[ext_resource path="res://game/ui-theme/progress_bar_fg.tres" type="StyleBox" id=4]
[ext_resource path="res://game/ui-theme/progress_bar_bg.tres" type="StyleBox" id=5]
[ext_resource path="res://game/ui-theme/button_style_base.tres" type="StyleBox" id=6]
[ext_resource path="res://game/ui-theme/panel_style_base.tres" type="StyleBox" id=7]
[ext_resource path="res://game/ui-theme/panel_style_popup.tres" type="StyleBox" id=8]
[ext_resource path="res://game/ui-theme/font_tiny.tres" type="DynamicFont" id=9]

[resource]
default_font = ExtResource( 3 )
Expand Down Expand Up @@ -242,11 +245,11 @@ PopupMenu/styles/panel = null
PopupMenu/styles/panel_disabled = null
PopupMenu/styles/separator = null
PopupPanel/styles/panel = ExtResource( 8 )
ProgressBar/colors/font_color = Color( 0, 0, 0, 1 )
ProgressBar/colors/font_color = Color( 1, 1, 1, 1 )
ProgressBar/colors/font_color_shadow = Color( 0, 0, 0, 1 )
ProgressBar/fonts/font = null
ProgressBar/styles/bg = null
ProgressBar/styles/fg = null
ProgressBar/fonts/font = ExtResource( 9 )
ProgressBar/styles/bg = ExtResource( 5 )
ProgressBar/styles/fg = ExtResource( 4 )
RichTextLabel/colors/default_color = Color( 1, 1, 1, 1 )
RichTextLabel/colors/font_color_selected = Color( 1, 1, 1, 1 )
RichTextLabel/colors/font_color_shadow = Color( 0, 0, 0, 1 )
Expand Down
6 changes: 6 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ window/size/height=720
window/stretch/mode="viewport"
window/stretch/aspect="expand"

[importer_defaults]

texture={
"flags/filter": false
}

[input]

menu={
Expand Down

0 comments on commit 8d5dd66

Please sign in to comment.