Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vote screen and revamped chatbox #252

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5c9359e
Reorganized Chatbox
TheSecondReal0 Dec 3, 2020
770b50e
Created vote screen and reorganized chatbox
TheSecondReal0 Dec 4, 2020
5c0531b
Improved chatbox
TheSecondReal0 Dec 4, 2020
7da8d5b
Misc
TheSecondReal0 Dec 4, 2020
07588dc
infilitrator hud no longer blocks interactpoint buttons
TheSecondReal0 Dec 4, 2020
137b9a2
Added more vote functionality
TheSecondReal0 Dec 7, 2020
5f18f2f
Multiple different chatboxes can be synced and reorganized
TheSecondReal0 Dec 8, 2020
01074f9
Chatbox actually syncs now
TheSecondReal0 Dec 8, 2020
0d81069
Misc work on voteui
TheSecondReal0 Dec 8, 2020
493cfed
Merge remote-tracking branch 'upstream/main' into vote-screen-and-rev…
TheSecondReal0 Dec 8, 2020
1916a71
Misc merge, I don't know how to prevent this
TheSecondReal0 Dec 8, 2020
854cf9b
Merge pull request #1 from opensuspect/main
TheRyeGuyWhoWillNowDie Dec 19, 2020
74ca34a
Merge branch 'main' into vote-screen-and-revamped-chatbox
TheRyeGuyWhoWillNowDie Dec 19, 2020
2ee04ab
Reorganized Chatbox
TheSecondReal0 Dec 3, 2020
e71618e
Created vote screen and reorganized chatbox
TheSecondReal0 Dec 4, 2020
6e0d641
Improved chatbox
TheSecondReal0 Dec 4, 2020
7363ddd
Misc
TheSecondReal0 Dec 4, 2020
41a3bb0
Added more vote functionality
TheSecondReal0 Dec 7, 2020
2e54176
Multiple different chatboxes can be synced and reorganized
TheSecondReal0 Dec 8, 2020
b1bb846
Chatbox actually syncs now
TheSecondReal0 Dec 8, 2020
186fa65
Misc work on voteui
TheSecondReal0 Dec 8, 2020
cf02999
Misc merge, I don't know how to prevent this
TheSecondReal0 Dec 8, 2020
8c9c6eb
disabled movement while chatbox is open
TheSecondReal0 Apr 11, 2021
2b1b8fa
added vote ui interact point to test map
TheSecondReal0 Apr 11, 2021
a115f0a
Merge branch 'rebasing-vote-screen-revamped-chatbox' into vote-screen…
TheSecondReal0 Apr 11, 2021
6fa8bf4
polishing rebase
TheSecondReal0 Apr 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 77 additions & 24 deletions src/assets/autoload/playermanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ extends Node
var inMenu = false
var ourrole
var ournumber
var tasks = [-1]
var taskstoassign
var assignedtasks

# stores messages so they can be shown on multiple chatboxes
var chatbox_cache: Array

#vars for role assignment
#Percent assigns based on what % should be x role, Amount assigns given amount to x role
#mustAssign specifies if the role is mandatory to have, team specifies a team number which
Expand All @@ -14,15 +21,15 @@ var ournumber
#in case of tie (check main.gd for details).
enum assignStyle {Percent, Amount}
var style: int = assignStyle.Percent
var enabledRoles: Array = ["infiltrator", "detective", "agent"]
var roles: Dictionary = {"infiltrator": {"percent": float(2)/7, "amount": 1, "mustAssign": true, "team": 1},
var enabledRoles: Array = ["traitor", "detective", "default"]
var roles: Dictionary = {"traitor": {"percent": float(2)/7, "amount": 1, "mustAssign": true, "team": 1},
"detective": {"percent": float(1)/7, "amount": 1, "mustAssign": false, "team": 0},
"agent": {"percent": 0, "amount": 0, "mustAssign": false, "team": 0}}
"default": {"percent": 0, "amount": 0, "mustAssign": false, "team": 0}}
var players: Dictionary = {}
var playerRoles: Dictionary = {}
var playerColors: Dictionary = {enabledRoles[0]: Color(1,0,0),# infiltrator
var playerColors: Dictionary = {enabledRoles[0]: Color(1,0,0),# traitor
enabledRoles[1]: Color(0,0,1),# detective
enabledRoles[2]: Color(1,1,1)}# agent
enabledRoles[2]: Color(1,1,1)}# default
Comment on lines -17 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official terminology is "infiltrator" and "agent", please don't change it back.

