Add item boxes, add asking

This commit is contained in:
Hamcha 2020-07-28 09:54:04 +02:00
parent 9383bc9803
commit a01a0215cd
Signed by: Hamcha
GPG Key ID: 41467804B19A3315
13 changed files with 356 additions and 3 deletions

BIN
Graphics/UI/handicons.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/handicons.png-8c76520aab77ec37eaad0980d02800ac.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Graphics/UI/handicons.png"
dest_files=[ "res://.import/handicons.png-8c76520aab77ec37eaad0980d02800ac.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
Graphics/UI/selected.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/selected.png-edb67f7b3e4969e516febc7f79b42937.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Graphics/UI/selected.png"
dest_files=[ "res://.import/selected.png-edb67f7b3e4969e516febc7f79b42937.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/midnight.png-3d811938da348be9b831f07b37a9d5f1.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Graphics/tgstation/midnight.png"
dest_files=[ "res://.import/midnight.png-3d811938da348be9b831f07b37a9d5f1.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -13,10 +13,18 @@ enum PopupName {
onready var logs = $Logs
onready var inspect_box = $InspectBox as RichTextLabel
onready var item_slots_container = $ItemSlots
onready var map_popup = $MapPopup
onready var sever_info_popup = $ServerInfoPopup
onready var scene = $"/root/scene"
onready var netgame = $"/root/Multiplayer"
const ItemBox = preload("res://Scenes/UI/Items/ItemBox.tscn")
var left_selected = null
var right_selected = null
const WHISPER_RADIUS = 32*3
const CHAT_RADIUS = 32*10
const SHOUT_RADIUS = 32*14
@ -30,6 +38,26 @@ func _ready() -> void:
serverMenu.connect("id_pressed", self, "_server_option_chosen")
serverMenu.add_item("Server info", ServerMenuItem.ServerInfo)
# Create item slots
for slot_id in range(4):
var item_slot = ItemBox.instance()
# By default, slot 2/3 are L/R, and 2 is selected
match slot_id:
1:
item_slot.selected = true
item_slot.current_hand = UIItemBox.CurrentHand.Left
left_selected = item_slot
2:
item_slot.current_hand = UIItemBox.CurrentHand.Right
right_selected = item_slot
# Connect signals
item_slot.connect("selected", self, "_itembox_selected", [item_slot])
item_slot.connect("used_in_hand", self, "_itembox_used", [item_slot])
item_slots_container.add_child(item_slot)
func _physics_process(_delta: float) -> void:
if inspect_mode:
var mouse_pos = scene.world.get_local_mouse_position() * scene.world.scale
@ -75,10 +103,13 @@ func close_popup(popup_name) -> void:
pass
const say_format = "%s says \"%s\"\n"
const ask_format = "%s asks \"%s\"\n"
const shout_format = "%s shouts \"[b]%s[/b]\"\n"
const whisper_format = "[i]%s whispers \"%s\"[/i]\n"
func _send_chat(text: String) -> void:
var escaped_text = text.replace("[", "[\u8203") # Hacky way to escape BBCode
var escaped_text = text.replace("[", "[\u8203").strip_edges() # Hacky way to escape BBCode
if text.ends_with("?"):
scene.rpc("broadcast_zone", ask_format % [netgame.player_name, escaped_text], scene.world.player.global_position, SHOUT_RADIUS)
if text.ends_with("!!"):
scene.rpc("broadcast_zone", shout_format % [netgame.player_name, escaped_text], scene.world.player.global_position, SHOUT_RADIUS)
elif text.begins_with("#"):
@ -93,11 +124,72 @@ func set_inspect(active: bool) -> void:
inspect_box.rect_global_position = get_viewport().get_mouse_position() + inspect_offset
func _input(event: InputEvent) -> void:
var no_popups = not check_popups()
if event.is_action_released("inspect"):
set_inspect(false)
elif event.is_action_pressed("inspect"):
set_inspect(true)
elif event.is_action_pressed("ui_scroll_left") and no_popups:
select_next_box(-1, Input.is_action_pressed("alt_hand"))
elif event.is_action_pressed("ui_scroll_right") and no_popups:
select_next_box(1, Input.is_action_pressed("alt_hand"))
elif event.is_action_pressed("swap_hands"):
swap_hands()
elif event is InputEventMouseMotion:
var mousemotion = event as InputEventMouseMotion
if inspect_mode:
inspect_box.rect_global_position = mousemotion.position + inspect_offset
func _itembox_selected(hand, item_box: UIItemBox) -> void:
left_selected.selected = false
right_selected.selected = false
match hand:
UIItemBox.CurrentHand.Left:
if item_box.current_hand != UIItemBox.CurrentHand.None:
left_selected.current_hand = item_box.current_hand
match item_box.current_hand:
UIItemBox.CurrentHand.Right:
right_selected = left_selected
else:
left_selected.current_hand = UIItemBox.CurrentHand.None
left_selected = item_box
UIItemBox.CurrentHand.Right:
if item_box.current_hand != UIItemBox.CurrentHand.None:
right_selected.current_hand = item_box.current_hand
match item_box.current_hand:
UIItemBox.CurrentHand.Left:
left_selected = right_selected
else:
right_selected.current_hand = UIItemBox.CurrentHand.None
right_selected = item_box
item_box.selected = true
item_box.current_hand = hand
func _itembox_used(item_box) -> void:
pass
func check_popups() -> bool:
return map_popup.visible or sever_info_popup.visible
func select_next_box(direction: int, right_hand: bool) -> void:
var box = left_selected as UIItemBox
if right_hand:
box = right_selected
var parent = box.get_parent()
var child_count = parent.get_child_count()
var index = box.get_index()
index += direction
if index < 0:
index = child_count + index
elif index >= child_count:
index -= child_count
var hand = UIItemBox.CurrentHand.Left
if right_hand:
hand = UIItemBox.CurrentHand.Right
_itembox_selected(hand, parent.get_child(index))
func swap_hands() -> void:
if left_selected.selected:
_itembox_selected(UIItemBox.CurrentHand.Left, right_selected)
else:
_itembox_selected(UIItemBox.CurrentHand.Right, left_selected)

View File

@ -189,6 +189,18 @@ scroll_active = false
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ItemSlots" type="HBoxContainer" parent="."]
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_top = -100.0
margin_bottom = -50.0
rect_scale = Vector2( 2, 2 )
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="chat_message_sent" from="Logs" to="." method="_send_chat"]
[connection signal="focus_entered" from="Logs/ResizablePanel/LineEdit" to="Logs" method="_chat_bar_status" binds= [ true ]]
[connection signal="focus_exited" from="Logs/ResizablePanel/LineEdit" to="Logs" method="_chat_bar_status" binds= [ false ]]

View File

@ -0,0 +1,64 @@
extends TextureRect
class_name UIItemBox
signal selected(hand)
signal used_in_hand()
enum CurrentHand {
None,
Left,
Right
}
var hovering = false
export var selected = false setget set_selected
export(CurrentHand) var current_hand = CurrentHand.None setget set_hand
const LEFT_Y_OFFSET = 0
const RIGHT_Y_OFFSET = 10
onready var hand_icon = $HandIcon
func _ready():
hand_icon.texture = hand_icon.texture.duplicate()
set_hand(current_hand)
func _mouse_hover(inside: bool) -> void:
hovering = inside
if hovering:
self_modulate.a = 1
else:
self_modulate.a = 0.86
func set_selected(val: bool) -> void:
selected = val
$SelectedOverlay.visible = selected
func set_hand(hand):
current_hand = hand
if hand_icon != null:
match hand:
CurrentHand.None:
hand_icon.visible = false
CurrentHand.Left:
hand_icon.visible = true
(hand_icon.texture as AtlasTexture).region.position.y = LEFT_Y_OFFSET
CurrentHand.Right:
hand_icon.visible = true
(hand_icon.texture as AtlasTexture).region.position.y = RIGHT_Y_OFFSET
func _gui_input(event):
if event is InputEventMouseButton:
var mouse_event = event as InputEventMouseButton
if mouse_event.pressed:
if mouse_event.button_index == BUTTON_LEFT:
if current_hand != CurrentHand.Left:
emit_signal("selected", CurrentHand.Left)
else:
emit_signal("used_in_hand")
elif mouse_event.button_index == BUTTON_RIGHT:
if current_hand != CurrentHand.Right:
emit_signal("selected", CurrentHand.Right)
else:
emit_signal("used_in_hand")

View File

@ -0,0 +1,53 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://Graphics/tgstation/midnight.png" type="Texture" id=1]
[ext_resource path="res://Scenes/UI/Items/ItemBox.gd" type="Script" id=2]
[ext_resource path="res://Graphics/UI/selected.png" type="Texture" id=3]
[ext_resource path="res://Graphics/UI/handicons.png" type="Texture" id=4]
[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 1 )
region = Rect2( 32, 32, 32, 32 )
margin = Rect2( 2, 2, 4, 4 )
[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 4 )
region = Rect2( 1, 0, 21, 9 )
margin = Rect2( 2, 2, 4, 4 )
[node name="ItemBox" type="TextureRect"]
self_modulate = Color( 1, 1, 1, 0.862745 )
margin_left = -1.0
margin_right = 35.0
margin_bottom = 53.0
mouse_default_cursor_shape = 2
texture = SubResource( 1 )
stretch_mode = 4
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SelectedOverlay" type="TextureRect" parent="."]
visible = false
modulate = Color( 1, 1, 1, 0.5 )
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
texture = ExtResource( 3 )
stretch_mode = 4
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HandIcon" type="TextureRect" parent="."]
visible = false
anchor_right = 1.0
margin_left = -0.176781
margin_top = -5.0
margin_right = -0.176781
mouse_filter = 2
texture = SubResource( 2 )
stretch_mode = 6
[connection signal="mouse_entered" from="." to="." method="_mouse_hover" binds= [ true ]]
[connection signal="mouse_exited" from="." to="." method="_mouse_hover" binds= [ false ]]

View File

@ -109,3 +109,4 @@ script = ExtResource( 4 )
background = ExtResource( 2 )
font = ExtResource( 3 )
[connection signal="about_to_show" from="." to="MarginContainer/VBoxContainer/Map" method="_reset_position"]
[connection signal="popup_hide" from="." to="MarginContainer/VBoxContainer/Map" method="_on_hide"]

View File

@ -27,6 +27,7 @@ var text_two_lines = false
onready var scene = $"/root/scene"
onready var speed_text = $"../HBoxContainer/HBoxContainer/CurrentSpeed"
onready var dir_text = $"../HBoxContainer/HBoxContainer/CurrentAngle"
onready var popup = $"../../.."
var last_pos = []
@ -139,7 +140,6 @@ func _input(event):
return
func update_font():
print(cell_size)
text_two_lines = cell_size < 70
if cell_size < 100:
font.size = 11
@ -152,3 +152,6 @@ func _recalc_offset(mult: float):
func _reset_position():
set_position = true
func _on_hide():
popup.visible = false

View File

@ -123,6 +123,11 @@ _global_script_classes=[ {
"class": "UICommand",
"language": "GDScript",
"path": "res://Classes/UICommand.gd"
}, {
"base": "TextureRect",
"class": "UIItemBox",
"language": "GDScript",
"path": "res://Scenes/UI/Items/ItemBox.gd"
} ]
_global_script_class_icons={
"ActivationRange": "",
@ -147,7 +152,8 @@ _global_script_class_icons={
"ProbeArea": "",
"ProbeElectric": "",
"ResourceQueue": "",
"UICommand": ""
"UICommand": "",
"UIItemBox": ""
}
[application]
@ -241,6 +247,26 @@ ui_zoomout={
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null)
]
}
ui_scroll_left={
"deadzone": 0.5,
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":4,"pressed":false,"doubleclick":false,"script":null)
]
}
ui_scroll_right={
"deadzone": 0.5,
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":5,"pressed":false,"doubleclick":false,"script":null)
]
}
alt_hand={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null)
]
}
swap_hands={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":88,"unicode":0,"echo":false,"script":null)
]
}
[layer_names]