Skip to content

Commit

Permalink
Merge pull request #75 from Alando1-doom/Weapon-and-item-announcement
Browse files Browse the repository at this point in the history
Weapon and item announcement
  • Loading branch information
Alando1-doom authored May 17, 2024
2 parents 5cc8936 + e450945 commit e7396fe
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CVARINFO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ user bool Toby_PlayMapNameAnnouncement = true;
user bool Toby_UseLegacyAmmoChecker = false;
user bool Toby_UseLegacyHealthChecker = false;

user bool Toby_SelectionNarrationWeapons = true;
user bool Toby_SelectionNarrationItems = true;

//Hit Marker CVAR

Expand Down
8 changes: 5 additions & 3 deletions MAPINFO.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
GameInfo
{
AddEventHandlers = "Toby_SoundBindingsLoaderStaticHandler"
AddEventHandlers = "Toby_SoundQueueStaticHandler"
AddEventHandlers = "ZS_MarkerHandler"
AddEventHandlers = "Toby_MenuStaticHandler"
AddEventHandlers = "Toby_MapAnnouncementStaticHandler"
AddEventHandlers = "Toby_PlayerStatusCheckStaticHandler"
AddEventHandlers = "Toby_SelectionNarrationHandler"
AddEventHandlers = "Toby_TitleScreenHandler"
AddEventHandlers = "hitmarkershandler"
AddEventHandlers = "Toby_SnapToTargetHandler"
AddEventHandlers = "Toby_DropoffDetectorHandler"
AddEventHandlers = "Toby_TargetDetectorStaticHandler"
AddEventHandlers = "Toby_TargetDetectorHandler"
AddEventHandlers = "Toby_ActorsInViewportStaticHandler"
AddEventHandlers = "Toby_QuickTurnHandler"
AddEventHandlers = "TobyEventHandler" //Line Spawner
}
AddEventHandlers = "Toby_QuickTurnHandler"
AddEventHandlers = "TobyEventHandler" //Line Spawner
}
4 changes: 4 additions & 0 deletions MENUDEF
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,8 @@ OptionMenu "toby_developer"
Option "Toby_PlayMapNameAnnouncement", "Toby_PlayMapNameAnnouncement", "OnOff"
Option "Toby_UseLegacyAmmoChecker", "Toby_UseLegacyAmmoChecker", "OnOff"
Option "Toby_UseLegacyHealthChecker", "Toby_UseLegacyHealthChecker", "OnOff"
StaticText ""
StaticText "User accessible options", "Gold"
Option "Toby_SelectionNarrationWeapons", "Toby_SelectionNarrationWeapons", "OnOff"
Option "Toby_SelectionNarrationItems", "Toby_SelectionNarrationItems", "OnOff"
}
7 changes: 7 additions & 0 deletions zscript.zs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ version "4.6"
#include "zscript/Utils/SoundQueue/Toby_NumberToSoundQueue.zs"
#include "zscript/Utils/SoundQueue/Toby_MonthToSoundQueue.zs"

//Sound bindings loader
#include "zscript/SoundBindings/Toby_SoundBindingsLoaderStaticHandler.zs"

//Player status checker
#include "zscript/StatusChecker/Toby_PlayerStatusCondition.zs"
#include "zscript/StatusChecker/Toby_HealthChecker.zs"
Expand All @@ -16,6 +19,10 @@ version "4.6"
#include "zscript/StatusChecker/Toby_ArmorChecker.zs"
#include "zscript/StatusChecker/Toby_PlayerStatusCheckStaticHandler.zs"

//Weapon/item selection narration
#include "zscript/SelectionNarration/Toby_SelectionNarrationHandler.zs"
#include "zscript/SelectionNarration/Toby_SelectionNarrator.zs"

//Markers
#include "zscript/Markers/ZS_MarkerHandler.zs"
#include "zscript/Markers/Toby_Markers.zs"
Expand Down
8 changes: 4 additions & 4 deletions zscript/AccessibleMenu/Toby_MenuStaticHandler.zs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class Toby_MenuStaticHandler : StaticEventHandler
ui Toby_MenuState previousMenuState;
ui Toby_MenuEventProcessor menuEventProcessor;
ui bool isNotFirstRun;