var rng = RandomNumberGenerator.new()
signal roles_assigned

Expand All @@ -31,19 +38,36 @@ func _ready():
# warning-ignore:return_value_discarded
GameManager.connect("state_changed_priority", self, "state_changed_priority")

func assigntasks():
for id in Network.peers:
taskstoassign = tasks
for task in taskstoassign:
if task == -1:
rng.randomize()
taskstoassign[task] = rng.randi_range(-1,0)
print("task assigned,",taskstoassign[task])
if id == 1:
assignedtasks = taskstoassign
print("host tasks assigned",taskstoassign)
else:
rpc_id(id,"gettasks",taskstoassign)
print("client tasks assigned",taskstoassign)

remote func gettasks(tasksget):
assignedtasks = tasksget
print("we got our tasks!")

# warning-ignore:unused_argument
func state_changed_priority(old_state: int, new_state: int, priority: int):
if priority != 3:
if priority != 2:
return
print("(playermanager.gd/state_changed_priority)")
match new_state:
GameManager.State.Normal:
assignRoles(Network.get_peers())
GameManager.State.Lobby:
TaskManager.reset_tasks()
#revoke special roles when players move to lobby
for i in playerRoles.keys():
playerRoles[i] = "agent"
playerRoles[i] = "default"
emit_signal("roles_assigned", playerRoles)

func assignRoles(players: Array):
Expand All @@ -56,27 +80,27 @@ func assignRoles(players: Array):
toAssign.shuffle()
#print(toAssign)
var playerAmount = toAssign.size()
TaskManager.assign_tasks()
assigntasks()

#if using percent, find how many of each role to assign
if style == assignStyle.Percent:
for i in enabledRoles:
if not roles.keys().has(i) or i == "agent":
if not roles.keys().has(i) or i == "default":
continue
#rounds down to be more predictable, if percent is 1/7th, role won't be assigned until there are 7 players
roles[i].amount = roundDown(roles[i].percent * playerAmount, 1)
if roles[i].amount < 1 and roles[i].mustAssign:
roles[i].amount = 1

# of players that aren't going to be assigned to a special role
var agents = playerAmount
var defaults = playerAmount
for i in enabledRoles:
if not roles.keys().has(i) or i == "agent":
if not roles.keys().has(i) or i == "default":
continue
agents -= roles[i].amount
if agents < 0:
agents = 0
roles.agent.amount = agents
defaults -= roles[i].amount
if defaults < 0:
defaults = 0
roles.default.amount = defaults
#print("roles: ", roles)

#actually assign roles
Expand All @@ -101,13 +125,6 @@ func roundDown(num, step):
return normRound - step
return normRound

#TODO recieve a signal that initiates the application of customization to a player sprite.

func getPlayerById(id) -> KinematicBody2D:
if players.has(id):
return players[id]
return null

func get_main_player() -> KinematicBody2D:
"""Gets the main player on the local client."""
for player in players.values():
Expand Down Expand Up @@ -145,3 +162,39 @@ func setourrole():
ourrole = PlayerManager.get_player_role(Network.myID)
print(ourrole)
emit_signal("roles_assigned", playerRoles)

signal message_received(sender, content, color)
signal message_received_server(sender, content, color)
signal bulk_messages_received(messages)

func send_message(content: String, color):
print("message sent")
if get_tree().is_network_server():
# sender is 1 because the server always has a network ID of 1
send_message_server(1, content, color)
rpc_id(1, "receive_message_server", Network.get_my_id(), content, color)

# used by the server to sync messages, not to send messages written by the host player
func send_message_server(sender: int, content: String, color):
print("message sent server")
if not get_tree().is_network_server():
return
rpc("receive_message", sender, content, color)

puppet func receive_message(sender: int, content: String, color):
print("message received")
emit_signal("message_received", sender, content, color)

