Added reverse cycling for the spray pattern selection. Also shows list index now.

This commit is contained in:
Kiri 2023-09-12 20:44:37 -07:00
parent 364fb7e7ab
commit c453013abf

View File

@ -174,8 +174,12 @@ class SnekTechSprayer : HDWeapon
} }
goto waiting; goto waiting;
unload:
KSPR A 2 { invoker.CycleSprayPattern(-1); }
goto waiting;
firemode: firemode:
KSPR A 2 { invoker.CycleSprayPattern(); } KSPR A 2 { invoker.CycleSprayPattern(1); }
goto waiting; goto waiting;
waiting: waiting:
@ -299,7 +303,7 @@ class SnekTechSprayer : HDWeapon
} }
} }
void CycleSprayPattern() void CycleSprayPattern(int increment)
{ {
// Find the current entry in the list of patterns. // Find the current entry in the list of patterns.
String currentPattern = CVar.GetCVar("snektech_spraypattern", owner.player).GetString(); String currentPattern = CVar.GetCVar("snektech_spraypattern", owner.player).GetString();
@ -313,8 +317,11 @@ class SnekTechSprayer : HDWeapon
currentIndex = -1; currentIndex = -1;
} }
// Increment the index. // Increment/decrement the index.
int newIndex = (currentIndex + 1) % patternList.size(); int newIndex = (currentIndex + increment) % patternList.size();
if(newIndex < 0) {
newIndex = patternList.size() - 1;
}
// Set the new CVar. // Set the new CVar.
currentPattern = patternList[newIndex]; currentPattern = patternList[newIndex];
@ -323,7 +330,14 @@ class SnekTechSprayer : HDWeapon
CVar.FindCVar("snektech_spraypattern").SetString(currentPattern); CVar.FindCVar("snektech_spraypattern").SetString(currentPattern);
// then update the per-player copy so the help text is correct // then update the per-player copy so the help text is correct
CVar.GetCVar("snektech_spraypattern", owner.player).SetString(currentPattern); CVar.GetCVar("snektech_spraypattern", owner.player).SetString(currentPattern);
owner.A_Log("Selected spray pattern: "..currentPattern, true);
// Print it.
owner.A_Log(
String.format(
"Selected spray pattern: (%d/%d) %s",
newIndex + 1, patternList.size(),
currentPattern),
true);
// Current pattern is referenced in the help text, so reset // Current pattern is referenced in the help text, so reset
// it. // it.
@ -352,6 +366,7 @@ class SnekTechSprayer : HDWeapon
return return
WEPHELP_FIREMODE .. " Cycle pattern (current: "..currentPattern..").\n".. WEPHELP_FIREMODE .. " Cycle pattern (current: "..currentPattern..").\n"..
WEPHELP_UNLOAD .. " Cycle pattern (backwards).\n"..
WEPHELP_ALTFIRE .. " Shake the can.\n".. WEPHELP_ALTFIRE .. " Shake the can.\n"..
WEPHELP_FIRE .. " "..messages[messageIndex % messages.Size()].."\n"; WEPHELP_FIRE .. " "..messages[messageIndex % messages.Size()].."\n";
} }