Added current quest interface + new quest template interface

This commit is contained in:
gotfishmakesticks 2023-11-16 14:29:14 +03:00
commit 008e74eba3
4 changed files with 169 additions and 2 deletions

View file

@ -190,6 +190,104 @@ offset_bottom = 40.0
text = "X"
script = ExtResource("2_ld3o5")
[node name="CurrentQuest" type="NinePatchRect" parent="QuestMenu"]
visible = false
offset_left = 64.0
offset_top = 64.0
offset_right = 576.0
offset_bottom = 576.0
texture = ExtResource("1_vb0tn")
region_rect = Rect2(0, 0, 5, 5)
patch_margin_left = 2
patch_margin_top = 2
patch_margin_right = 2
patch_margin_bottom = 2
[node name="Header" type="Label" parent="QuestMenu/CurrentQuest"]
offset_right = 512.0
offset_bottom = 64.0
text = "Current Quest Status"
horizontal_alignment = 1
vertical_alignment = 1
[node name="QuestStatus" type="Label" parent="QuestMenu/CurrentQuest"]
layout_mode = 0
offset_left = 16.0
offset_top = 64.0
offset_right = 496.0
offset_bottom = 448.0
text = "Type: Elimination
Objective: Destroy 1 hostile ship [ 0 / 1 ]
Reward: 100 money units
Restrictions:
- No deaths
- Timer: 60 seconds"
vertical_alignment = 1
[node name="AbandonQuest" type="Button" parent="QuestMenu/CurrentQuest"]
layout_mode = 0
offset_left = 1.0
offset_top = 448.0
offset_right = 256.0
offset_bottom = 511.0
text = "Abandon quest"
[node name="CompleteQuest" type="Button" parent="QuestMenu/CurrentQuest"]
offset_left = 256.0
offset_top = 448.0
offset_right = 511.0
offset_bottom = 511.0
disabled = true
text = "Complete quest"
[node name="NewQuest" type="NinePatchRect" parent="QuestMenu"]
visible = false
offset_left = 64.0
offset_top = 64.0
offset_right = 576.0
offset_bottom = 576.0
texture = ExtResource("1_vb0tn")
region_rect = Rect2(0, 0, 5, 5)
patch_margin_left = 2
patch_margin_top = 2
patch_margin_right = 2
patch_margin_bottom = 2
[node name="Header" type="Label" parent="QuestMenu/NewQuest"]
offset_right = 512.0
offset_bottom = 64.0
text = "New Quest"
horizontal_alignment = 1
vertical_alignment = 1
[node name="QuestStatus" type="Label" parent="QuestMenu/NewQuest"]
layout_mode = 0
offset_left = 16.0
offset_top = 64.0
offset_right = 496.0
offset_bottom = 448.0
text = "Type: Elimination
Objective: Destroy 1 hostile ship
Reward: 100 money units
Restrictions:
- No deaths
- Timer: 60 seconds"
vertical_alignment = 1
[node name="AcceptQuest" type="Button" parent="QuestMenu/NewQuest"]
layout_mode = 0
offset_left = 1.0
offset_top = 448.0
offset_right = 511.0
offset_bottom = 511.0
text = "Accept quest"
[node name="EquipmentMenu" type="NinePatchRect" parent="."]
visible = false
layout_mode = 0

View file