remote func receive_message_server(sender: int, content: String, color):
print("message received server")
if not get_tree().is_network_server():
return
if get_tree().get_rpc_sender_id() != sender:
return
emit_signal("message_received_server", sender, content, color)

func send_bulk_messages(messages):
rpc("receive_bulk_messages", messages)

puppet func receive_bulk_messages(messages: Array):
emit_signal("bulk_messages_received", messages)
41 changes: 14 additions & 27 deletions src/assets/autoload/uimanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ var ui_list: Dictionary = {
"interactui": {"scene": preload("res://assets/ui/hud/interactui/interactui.tscn")},
"killui": {"scene": preload("res://assets/ui/hud/infiltrator_hud/infiltrator_hud.tscn")},
"rolescreen": {"scene": preload("res://assets/ui/hud/defaulthud/rolescreen/rolescreen.tscn")},

#common UI
"pausemenu": {"scene": preload("res://assets/ui/pausemenu/pausemenu.tscn")},
"chatbox": {"scene": preload("res://assets/ui/lobbyui/chatbox/chatbox.tscn")},
"pausemenu": {"scene": preload("res://assets/ui/pausemenu/pausemenu.tscn")},
"keybind": {"scene": preload("res://assets/ui/submenus/settings/keybind/keybind.tscn")},
"appearance_editor": {"scene": preload("res://assets/ui/submenus/appearance_editor/appearance_editor.tscn")},


#lobby UI
"chatbox": {"scene": preload("res://assets/ui/lobbyui/chatbox/chatbox.tscn")},
"voteui": {"scene": preload("res://assets/ui/lobbyui/voteui/voteui.tscn")},

#task UI
"clockset": {"scene": preload("res://assets/ui/tasks/clockset/clockset.tscn")}
}
Expand All @@ -33,9 +36,7 @@ var ui_controller_node: Node
signal open_ui(ui_name, ui_data, reinstance)
signal close_ui(ui_name, free)
signal instance_ui(ui_name, ui_data)
signal update_ui(ui_name, ui_data)
signal free_ui(ui_name)
signal close_all_ui()

func _ready():
configfile = ConfigFile.new()
Expand All @@ -51,10 +52,8 @@ func _ready():
else:
keybinds[key] = null
set_game_binds()
# warning-ignore:return_value_discarded
# warning-ignore:return_value_discarded
GameManager.connect("state_changed", self, "state_changed")
# warning-ignore:return_value_discarded
GameManager.connect("state_changed_priority", self, "state_changed_priority")

#ui data is data to pass to the ui, such as a task identifier
#reinstance is whether or not to recreate the corresponding ui node if it already exists
Expand All @@ -75,19 +74,11 @@ func instance_ui(ui_name: String, ui_data: Dictionary = {}):
push_error("instance_ui() called with invalid ui name " + ui_name)
emit_signal("instance_ui", ui_name, ui_data)

func update_ui(ui_name: String, ui_data: Dictionary = {}):
if not ui_list.keys().has(ui_name):
push_error("update_ui() called with invalid ui name " + ui_name)
emit_signal("update_ui", ui_name, ui_data)
Comment on lines -78 to -81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these functions here removed?


func free_ui(ui_name: String):
if not ui_list.keys().has(ui_name):
push_error("free_ui() called with invalid ui name " + ui_name)
emit_signal("free_ui", ui_name)

func close_all_ui(free: bool = false):
emit_signal("close_all_ui", free)

func get_ui(ui_name: String):
if not ui_list.keys().has(ui_name):
push_error("get_ui() called with invalid ui name " + ui_name)
Expand All @@ -110,15 +101,11 @@ func ui_closed(menuName):

# warning-ignore:unused_argument
func state_changed(old_state, new_state):
if new_state == GameManager.State.Normal:
pass
if new_state == GameManager.State.Start:
open_uis = []

func state_changed_priority(old_state, new_state, priority):
if priority != 0:
return
if new_state == GameManager.State.Normal:
# needs to call _on_ready to connect signals, before roles are assigned
open_ui("rolescreen")
Comment on lines -115 to -121
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By deleting this, the rolescreen doesn't appear in the end of the turn


func in_ui() -> bool:
return not open_uis.empty()

