-
Notifications
You must be signed in to change notification settings - Fork 838
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Squad transfer tablet * Removes toggle right click button * Revert "Removes toggle right click button" This reverts commit 815da8d. * Psy + lumi reviews --------- Co-authored-by: TiviPlus <[email protected]>
- Loading branch information
Showing
5 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/obj/item/squad_transfer_tablet | ||
name = "squad transfer tablet" | ||
desc = "A tablet for quickly transfering the squaddies from under one incompetent squad leader to another." | ||
icon = 'icons/Marine/marine-navigation.dmi' | ||
icon_state = "req_tablet_off" | ||
flags_equip_slot = ITEM_SLOT_POCKET | ||
w_class = WEIGHT_CLASS_SMALL | ||
interaction_flags = INTERACT_MACHINE_TGUI | ||
/// REF()s for all currently active transfering marines | ||
var/list/active_requests = list() | ||
|
||
/obj/item/squad_transfer_tablet/ui_interact(mob/user, datum/tgui/ui) | ||
ui = SStgui.try_update_ui(user, src, ui) | ||
if(!ui) | ||
ui = new(user, src, "SquadTransfer", name) | ||
ui.open() | ||
|
||
/obj/item/squad_transfer_tablet/ui_data(mob/user) | ||
var/list/data = list() | ||
data["active_squads"] = list() | ||
for(var/datum/squad/squad AS in SSjob.active_squads[user.faction]) | ||
var/list/mob/living/carbon/human/members = list() | ||
for(var/mob/living/carbon/human/member AS in squad.get_all_members()) | ||
members[member.real_name] = REF(member) | ||
|
||
data["active_squads"] += list(list("name" = squad.name, "id" = squad.id, "color" = squad.color, "members" = members)) | ||
data["active_requests"] = active_requests | ||
return data | ||
|
||
/obj/item/squad_transfer_tablet/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state) | ||
. = ..() | ||
if(.) | ||
return | ||
if(!ishuman(usr)) | ||
return | ||
var/mob/living/carbon/human/human_user = usr | ||
if(!ismarineleaderjob(human_user.job) && !issommarineleaderjob(human_user.job) && !ismarinecommandjob(human_user.job) && !issommarinecommandjob(human_user.job)) | ||
to_chat(human_user, span_notice("Only command roles my request squad changes!")) | ||
return FALSE | ||
if(action != "transfer") | ||
return FALSE | ||
if(params["transfer_target"] in active_requests) | ||
to_chat(human_user, span_info("Target cannot be transfered: Transfer request already active.")) | ||
return FALSE | ||
var/mob/living/carbon/human/target = locate(params["transfer_target"]) | ||
if(!istype(target)) | ||
to_chat(human_user, span_info("Target cannot be transfered: Target error.")) | ||
return FALSE | ||
var/new_squad_id = params["squad_id"] | ||
var/datum/squad/new_squad = SSjob.squads[new_squad_id] | ||
if(!new_squad) | ||
to_chat(human_user, span_info("Target cannot be transfered: Squad error.")) | ||
return FALSE | ||
to_chat(human_user, span_info("Transfer request sent.")) | ||
active_requests += params["transfer_target"] | ||
INVOKE_ASYNC(src, PROC_REF(process_transfer), target, new_squad, human_user) | ||
return TRUE | ||
|
||
///handles actual transfering of squaddies, async so ui act doesnt sleep | ||
/obj/item/squad_transfer_tablet/proc/process_transfer(mob/living/carbon/human/target, datum/squad/new_squad, mob/living/carbon/human/user) | ||
if(tgui_alert(target, "Would you like to transfer to [new_squad.name]? [new_squad.desc ? "Description: [new_squad.desc]" : ""]", "Requested squad Transfer to [new_squad.name]", list("Yes", "No"), 10 SECONDS) != "Yes") | ||
active_requests -= REF(target) | ||
log_game("[key_name(target)] has rejected a squad transfer request to [new_squad.name] from [key_name(user)].") | ||
to_chat(user, span_notice("[target.real_name] has rejected your transfer request")) | ||
return | ||
log_game("[key_name(target)] has accepted a squad transfer request to [new_squad.name] from [key_name(user)].") | ||
to_chat(user, span_notice("[target.real_name] has accepted your transfer request")) | ||
target.change_squad(new_squad.id) | ||
active_requests -= REF(target) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Stack, Button, Section } from '../components'; | ||
import { Window } from '../layouts'; | ||
import { useBackend, useLocalState } from '../backend'; | ||
|
||
type SquadSelectorData = { | ||
active_squads?: SquadEntry[]; | ||
active_requests?: string[]; | ||
}; | ||
|
||
type SquadEntry = { | ||
name: string; | ||
id: string; | ||
color: string; | ||
members?: string[]; | ||
}; | ||
|
||
export const SquadTransfer = (props, context) => { | ||
const { act, data } = useBackend<SquadSelectorData>(context); | ||
const { active_squads } = data; | ||
const [selectedSquad, setSelectedSquad] = useLocalState<string>( | ||
context, | ||
'selectedSquad', | ||
'' | ||
); | ||
|
||
const [selectedMember, setSelectedMember] = useLocalState<string>( | ||
context, | ||
'selectedMember', | ||
'' | ||
); | ||
|
||
const selectedSquadEntry = active_squads?.find( | ||
(i) => i.name === selectedSquad | ||
); | ||
|
||
return ( | ||
<Window width={380} height={360}> | ||
<Window.Content> | ||
<Stack> | ||
<Stack.Item> | ||
<Section title={'Transfer from'} width={'120px'}> | ||
<Stack vertical> | ||
{active_squads?.map((squad) => ( | ||
<Stack.Item key={squad.name}> | ||
<Button | ||
width={'110px'} | ||
onClick={() => setSelectedSquad(squad.name)} | ||
backgroundColor={ | ||
selectedSquad === squad.name ? null : squad.color | ||
} | ||
selected={selectedSquad === squad.name}> | ||
{squad.name} | ||
</Button> | ||
</Stack.Item> | ||
))} | ||
</Stack> | ||
</Section> | ||
</Stack.Item> | ||
<Stack.Item> | ||
<Section title={'Transfered'} width={'120px'}> | ||
<Stack vertical> | ||
{selectedSquadEntry?.members | ||
? Object.keys(selectedSquadEntry.members).map((name) => ( | ||
<Stack.Item key={name}> | ||
<Button | ||
width={'110px'} | ||
onClick={() => setSelectedMember(name)} | ||
selected={selectedMember === name}> | ||
{name} | ||
</Button> | ||
</Stack.Item> | ||
)) | ||
: null} | ||
</Stack> | ||
</Section> | ||
</Stack.Item> | ||
<Stack.Item> | ||
<Section title={'Transfer to'} width={'120px'}> | ||
<Stack vertical> | ||
{active_squads?.map((squad) => ( | ||
<Stack.Item key={squad.name}> | ||
<Button | ||
width={'110px'} | ||
onClick={() => | ||
act('transfer', { | ||
transfer_target: | ||
selectedSquadEntry?.members?.[selectedMember], | ||
squad_id: squad?.id, | ||
}) | ||
} | ||
backgroundColor={ | ||
selectedSquad === squad.name ? null : squad.color | ||
} | ||
disabled={selectedSquad === squad.name}> | ||
{squad.name} | ||
</Button> | ||
</Stack.Item> | ||
))} | ||
</Stack> | ||
</Section> | ||
</Stack.Item> | ||
</Stack> | ||
</Window.Content> | ||
</Window> | ||
); | ||
}; |