//=============================================================================// // Map Vote Mutator v0.5 Copyright(C) 2005 Adam Mummery-Smith B.S.E. // //=============================================================================// class MapVoteController extends U2PlayerController; //=============================================================================// // Class: MapVoteController | Date: December 2005 // //-----------------------------------------------------------------------------// // Project: Map Vote Mutator | Author: Adam Mummery-Smith // //-----------------------------------------------------------------------------// // Description: This class adds the user-interaction part to the map vote // // system, since it contains the exec functions which makes it // // all possible... but you knew that - didn't you? // //-----------------------------------------------------------------------------// // Usage: N/A // //-----------------------------------------------------------------------------// // Note: 1) This version includes my (alpha) version of the GUI designer // // that I have experimented with before as a stand-alone system. // // Ask me for documentation if you're interested in using this // // yourself. // // 2) explode() and implode() need a lot of work // // 3) I know that over-riding the playercontroller is a bad idea // // mutatorwise, but there isn't an elegant way of doing this // // in any other way. // //=============================================================================// //----------------------------------------------------------------------------- // Load external stuff #exec OBJ LOAD File=..\Textures\UIResT.utx //----------------------------------------------------------------------------- // Declarations // HUD Plugin manages all the drawing to canvas that we require var MapVoteHUDPlugin h; var MapVoteGameReplicationInfo MyGRI; // Variables which keep track of player's votes in each map var array< struct VotedForMap { var int votedTimes; var string votedMap; } > VotedForMaps; var int totalVotes; var float lastVoteTime; // Local (client-side) copy of map rotations var string VoteableMaps[10], next; var array MapsInRotation; var array AllMaps; // Server-side variables used to control dumping of AllMaps to clients var string ReplicatedMapList[20]; var int ReplicatedMapListSize, currentSegment; var bool bSendingMaplist, bSentMapList; // Make sure we only draw the ASCII logo once var bool logodone; // Error messages var localized string QueuedMapMsg, AlreadyQueuedMsg; // a map is already queued var localized string TooManyRequestsMsg, TooManyIdenticalRequestsMsg; // too many votes var localized string TooSoonToVoteMsg; // wait until delay has passed // Voting UI Support var config bool DisableGUI; // Set true to use the old-style command-line interface var config int VoteGUINumRows; // Number of rows to display in the vote GUI var bool bDisplayMapChooser; // Set as a flag to let the HUD plugin know we want to // display the vote GUI var config Sound MapVoteScrollSound; var config Sound MapVoteClickSound; var config string voteStyle; // Type of mapvote interface to use var string voteStyles[3]; // Voting UI localized text strings var localized string MapVoteWindowTitle, MapVoteHelpLine1, MapVoteHelpLine2; // MapVote Graphical Config Support var array< struct ConfigLine { var() string Description; var() string Value; var() string HelpText1; var() string HelpText2; } > ConfigLines; var bool bDisplayConfigGUI, bConfigGUIInitDone; var int cfgPos; var localized string MapVoteConfigWindowTitle; // 'Internal' variables which control the voting GUI var array< struct VoteLine { var() int Num; var() String Text; var() bool AdminOnly; var() Color Colour; } > VoteLines; var int pos, start, total; var int linespacing, numspacing, bracketspacing; //=============================================================================// // GUI Editing Support // //-----------------------------------------------------------------------------// // This is used to place GUI elements in-game to help with designing the GUI // // for a particular mutator. It's a bit cobbled at the moment and relies on a // // lot of EXEC functions, but is certainly easier than adding all the GUI // // components programatically and positioning them using trial and error. // //=============================================================================// // // Flag which says we're in GUI editing mode // var() config bool bGUIEdit; // // // Array of GUI elements that we will work with // var() config array< struct GUIElement { var() bool bDisplayed; // var() Material mat; // var() float top; // var() float left; // var() float xSize; // var() float ySize; // var() float u; // var() float v; // var() float uSize; // var() float vSize; // var() int alpha; } > GUIElements; // // // Element currently being edited // var() config int currentElement; // // // Parameter currently being edited // var() enum EEditType { // ET_Position, // ET_Size, // ET_UV, // ET_UVSize // } currentEditType; // var() config int moveAmount; // // // The "window" is a pseudo-component designed to help determine dimensions and // // nothing else // var() config int windowX, windowY, windowWidth, windowHeight, windowAlpha; // var() config bool bDisplayWindow; // var() config Material windowMaterial; // // // The "cursor" is a flashing box which surrounds the current element if required // var() config bool bDisplayCursor; // Can be enabled/disabled // var() config int cursorFlashRate; // 1=slow, 100=flicker, default=70 // var() config color cursorColor; // var float lastFlashTime; // Vars to keep track of when to flash // var bool currentFlashState; // //----------------------------------------------------------------------------- replication { unreliable if (Role < ROLE_Authority) RequestMap, ServerDisplayMapList; reliable if (Role == ROLE_Authority) ClientClearLocalMapList, ClientUpdateLocalMapList, ClientUpdateVotableMapList, ClientUpdateFullMapList, ClientDisplayGUI, ReBuildVoteLineArray, ClientNotifyVoteFailed, ClientNotifyVoteAccepted; reliable if (Role == ROLE_Authority) next; reliable if (Role < ROLE_Authority) DisableGUI; } //----------------------------------------------------------------------------- simulated event PostNetReceive() { // Make sure we have a HUD plugin on clients SpawnHUDPlugin(); } //----------------------------------------------------------------------------- // Tries to spawn the HUD plugin simulated function SpawnHUDPlugin() { if ( ViewPort(Player)? ) { if (!logodone) DrawPrettyLogo(); if (!h?) { Log ("MapVote: Spawning HUD Plugin"); h = new class 'MapVoteHUDPlugin'; h.Register(Level, self); if (h?) Log ("MapVote: HUD Plugin successfully spawned"); else Log ("MapVote: HUD Plugin creation failed"); } } } //----------------------------------------------------------------------------- // Does what it says on the tin simulated exec function DrawPrettyLogo() { logodone = true; if (Level.GetLocalPlayerController() == self) { ClientMessage("+-----------------------------------------------------------------+"); ClientMessage("| .-------------. .-------------. .-------------. |"); ClientMessage("| | | | | | | |"); ClientMessage("| '---------. | | .---------' | .---------' |"); ClientMessage("| .---------' | | '---------. | '---------. |"); ClientMessage("| | < | | | | |"); ClientMessage("| '---------. | '---------. | | .---------' |"); ClientMessage("| .---------' | .---------' | | '---------. |"); ClientMessage("| | | | | | | |"); ClientMessage("| '-------------' '-------------' '-------------' |"); ClientMessage("| |"); ClientMessage("| o o o |"); ClientMessage("| ooooo ooooo oooo o ooooo oooo ooooo ooooo oooo ooooo |"); ClientMessage("| o o o ooo ooooo o o o o o o o ooo ooo o o o o |"); ClientMessage("| ooo o oooo oooo o ooooo o o ooo oooo ooooo o o o |"); ClientMessage("| oooo |"); ClientMessage("+-----------------------------------------------------------------+"); ClientMessage("| MAP VOTE MUTATOR VERSION 0.5 |"); ClientMessage("+-----------------------------------------------------------------+"); ClientMessage("| Useage: |"); ClientMessage("| MAPVOTE - start a map vote using the graphical interface |"); ClientMessage("| MAPVOTECFG - configure MapVote options |"); ClientMessage("+-----------------------------------------------------------------+"); } } //----------------------------------------------------------------------------- // Functions called by the UI to determine if a poll should be displayed interface function bool ShowPoll() { MyGRI = MapVoteGameReplicationInfo(GameReplicationInfo); return Super.ShowPoll() && MyGRI.PendingMap == ""; } simulated function bool ShowMapVotePoll() { MyGRI = MapVoteGameReplicationInfo(GameReplicationInfo); return bPendingVote && MyGRI? && MyGRI.PendingMap? && MyGRI.PendingMap != ""; } simulated function bool VotedMapDeferred() { MyGRI = MapVoteGameReplicationInfo(GameReplicationInfo); return MyGRI.PendingMapDeferred; } simulated function string GetNominatedMapName() { MyGRI = MapVoteGameReplicationInfo(GameReplicationInfo); return MyGRI.PendingMap; } simulated function bool DisplayMapSelectionGUI() { return (bDisplayConfigGUI || (!DisableGUI && bDisplayMapChooser)); } //----------------------------------------------------------------------------- // Called by the HUD Plugin to see if we want to enable GUI editing //simulated function bool GUIEditMode() { return bGUIEdit; } //----------------------------------------------------------------------------- // Console function to change mapvote GUI parameters exec function MapVoteCfg(string command) { Local Array params; StrArray(command, " ", params); if (params[0] ~= "disablegui") { if (DisableGUI) return; DisableGUI = true; bDisplayMapChooser = false; ClearProgressMessages(); SetProgressTime(6); SetProgressMessage(0, "Map Vote GUI is now disabled", class'Canvas'.Static.MakeColor(255,0,0)); ClientMessage("Map Vote GUI is now disabled"); SendEvent("HideConsole"); } else if (params[0] ~= "enablegui") { if (!DisableGUI) return; DisableGUI = false; bDisplayMapChooser = false; ClearProgressMessages(); SetProgressTime(6); SetProgressMessage(0, "Map Vote GUI is now enabled", class'Canvas'.Static.MakeColor(0,255,0)); ClientMessage("Map Vote GUI is now enabled"); SendEvent("HideConsole"); } else if (params[0] ~= "menusize") { VoteGUINumRows = int(params[1]); pos = 0; start = 0; if (VoteGUINumRows < 3) VoteGUINumRows = 3; if (VoteGUINumRows > 12) VoteGUINumRows = 12; if (VoteGUINumRows == 0) { VoteGUINumRows = 8; DisableGUI = true; } else { DisableGUI = false; } SendEvent("HideConsole"); } else if (params[0] ~= "style") { if (!(params[1] ~= "small") && !(params[1] ~= "verysmall")) params[1] = "normal"; voteStyle = params[1]; SendEvent("HideConsole"); } else { bDisplayConfigGUI = !bDisplayConfigGUI; // Show/hide the configuration GUI cfgPos = 0; ClientMessage(""); ClientMessage("Usage: MapVoteCfg enablegui - enables the graphical mapvote (default)"); ClientMessage(" MapVoteCfg disablegui - disables the graphical mapvote"); ClientMessage(" MapVoteCfg menusize - set the number of items to display on the map vote menu"); ClientMessage(" MapVoteCfg style