It's Cow Game! Version 2.04!
This commit is contained in:
commit
a9e1ed9ddd
3148 changed files with 95332 additions and 0 deletions
BIN
UI/Shopping/AddButton.png
Normal file
BIN
UI/Shopping/AddButton.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 171 B |
34
UI/Shopping/AddButton.png.import
Normal file
34
UI/Shopping/AddButton.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ciyd36jniatt3"
|
||||
path="res://.godot/imported/AddButton.png-157ee624f3e60b5c2290a93393edf262.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://UI/Shopping/AddButton.png"
|
||||
dest_files=["res://.godot/imported/AddButton.png-157ee624f3e60b5c2290a93393edf262.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
UI/Shopping/AllButton.png
Normal file
BIN
UI/Shopping/AllButton.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 240 B |
34
UI/Shopping/AllButton.png.import
Normal file
34
UI/Shopping/AllButton.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c14hghr12eyuy"
|
||||
path="res://.godot/imported/AllButton.png-071b7334236c9e48877105ff104a55cd.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://UI/Shopping/AllButton.png"
|
||||
dest_files=["res://.godot/imported/AllButton.png-071b7334236c9e48877105ff104a55cd.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
19
UI/Shopping/CostDisplay.gd
Normal file
19
UI/Shopping/CostDisplay.gd
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
extends HBoxContainer
|
||||
|
||||
var showSymbol = true
|
||||
|
||||
func set_display(amount:int):
|
||||
var amountText = ""
|
||||
|
||||
if amount < 0:
|
||||
$Amount.set("theme_override_colors/font_color", Color.RED)
|
||||
elif amount > 0:
|
||||
if showSymbol:
|
||||
amountText = "+ "
|
||||
$Amount.set("theme_override_colors/font_color", Color.GREEN)
|
||||
else:
|
||||
$Amount.set("theme_override_colors/font_color", Color.WHITE)
|
||||
|
||||
amountText += str(amount)
|
||||
|
||||
$Amount.text = amountText
|
||||
24
UI/Shopping/CostDisplay.tscn
Normal file
24
UI/Shopping/CostDisplay.tscn
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://b68rx34bofp4j"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bc3gbxx1ruhd3" path="res://Items/Foods/Fruits/Sprites/Grape.png" id="1_k5ytr"]
|
||||
|
||||
[node name="CostDisplay" type="HBoxContainer"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="Amount" type="Label" parent="."]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 1
|
||||
theme_override_colors/font_color = Color(0, 1, 0, 1)
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 6
|
||||
text = "+ 500"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
custom_minimum_size = Vector2(20, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
texture = ExtResource("1_k5ytr")
|
||||
expand_mode = 3
|
||||
BIN
UI/Shopping/FiveButton.png
Normal file
BIN
UI/Shopping/FiveButton.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 228 B |
34
UI/Shopping/FiveButton.png.import
Normal file
34
UI/Shopping/FiveButton.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://d0w7ntktx1ha3"
|
||||
path="res://.godot/imported/FiveButton.png-5d2c6b1160bf77df28fe324029e83f30.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://UI/Shopping/FiveButton.png"
|
||||
dest_files=["res://.godot/imported/FiveButton.png-5d2c6b1160bf77df28fe324029e83f30.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
144
UI/Shopping/InventoryDisplayer.gd
Normal file
144
UI/Shopping/InventoryDisplayer.gd
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
extends VBoxContainer
|
||||
|
||||
signal buttonPressed(item)
|
||||
signal fiveButtonPressed(item)
|
||||
signal allButtonPressed(item)
|
||||
signal itemClicked(item)
|
||||
|
||||
var displayScene = preload("res://UI/Shopping/ItemShopDisplay.tscn")
|
||||
var inventory
|
||||
|
||||
var positiveOptions = true
|
||||
var negativeOptions = false
|
||||
var fiveButtons = false
|
||||
var allButtons = false
|
||||
|
||||
var quantitiesShown = true
|
||||
|
||||
func _ready():
|
||||
inventory = Inventory.new()
|
||||
|
||||
func set_title(title):
|
||||
$Title.text = title
|
||||
$Title.visible = true
|
||||
|
||||
func disconnect_signals():
|
||||
for display in %Items.get_children():
|
||||
var connections = display.buttonPressed.get_connections()
|
||||
for connection in connections:
|
||||
display.buttonPressed.disconnect(connection["callable"])
|
||||
|
||||
connections = display.itemClicked.get_connections()
|
||||
for connection in connections:
|
||||
display.itemClicked.disconnect(connection["callable"])
|
||||
|
||||
connections = display.fiveButtonPressed.get_connections()
|
||||
for connection in connections:
|
||||
display.fiveButtonPressed.disconnect(connection["callable"])
|
||||
|
||||
connections = display.allButtonPressed.get_connections()
|
||||
for connection in connections:
|
||||
display.allButtonPressed.disconnect(connection["callable"])
|
||||
|
||||
func update_display():
|
||||
disconnect_signals()
|
||||
|
||||
var displaysMade = %Items.get_children().size()
|
||||
for i in range(inventory.items.size()):
|
||||
if i >= displaysMade:
|
||||
var newDisplay = displayScene.instantiate()
|
||||
%Items.add_child(newDisplay)
|
||||
|
||||
setup_new_display(newDisplay)
|
||||
|
||||
var currentDisplay = %Items.get_child(i)
|
||||
currentDisplay.set_sprite(inventory.items[i].get_sprite())
|
||||
currentDisplay.set_item_name(inventory.items[i].get_name())
|
||||
currentDisplay.set_quantity(inventory.quantities[i])
|
||||
|
||||
currentDisplay.buttonPressed.connect(button_pressed.bind(inventory.items[i]))
|
||||
currentDisplay.fiveButtonPressed.connect(five_button_pressed.bind(inventory.items[i]))
|
||||
currentDisplay.allButtonPressed.connect(all_button_pressed.bind(inventory.items[i]))
|
||||
currentDisplay.itemClicked.connect(item_clicked.bind(inventory.items[i]))
|
||||
currentDisplay.visible = true
|
||||
|
||||
for i in range(inventory.items.size(), displaysMade):
|
||||
%Items.get_child(i).visible = false
|
||||
|
||||
func remove_item(item, quantity):
|
||||
var originalInvSize = inventory.items.size()
|
||||
var displaysMade = %Items.get_children().size()
|
||||
for i in range(originalInvSize):
|
||||
var currentInvItem = inventory.items[originalInvSize - i - 1]
|
||||
if currentInvItem.equals(item):
|
||||
var newQuantity = inventory.quantities[originalInvSize - i - 1] - quantity
|
||||
var currentDisplay = %Items.get_child(originalInvSize - i - 1)
|
||||
if newQuantity <= 0:
|
||||
%Items.remove_child(currentDisplay)
|
||||
currentDisplay.queue_free()
|
||||
else:
|
||||
currentDisplay.set_quantity(newQuantity)
|
||||
break
|
||||
|
||||
func add_item(item, quantity):
|
||||
var itemFound = false
|
||||
|
||||
var originalInvSize = inventory.items.size()
|
||||
var displaysMade = %Items.get_children().size()
|
||||
for i in range(originalInvSize):
|
||||
var currentInvItem = inventory.items[originalInvSize - i - 1]
|
||||
if currentInvItem.equals(item):
|
||||
var newQuantity = inventory.quantities[originalInvSize - i - 1] + quantity
|
||||
if (originalInvSize - i - 1) < displaysMade:
|
||||
var currentDisplay = %Items.get_child(originalInvSize - i - 1)
|
||||
currentDisplay.set_quantity(newQuantity)
|
||||
itemFound = true
|
||||
else:
|
||||
quantity = newQuantity
|
||||
break
|
||||
|
||||
if !itemFound:
|
||||
var newDisplay = displayScene.instantiate()
|
||||
%Items.add_child(newDisplay)
|
||||
setup_new_display(newDisplay)
|
||||
|
||||
newDisplay.set_sprite(item.get_sprite())
|
||||
newDisplay.set_item_name(item.get_name())
|
||||
newDisplay.set_quantity(quantity)
|
||||
|
||||
newDisplay.buttonPressed.connect(button_pressed.bind(item))
|
||||
newDisplay.fiveButtonPressed.connect(five_button_pressed.bind(item))
|
||||
newDisplay.allButtonPressed.connect(all_button_pressed.bind(item))
|
||||
newDisplay.itemClicked.connect(item_clicked.bind(item))
|
||||
|
||||
func setup_new_display(newDisplay):
|
||||
if fiveButtons:
|
||||
newDisplay.show_five_button()
|
||||
|
||||
if allButtons:
|
||||
newDisplay.show_all_button()
|
||||
|
||||
if !quantitiesShown:
|
||||
newDisplay.hide_quantity()
|
||||
|
||||
if negativeOptions:
|
||||
newDisplay.show_negatives()
|
||||
else:
|
||||
newDisplay.hide_negatives()
|
||||
|
||||
if positiveOptions:
|
||||
newDisplay.show_positives()
|
||||
else:
|
||||
newDisplay.hide_positives()
|
||||
|
||||
func button_pressed(item):
|
||||
buttonPressed.emit(item)
|
||||
|
||||
func five_button_pressed(item):
|
||||
fiveButtonPressed.emit(item)
|
||||
|
||||
func all_button_pressed(item):
|
||||
allButtonPressed.emit(item)
|
||||
|
||||
func item_clicked(item):
|
||||
itemClicked.emit(item)
|
||||
105
UI/Shopping/ItemShopDisplay.tscn
Normal file
105
UI/Shopping/ItemShopDisplay.tscn
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://cmb5smyr2onii"]
|
||||
|
||||
[ext_resource type="Script" path="res://UI/MenuBar/Inventory/ItemInventoryDisplay.gd" id="1_ng4nb"]
|
||||
[ext_resource type="Texture2D" uid="uid://ct5a5b2148uia" path="res://Items/Foods/Fruits/Sprites/Orange.png" id="2_qui5t"]
|
||||
[ext_resource type="Texture2D" uid="uid://djqlquwgjrk71" path="res://UI/Shopping/RemoveButton.png" id="3_n8q4i"]
|
||||
[ext_resource type="Texture2D" uid="uid://ciyd36jniatt3" path="res://UI/Shopping/AddButton.png" id="4_8tgfh"]
|
||||
[ext_resource type="Texture2D" uid="uid://d0w7ntktx1ha3" path="res://UI/Shopping/FiveButton.png" id="5_egqeo"]
|
||||
[ext_resource type="Texture2D" uid="uid://c14hghr12eyuy" path="res://UI/Shopping/AllButton.png" id="6_witnx"]
|
||||
|
||||
[sub_resource type="Theme" id="Theme_tw8r0"]
|
||||
|
||||
[node name="ItemShopDisplay" type="PanelContainer"]
|
||||
offset_right = 276.0
|
||||
offset_bottom = 39.0
|
||||
script = ExtResource("1_ng4nb")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
theme_override_constants/margin_left = 3
|
||||
theme_override_constants/margin_top = 2
|
||||
theme_override_constants/margin_right = 5
|
||||
theme_override_constants/margin_bottom = 2
|
||||
|
||||
[node name="ItemInventoryDisplay" type="HSplitContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="ItemSprite" type="TextureRect" parent="MarginContainer/ItemInventoryDisplay"]
|
||||
layout_mode = 2
|
||||
theme = SubResource("Theme_tw8r0")
|
||||
texture = ExtResource("2_qui5t")
|
||||
expand_mode = 2
|
||||
|
||||
[node name="HSplitContainer" type="HBoxContainer" parent="MarginContainer/ItemInventoryDisplay"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="ItemName" type="Label" parent="MarginContainer/ItemInventoryDisplay/HSplitContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 10.0
|
||||
text = "Cucumber Ash"
|
||||
vertical_alignment = 1
|
||||
text_overrun_behavior = 3
|
||||
|
||||
[node name="Quantity" type="Label" parent="MarginContainer/ItemInventoryDisplay/HSplitContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 10
|
||||
text = "x10"
|
||||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Buttons" type="HBoxContainer" parent="MarginContainer/ItemInventoryDisplay/HSplitContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
theme_override_constants/separation = 5
|
||||
|
||||
[node name="MinusButton" type="TextureButton" parent="MarginContainer/ItemInventoryDisplay/HSplitContainer/Buttons"]
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(20, 20)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
texture_normal = ExtResource("3_n8q4i")
|
||||
texture_pressed = ExtResource("3_n8q4i")
|
||||
texture_hover = ExtResource("3_n8q4i")
|
||||
texture_disabled = ExtResource("3_n8q4i")
|
||||
texture_focused = ExtResource("3_n8q4i")
|
||||
|
||||
[node name="PlusButton" type="TextureButton" parent="MarginContainer/ItemInventoryDisplay/HSplitContainer/Buttons"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 4
|
||||
texture_normal = ExtResource("4_8tgfh")
|
||||
texture_pressed = ExtResource("4_8tgfh")
|
||||
texture_hover = ExtResource("4_8tgfh")
|
||||
texture_disabled = ExtResource("4_8tgfh")
|
||||
texture_focused = ExtResource("4_8tgfh")
|
||||
|
||||
[node name="5Button" type="TextureButton" parent="MarginContainer/ItemInventoryDisplay/HSplitContainer/Buttons"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 4
|
||||
texture_normal = ExtResource("5_egqeo")
|
||||
texture_pressed = ExtResource("5_egqeo")
|
||||
texture_hover = ExtResource("5_egqeo")
|
||||
texture_disabled = ExtResource("5_egqeo")
|
||||
texture_focused = ExtResource("5_egqeo")
|
||||
|
||||
[node name="AllButton" type="TextureButton" parent="MarginContainer/ItemInventoryDisplay/HSplitContainer/Buttons"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 4
|
||||
texture_normal = ExtResource("6_witnx")
|
||||
texture_pressed = ExtResource("6_witnx")
|
||||
texture_hover = ExtResource("6_witnx")
|
||||
texture_disabled = ExtResource("6_witnx")
|
||||
texture_focused = ExtResource("6_witnx")
|
||||
|
||||
[connection signal="pressed" from="MarginContainer/ItemInventoryDisplay/HSplitContainer/Buttons/MinusButton" to="." method="_on_minus_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/ItemInventoryDisplay/HSplitContainer/Buttons/PlusButton" to="." method="_on_plus_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/ItemInventoryDisplay/HSplitContainer/Buttons/5Button" to="." method="_on_5_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/ItemInventoryDisplay/HSplitContainer/Buttons/AllButton" to="." method="_on_all_button_pressed"]
|
||||
33
UI/Shopping/NotEnoughGrapesLabel.gd
Normal file
33
UI/Shopping/NotEnoughGrapesLabel.gd
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
extends Label
|
||||
|
||||
var showing
|
||||
var showTime = 3
|
||||
|
||||
var totalFadeTime = 1
|
||||
var fadeTimer = 1
|
||||
|
||||
func _ready():
|
||||
modulate.a = 0
|
||||
showing = false
|
||||
|
||||
func show_up():
|
||||
showing = true
|
||||
showTime = 3
|
||||
fadeTimer = totalFadeTime
|
||||
modulate.a = 1
|
||||
|
||||
func hide_now():
|
||||
modulate.a = 0
|
||||
showing = false
|
||||
|
||||
func _process(delta):
|
||||
if showing:
|
||||
if showTime <= 0:
|
||||
fadeTimer -= delta
|
||||
|
||||
modulate.a = fadeTimer/totalFadeTime
|
||||
|
||||
if fadeTimer <= 0:
|
||||
showing = false
|
||||
else:
|
||||
showTime -= delta
|
||||
BIN
UI/Shopping/RemoveButton.png
Normal file
BIN
UI/Shopping/RemoveButton.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 160 B |
34
UI/Shopping/RemoveButton.png.import
Normal file
34
UI/Shopping/RemoveButton.png.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://djqlquwgjrk71"
|
||||
path="res://.godot/imported/RemoveButton.png-6412181456bb9421fa72507118fef19a.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://UI/Shopping/RemoveButton.png"
|
||||
dest_files=["res://.godot/imported/RemoveButton.png-6412181456bb9421fa72507118fef19a.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
158
UI/Shopping/ShopInterface.gd
Normal file
158
UI/Shopping/ShopInterface.gd
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
extends Window
|
||||
|
||||
var itemShopDisplayScene = preload("res://UI/Shopping/ItemShopDisplay.tscn")
|
||||
@onready var inventoryItemDisplayer = %PlayerInventoryItems
|
||||
@onready var shopItemDisplayer = %ShopInventoryItems
|
||||
@onready var playerTradeItemDisplayer = %PlayerTradeItems
|
||||
@onready var shopTradeItemDisplayer = %ShopTradeItems
|
||||
|
||||
@onready var costDisplay = %CostDisplay
|
||||
|
||||
var shopItems = []
|
||||
|
||||
var playerTradeItems:Inventory
|
||||
var shopTradeItems:Inventory
|
||||
|
||||
func _ready():
|
||||
inventoryItemDisplayer.buttonPressed.connect(add_to_player_trade)
|
||||
playerTradeItemDisplayer.buttonPressed.connect(remove_from_player_trade)
|
||||
|
||||
shopItemDisplayer.buttonPressed.connect(add_to_shop_trade)
|
||||
shopTradeItemDisplayer.buttonPressed.connect(remove_from_shop_trade)
|
||||
|
||||
shopItemDisplayer.quantitiesShown = false
|
||||
|
||||
playerTradeItemDisplayer.negativeOptions = true
|
||||
shopTradeItemDisplayer.negativeOptions = true
|
||||
|
||||
playerTradeItemDisplayer.positiveOptions = false
|
||||
shopTradeItemDisplayer.positiveOptions = false
|
||||
|
||||
func opened():
|
||||
get_tree().paused = true
|
||||
set_up_inventory()
|
||||
set_up_shop_inventory()
|
||||
|
||||
playerTradeItems = Inventory.new()
|
||||
shopTradeItems = Inventory.new()
|
||||
|
||||
update_cost_display()
|
||||
|
||||
func set_up_inventory():
|
||||
inventoryItemDisplayer.inventory = InventoryManager.get_inventory()
|
||||
inventoryItemDisplayer.update_display()
|
||||
|
||||
func set_up_shop_inventory():
|
||||
shopItemDisplayer.inventory.items = shopItems
|
||||
for i in shopItems.size():
|
||||
shopItemDisplayer.inventory.quantities.append(1)
|
||||
|
||||
shopItemDisplayer.update_display()
|
||||
|
||||
func add_to_shop_trade(item):
|
||||
shopTradeItems.add_item(item)
|
||||
|
||||
shopTradeItemDisplayer.inventory = shopTradeItems
|
||||
shopTradeItemDisplayer.update_display()
|
||||
|
||||
update_cost_display()
|
||||
|
||||
func remove_from_shop_trade(item):
|
||||
shopTradeItems.remove_item(item)
|
||||
|
||||
shopTradeItemDisplayer.inventory = shopTradeItems
|
||||
shopTradeItemDisplayer.update_display()
|
||||
|
||||
update_cost_display()
|
||||
|
||||
func add_to_player_trade(item):
|
||||
InventoryManager.remove_item_from_inventory(item)
|
||||
playerTradeItems.add_item(item)
|
||||
|
||||
playerTradeItemDisplayer.inventory = playerTradeItems
|
||||
playerTradeItemDisplayer.update_display()
|
||||
inventoryItemDisplayer.update_display()
|
||||
|
||||
update_cost_display()
|
||||
|
||||
func remove_from_player_trade(item):
|
||||
InventoryManager.add_item_to_inventory(item)
|
||||
playerTradeItems.remove_item(item)
|
||||
|
||||
playerTradeItemDisplayer.inventory = playerTradeItems
|
||||
playerTradeItemDisplayer.update_display()
|
||||
inventoryItemDisplayer.update_display()
|
||||
|
||||
update_cost_display()
|
||||
|
||||
func update_cost_display():
|
||||
var cost = get_cost()
|
||||
costDisplay.set_display(cost)
|
||||
|
||||
func get_cost():
|
||||
var playerOffering = 0
|
||||
var shopOffering = 0
|
||||
|
||||
for i in range(playerTradeItems.items.size()):
|
||||
playerOffering += playerTradeItems.items[i].value * playerTradeItems.quantities[i]
|
||||
|
||||
for i in range(shopTradeItems.items.size()):
|
||||
shopOffering += shopTradeItems.items[i].value * shopTradeItems.quantities[i]
|
||||
|
||||
return playerOffering - shopOffering
|
||||
|
||||
func reset_items():
|
||||
for i in range(playerTradeItems.items.size()):
|
||||
var currentItem = playerTradeItems.items[i]
|
||||
InventoryManager.add_item_to_inventory(currentItem, playerTradeItems.quantities[i])
|
||||
|
||||
playerTradeItems = Inventory.new()
|
||||
playerTradeItemDisplayer.inventory = playerTradeItems
|
||||
playerTradeItemDisplayer.update_display()
|
||||
|
||||
shopTradeItems = Inventory.new()
|
||||
shopTradeItemDisplayer.inventory = shopTradeItems
|
||||
shopTradeItemDisplayer.update_display()
|
||||
|
||||
func _on_leave_button_pressed():
|
||||
reset_items()
|
||||
get_tree().paused = false
|
||||
hide()
|
||||
|
||||
func _on_confirm_button_pressed():
|
||||
var currentCost = get_cost()*-1
|
||||
var currentGrapesOwned = InventoryManager.get_grape_count()
|
||||
|
||||
if currentGrapesOwned >= currentCost:
|
||||
$NotEnoughGrapesLabel.hide_now()
|
||||
if shopTradeItems.items.size() > 0 or playerTradeItems.items.size() > 0:
|
||||
$AcceptedLabel.show_up()
|
||||
if currentCost > 0:
|
||||
$AcceptedLabel.text = "Offer accepted (" + str(currentCost*-1) + " grapes)"
|
||||
elif currentCost < 0:
|
||||
$AcceptedLabel.text = "Offer accepted (+" + str(currentCost*-1) + " grapes)"
|
||||
else:
|
||||
$AcceptedLabel.text = "Offer accepted"
|
||||
confirm_trade()
|
||||
else:
|
||||
$NotEnoughGrapesLabel.show_up()
|
||||
$AcceptedLabel.hide_now()
|
||||
|
||||
func confirm_trade():
|
||||
var currentCost = get_cost()
|
||||
InventoryManager.alter_grape_count(currentCost)
|
||||
|
||||
for i in range(shopTradeItems.items.size()):
|
||||
InventoryManager.add_item_to_inventory(shopTradeItems.items[i], shopTradeItems.quantities[i])
|
||||
|
||||
playerTradeItems = Inventory.new()
|
||||
playerTradeItemDisplayer.inventory = playerTradeItems
|
||||
playerTradeItemDisplayer.update_display()
|
||||
|
||||
shopTradeItems = Inventory.new()
|
||||
shopTradeItemDisplayer.inventory = shopTradeItems
|
||||
shopTradeItemDisplayer.update_display()
|
||||
|
||||
inventoryItemDisplayer.update_display()
|
||||
|
||||
update_cost_display()
|
||||
194
UI/Shopping/ShopInterface.tscn
Normal file
194
UI/Shopping/ShopInterface.tscn
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://b52b85cx77aoq"]
|
||||
|
||||
[ext_resource type="Script" path="res://UI/Shopping/ShopInterface.gd" id="1_p0uei"]
|
||||
[ext_resource type="PackedScene" uid="uid://c3ku75p4ep3c7" path="res://UI/Inventory/InventoryDisplayer.tscn" id="2_j36jt"]
|
||||
[ext_resource type="PackedScene" uid="uid://b68rx34bofp4j" path="res://UI/Shopping/CostDisplay.tscn" id="3_s611d"]
|
||||
[ext_resource type="Script" path="res://UI/Shopping/CostDisplay.gd" id="4_514jh"]
|
||||
[ext_resource type="Script" path="res://UI/Shopping/NotEnoughGrapesLabel.gd" id="5_16w8e"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_t8sg3"]
|
||||
bg_color = Color(0.25098, 0.466667, 0.203922, 1)
|
||||
border_width_left = 4
|
||||
border_width_top = 4
|
||||
border_width_right = 4
|
||||
border_width_bottom = 4
|
||||
border_color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="ShopInterface" type="Window"]
|
||||
process_mode = 3
|
||||
size = Vector2i(600, 510)
|
||||
unresizable = true
|
||||
borderless = true
|
||||
always_on_top = true
|
||||
script = ExtResource("1_p0uei")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
custom_minimum_size = Vector2(600, 510)
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_t8sg3")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/margin_left = 4
|
||||
theme_override_constants/margin_top = 4
|
||||
theme_override_constants/margin_right = 4
|
||||
|
||||
[node name="Invs" type="HSplitContainer" parent="PanelContainer/VBoxContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
collapsed = true
|
||||
dragger_visibility = 1
|
||||
|
||||
[node name="Inventory" type="VSplitContainer" parent="PanelContainer/VBoxContainer/MarginContainer/Invs"]
|
||||
custom_minimum_size = Vector2(0, 210)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
collapsed = true
|
||||
dragger_visibility = 2
|
||||
|
||||
[node name="Inventory Label" type="Label" parent="PanelContainer/VBoxContainer/MarginContainer/Invs/Inventory"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 8
|
||||
theme_override_font_sizes/font_size = 32
|
||||
text = "Inventory"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="PlayerInventoryItems" parent="PanelContainer/VBoxContainer/MarginContainer/Invs/Inventory" instance=ExtResource("2_j36jt")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Shop" type="VSplitContainer" parent="PanelContainer/VBoxContainer/MarginContainer/Invs"]
|
||||
custom_minimum_size = Vector2(0, 200)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
collapsed = true
|
||||
dragger_visibility = 2
|
||||
|
||||
[node name="ShopLabel" type="Label" parent="PanelContainer/VBoxContainer/MarginContainer/Invs/Shop"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 8
|
||||
theme_override_font_sizes/font_size = 32
|
||||
text = "Shop"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="ShopInventoryItems" parent="PanelContainer/VBoxContainer/MarginContainer/Invs/Shop" instance=ExtResource("2_j36jt")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer2" type="MarginContainer" parent="PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 4
|
||||
theme_override_constants/margin_right = 4
|
||||
|
||||
[node name="TradeZone" type="VSplitContainer" parent="PanelContainer/VBoxContainer/MarginContainer2"]
|
||||
layout_mode = 2
|
||||
dragger_visibility = 2
|
||||
|
||||
[node name="TradeLabel" type="Label" parent="PanelContainer/VBoxContainer/MarginContainer2/TradeZone"]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 8
|
||||
theme_override_font_sizes/font_size = 32
|
||||
text = "Trade"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TradeSides" type="HSplitContainer" parent="PanelContainer/VBoxContainer/MarginContainer2/TradeZone"]
|
||||
custom_minimum_size = Vector2(0, 160)
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
dragger_visibility = 2
|
||||
|
||||
[node name="PlayerSide" type="VSplitContainer" parent="PanelContainer/VBoxContainer/MarginContainer2/TradeZone/TradeSides"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
dragger_visibility = 2
|
||||
|
||||
[node name="YouLabel" type="Label" parent="PanelContainer/VBoxContainer/MarginContainer2/TradeZone/TradeSides/PlayerSide"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
text = "You"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="PlayerTradeItems" parent="PanelContainer/VBoxContainer/MarginContainer2/TradeZone/TradeSides/PlayerSide" instance=ExtResource("2_j36jt")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ShopSide" type="VSplitContainer" parent="PanelContainer/VBoxContainer/MarginContainer2/TradeZone/TradeSides"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
dragger_visibility = 2
|
||||
|
||||
[node name="ThemLabel" type="Label" parent="PanelContainer/VBoxContainer/MarginContainer2/TradeZone/TradeSides/ShopSide"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
text = "Them"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="ShopTradeItems" parent="PanelContainer/VBoxContainer/MarginContainer2/TradeZone/TradeSides/ShopSide" instance=ExtResource("2_j36jt")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="CostDisplay" parent="PanelContainer/VBoxContainer" instance=ExtResource("3_s611d")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
script = ExtResource("4_514jh")
|
||||
|
||||
[node name="MarginContainer3" type="MarginContainer" parent="PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_bottom = 4
|
||||
|
||||
[node name="Buttons" type="HSplitContainer" parent="PanelContainer/VBoxContainer/MarginContainer3"]
|
||||
layout_mode = 2
|
||||
dragger_visibility = 1
|
||||
|
||||
[node name="ConfirmButton" type="Button" parent="PanelContainer/VBoxContainer/MarginContainer3/Buttons"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 10
|
||||
theme_override_font_sizes/font_size = 22
|
||||
text = "Confirm"
|
||||
|
||||
[node name="LeaveButton" type="Button" parent="PanelContainer/VBoxContainer/MarginContainer3/Buttons"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 2
|
||||
theme_override_font_sizes/font_size = 22
|
||||
text = "Leave"
|
||||
|
||||
[node name="NotEnoughGrapesLabel" type="Label" parent="."]
|
||||
offset_top = 400.0
|
||||
offset_right = 592.0
|
||||
offset_bottom = 428.0
|
||||
theme_override_colors/font_color = Color(0.811765, 0.803922, 0, 1)
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 5
|
||||
theme_override_font_sizes/font_size = 20
|
||||
text = "Offer declined"
|
||||
horizontal_alignment = 1
|
||||
script = ExtResource("5_16w8e")
|
||||
|
||||
[node name="AcceptedLabel" type="Label" parent="."]
|
||||
offset_top = 400.0
|
||||
offset_right = 592.0
|
||||
offset_bottom = 428.0
|
||||
theme_override_colors/font_color = Color(0.329412, 0.917647, 0, 1)
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 5
|
||||
theme_override_font_sizes/font_size = 20
|
||||
text = "Offer accepted"
|
||||
horizontal_alignment = 1
|
||||
script = ExtResource("5_16w8e")
|
||||
|
||||
[connection signal="pressed" from="PanelContainer/VBoxContainer/MarginContainer3/Buttons/ConfirmButton" to="." method="_on_confirm_button_pressed"]
|
||||
[connection signal="pressed" from="PanelContainer/VBoxContainer/MarginContainer3/Buttons/LeaveButton" to="." method="_on_leave_button_pressed"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue