Gun huds V2 [NOW WITH COMPONENTS!] (#4333)

* start

* Update tgstation.dme

* Update human.dm

* aaa

* aaaaaa

* Advanced shit here.

* NEXT GEN FPS

* Update gun_hud.dm

* Update gun_safety.dm

* Update ballistic.dm

* Delete gun_safety.dm

* Create gun_safety.dm

* eeee

* WAKE THE FUCK UP SAMURAI

* aaaa

* aaaa

* v2.3

* aa

* Update gun_hud_component.dm

* aaaaaaaa

* aaaaaaaaaa

* Update gun_hud_component.dm

* Update weldingtool.dm

* Update gun_hud_component.dm

* aaaaa

* aaa

* JAMMED"

* Update gun_hud_component.dm

* Update gun_hud_component.dm

* Update gun_hud_component.dm

* Fullauto stack tracing added

* aaaaaa

* TICK TEST

* Update fullauto.dm

* Update fullauto.dm

* REVERT THIS MAYBE

* Update fullauto.dm

* Update fullauto.dm

* Update fullauto.dm

* Update fullauto.dm

* WORK YOU BITCH

* Update fullauto.dm

* a

* Update gun_hud_upgrades.dm

* aaaa

* aaaaaaaaa

* aaaaa

* Update gun_hud_component.dm

* Update gun_hud_component.dm
This commit is contained in:
Gandalf
2021-04-03 18:20:25 +01:00
committed by GitHub
parent a5420a7141
commit f8c8d0bc26
17 changed files with 327 additions and 9 deletions
+3
View File
@@ -46,6 +46,9 @@
#define ANTAG_HUD "23"
// for fans to identify pins
#define FAN_HUD "24"
//SKYRAT EDIT ADDITION - GUNHUD
// ammo of guns
#define AMMO_HUD "25"
//by default everything in the hud_list of an atom is an image
//a value in hud_list with one of these will change that behavior
@@ -17,3 +17,5 @@
#define COMSIG_GUN_AUTOFIRE_DESELECTED "gun_autofire_deselected"
///The gun needs to update the gun hud!
#define COMSIG_UPDATE_AMMO_HUD "update_ammo_hud"
///The gun has jammed.
#define COMSIG_GUN_JAMMED "gun_jammed"
+3
View File
@@ -181,3 +181,6 @@
//Families
#define ui_wanted_lvl "NORTH,11"
//SKYRAT HUD DEFINES BELOW
#define ui_ammocounter "EAST-1:28,CENTER-5:9"
+2
View File
@@ -29,6 +29,8 @@ GLOBAL_LIST_INIT(available_ui_styles, list(
var/atom/movable/screen/ling/chems/lingchemdisplay
var/atom/movable/screen/ling/sting/lingstingdisplay
var/atom/movable/screen/ammo_counter //SKYRAT EDIT ADDITION
var/atom/movable/screen/blobpwrdisplay
var/atom/movable/screen/alien_plasma_display
+6
View File
@@ -315,6 +315,12 @@
combo_display = new /atom/movable/screen/combo()
infodisplay += combo_display
//SKYRAT EDIT ADDITION
ammo_counter = new /atom/movable/screen/ammo_counter()
ammo_counter.hud = src
infodisplay += ammo_counter
//SKYRAT EDIT END
for(var/atom/movable/screen/inventory/inv in (static_inventory + toggleable_inventory))
if(inv.slot_id)
inv.hud = src
@@ -79,6 +79,7 @@
damtype = BRUTE
update_appearance()
if(!can_off_process)
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD) //SKYRAT EDIT ADDITION
STOP_PROCESSING(SSobj, src)
return
//Welders left on now use up fuel, but lets not have them run out quite that fast
@@ -88,6 +89,7 @@
burned_fuel_for += delta_time
if(burned_fuel_for >= WELDER_FUEL_BURN_INTERVAL)
use(1)
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD) //SKYRAT EDIT ADDITION
update_appearance()
//This is to start fires. process() is only called if the welder is on.
@@ -208,6 +210,7 @@
. = welding
welding = new_value
set_light_on(welding)
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD) //SKYRAT EDIT ADDITION
//Turns off the welder if there is no more fuel (does this really need to be its own proc?)
@@ -257,6 +257,7 @@
if (bolt_type == BOLT_TYPE_OPEN && !bolt_locked)
chamber_round(TRUE)
update_appearance()
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD)
return TRUE
else
to_chat(user, "<span class='warning'>You cannot seem to get \the [src] out of your hands!</span>")
@@ -285,6 +286,7 @@
if (display_message)
to_chat(user, "<span class='notice'>You pull the [magazine_wording] out of \the [src].</span>")
update_appearance()
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD)
/obj/item/gun/ballistic/can_shoot()
return chambered
+2
View File
@@ -81,6 +81,7 @@
cell.give(100)
if(!chambered) //if empty chamber we try to charge a new shot
recharge_newshot(TRUE)
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD) //SKYRAT EDIT ADDITION
update_appearance()
/obj/item/gun/energy/attack_self(mob/living/user as mob)
@@ -138,6 +139,7 @@
chambered = null
recharge_newshot(TRUE)
update_appearance()
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD) //SKYRAT EDIT ADDITION
return
/obj/item/gun/energy/update_icon_state()
@@ -0,0 +1,4 @@
This is the directory for any hud additions, please add them appropriately and log them in this file.
Current huds:
- Gun hud - Gunhud
@@ -21,6 +21,7 @@
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, .proc/wake_up)
RegisterSignal(parent, COMSIG_GUN_AUTOFIRE_SELECTED, .proc/wake_up)
RegisterSignal(parent, list(COMSIG_PARENT_PREQDELETED, COMSIG_ITEM_DROPPED, COMSIG_GUN_AUTOFIRE_DESELECTED), .proc/autofire_off)
RegisterSignal(parent, COMSIG_GUN_JAMMED, .proc/stop_autofiring)
if(_autofire_shot_delay)
autofire_shot_delay = _autofire_shot_delay
if(ismob(gun.loc))
@@ -29,7 +30,8 @@
/datum/component/automatic_fire/Destroy()
UnregisterSignal(parent, list(COMSIG_PARENT_PREQDELETED, COMSIG_ITEM_DROPPED, COMSIG_GUN_AUTOFIRE_DESELECTED))
UnregisterSignal(parent, list(COMSIG_PARENT_PREQDELETED, COMSIG_ITEM_DROPPED, COMSIG_GUN_AUTOFIRE_DESELECTED, COMSIG_GUN_JAMMED, \
COMSIG_GUN_AUTOFIRE_SELECTED, COMSIG_ITEM_EQUIPPED))
autofire_off()
return ..()
@@ -45,7 +47,6 @@
/datum/component/automatic_fire/proc/wake_up(datum/source, mob/user, slot)
SIGNAL_HANDLER
if(autofire_stat & (AUTOFIRE_STAT_ALERT))
return //We've updated the firemode. No need for more.
if(autofire_stat & AUTOFIRE_STAT_FIRING)
@@ -94,8 +95,9 @@
if(!QDELETED(shooter))
UnregisterSignal(shooter, COMSIG_MOB_LOGOUT)
shooter = null
parent.UnregisterSignal(parent, COMSIG_AUTOFIRE_SHOT)
parent.UnregisterSignal(src, COMSIG_AUTOFIRE_ONMOUSEDOWN)
parent.UnregisterSignal(parent, COMSIG_AUTOFIRE_SHOT)
/datum/component/automatic_fire/proc/on_client_login(mob/source)
SIGNAL_HANDLER
@@ -151,6 +153,7 @@
/datum/component/automatic_fire/proc/start_autofiring()
if(autofire_stat == AUTOFIRE_STAT_FIRING)
return //Already pew-pewing.
autofire_stat = AUTOFIRE_STAT_FIRING
clicker.mouse_override_icon = 'icons/effects/mouse_pointers/weapon_pointer.dmi'
@@ -259,12 +262,15 @@
if(clicker.mob.get_active_held_item() != src)
return COMPONENT_AUTOFIRE_ONMOUSEDOWN_BYPASS
/obj/item/gun/proc/do_autofire(datum/source, atom/target, mob/living/shooter, params)
SIGNAL_HANDLER_DOES_SLEEP
if(!can_shoot())
shoot_with_empty_chamber(shooter)
return NONE
SIGNAL_HANDLER
if(!can_shoot())
shoot_with_empty_chamber(shooter)
return FALSE
INVOKE_ASYNC(src, .proc/do_autofire_shot, source, target, shooter, params)
return COMPONENT_AUTOFIRE_SHOT_SUCCESS
/obj/item/gun/proc/do_autofire_shot(datum/source, atom/target, mob/living/shooter, params)
var/obj/item/gun/akimbo_gun = shooter.get_inactive_held_item()
var/bonus_spread = 0
if(istype(akimbo_gun) && weapon_weight < WEAPON_MEDIUM)
@@ -272,7 +278,7 @@
bonus_spread = dual_wield_spread
addtimer(CALLBACK(akimbo_gun, /obj/item/gun.proc/process_fire, target, shooter, TRUE, params, null, bonus_spread), 1)
process_fire(target, shooter, TRUE, params, null, bonus_spread)
return COMPONENT_AUTOFIRE_SHOT_SUCCESS //All is well, we can continue shooting.
#undef AUTOFIRE_MOUSEUP
#undef AUTOFIRE_MOUSEDOWN
@@ -239,6 +239,7 @@
update_appearance()
firemode_action.button_icon_state = "fireselect_[fire_select]"
firemode_action.UpdateButtonIcon()
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD)
return TRUE
//called after the gun has successfully fired its chambered ammo.
@@ -384,6 +385,7 @@
playsound(src, 'sound/weapons/empty.ogg', 100, TRUE)
user.visible_message("<span class='notice'>[user] toggles [src]'s safety [safety ? "<font color='#00ff15'>ON</font>" : "<font color='#ff0000'>OFF</font>"].",
"<span class='notice'>You toggle [src]'s safety [safety ? "<font color='#00ff15'>ON</font>" : "<font color='#ff0000'>OFF</font>"].</span>")
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD)
/obj/item/gun/proc/handle_pins(mob/living/user)
if(pin)
@@ -434,6 +436,7 @@
return FALSE
process_chamber()
update_appearance()
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD)
return TRUE
/obj/item/gun/proc/process_fire(atom/target, mob/living/user, message = TRUE, params = null, zone_override = "", bonus_spread = 0)
@@ -488,6 +491,8 @@
user.update_inv_hands()
SSblackbox.record_feedback("tally", "gun_fired", 1, type)
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD)
return TRUE
/obj/item/gun/proc/reset_semicd()
@@ -0,0 +1,165 @@
/datum/component/ammo_hud
var/atom/movable/screen/ammo_counter/hud
/datum/component/ammo_hud/Initialize()
. = ..()
if(!istype(parent, /obj/item/gun) && !istype(parent, /obj/item/weldingtool))
return COMPONENT_INCOMPATIBLE
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, .proc/wake_up)
/datum/component/ammo_hud/Destroy()
turn_off()
return ..()
/datum/component/ammo_hud/proc/wake_up(datum/source, mob/user, slot)
SIGNAL_HANDLER
RegisterSignal(parent, list(COMSIG_PARENT_PREQDELETED, COMSIG_ITEM_DROPPED), .proc/turn_off)
if(ishuman(user))
var/mob/living/carbon/human/H = user
if(H.is_holding(parent))
if(H.hud_used)
hud = H.hud_used.ammo_counter
turn_on()
else
turn_off()
/datum/component/ammo_hud/proc/turn_on()
SIGNAL_HANDLER
RegisterSignal(parent, COMSIG_UPDATE_AMMO_HUD, .proc/update_hud)
hud.turn_on()
update_hud()
/datum/component/ammo_hud/proc/turn_off()
SIGNAL_HANDLER
UnregisterSignal(parent, list(COMSIG_PARENT_PREQDELETED, COMSIG_ITEM_DROPPED, COMSIG_UPDATE_AMMO_HUD))
if(hud)
hud.turn_off()
hud = null
/datum/component/ammo_hud/proc/update_hud()
SIGNAL_HANDLER
if(istype(parent, /obj/item/gun/ballistic))
var/obj/item/gun/ballistic/pew = parent
hud.maptext = null
hud.icon_state = "backing"
var/backing_color = COLOR_CYAN
if(!pew.magazine)
hud.set_hud(backing_color, "oe", "te", "he", "no_mag")
return
if(!pew.get_ammo())
hud.set_hud(backing_color, "oe", "te", "he", "empty_flash")
return
var/indicator
var/rounds = num2text(pew.get_ammo(TRUE))
var/oth_o
var/oth_t
var/oth_h
switch(pew.fire_select)
if(SELECT_SEMI_AUTOMATIC)
indicator = "semi"
if(SELECT_BURST_SHOT)
indicator = "burst"
if(SELECT_FULLY_AUTOMATIC)
indicator = "auto"
if(pew.safety)
indicator = "safe"
if(pew.jammed)
indicator = "jam"
switch(length(rounds))
if(1)
oth_o = "o[rounds[1]]"
if(2)
oth_o = "o[rounds[2]]"
oth_t = "t[rounds[1]]"
if(3)
oth_o = "o[rounds[3]]"
oth_t = "t[rounds[2]]"
oth_h = "h[rounds[1]]"
else
oth_o = "o9"
oth_t = "t9"
oth_h = "h9"
hud.set_hud(backing_color, oth_o, oth_t, oth_h, indicator)
else if(istype(parent, /obj/item/gun/energy))
var/obj/item/gun/energy/pew = parent
hud.icon_state = "eammo_counter"
hud.cut_overlays()
hud.maptext_x = -12
var/obj/item/ammo_casing/energy/shot = pew.ammo_type[pew.select]
var/batt_percent = FLOOR(clamp(pew.cell.charge / pew.cell.maxcharge, 0, 1) * 100, 1)
var/shot_cost_percent = FLOOR(clamp(shot.e_cost / pew.cell.maxcharge, 0, 1) * 100, 1)
if(batt_percent > 99 || shot_cost_percent > 99)
hud.maptext_x = -12
else
hud.maptext_x = -8
if(!pew.can_shoot())
hud.icon_state = "eammo_counter_empty"
hud.maptext = "<span class='maptext'><div align='center' valign='middle' style='position:relative'><font color='[COLOR_RED]'><b>[batt_percent]%</b></font><br><font color='[COLOR_CYAN]'>[shot_cost_percent]%</font></div></span>"
return
if(batt_percent <= 25)
hud.maptext = "<span class='maptext'><div align='center' valign='middle' style='position:relative'><font color='[COLOR_YELLOW]'><b>[batt_percent]%</b></font><br><font color='[COLOR_CYAN]'>[shot_cost_percent]%</font></div></span>"
return
hud.maptext = "<span class='maptext'><div align='center' valign='middle' style='position:relative'><font color='[COLOR_VIBRANT_LIME]'><b>[batt_percent]%</b></font><br><font color='[COLOR_CYAN]'>[shot_cost_percent]%</font></div></span>"
else if(istype(parent, /obj/item/weldingtool))
var/obj/item/weldingtool/welder = parent
hud.maptext = null
var/backing_color = COLOR_TAN_ORANGE
hud.icon_state = "backing"
if(welder.get_fuel() < 1)
hud.set_hud(backing_color, "oe", "te", "he", "empty_flash")
return
var/indicator
var/fuel = num2text(welder.get_fuel())
var/oth_o
var/oth_t
var/oth_h
if(welder.welding)
indicator = "flame_on"
else
indicator = "flame_off"
fuel = num2text(welder.get_fuel())
switch(length(fuel))
if(1)
oth_o = "o[fuel[1]]"
if(2)
oth_o = "o[fuel[2]]"
oth_t = "t[fuel[1]]"
if(3)
oth_o = "o[fuel[3]]"
oth_t = "t[fuel[2]]"
oth_h = "h[fuel[1]]"
else
oth_o = "o9"
oth_t = "t9"
oth_h = "h9"
hud.set_hud(backing_color, oth_o, oth_t, oth_h, indicator)
/obj/item/gun/ballistic/ComponentInitialize()
. = ..()
AddComponent(/datum/component/ammo_hud)
/obj/item/gun/energy/ComponentInitialize()
. = ..()
AddComponent(/datum/component/ammo_hud)
/obj/item/weldingtool/ComponentInitialize()
. = ..()
AddComponent(/datum/component/ammo_hud)
@@ -0,0 +1,86 @@
/////////////////////////
//Customizable ammo hud//
/////////////////////////
/*
This hud is controlled namely by the ammo_hud component. Generally speaking this is inactive much like all other hud components until it's needed.
It does not do any calculations of it's own, you must do this externally.
If you wish to use this hud, use the ammo_hud component or create another one which interacts with it via the below procs.
proc/turn_off
proc/turn_on
proc/set_hud
Check the gun_hud.dmi for all available icons you can use.
*/
/atom/movable/screen/ammo_counter
name = "ammo counter"
icon = 'modular_skyrat/modules/gunhud/icons/hud/gun_hud.dmi'
icon_state = "backing"
screen_loc = ui_ammocounter
invisibility = INVISIBILITY_ABSTRACT
///This is the color assigned to the OTH backing, numbers and indicator.
var/backing_color = COLOR_RED
///This is the "backlight" of the numbers, and only the numbers. Generally you should leave this alone if you aren't making some mutant project.
var/oth_backing = "oth_light"
//Below are the OTH numbers, these are assigned by oX, tX and hX, x being the number you wish to display(0-9)
///OTH position X00
var/oth_o
///OTH position 0X0
var/oth_t
///OTH position 00X
var/oth_h
///This is the custom indicator sprite that will appear in the box at the bottom of the ammo hud, use this for something like semi/auto toggle on a gun.
var/indicator
///This proc simply resets the hud to standard and removes it from the players visible hud.
/atom/movable/screen/ammo_counter/proc/turn_off()
invisibility = INVISIBILITY_ABSTRACT
maptext = null
backing_color = COLOR_RED
oth_backing = ""
oth_o = ""
oth_t = ""
oth_h = ""
indicator = ""
update_appearance()
///This proc turns the hud on, but does not set it to anything other than the currently set values
/atom/movable/screen/ammo_counter/proc/turn_on()
invisibility = 0
///This is the main proc for altering the hud's appeareance, it controls the setting of the overlays. Use the OTH and below variables to set it accordingly.
/atom/movable/screen/ammo_counter/proc/set_hud(_backing_color, _oth_o, _oth_t, _oth_h, _indicator, _oth_backing = "oth_light")
backing_color = _backing_color
oth_backing = _oth_backing
oth_o = _oth_o
oth_t = _oth_t
oth_h = _oth_h
indicator = _indicator
update_appearance()
/atom/movable/screen/ammo_counter/update_overlays()
. = ..()
if(oth_backing)
var/mutable_appearance/oth_backing_overlay = mutable_appearance(icon, oth_backing)
oth_backing_overlay.color = backing_color
. += oth_backing_overlay
if(oth_o)
var/mutable_appearance/o_overlay = mutable_appearance(icon, oth_o)
o_overlay.color = backing_color
. += o_overlay
if(oth_t)
var/mutable_appearance/t_overlay = mutable_appearance(icon, oth_t)
t_overlay.color = backing_color
. += t_overlay
if(oth_h)
var/mutable_appearance/h_overlay = mutable_appearance(icon, oth_h)
h_overlay.color = backing_color
. += h_overlay
if(indicator)
var/mutable_appearance/indicator_overlay = mutable_appearance(icon, indicator)
indicator_overlay.color = backing_color
. += indicator_overlay
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