ui Toby_SoundBindingsContainer menuSoundBindingsContainer;
ui Toby_SoundBindingsLoaderStaticHandler bindings;

ui int lastKeyPressed;

Expand Down Expand Up @@ -70,9 +69,10 @@ class Toby_MenuStaticHandler : StaticEventHandler
previousMenuState = new("Toby_MenuState");
currentMenuState.SetNullState();
previousMenuState.SetNullState();
menuSoundBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_MenuSoundBindings");
bindings = Toby_SoundBindingsLoaderStaticHandler.GetInstance();

menuEventProcessor = new("Toby_MenuEventProcessor");
menuEventProcessor.Init(menuSoundBindingsContainer);
menuEventProcessor.Init(bindings.menuSoundBindingsContainer);
}

ui void HandleUiProcessor(int detectedChange)
Expand Down
17 changes: 8 additions & 9 deletions zscript/ActorsInViewport/Toby_ActorsInViewportStaticHandler.zs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class Toby_ActorsInViewportStaticHandler: StaticEventHandler
Array<Toby_ViewportProjector> projectors;
ui Array<bool> checkingActorsInViewport;
ui Array<int> narrationPresets;

ui Toby_SoundBindingsContainer actorsInViewportSoundBindings;
ui Toby_SoundBindingsLoaderStaticHandler bindings;

