VR+tgui additions:

* Adds "VR Sleepers" which allow the user to enter a virtual body in a virtual world (it's basically a glorified teleporter)
* Allows tgui to process fontawesome icons in stacks, fontawesome icons can stack over each other to fake a new icon (eg a ban icon over a camera to mean "ban cameras")
* tgui buttons are now a MINIMUM of 20px high, as opposed to being permanently 20px high, this is so that large fontawesome icons don't look hideous.
This commit is contained in:
Remie Richards
2016-07-17 13:03:01 +01:00
parent c6033b06a2
commit 1bdbf16ea3
8 changed files with 324 additions and 18 deletions
+55
View File
@@ -0,0 +1,55 @@
/mob/living/carbon/human/virtual_reality
var/mob/living/carbon/human/real_me //The human controlling us, can be any human (including virtual ones... inception...)
var/obj/machinery/vr_sleeper/vr_sleeper
var/datum/action/quit_vr/quit_action
/mob/living/carbon/human/virtual_reality/New()
..()
quit_action = new()
quit_action.Grant(src)
/mob/living/carbon/human/virtual_reality/death()
revert_to_reality()
..()
/mob/living/carbon/human/virtual_reality/Destroy()
revert_to_reality()
return ..()
/mob/living/carbon/human/virtual_reality/ghost()
set category = "OOC"
set name = "Ghost"
set desc = "Relinquish your life and enter the land of the dead."
var/mob/living/carbon/human/H = real_me
revert_to_reality(FALSE, FALSE)
if(H)
H.ghost()
/mob/living/carbon/human/virtual_reality/proc/revert_to_reality(refcleanup = TRUE, deathchecks = TRUE)
if(real_me && mind)
mind.transfer_to(real_me)
if(deathchecks && vr_sleeper && vr_sleeper.you_die_in_the_game_you_die_for_real)
real_me.death(0)
if(refcleanup)
vr_sleeper.vr_human = null
vr_sleeper = null
real_me = null
/datum/action/quit_vr
name = "Quit Virtual Reality"
/datum/action/quit_vr/Trigger()
if(..())
if(istype(owner, /mob/living/carbon/human/virtual_reality))
var/mob/living/carbon/human/virtual_reality/VR = owner
VR.revert_to_reality(FALSE, FALSE)
else
Remove(owner)
+175
View File
@@ -0,0 +1,175 @@
//Glorified teleporter that puts you in a new human body.
// it's """VR"""
/obj/machinery/vr_sleeper
name = "virtual reality sleeper"
desc = "a sleeper modified to alter the subconscious state of the user, allowing them to visit virtual worlds"
icon = 'icons/obj/Cryogenic2.dmi'
icon_state = "sleeper"
state_open = TRUE
anchored = TRUE
var/you_die_in_the_game_you_die_for_real = FALSE
var/datum/effect_system/spark_spread/sparks
var/mob/living/carbon/human/virtual_reality/vr_human
var/static/list/available_vr_spawnpoints
var/vr_category = "default" //Specific category of spawn points to pick from
var/allow_creating_vr_humans = TRUE //So you can have vr_sleepers that always spawn you as a specific person or 1 life/chance vr games
/obj/machinery/vr_sleeper/New()
..()
sparks = new /datum/effect_system/spark_spread()
sparks.set_up(2,0)
sparks.attach(src)
update_icon()
if(!available_vr_spawnpoints || !available_vr_spawnpoints.len) //(re)build spawnpoint lists
available_vr_spawnpoints = list()
for(var/obj/effect/landmark/vr_spawn/V in landmarks_list)
available_vr_spawnpoints[V.vr_category] = list()
var/turf/T = get_turf(V)
if(T)
available_vr_spawnpoints[V.vr_category] |= T
/obj/machinery/vr_sleeper/attack_hand(mob/user)
if(occupant)
ui_interact(user)
else
if(state_open)
close_machine()
else
open_machine()
/obj/machinery/vr_sleeper/relaymove(mob/user)
open_machine()
/obj/machinery/vr_sleeper/Destroy()
open_machine()
cleanup_vr_human()
qdel(sparks)
sparks = null
return ..()
/obj/machinery/vr_sleeper/emag_act(mob/user)
you_die_in_the_game_you_die_for_real = TRUE
sparks.start()
/obj/machinery/vr_sleeper/update_icon()
icon_state = "[initial(icon_state)][state_open ? "-open" : ""]"
/obj/machinery/vr_sleeper/open_machine()
if(!state_open)
if(vr_human)
vr_human.revert_to_reality(FALSE, FALSE)
if(occupant)
SStgui.close_user_uis(occupant, src)
..()
/obj/machinery/vr_sleeper/close_machine()
..()
if(occupant)
ui_interact(occupant)
/obj/machinery/vr_sleeper/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = 0, datum/tgui/master_ui = null, datum/ui_state/state = default_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "vr_sleeper", "VR Sleeper", 475, 340, master_ui, state)
ui.open()
/obj/machinery/vr_sleeper/ui_act(action, params)
if(..())
return
switch(action)
if("vr_connect")
if(ishuman(occupant) && occupant.mind)
occupant << "<span class='warning'>Transfering to virtual reality...</span>"
if(vr_human)
vr_human.revert_to_reality(FALSE, FALSE)
occupant.mind.transfer_to(vr_human)
vr_human.real_me = occupant
vr_human << "<span class='notice'>Transfer successful! you are now playing as [vr_human] in VR!</span>"
SStgui.close_user_uis(vr_human, src)
else
if(allow_creating_vr_humans)
occupant << "<span class='warning'>Virtual avatar not found, attempting to create one...</span>"
var/turf/T = get_vr_spawnpoint()
if(T)
build_virtual_human(occupant, T)
vr_human << "<span class='notice'>Transfer successful! you are now playing as [vr_human] in VR!</span>"
else
occupant << "<span class='warning'>Virtual world misconfigured, aborting transfer</span>"
else
occupant << "<span class='warning'>The virtual world does not support the creation of new virtual avatars, aborting transfer</span>"
. = TRUE
if("delete_avatar")
if(!occupant || usr == occupant)
if(vr_human)
qdel(vr_human)
else
usr << "<span class='warning'>The VR Sleeper's safeties prevent you from doing that."
. = TRUE
if("toggle_open")
if(state_open)
close_machine()
else
open_machine()
. = TRUE
/obj/machinery/vr_sleeper/ui_data(mob/user)
var/list/data = list()
if(vr_human && !qdeleted(vr_human))
data["can_delete_avatar"] = TRUE
var/status
switch(user.stat)
if(CONSCIOUS)
status = "Conscious"
if(DEAD)
status = "Dead"
if(UNCONSCIOUS)
status = "Unconscious"
data["vr_avatar"] = list("name" = vr_human.name, "status" = status, "health" = vr_human.health, "maxhealth" = vr_human.maxHealth)
data["toggle_open"] = state_open
data["isoccupant"] = (user == occupant)
return data
/obj/machinery/vr_sleeper/proc/get_vr_spawnpoint() //proc so it can be overriden for team games or something
return safepick(available_vr_spawnpoints[vr_category])
/obj/machinery/vr_sleeper/proc/build_virtual_human(mob/living/carbon/human/H, location, transfer = TRUE)
if(H)
cleanup_vr_human()
vr_human = new /mob/living/carbon/human/virtual_reality(location)
vr_human.vr_sleeper = src
vr_human.real_me = H
H.dna.transfer_identity(vr_human)
vr_human.name = H.name
vr_human.real_name = H.real_name
vr_human.socks = H.socks
vr_human.undershirt = H.undershirt
vr_human.underwear = H.underwear
vr_human.updateappearance(1,1,1)
if(transfer && H.mind)
H.mind.transfer_to(vr_human)
/obj/machinery/vr_sleeper/proc/cleanup_vr_human()
if(vr_human)
vr_human.death(0)
/obj/effect/landmark/vr_spawn //places you can spawn in VR, auto selected by the vr_sleeper during get_vr_spawnpoint()
var/vr_category = "default" //So we can have specific sleepers, eg: "Basketball VR Sleeper", etc.
+2
View File
@@ -1824,6 +1824,8 @@
#include "code\modules\vehicles\secway.dm"
#include "code\modules\vehicles\speedbike.dm"
#include "code\modules\vehicles\vehicle.dm"
#include "code\modules\VR\vr_human.dm"
#include "code\modules\VR\vr_sleeper.dm"
#include "code\modules\zombie\items.dm"
#include "code\modules\zombie\organs.dm"
#include "code\orphaned_procs\AStar.dm"
+1 -1
View File
File diff suppressed because one or more lines are too long
+11 -11
View File
File diff suppressed because one or more lines are too long
+27 -4
View File
@@ -19,7 +19,7 @@
styles () {
let extra = ''
if (this.get('class'))
extra += ' ' + this.get('class');
extra += ' ' + this.get('class');
if (this.get('tooltip-side'))
extra = ` tooltip-${this.get('tooltip-side')}`
if (this.get('grid'))
@@ -35,15 +35,35 @@
} else {
return `inactive disabled ${extra}`
}
}
},
}
},
oninit () {
this.on('press', (event) => {
const { action, params } = this.get()
act(this.get('config.ref'), action, params)
event.node.blur()
})
}
},
data: {
iconStackToHTML(icon_stack){ //turns a string such as 'square-o 2x, twitter 1x' into fully valid fontawesome syntax+HTML
let resultHTML = '';
let icons = icon_stack.split(',');
if(icons.length){
resultHTML += '<span class=\"fa-stack\">';
for (let iconinfo of icons){
let regex = /([\w\-]+)\s*(\dx)/g;
let components = regex.exec(iconinfo);
let icon = components[1]; //0 is the entire string
let size = components[2];
resultHTML += '<i class=\"fa fa-' + icon + ' fa-stack-' + size + '\"></i>';
}
}
if(resultHTML){
resultHTML += '</span>';
}
return resultHTML;
}
}
}
</script>
@@ -57,5 +77,8 @@
{{#if icon}}
<i class='fa fa-{{icon}}'></i>
{{/if}}
{{#if icon_stack}}
{{{iconStackToHTML(icon_stack)}}}
{{/if}}
{{yield}}
</span>
+4 -2
View File
@@ -14,8 +14,8 @@ span.button
@extend {context} $fontReset
display: inline-block
vertical-align: middle
height: 20px
line-height: @height - 3px
min-height: 20px
line-height: @min-height - 3px
padding: 0 5px
white-space: nowrap
@@ -39,3 +39,5 @@ span:not(.button) + span.button
span.button + span:not(.button)
margin-left: 5px
+49
View File
@@ -0,0 +1,49 @@
<script>
component.exports = {
data: {
healthState(health) {
let maxhealth = this.get('data.vr_avatar.maxhealth')
if(health > (maxhealth/1.5)) return 'good'
else if(health > (maxhealth/3)) return 'average'
else return 'bad'
}
}
}
</script>
<ui-display>
{{#if data.vr_avatar}}
<ui-display title='Virtual Avatar'>
<ui-section label='Name'>
{{data.vr_avatar.name}}
</ui-section>
<ui-section label='Status'>
{{data.vr_avatar.status}}
</ui-section>
<ui-section label='Health'>
<ui-bar min='0' max='{{adata.vr_avatar.maxhealth}}' value='{{adata.vr_avatar.health}}' state='{{healthState(adata.vr_avatar.health)}}'>{{Math.round(adata.vr_avatar.health)}}/{{adata.vr_avatar.maxhealth}}</ui-bar>
</ui-section>
</ui-display>
{{else}}
<ui-display title='Virtual Avatar'>
No Virtual Avatar detected
</ui-display>
{{/if}}
<ui-display title='VR Commands'>
<ui-button icon='{{data.toggle_open ? "times" : "plus"}}' action='toggle_open'>
{{data.toggle_open ? "Close" : "Open"}} the VR Sleeper
</ui-button>
{{#if data.isoccupant}}
<ui-button icon='signal' action='vr_connect'>
Connect to VR
</ui-button>
{{/if}}
{{#if data.vr_avatar}}
<ui-button icon='ban' action='delete_avatar'>
Delete Virtual Avatar
</ui-button>
{{/if}}
</ui-display>
</ui-display>