@ -9,6 +9,12 @@ var base
@onready var buy_input = $TradingMenu/BuyInput
@onready var sell_button = $TradingMenu/SellButton
@onready var buy_button = $TradingMenu/BuyButton
@onready var current_quest_status = $QuestMenu/CurrentQuest/QuestStatus
@onready var abandon_quest = $QuestMenu/CurrentQuest/AbandonQuest
@onready var complete_quest = $QuestMenu/CurrentQuest/CompleteQuest
@onready var current_quest = $QuestMenu/CurrentQuest
@onready var new_quest = $QuestMenu/NewQuest
@onready var accept_quest = $QuestMenu/NewQuest/AcceptQuest
var base_types = ["Power Supply", "Mining", "Food Production", "Trading", "Modules"]
@ -19,6 +25,9 @@ func _ready():
sell_button.button_up.connect(sell_item)
buy_input.text_changed.connect(buy_text_changed)
sell_input.text_changed.connect(sell_text_changed)
abandon_quest.button_up.connect(quest_abandon)
complete_quest.button_up.connect(quest_complete)
accept_quest.button_up.connect(quest_accept)
func update_lists():
buy_list.clear()
@ -95,3 +104,54 @@ func buy_text_changed(_new_text):
func sell_text_changed(_new_text):
sell_input.placeholder_text = "Amount to buy"
func quest_abandon():
ship.quest.fail()
current_quest.visible = false
new_quest.visible = true
func quest_complete():
if !ship.quest_completed:
return
ship.money += ship.quest.reward_money
ship.quest_completed = false
current_quest.visible = false
new_quest.visible = true
func quest_accept():
pass
func quest_status_update():
var restriction_typing = {
Quest.RESTRICTIONS.NO_DEATHS : '- Destruction of your ship will lead to quest failure.',
Quest.RESTRICTIONS.NO_WEAPON : '- Using any weapon (even accidently) is prohibited.',
Quest.RESTRICTIONS.TIMER : '- You have {sec} seconds to complete the quest since it is accepted.'
}
if ship.quest.data.has('timer'):
restriction_typing[Quest.RESTRICTIONS.TIMER] = restriction_typing[Quest.RESTRICTIONS.TIMER].format(ship.quest.data['timer'])
var template = "Type: {type}\n\nObjective: {objective_text}\n\nReward: {reward} money units\n\nRestrictions: {restrictions}"
var typed_templates = {
Quest.TYPE.ELIMINATION : {
"type" : "Elimination",
"objective" : "Destroy {req} hostile ships [ {cur} / {req} ]".format({"cur" : ship.quest.progress, "req" : ship.quest.progress_max})
},
Quest.TYPE.DELIVERY : {
"type" : "Delivery",
"objective" : "Deliver a cargo to markered base (check the minimap)."
}
}
var restrictions = ""
if len(ship.quest.restrictions) == 0 :
restrictions = "None"
else:
for restriction in ship.quest.restrictions:
restrictions.append("\n", restriction_typing[restriction])
var formatting = {
"type" : typed_templates[ship.quest.type]['type'],
"objective_text" : typed_templates[ship.quest.type]['objective'],
"reward" : ship.quest.reward_money,
"restrictions" : restrictions
}
current_quest_status.text = template.format(formatting)
complete_quest.disabled = !ship.quest_completed

View file

@ -4,20 +4,28 @@ extends BaseButton
@onready var quest_menu = $"../../QuestMenu"
@onready var equipment_menu = $"../../EquipmentMenu"
@onready var info_menu = $"../../InfoMenu"
@onready var base_menu = $"../.."
func _ready():
button_up.connect(open)
func open():
var menu
var submenu = null
match name:
"TradingMenuGoto":
menu = trading_menu
"QuestMenuGoto":
menu = quest_menu
var ship_has_quest = !base_menu.ship.quest.new or base_menu.ship.quest_completed
submenu = base_menu.current_quest if ship_has_quest else base_menu.new_quest
if ship_has_quest:
base_menu.quest_status_update()
"EquipmentMenuGoto":
menu = equipment_menu
"InfoMenuGoto":
menu = info_menu
menu.visible = true
if submenu != null:
submenu.visible = true
get_parent().visible = false

View file

@ -15,6 +15,7 @@ var allow_shooting = true
var faction = "player"
var money : float = 1000
var quest : Quest = Quest.new()
var quest_completed : bool = false
signal destroyed
@ -26,7 +27,7 @@ func _ready():
secondary_slot.add_child(Game.get_weapon("SingleRocketMk1").instantiate())
quest.create(Quest.TYPE.ELIMINATION, 1, 100)
quest.create(Quest.TYPE.ELIMINATION, 2, 200)
func _process(_delta):
if hull.hp < 0: destroy()
@ -48,7 +49,7 @@ func add_quest(quest : Quest):
func kill_quest(success : bool):
if success:
money += quest.reward_money
quest_completed = true
quest.new = true
func timer_failed():