override void OnRegister()
{
Expand All @@ -30,7 +29,7 @@ class Toby_ActorsInViewportStaticHandler: StaticEventHandler
if (!isNotFirstRun)
{
isNotFirstRun = true;
actorsInViewportSoundBindings = Toby_SoundBindingsContainer.Create("Toby_ActorsInViewportSoundBindings");
bindings = Toby_SoundBindingsLoaderStaticHandler.GetInstance();
for (int i = 0; i < maxPlayers; i++)
{
checkingActorsInViewport.push(false);
Expand Down Expand Up @@ -126,27 +125,27 @@ class Toby_ActorsInViewportStaticHandler: StaticEventHandler

if (narrationPresets[consoleplayer] == 0)
{
Toby_ActorsInViewportPresets.PlayGeneralOverview(storages[consoleplayer], actorsInViewportSoundBindings);
Toby_ActorsInViewportPresets.PlayGeneralOverview(storages[consoleplayer], bindings.actorsInViewportSoundBindings);
}
if (narrationPresets[consoleplayer] == 1)
{
Toby_ActorsInViewportPresets.PlayDetailedOverviewByScreenPosition(storages[consoleplayer], actorsInViewportSoundBindings);
Toby_ActorsInViewportPresets.PlayDetailedOverviewByScreenPosition(storages[consoleplayer], bindings.actorsInViewportSoundBindings);
}
if (narrationPresets[consoleplayer] == 2)
{
Toby_ActorsInViewportPresets.PlayDetailedOverviewByDistance(storages[consoleplayer], actorsInViewportSoundBindings);
Toby_ActorsInViewportPresets.PlayDetailedOverviewByDistance(storages[consoleplayer], bindings.actorsInViewportSoundBindings);
}
if (narrationPresets[consoleplayer] == 3)
{
Toby_ActorsInViewportPresets.PlayDetailedOverviewByDistanceAndScreenPosition(storages[consoleplayer], actorsInViewportSoundBindings);
Toby_ActorsInViewportPresets.PlayDetailedOverviewByDistanceAndScreenPosition(storages[consoleplayer], bindings.actorsInViewportSoundBindings);
}
if (narrationPresets[consoleplayer] == 4)
{
Toby_ActorsInViewportPresets.PlayDetailedOverviewByLevel(storages[consoleplayer], actorsInViewportSoundBindings);
Toby_ActorsInViewportPresets.PlayDetailedOverviewByLevel(storages[consoleplayer], bindings.actorsInViewportSoundBindings);
}
if (narrationPresets[consoleplayer] == 5)
{
Toby_ActorsInViewportPresets.PlayDetailedOverviewByLevelAndScreenPosition(storages[consoleplayer], actorsInViewportSoundBindings);
Toby_ActorsInViewportPresets.PlayDetailedOverviewByLevelAndScreenPosition(storages[consoleplayer], bindings.actorsInViewportSoundBindings);
}

checkingActorsInViewport[consoleplayer] = false;
Expand Down
6 changes: 3 additions & 3 deletions zscript/MapAnnouncements/Toby_MapAnnouncementStaticHandler.zs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Toby_MapAnnouncementStaticHandler : StaticEventHandler
{
ui Toby_MapAnnouncementManager manager;
ui Toby_SoundBindingsContainer mapNamesBindingsContainer;
ui Toby_SoundBindingsLoaderStaticHandler bindings;
ui bool isNotFirstRun;

bool isSaveGame;
Expand All @@ -18,8 +18,8 @@ class Toby_MapAnnouncementStaticHandler : StaticEventHandler
if (!isNotFirstRun)
{
isNotFirstRun = true;
mapNamesBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_MapNameSoundBindings");
manager = Toby_MapAnnouncementManager.Create(mapNamesBindingsContainer);
bindings = Toby_SoundBindingsLoaderStaticHandler.GetInstance();
manager = Toby_MapAnnouncementManager.Create(bindings.mapNamesBindingsContainer);
}

if (worldLoadedEvent)
Expand Down
122 changes: 122 additions & 0 deletions zscript/SelectionNarration/Toby_SelectionNarrationHandler.zs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
class Toby_SelectionNarrationHandler : EventHandler
{
int maxPlayers;
Array<string> previousWeapon;
Array<string> previousItem;
private ui bool isNotFirstRun;
private ui Toby_SoundBindingsLoaderStaticHandler bindings;

override void OnRegister()
{
Toby_Logger.Message("Toby_SelectionNarrationHandler registered!", "Toby_Developer");
}

override void UITick()
{
if (!isNotFirstRun)
{
isNotFirstRun = true;
bindings = Toby_SoundBindingsLoaderStaticHandler.GetInstance();
}
}

override void WorldLoaded(WorldEvent e)
{
maxPlayers = 8;
for (int i = 0; i < maxPlayers; i++)
{
previousWeapon.push("");
previousItem.push("");
}
}

override void WorldTick()
{
DetectAndNarrateWeaponSwitch();
DetectAndNarrateItemSwitch();
}

override void InterfaceProcess(ConsoleEvent e)
{
Array<String> eventAndArguments;
e.Name.split(eventAndArguments, ":", TOK_KEEPEMPTY);
string event = eventAndArguments[0];
Array<string> args;
if (eventAndArguments.Size() > 1)
{
for (int i = 1; i < eventAndArguments.Size(); i++)
{
args.push(eventAndArguments[i]);
}
}

if (event == "Toby_SelectionNarrationWeapon")
{
Toby_SelectionNarrator.NarrateWeaponName(args[0], bindings.weaponsSoundBindingsContainer);
}

if (event == "Toby_SelectionNarrationItem")
{
Toby_SelectionNarrator.NarrateItemName(args[0], args[1].ToInt(), bindings.itemsSoundBindingsContainer);
}
}

private void DetectAndNarrateWeaponSwitch()
{
for (int i = 0; i < maxPlayers; i++)
{
if (!players[i].mo) { continue; }
string currentWeapon = players[i].mo.player.ReadyWeapon.GetClassName();
if (currentWeapon == previousWeapon[i]) { continue; }
if (previousWeapon[i] == "")
{
previousWeapon[i] = currentWeapon;
continue;
}
if (Cvar.GetCvar("Toby_SelectionNarrationWeapons", players[i]).GetBool())
{
EventHandler.SendInterfaceEvent(i, "Toby_SelectionNarrationWeapon:"..currentWeapon);
}
previousWeapon[i] = currentWeapon;
}
}

private void DetectAndNarrateItemSwitch()
{
for (int i = 0; i < maxPlayers; i++)
{
if (!players[i].mo) { continue; }
string currentItem = "";
int amount = 0;
if (players[i].mo.InvSel)
{
Inventory inv = players[i].mo.InvSel;
currentItem = inv.GetClassName();
amount = inv.amount;
}
if (currentItem == previousItem[i]) { continue; }
if (previousItem[i] == "")
{
previousItem[i] = currentItem;
continue;
}
if (Cvar.GetCvar("Toby_SelectionNarrationItems", players[i]).GetBool())
{
EventHandler.SendInterfaceEvent(i, "Toby_SelectionNarrationItem:"..currentItem..":"..amount);
}
previousItem[i] = currentItem;
}
}

private int GetSbarItemCount(Actor a)
{
int count = 0;
for(Inventory item = a.inv; item != null; item = item.inv) {
if (item.bInvBar)
{
count++;
}
}
return count;
}
}
41 changes: 41 additions & 0 deletions zscript/SelectionNarration/Toby_SelectionNarrator.zs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Toby_SelectionNarrator
{
ui static void NarrateWeaponName(string weaponName, Toby_SoundBindingsContainer weaponsSoundBindings)
{
Toby_SoundQueueStaticHandler.Clear();

for (int i = 0; i < weaponsSoundBindings.soundBindings.Size(); i++)
{
string className = weaponsSoundBindings.soundBindings[i].At("ActorClass");
if (weaponName == className)
{
string soundName = weaponsSoundBindings.soundBindings[i].At("SoundToPlay");
Toby_SoundQueueStaticHandler.AddSound(soundName, -1);
break;
}
}

Toby_SoundQueueStaticHandler.PlayQueue(0);
}

ui static void NarrateItemName(string itemName, int amount, Toby_SoundBindingsContainer itemsSoundBindings)
{
Toby_SoundQueueStaticHandler.Clear();

for (int i = 0; i < itemsSoundBindings.soundBindings.Size(); i++)
{
string className = itemsSoundBindings.soundBindings[i].At("ActorClass");
if (itemName == className)
{
string soundName = itemsSoundBindings.soundBindings[i].At("SoundToPlay");
Toby_SoundQueueStaticHandler.AddSound(soundName, -1);
break;
}
}

Toby_NumberToSoundQueue numberToSoundQueue = Toby_NumberToSoundQueue.Create();
Toby_SoundQueueStaticHandler.AddQueue(numberToSoundQueue.CreateQueueFromInt(amount));

Toby_SoundQueueStaticHandler.PlayQueue(0);
}
}
Empty file.
41 changes: 41 additions & 0 deletions zscript/SoundBindings/Toby_SoundBindingsLoaderStaticHandler.zs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Toby_SoundBindingsLoaderStaticHandler : StaticEventHandler
{
ui bool isNotFirstRun;

ui Toby_SoundBindingsContainer keysSoundBindingsContainer;
ui Toby_SoundBindingsContainer weaponsSoundBindingsContainer;
ui Toby_SoundBindingsContainer itemsSoundBindingsContainer;
ui Toby_SoundBindingsContainer ammoSoundBindingsContainer;
ui Toby_SoundBindingsContainer armorSoundBindingsContainer;
ui Toby_SoundBindingsContainer targetDetectorBindingsContainer;
ui Toby_SoundBindingsContainer mapNamesBindingsContainer;
ui Toby_SoundBindingsContainer actorsInViewportSoundBindings;
ui Toby_SoundBindingsContainer menuSoundBindingsContainer;

ui static Toby_SoundBindingsLoaderStaticHandler GetInstance()
{
return Toby_SoundBindingsLoaderStaticHandler(StaticEventHandler.Find("Toby_SoundBindingsLoaderStaticHandler"));
}

override void OnRegister()
{
Toby_Logger.Message("Toby_SoundBindingsLoaderStaticHandler registered!", "Toby_Developer");
}

override void UITick()
{
if (!isNotFirstRun)
{
isNotFirstRun = true;
keysSoundBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_KeyNameSoundBindings");
weaponsSoundBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_WeaponNameSoundBindings");
itemsSoundBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_ItemNameSoundBindings");
ammoSoundBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_AmmoNameSoundBindings");
armorSoundBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_ArmorNameSoundBindings");
targetDetectorBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_TargetDetectorSoundBindings");
mapNamesBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_MapNameSoundBindings");
actorsInViewportSoundBindings = Toby_SoundBindingsContainer.Create("Toby_ActorsInViewportSoundBindings");
menuSoundBindingsContainer = Toby_SoundBindingsContainer.Create("Toby_MenuSoundBindings");
}
}
}
Loading

0 comments on commit e7396fe

Please sign in to comment.