diff --git a/code/__DEFINES/atom_hud.dm b/code/__DEFINES/atom_hud.dm index 6495c88136e..669ec8c4134 100644 --- a/code/__DEFINES/atom_hud.dm +++ b/code/__DEFINES/atom_hud.dm @@ -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 diff --git a/code/__DEFINES/~skyrat_defines/signals.dm b/code/__DEFINES/~skyrat_defines/signals.dm index 10ed986cb62..59e62107691 100644 --- a/code/__DEFINES/~skyrat_defines/signals.dm +++ b/code/__DEFINES/~skyrat_defines/signals.dm @@ -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" diff --git a/code/_onclick/hud/_defines.dm b/code/_onclick/hud/_defines.dm index bee229fa21c..514e5beddbe 100644 --- a/code/_onclick/hud/_defines.dm +++ b/code/_onclick/hud/_defines.dm @@ -181,3 +181,6 @@ //Families #define ui_wanted_lvl "NORTH,11" + +//SKYRAT HUD DEFINES BELOW +#define ui_ammocounter "EAST-1:28,CENTER-5:9" diff --git a/code/_onclick/hud/hud.dm b/code/_onclick/hud/hud.dm index ce9be78fe4b..4c28a6c189d 100644 --- a/code/_onclick/hud/hud.dm +++ b/code/_onclick/hud/hud.dm @@ -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 diff --git a/code/_onclick/hud/human.dm b/code/_onclick/hud/human.dm index 572220dc3bc..f9ecdce76e8 100644 --- a/code/_onclick/hud/human.dm +++ b/code/_onclick/hud/human.dm @@ -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 diff --git a/code/game/objects/items/tools/weldingtool.dm b/code/game/objects/items/tools/weldingtool.dm index 746133c2201..a8704c50ab8 100644 --- a/code/game/objects/items/tools/weldingtool.dm +++ b/code/game/objects/items/tools/weldingtool.dm @@ -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?) diff --git a/code/modules/projectiles/guns/ballistic.dm b/code/modules/projectiles/guns/ballistic.dm index 5d52c8e2916..55c960100ca 100644 --- a/code/modules/projectiles/guns/ballistic.dm +++ b/code/modules/projectiles/guns/ballistic.dm @@ -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, "You cannot seem to get \the [src] out of your hands!") @@ -285,6 +286,7 @@ if (display_message) to_chat(user, "You pull the [magazine_wording] out of \the [src].") update_appearance() + SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD) /obj/item/gun/ballistic/can_shoot() return chambered diff --git a/code/modules/projectiles/guns/energy.dm b/code/modules/projectiles/guns/energy.dm index 51533ec5bad..21615cefb1d 100644 --- a/code/modules/projectiles/guns/energy.dm +++ b/code/modules/projectiles/guns/energy.dm @@ -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() diff --git a/modular_skyrat/master_files/code/_onclick/hud/readme.md b/modular_skyrat/master_files/code/_onclick/hud/readme.md new file mode 100644 index 00000000000..428e5d56227 --- /dev/null +++ b/modular_skyrat/master_files/code/_onclick/hud/readme.md @@ -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 diff --git a/modular_skyrat/master_files/code/datums/components/fullauto.dm b/modular_skyrat/master_files/code/datums/components/fullauto.dm index 7286e1d36de..9fea4581358 100644 --- a/modular_skyrat/master_files/code/datums/components/fullauto.dm +++ b/modular_skyrat/master_files/code/datums/components/fullauto.dm @@ -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 diff --git a/modular_skyrat/master_files/code/modules/projectiles/guns/gun.dm b/modular_skyrat/master_files/code/modules/projectiles/guns/gun.dm index c23bafac9a4..333f97b2fb8 100644 --- a/modular_skyrat/master_files/code/modules/projectiles/guns/gun.dm +++ b/modular_skyrat/master_files/code/modules/projectiles/guns/gun.dm @@ -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("[user] toggles [src]'s safety [safety ? "ON" : "OFF"].", "You toggle [src]'s safety [safety ? "ON" : "OFF"].") + 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() diff --git a/modular_skyrat/modules/gunhud/code/gun_hud_component.dm b/modular_skyrat/modules/gunhud/code/gun_hud_component.dm new file mode 100644 index 00000000000..9a6810c58c2 --- /dev/null +++ b/modular_skyrat/modules/gunhud/code/gun_hud_component.dm @@ -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 = "
[batt_percent]%
[shot_cost_percent]%
" + return + if(batt_percent <= 25) + hud.maptext = "
[batt_percent]%
[shot_cost_percent]%
" + return + hud.maptext = "
[batt_percent]%
[shot_cost_percent]%
" + + 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) diff --git a/modular_skyrat/modules/gunhud/code/hud/gun_hud.dm b/modular_skyrat/modules/gunhud/code/hud/gun_hud.dm new file mode 100644 index 00000000000..a282af67369 --- /dev/null +++ b/modular_skyrat/modules/gunhud/code/hud/gun_hud.dm @@ -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 + diff --git a/modular_skyrat/modules/gunhud/icons/hud/gun_hud.dmi b/modular_skyrat/modules/gunhud/icons/hud/gun_hud.dmi new file mode 100644 index 00000000000..c412d504196 Binary files /dev/null and b/modular_skyrat/modules/gunhud/icons/hud/gun_hud.dmi differ diff --git a/modular_skyrat/modules/gunhud/readme.md b/modular_skyrat/modules/gunhud/readme.md new file mode 100644 index 00000000000..e580d96643a --- /dev/null +++ b/modular_skyrat/modules/gunhud/readme.md @@ -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. diff --git a/modular_skyrat/modules/gunsgalore/code/guns/master.dm b/modular_skyrat/modules/gunsgalore/code/guns/master.dm index d08239e5389..da0910adf0b 100644 --- a/modular_skyrat/modules/gunsgalore/code/guns/master.dm +++ b/modular_skyrat/modules/gunsgalore/code/guns/master.dm @@ -81,6 +81,7 @@ jammed = TRUE playsound(src, 'sound/effects/stall.ogg', 60, TRUE) to_chat(user, "The [src] jams!") + SEND_SIGNAL(src, COMSIG_GUN_JAMMED) else if(jammed) to_chat(user, "You start to unjam the bolt!") if(do_after(user, unjam_time)) diff --git a/tgstation.dme b/tgstation.dme index 194fb6c4241..ff55a2581b8 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -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"