Expand All @@ -142,12 +129,12 @@ func set_game_binds():#Set new binds
#Erases the key binds of previous action
# warning-ignore:void_assignment
erase = InputMap.action_erase_events(key)

if value != null:
var new_key = InputEventKey.new()
new_key.set_scancode(value)
InputMap.action_add_event(key, new_key)

#print(keybinds)

func write_config():
Expand All @@ -167,7 +154,7 @@ func write_keybinds():
configFile.set_value("Keybinds","ui_down",int(83))
configFile.set_value("Keybinds","ui_left",int(65))
configFile.set_value("Keybinds","ui_right",int(68))

configFile.save(file)

# warning-ignore:shadowed_variable
Expand Down
Binary file modified src/assets/common/themes/iso_dark.theme
Binary file not shown.
79 changes: 74 additions & 5 deletions src/assets/maps/test/test.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=28 format=2]
[gd_scene load_steps=33 format=2]

[ext_resource path="res://assets/common/textures/icons/spawnpad.png" type="Texture" id=1]
[ext_resource path="res://assets/maps/common/dynamic/testdoor/testdoor.tscn" type="PackedScene" id=2]
Expand Down Expand Up @@ -27,7 +27,7 @@ interact_data = {
}
advanced/network_sync = false

[sub_resource type="Resource" id=12]
[sub_resource type="Resource" id=2]
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 11 )
Expand All @@ -44,7 +44,7 @@ resource_local_to_scene = true
resource_name = "InteractTask"
script = ExtResource( 8 )
task_text = ""
ui_resource = SubResource( 12 )
ui_resource = SubResource( 2 )
outputs/toggle_map_interactions = false
outputs/output_map_interactions = [ ]
is_task_global = false
Expand Down Expand Up @@ -90,7 +90,7 @@ interact_data = {
}
advanced/network_sync = false

[sub_resource type="Resource" id=13]
[sub_resource type="Resource" id=8]
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 11 )
Expand All @@ -106,7 +106,7 @@ advanced/free_on_close = false
resource_local_to_scene = true
script = ExtResource( 8 )
task_text = ""
ui_resource = SubResource( 13 )
ui_resource = SubResource( 8 )
outputs/toggle_map_interactions = false
outputs/output_map_interactions = [ ]
is_task_global = false
Expand All @@ -130,6 +130,59 @@ task_resource = SubResource( 9 )
ui_resource = SubResource( 10 )
map_resource = SubResource( 7 )

[sub_resource type="Resource" id=12]
resource_local_to_scene = true
resource_name = "InteractMap"
script = ExtResource( 10 )
interact_with = NodePath("")
interact_data = {

}
advanced/network_sync = false

[sub_resource type="Resource" id=13]
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 11 )
ui_name = ""
ui_data = {

}
action = 0
advanced/reinstance = false
advanced/free_on_close = false

[sub_resource type="Resource" id=14]
resource_local_to_scene = true
resource_name = "InteractTask"
script = ExtResource( 8 )
task_text = ""
ui_resource = SubResource( 13 )
outputs/toggle_map_interactions = false
outputs/output_map_interactions = [ ]
is_task_global = false

[sub_resource type="Resource" id=15]
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 11 )
ui_name = "voteui"
ui_data = {

}
action = 0
advanced/reinstance = false
advanced/free_on_close = false

[sub_resource type="Resource" id=16]
resource_local_to_scene = true
resource_name = "Interact"
script = ExtResource( 9 )
interact_type = 1
task_resource = SubResource( 14 )
ui_resource = SubResource( 15 )
map_resource = SubResource( 12 )

[node name="test" type="YSort"]
script = ExtResource( 15 )

Expand Down Expand Up @@ -227,6 +280,22 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="voteui" parent="." instance=ExtResource( 5 )]
position = Vector2( 0, 150 )
interact_resource = SubResource( 16 )
display_text = "Vote UI"

[node name="Label" type="Label" parent="voteui"]
margin_left = -40.0
margin_top = -20.0
margin_right = 40.0
text = "Vote UI"
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}

[node name="SpawnPoints" type="Node2D" parent="."]

[node name="Position2D" type="Position2D" parent="SpawnPoints"]
Expand Down
Loading