It's Cow Game! Version 2.04!
This commit is contained in:
commit
a9e1ed9ddd
3148 changed files with 95332 additions and 0 deletions
51
Interactions/Interactable/Action_Menu.gd
Normal file
51
Interactions/Interactable/Action_Menu.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
extends Node2D
|
||||
|
||||
signal action_selected(ID)
|
||||
|
||||
var next_ID = 1
|
||||
var availabilityChecks = {}
|
||||
|
||||
var defaultOptionsAdded = false
|
||||
|
||||
var shortcuts = [KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9]
|
||||
var action_ids
|
||||
|
||||
func _process(delta):
|
||||
var popupMenu:PopupMenu = $PopupMenu
|
||||
if popupMenu.visible:
|
||||
for i in range(popupMenu.item_count):
|
||||
var currentID = popupMenu.get_item_id(i)
|
||||
if currentID < shortcuts.size() and Input.is_action_just_pressed(str(currentID)):
|
||||
_on_popup_menu_id_pressed(currentID)
|
||||
if currentID == popupMenu.item_count:
|
||||
popupMenu.hide()
|
||||
break
|
||||
|
||||
func appear():
|
||||
var popupMenu:PopupMenu = $PopupMenu
|
||||
popupMenu.show()
|
||||
|
||||
for i in range(popupMenu.item_count):
|
||||
var currentID = popupMenu.get_item_id(i)
|
||||
|
||||
if currentID in availabilityChecks.keys():
|
||||
var result = availabilityChecks[currentID].call()
|
||||
popupMenu.set_item_disabled(i, !result)
|
||||
|
||||
if !defaultOptionsAdded:
|
||||
defaultOptionsAdded = true
|
||||
add_action("Cancel")
|
||||
|
||||
func add_availability_check(ID, availabilityCheck):
|
||||
availabilityChecks[ID] = availabilityCheck
|
||||
|
||||
func add_action(actionName):
|
||||
$PopupMenu.add_item(actionName, next_ID)
|
||||
|
||||
var last_ID = next_ID
|
||||
next_ID += 1
|
||||
|
||||
return last_ID
|
||||
|
||||
func _on_popup_menu_id_pressed(id):
|
||||
action_selected.emit(id)
|
||||
18
Interactions/Interactable/Interactable.gd
Normal file
18
Interactions/Interactable/Interactable.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
extends Node2D
|
||||
|
||||
var WindowSize = Vector2(880,620)
|
||||
|
||||
func _on_panel_gui_input(event):
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
$ActionMenu.appear()
|
||||
$ActionMenu.get_node("PopupMenu").position = GetPopUpPos()
|
||||
|
||||
func GetPopUpPos():
|
||||
var MousePos = get_viewport().get_mouse_position()
|
||||
var PopUpPos = MousePos
|
||||
var MenuSize = get_node("ActionMenu/PopupMenu").size
|
||||
|
||||
if MenuSize.x + MousePos.x > WindowSize.x: PopUpPos.x -= MenuSize.x
|
||||
if MenuSize.y + MousePos.y > WindowSize.y: PopUpPos.y -= MenuSize.y
|
||||
|
||||
return PopUpPos
|
||||
29
Interactions/Interactable/Interaction.gd
Normal file
29
Interactions/Interactable/Interaction.gd
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Interaction
|
||||
|
||||
@export var disableAddingActions:bool = false
|
||||
|
||||
var IDs = []
|
||||
var actionFunctions = []
|
||||
|
||||
func add_action(interactionName:String, action_function, availabilityCheck = null):
|
||||
if disableAddingActions:
|
||||
return
|
||||
|
||||
var actionMenu = get_parent().get_node("Interactable/ActionMenu")
|
||||
|
||||
var newID = actionMenu.add_action(interactionName)
|
||||
actionMenu.action_selected.connect(action_chosen)
|
||||
|
||||
IDs.append(newID)
|
||||
actionFunctions.append(action_function)
|
||||
|
||||
if availabilityCheck != null:
|
||||
actionMenu.add_availability_check(newID, availabilityCheck)
|
||||
|
||||
func action_chosen(ID:int):
|
||||
for i in range(0, IDs.size()):
|
||||
if IDs[i] == ID:
|
||||
var cow = get_tree().get_root().get_node("MainGame/Cow")
|
||||
cow.interact(self, actionFunctions[i], $InteractionArea.global_position)
|
||||
11
Interactions/Interactable/action_menu.tscn
Normal file
11
Interactions/Interactable/action_menu.tscn
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://bln4jur7glsny"]
|
||||
|
||||
[ext_resource type="Script" path="res://Interactions/Interactable/Action_Menu.gd" id="1_3sydg"]
|
||||
|
||||
[node name="ActionMenu" type="Node2D"]
|
||||
script = ExtResource("1_3sydg")
|
||||
|
||||
[node name="PopupMenu" type="PopupMenu" parent="."]
|
||||
size = Vector2i(100, 50)
|
||||
|
||||
[connection signal="id_pressed" from="PopupMenu" to="." method="_on_popup_menu_id_pressed"]
|
||||
25
Interactions/Interactable/interactable.tscn
Normal file
25
Interactions/Interactable/interactable.tscn
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bqibe7ha6r5ls"]
|
||||
|
||||
[ext_resource type="Script" path="res://Interactions/Interactable/Interactable.gd" id="1_wos4h"]
|
||||
[ext_resource type="PackedScene" uid="uid://bln4jur7glsny" path="res://Interactions/Interactable/action_menu.tscn" id="2_qa6qc"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_514te"]
|
||||
|
||||
[node name="Interactable" type="Node2D"]
|
||||
script = ExtResource("1_wos4h")
|
||||
|
||||
[node name="ActionMenu" parent="." instance=ExtResource("2_qa6qc")]
|
||||
|
||||
[node name="PopupMenu" parent="ActionMenu" index="0"]
|
||||
allow_search = false
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
offset_left = -101.0
|
||||
offset_top = -102.0
|
||||
offset_right = 102.0
|
||||
offset_bottom = 103.0
|
||||
theme_override_styles/panel = SubResource("StyleBoxEmpty_514te")
|
||||
|
||||
[connection signal="gui_input" from="Panel" to="." method="_on_panel_gui_input"]
|
||||
|
||||
[editable path="ActionMenu"]
|
||||
11
Interactions/Interactable/interactable_tutorialExit.gd
Normal file
11
Interactions/Interactable/interactable_tutorialExit.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends "res://Interactions/Interactable/Interactable.gd"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
12
Interactions/Interactable/interaction.tscn
Normal file
12
Interactions/Interactable/interaction.tscn
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://c5ded8kcouyci"]
|
||||
|
||||
[ext_resource type="Script" path="res://Interactions/Interactable/Interaction.gd" id="1_421lg"]
|
||||
|
||||
[node name="Interaction" type="Node2D"]
|
||||
script = ExtResource("1_421lg")
|
||||
|
||||
[node name="InteractionArea" type="Area2D" parent="."]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="InteractionArea"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue