-
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.
- Loading branch information
Showing
9 changed files
with
214 additions
and
29 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
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
53 changes: 53 additions & 0 deletions
53
destination/destination_menu/fuel_station_tab/fuel_station_container.gd
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,53 @@ | ||
extends VBoxContainer | ||
|
||
signal buy_fuel(refill_amount, price) | ||
|
||
var spaceship: Spaceship | ||
var purchase_handler: PurchaseHandler | ||
var price_per_unit = 2 | ||
|
||
# This is for the next refill | ||
var refill_amount = 0 | ||
var refill_price = 0 | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
purchase_handler = get_node_by_group("PurchaseHandler") | ||
spaceship = get_node_by_group("Spaceship") | ||
update_labels() | ||
|
||
func get_node_by_group(group_name): | ||
var ph_results = get_tree().get_nodes_in_group(group_name) | ||
if ph_results.size() > 0: | ||
return ph_results[0] | ||
return null | ||
|
||
func update_labels(): | ||
$GridContainer/FuelLevelValue.text = "%d / %d" % [spaceship.current_fuel, spaceship.total_fuel_capacity] | ||
$GridContainer/PricePerUnit.text = "%d Cu/l" % price_per_unit | ||
|
||
var total_money = spaceship.get_parent().capitalism_units | ||
var full_refill_price = 0 | ||
refill_amount = spaceship.total_fuel_capacity - spaceship.current_fuel | ||
|
||
if spaceship.tanks_are_full(): | ||
$AlreadyFullLabel.visible = true | ||
$NotEnoughCuLabel.visible = false | ||
else: | ||
full_refill_price = refill_amount * price_per_unit | ||
$AlreadyFullLabel.visible = false | ||
$NotEnoughCuLabel.visible = full_refill_price > total_money | ||
|
||
if full_refill_price > total_money: | ||
refill_amount = floor(total_money / price_per_unit) | ||
|
||
refill_price = refill_amount * price_per_unit | ||
|
||
$GridContainer/FullRefillPrice.text = "%d Cu" % full_refill_price | ||
$BuyFuelButton.text = "Buy %d liters of fuel now for only %d Cu!" % [refill_amount, refill_price] | ||
|
||
func _on_BuyFuelButton_pressed(): | ||
if purchase_handler.purchase_item(refill_price, "%d liters of fuel" % refill_amount): | ||
spaceship.refill_fuel(refill_amount) | ||
emit_signal("purchase_successful") | ||
update_labels() |
91 changes: 91 additions & 0 deletions
91
destination/destination_menu/fuel_station_tab/fuel_station_container.tscn
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,91 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://destination/destination_menu/fuel_station_tab/fuel_station_container.gd" type="Script" id=1] | ||
|
||
[node name="FuelStationOptionContainer" type="VBoxContainer"] | ||
margin_left = 20.0 | ||
margin_top = 20.0 | ||
margin_right = 711.0 | ||
margin_bottom = 572.0 | ||
custom_constants/separation = 20 | ||
script = ExtResource( 1 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="RefillInfoLabel" type="Label" parent="."] | ||
margin_right = 691.0 | ||
margin_bottom = 20.0 | ||
text = "Here you can refill your spaceship's fuel tanks." | ||
clip_text = true | ||
|
||
[node name="GridContainer" type="GridContainer" parent="."] | ||
margin_top = 40.0 | ||
margin_right = 691.0 | ||
margin_bottom = 108.0 | ||
columns = 2 | ||
|
||
[node name="LabelCurrentFuel" type="Label" parent="GridContainer"] | ||
margin_right = 218.0 | ||
margin_bottom = 20.0 | ||
text = "Current fuel: " | ||
|
||
[node name="FuelLevelValue" type="Label" parent="GridContainer"] | ||
margin_left = 222.0 | ||
margin_right = 306.0 | ||
margin_bottom = 20.0 | ||
text = "??? / ???" | ||
|
||
[node name="LabelPricePerUnit" type="Label" parent="GridContainer"] | ||
margin_top = 24.0 | ||
margin_right = 218.0 | ||
margin_bottom = 44.0 | ||
text = "Price per fuel liter:" | ||
|
||
[node name="PricePerUnit" type="Label" parent="GridContainer"] | ||
margin_left = 222.0 | ||
margin_top = 24.0 | ||
margin_right = 306.0 | ||
margin_bottom = 44.0 | ||
text = "??? Cu/l" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="LabelFullRefillPrice" type="Label" parent="GridContainer"] | ||
margin_top = 48.0 | ||
margin_right = 218.0 | ||
margin_bottom = 68.0 | ||
text = "Price for a complete refill: " | ||
|
||
[node name="FullRefillPrice" type="Label" parent="GridContainer"] | ||
margin_left = 222.0 | ||
margin_top = 48.0 | ||
margin_right = 306.0 | ||
margin_bottom = 68.0 | ||
text = "??? Cu" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="AlreadyFullLabel" type="Label" parent="."] | ||
margin_top = 128.0 | ||
margin_right = 691.0 | ||
margin_bottom = 148.0 | ||
text = "Your tanks are full!" | ||
|
||
[node name="NotEnoughCuLabel" type="Label" parent="."] | ||
margin_top = 168.0 | ||
margin_right = 691.0 | ||
margin_bottom = 211.0 | ||
text = "You don't have enough capitalism units for a complete refill. | ||
You can spend your whole savings to buy as much fuel as possible though!" | ||
|
||
[node name="BuyFuelButton" type="Button" parent="."] | ||
margin_top = 231.0 | ||
margin_right = 364.0 | ||
margin_bottom = 257.0 | ||
size_flags_horizontal = 0 | ||
text = "Buy ??? liters of fuel now for only ??? Cu!" | ||
|
||
[connection signal="pressed" from="BuyFuelButton" to="." method="_on_BuyFuelButton_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
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 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