+26
View File
@@ -0,0 +1,26 @@
## Title: Gunpoint
MODULE ID: GUNHUD
### Description:
Adds a dynamic hud system for energy and some ballistics guns.
### TG Proc Changes:
- N/A
### Defines:
.code\__DEFINES\atom_hud.dm > #define AMMO_HUD "25"
.code\modules\projectiles\guns\ballistic.dm > /obj/item/gun/ballistic/examine(mob/user)
### Master file additions
- Hud directory > _defines.dm, human.dm, hud.dm
### Included files that are not contained in this module:
- N/A
### Credits:
Gandalf2k15 - OG creation.
@@ -81,6 +81,7 @@
jammed = TRUE
playsound(src, 'sound/effects/stall.ogg', 60, TRUE)
to_chat(user, "<span class='danger'>The [src] jams!</span>")
SEND_SIGNAL(src, COMSIG_GUN_JAMMED)
else if(jammed)
to_chat(user, "You start to unjam the bolt!")
if(do_after(user, unjam_time))
+2
View File
@@ -3908,6 +3908,8 @@
#include "modular_skyrat\modules\ghostcafe\code\game\objects\structures\ghost_role_spawners.dm"
#include "modular_skyrat\modules\ghostcafe\code\game\objects\structures\stackspawner_machine.dm"
#include "modular_skyrat\modules\ghostcafe\code\modules\mob\living\silicon\robot\robot_ghostcafe.dm"
#include "modular_skyrat\modules\gunhud\code\gun_hud_component.dm"
#include "modular_skyrat\modules\gunhud\code\hud\gun_hud.dm"
#include "modular_skyrat\modules\gunpoint\code\datum\gunpoint\gunpoint.dm"
#include "modular_skyrat\modules\gunpoint\code\datum\gunpoint\gunpoint_datum.dm"
#include "modular_skyrat\modules\gunpoint\code\datum\gunpoint\gunpoint_radial.dm"