From c4324182eca277be19a75b8551182937124f2e6a Mon Sep 17 00:00:00 2001 From: copygirl Date: Mon, 17 Apr 2023 11:39:40 +0200 Subject: [PATCH] Add crosshair --- assets/crosshair.png | Bin 0 -> 725 bytes assets/crosshair.png.import | 34 ++++++++++++++++++++++++++++++++++ scenes/Main.tscn | 29 ++++++++++++++++++++++++++++- scripts/Crosshair.gd | 4 ++++ scripts/PickupController.gd | 2 ++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 assets/crosshair.png create mode 100644 assets/crosshair.png.import create mode 100644 scripts/Crosshair.gd diff --git a/assets/crosshair.png b/assets/crosshair.png new file mode 100644 index 0000000000000000000000000000000000000000..8e6387f9665fd8e63a12b31a5e51ed69fefcceed GIT binary patch literal 725 zcmV;`0xJE9P)EX>4Tx04R}tkv&MmKpe$i(@Kj}MC>5qkfAzR2Nmh4RVYG*P%E_RU~=gfG-*gu zTpR`0f`cE6RRrd-(Wz7vovp=l&dhYTjaiPb8jYhG`RT5YKGd z2Iqa^2rJ1d@j3ChNf#u3x1ki;UEAVGwJ8p^1^MvPXS6botEPk8u;UB5&wg<_X|`2CnpuzuExepQP72 zTJ#9$-v%zOJDRcwTgF6bium8GTa@7`z2~*IK=`_i_3FWT>mu4RCM> zj1?(+-Q(S%?%w`A)9&vF;vI6+3R4KX00006VoOIv0RI600RN!9r;`8x010qNS#tmY zE+YT{E+YYWr9XB6000McNliru=L8W6Bne$rbu9n@02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{006B?L_t(Y$L&_j4g?_x1LFUG5qw+cwsErA%mB@Du{Wbq zP#zUI7=Z2z0QhXEDvRWoUHkGzRU+bcp-UVQ@)!#MxI07y?vAblX?rXO%67UAv;(Lb zpnctLC`101SgU2iIIry5&A?h6s@aE32C=G7&G>@Ved>Lkt*TW>v>P#L1eCJ9)&EBm z&YIEl#KgZloKb`TTab)RwXu0VresDnTt)~m1j(pwKN!IUaz=n~qV38a00000NkvXX Hu0mjf7X&jU literal 0 HcmV?d00001 diff --git a/assets/crosshair.png.import b/assets/crosshair.png.import new file mode 100644 index 0000000..39777bf --- /dev/null +++ b/assets/crosshair.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dkc0fn50ueqc5" +path="res://.godot/imported/crosshair.png-7a5ee98d03b748045923e3a0fa977b20.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/crosshair.png" +dest_files=["res://.godot/imported/crosshair.png-7a5ee98d03b748045923e3a0fa977b20.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 diff --git a/scenes/Main.tscn b/scenes/Main.tscn index a1e7152..24be565 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -1,8 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://bn6y24u16jtdj"] +[gd_scene load_steps=7 format=3 uid="uid://bn6y24u16jtdj"] [ext_resource type="PackedScene" uid="uid://b7o2y54duqxft" path="res://scenes/World.tscn" id="1_px6sj"] [ext_resource type="Shader" path="res://shaders/outline.gdshader" id="2_dd8cf"] [ext_resource type="Script" path="res://scripts/CloneMainCamera.gd" id="2_m7qgc"] +[ext_resource type="Texture2D" uid="uid://dkc0fn50ueqc5" path="res://assets/crosshair.png" id="4_6ai7y"] +[ext_resource type="Script" path="res://scripts/Crosshair.gd" id="5_mrx5k"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_7rvwk"] shader = ExtResource("2_dd8cf") @@ -31,3 +33,28 @@ render_target_update_mode = 4 [node name="ClonedCamera" type="Camera3D" parent="SubViewportContainer/OutlineViewport"] cull_mask = 2 script = ExtResource("2_m7qgc") + +[node name="HUD" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 1 + +[node name="Crosshair" type="TextureRect" parent="HUD"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -10.5 +offset_top = -10.5 +offset_right = 10.5 +offset_bottom = 10.5 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("4_6ai7y") +script = ExtResource("5_mrx5k") diff --git a/scripts/Crosshair.gd b/scripts/Crosshair.gd new file mode 100644 index 0000000..87e48ff --- /dev/null +++ b/scripts/Crosshair.gd @@ -0,0 +1,4 @@ +extends TextureRect + +func _process(_delta: float) -> void: + visible = Input.mouse_mode == Input.MOUSE_MODE_CAPTURED diff --git a/scripts/PickupController.gd b/scripts/PickupController.gd index 3016543..7ff6371 100644 --- a/scripts/PickupController.gd +++ b/scripts/PickupController.gd @@ -17,6 +17,8 @@ func _ready() -> void: func _input(event: InputEvent) -> void: + if Input.mouse_mode != Input.MOUSE_MODE_CAPTURED: return + ensure_current_item_valid() if !current_item: return