1
0
KF2-Dev-Scripts/KFGame/Classes/KFGFxWidget_KickVote.uc

204 lines
5.4 KiB
Ucode
Raw Normal View History

2020-12-13 15:01:13 +00:00
//=============================================================================
// KFGFxWidget_KickVote
//=============================================================================
// HUD Widget that displays when a kick vote has started
//=============================================================================
// Killing Floor 2
// Copyright (C) 2015 Tripwire Interactive LLC
// - Zane Gholson 07/07/2014
//=============================================================================
class KFGFxWidget_KickVote extends GFxObject;
var localized string VoteKickString;
var localized string VoteSkipTraderString;
var localized string VoteSkipTraderDetailString;
2021-11-16 17:03:42 +00:00
var localized string VotePauseGameString;
var localized string VotePauseGameDetailString;
var localized string VoteResumeGameString;
var localized string VoteResumeGameDetailString;
2020-12-13 15:01:13 +00:00
var bool bIsVoteActive;
var bool bShowChoicesOnTimerUpdate;
var const string GBA_VoteYes;
var const string GBA_VoteNo;
var GFxObject KickVoteData;
2021-11-16 17:03:42 +00:00
enum EVoteType
{
VT_NONE,
VT_KICK,
VT_SKIP_TRADER,
VT_PAUSE_GAME,
VT_RESUME_GAME
};
var EVoteType CurrentActiveVote;
2020-12-13 15:01:13 +00:00
function InitializeHUD()
{
//LocalizeText();
}
2021-11-16 17:03:42 +00:00
function LocalizeText(EVoteType Type)
2020-12-13 15:01:13 +00:00
{
local GFxObject TempObject;
local KFPlayerInput KFInput;
local KeyBind TempKeyBind;
TempObject = CreateObject("Object");
KFInput = KFPlayerInput(GetPC().PlayerInput);
KFInput.GetKeyBindFromCommand(TempKeyBind, GBA_VoteYes);
TempObject.SetString("yesKey", String(TempKeyBind.Name));
KFInput.GetKeyBindFromCommand(TempKeyBind, GBA_VoteNo);
TempObject.SetString("noKey", String(TempKeyBind.Name));
TempObject.SetString("yes", Class'KFCommon_LocalizedStrings'.default.YesString);
TempObject.SetString("no", Class'KFCommon_LocalizedStrings'.default.NoString);
2021-11-16 17:03:42 +00:00
TempObject.SetString("voteKick", GetVoteString(Type));
2020-12-13 15:01:13 +00:00
SetObject("localizedText", TempObject);
}
function ResetVote()
{
bShowChoicesOnTimerUpdate = false;
ActionScriptVoid("onYesReleased");
ActionScriptVoid("onNoReleased");
}
2021-11-16 17:03:42 +00:00
function ShowVote(PlayerReplicationInfo PRI, byte VoteDuration, bool bShowChoices, EVoteType Type)
2020-12-13 15:01:13 +00:00
{
if(PRI != none)
{
2021-11-16 17:03:42 +00:00
LocalizeText(Type); //Added this here if the user changes their keybind, it will update
2020-12-13 15:01:13 +00:00
bIsVoteActive = true;
2021-11-16 17:03:42 +00:00
CurrentActiveVote = Type;
2020-12-13 15:01:13 +00:00
SendVoteToAS3(PRI.PlayerName, VoteDuration, bShowChoices);
}
else
{
bIsVoteActive = false;
2021-11-16 17:03:42 +00:00
CurrentActiveVote = VT_NONE;
2020-12-13 15:01:13 +00:00
}
}
function SendVoteToAS3(string PlayerName, byte VoteDuration, bool bShowChoices)
{
if(KickVoteData == None)
{
KickVoteData = CreateObject("Object");
}
2021-11-16 17:03:42 +00:00
KickVoteData.SetString("playerName", GetVotePlayerDataString(PlayerName, CurrentActiveVote));
2020-12-13 15:01:13 +00:00
KickVoteData.SetInt("voteDuration", VoteDuration);
KickVoteData.SetBool("bShowChoices", bShowChoices);
bShowChoicesOnTimerUpdate = bShowChoices;
SetObject("kickVoteData", kickVoteData);
UpdateUsingGamepad(GetPC().PlayerInput.bUsingGamepad); // Moved call to here as the initialize seemed to be too early to show controller controls in some cases (orbis mainly) - HSL
}
function UpdateVoteDuration(byte VoteDuration)
{
if(kickVoteData != None)
{
KickVoteData.SetInt("voteDuration", VoteDuration);
KickVoteData.SetBool("bShowChoices", bShowChoicesOnTimerUpdate);
SetObject("kickVoteData", kickVoteData);
UpdateUsingGamepad(GetPC().PlayerInput.bUsingGamepad);
}
}
function UpdateUsingGamepad(bool bIsUsingGamepad)
{
SetBool("bUsingGamepad", bIsUsingGamepad);
if(!bIsUsingGamepad)
{
//the gamepad text will show on the input so we need to change it back to keyboard, it is simpler to just relocalize
2021-11-16 17:03:42 +00:00
LocalizeText(CurrentActiveVote);
2020-12-13 15:01:13 +00:00
}
}
function UpdateVoteCount(byte YesVotes, byte NoVotes)
{
ActionScriptVoid("updateKickVoteCount");
}
function VoteClosed()
{
bIsVoteActive = false;
SetVisible(false);
}
function OnYesPressed()
{
if(bIsVoteActive)
{
ActionScriptVoid("onYesPressed");
}
}
function OnYesReleased()
{
if(bIsVoteActive)
{
ActionScriptVoid("onYesReleased");
}
}
function OnNoPressed()
{
if(bIsVoteActive)
{
ActionScriptVoid("onNoPressed");
}
}
function OnNoReleased()
{
if(bIsVoteActive)
{
ActionScriptVoid("onNoReleased");
}
}
2021-11-16 17:03:42 +00:00
function string GetVoteString(EVoteType Type)
{
switch(Type)
{
case VT_KICK: return VoteKickString;
case VT_SKIP_TRADER: return VoteSkipTraderString;
case VT_PAUSE_GAME: return VotePauseGameString;
case VT_RESUME_GAME: return VoteResumeGameString;
case VT_NONE: `Log("None vote type"); return VoteKickString;
default: `Log("Unkown vote type"); return VoteKickString;
}
}
function string GetVotePlayerDataString(string PlayerName, EVoteType Type)
{
switch(Type)
{
case VT_SKIP_TRADER: return PlayerName@VoteSkipTraderDetailString;
case VT_PAUSE_GAME: return PlayerName@VotePauseGameDetailString;
case VT_RESUME_GAME: return PlayerName@VoteResumeGameDetailString;
case VT_KICK: return PlayerName;
case VT_NONE: `Log("None vote type"); return PlayerName;
default: `Log("Unkown vote type"); return PlayerName;
}
}
2020-12-13 15:01:13 +00:00
DefaultProperties
{
//defaults
GBA_VoteYes="GBA_VoteYes"
GBA_VoteNo="GBA_VoteNo"
2021-11-16 17:03:42 +00:00
CurrentActiveVote=VT_NONE
2020-12-13 15:01:13 +00:00
}