Commit 53738741 authored by Razer's avatar Razer
Browse files

Updated Desolation Clan Functions

parent 8212b6e4
......@@ -16,9 +16,6 @@ if!(isServer) then {
_clanName = ["Enter Clan Name:","CREATE"] call BASE_fnc_getTextInput; // TODO get user input
if (_clanName == "") exitWith {}; // Cancel or no name
if (count(_clanName splitString " ") > 1) exitWith {systemChat "Whitespaces are not allowed"};
if (count(_clanName splitString "'""") > 1) exitWith {systemChat "Strings are not allowed"};
[player,_clanName] remoteExec ["DS_fnc_createClan",2]; // Send request to server
_timeout = diag_tickTime + 5;
......
#define SELF DS_fnc_RscDisplayDSRJournalClan
// TODO Hide right page data unless player is selected
// TODO Update player list onkick / setrank
// DS_fnc_RscDisplayDSRJournalClan = {};
params ["_mode","_params","_class"];
switch _mode do {
case "onLoad":{
_params params ["_display"];
// Get control classes
_titleClan = _display getVariable "TitleClan";
_TextClanPlayers = _display getVariable "TextClanPlayers";
_listPlayers = _display getVariable "ListPlayers";
// TODO ADD COMMANDS BASED ON RANK (DEFINE RANKS)
_TextUserInfo = _display getVariable "TextUserInfo";
_TextRank = _display getVariable "TextRank";
_ComboRank = _display getVariable "ComboRank";
_TextComment = _display getVariable "TextComment";
_EditComment = _display getVariable "EditComment";
_clanUUID = player getVariable ["clanUUID",""];
if (_clanUUID == "") exitWith {_display closeDisplay 1};
// [name, owners uuid, owners steamid, owners lastnick, [members],[variables]]
// [[player uuid, steamid, lastnick, rank, comment], [player uuid, steamid, lastnick, rank, comment]]
_clanData = [_clanUUID] call DB_fnc_getClanData;
_clanData params ["_clanName","_ownerUUID","_ownerSteamID","_ownerName","_clanMembers","_clanVariables"];
_display setVariable ["ClanData",_clanData];
_isOnline = {
params ["_pUUID"];
if ((allPlayers findIf {_x getVariable ["pUUID",""] == _pUUID}) != -1) then {
// Online
[0,1,0,1]
} else {
// Offline
[1,0,0,1]
_this spawn {
params ["_mode","_params","_class"];
_params params ["_display"];
// Get control classes
_titleClan = _display getVariable "TitleClan";
_TextClanPlayers = _display getVariable "TextClanPlayers";
_listPlayers = _display getVariable "ListPlayers";
// TODO ADD COMMANDS BASED ON RANK (DEFINE RANKS)
_textUserInfo = _display getVariable "TextUserInfo";
_textRank = _display getVariable "TextRank";
_comboRank = _display getVariable "ComboRank";
_textComment = _display getVariable "TextComment";
_editComment = _display getVariable "EditComment";
_buttonSetRank = _display getVariable "ButtonSetRank";
_buttonSaveComment = _display getVariable "ButtonSaveComment";
_buttonKick = _display getVariable "ButtonKick";
_clanUUID = player getVariable ["clanUUID",""];
if (_clanUUID == "") exitWith {_display closeDisplay 1};
// [name, owners uuid, owners steamid, owners lastnick, [members],[variables]]
// [[player uuid, steamid, lastnick, rank, comment], [player uuid, steamid, lastnick, rank, comment]]
_clanData = [_clanUUID] call DB_fnc_getClanData;
_clanData params ["_clanUUID","_clanName","_ownerUUID","_ownerSteamID","_ownerName","_clanMembers","_clanVariables"];
// Get player rank
_pUUID = player getVariable ["pUUID",""];
_playerRank = (_clanMembers select (_clanMembers findIf {_x select 0 == _pUUID})) select 3;
_display setVariable ["PlayerRank",_playerRank];
// Remove Buttons from normal players
if (_playerRank == 100) then {
_buttonSetRank ctrlEnable false;
_buttonSaveComment ctrlEnable false;
_comboRank ctrlEnable false;
};
_buttonKick ctrlEnable false;
_getStatusColor = {
params ["_memberUUID"];
private _isOnline = ((allPlayers findIf {_x getVariable ["pUUID",""] == _memberUUID}) != -1);
if (_isOnline) then {
// Online
[0,1,0,1]
} else {
// Offline
[1,0,0,1]
};
};
// Set clan name
_titleClan ctrlSetStructuredText parseText format ["<t align='center' size='1.2'>Clan: %1</t>",_clanName];
_editComment ctrlSetText ""; // Restore on player select
// Add members to list (sort by rank?)
for "_i" from 0 to (count _clanMembers) - 1 do {
(_clanMembers select _i) params ["_memberUUID","_memberSteamID","_memberName","_memberRank","_memberComment"];
_index = _listPlayers lbAdd _memberName;
_listPlayers lbSetColor [_index,[_memberUUID] call _getStatusColor];
_listPlayers lbSetData [_index,str(_clanMembers select _i)];
_listPlayers lbSetSelected [0,true]; // Select first row (owner)
};
// Add event to update selected target player
_listPlayers ctrlAddEventHandler ["LBSelChanged",{
params ["_control","_selectedIndex"];
if (_selectedIndex == -1) exitWith {};
_display = ctrlParent _control;
_memberData = parseSimpleArray(_control lbData _selectedIndex);
_memberData params ["_memberUUID","_memberSteamID","_memberName","_memberRank","_memberComment"];
diag_log str(_memberData);
_playerRank = _display getVariable "playerRank";
_pUUID = player getVariable ["pUUID",""];
// Add ability to kick
_buttonKick = _display getVariable "ButtonKick";
_buttonKick ctrlEnable false;
// Allow kick if not self, is admin/owner and target not owner
if (_pUUID != _memberUUID && _playerRank <= 10 && _memberRank != 0) then {
_buttonKick ctrlEnable true;
};
// RANK
// Todo only allow owner to change owner
// If owner wants to change owner add BIS_fnc_guiMessage to confirm owner change
_ranks = [["Owner",0],["Admin",10],["Member",100]]; // TODO DEFINE SOMEWHERE ELSE
_comboRank = _display getVariable "ComboRank";
_currentRank = (_ranks findIf {_memberRank == _x select 1});
_comboRank lbAdd ((_ranks select _currentRank) select 0);
_comboRank lbSetCurSel 0;
_ranks deleteAt _currentRank;
// If admin (Allow change)
if (_playerRank <= 10) then {
// Add remaining ranks
_ranks apply {
_index = _comboRank lbAdd (_x select 0);
};
};
// Select current
_display setVariable ["TargetMemberData",_memberData];
// Update comment
_editComment = _display getVariable "EditComment";
_editComment ctrlSetText _memberComment;
}];
//--- Add button events
// Kick
_buttonKick ctrlAddEventHandler ["ButtonClick",{
["kick",_this] spawn DS_fnc_RscDisplayDSRJournalClan;
}];
// Save comment
_buttonSaveComment ctrlAddEventHandler ["ButtonClick",{
["savecomment",_this] spawn DS_fnc_RscDisplayDSRJournalClan;
}];
// Rank
_buttonSetRank ctrlAddEventHandler ["ButtonClick",{
["setrank",_this] spawn DS_fnc_RscDisplayDSRJournalClan;
}];
// Leave
_buttonLeave = _display getVariable "ButtonLeave";
_buttonLeave ctrlAddEventHandler ["ButtonClick",{
["leave",_this] spawn DS_fnc_RscDisplayDSRJournalClan;
}];
//--- Add arrow events
_leftArrowCtrl = _display getVariable "arrowLeft";
_rightArrowCtrl = _display getVariable "arrowRight";
_leftArrowCtrl ctrlSetText "Exit";
_rightArrowCtrl ctrlSetText "Notes";
_rightArrowCtrl ctrlAddEventHandler ["ButtonClick",{
["nextpage",_this] spawn DS_fnc_RscDisplayDSRJournalClan;
}];
_leftArrowCtrl ctrlAddEventHandler ["ButtonClick",{
["previouspage", _this] spawn DS_fnc_RscDisplayDSRJournalClan;
}];
};
// Set clan name
_titleClan ctrlSetStructuredText parseText format ["<t align='center' size='1.5'>Clan: %1</t>",_clanName];
// Add owner to list
_listPlayers lbAdd _ownerName;
_listPlayers lbSetColor [0,[_ownerUUID] call _isOnline];
// Add members to list (sort by rank?)
for "_i" from 0 to (count _clanMembers) - 1 do {
(_clanMembers select _i) params ["_memberUUID","_memberSteamID","_memberName","_memberRank","_memberComment"];
_index = _listPlayers lbAdd _memberName;
_listPlayers lbSetColor [_index,[_ownerUUID] call _isOnline];
};
// Add event to update selected target player
_listPlayers ctrlAddEventHandler ["onLBListSelChanged",{
params ["_control","_selectedIndex"];
_display = ctrlParent _control;
if (_selectedIndex == -1) exitWith {};
_clanData = _display getVariable "ClanData";
// Select owner or member
_targetUUID = [((_clanData#4)#(_selectedIndex - 1))#0,_clanData#1] select (_selectedIndex == 0);
_targetName = [((_clanData#4)#(_selectedIndex - 1))#2,_clanData#2] select (_selectedIndex == 0);
_display setVariable ["TargetUserData",[_targetUUID,_targetName]];
}];
//--- Add button events
// Kick
_buttonKick = _display getVariable "ButtonKick";
_buttonSaveComment ctrlAddEventHandler ["ButtonClick",{
["kick",_this] spawn SELF;
}];
// Save comment
_buttonSaveComment = _display getVariable "ButtonSaveComment";
_buttonSaveComment ctrlAddEventHandler ["ButtonClick",{
["savecomment",_this] spawn SELF;
}];
// Rank
_buttonSetRank = _display getVariable "ButtonSetRank";
_buttonSetRank ctrlAddEventHandler ["ButtonClick",{
["setrank",_this] spawn SELF;
}];
// Leave
_buttonLeave = _display getVariable "ButtonLeave";
_buttonLeave ctrlAddEventHandler ["ButtonClick",{
["leave",_this] spawn SELF;
}];
//--- Add arrow events
_leftArrowCtrl = _display getVariable "arrowLeft";
_rightArrowCtrl = _display getVariable "arrowRight";
_leftArrowCtrl ctrlSetText "Exit";
_rightArrowCtrl ctrlSetText "Notes";
_rightArrowCtrl ctrlAddEventHandler ["ButtonClick",{
["nextpage",_this] spawn SELF;
}];
_leftArrowCtrl ctrlAddEventHandler ["ButtonClick",{
["previouspage", _this] spawn SELF;
}];
};
case "kick":{
_params params ["_buttonKick"];
_display = ctrlParent _buttonKick;
_listPlayers = _display getVariable "ListPlayers";
_selectedPlayer = _display getVariable ["TargetUserData",[]];
_selectedPlayer params ["_clanUUID","_targetUUID","_nameTarget"];
_selectedPlayer = _display getVariable ["TargetMemberData",[]];
if (_selectedPlayer isEqualTo []) exitWith {};
_selectedPlayer params ["_memberUUID","_memberSteamID","_memberName","_memberRank","_memberComment"];
_clanUUID = player getVariable "clanUUID";
_confirm = [(format ["Are you sure you want to kick player: %1?",_nameTarget]),"Confirm Kick",true,true] call BIS_fnc_guiMessage;
_confirm = [(format ["Are you sure you want to kick player: %1?",_memberName]),"Confirm Kick",true,true] call BIS_fnc_guiMessage;
if (_confirm) then {
// TODO Make sure kick was success
[_targetUUID,_clanUUID] remoteExec ["DB_fnc_removeClanPlayer",2];
[_memberUUID,_clanUUID] remoteExec ["DB_fnc_removeClanPlayer",2];
systemChat "Player kicked";
};
};
case "leave":{
_params params ["_buttonLeave"];
// TODO If clan owener, change owner?
// TODO If clan owner, change owner?
if ([player] call DB_fnc_isClanOwner) exitWith {
systemChat "Change clan owner first!";
};
_display = ctrlParent _buttonLeave;
_confirm = ["Are you sure?","Confirm leave",true,true] call BIS_fnc_guiMessage;
......@@ -129,16 +188,51 @@ switch _mode do {
// TODO get success
[player] remoteExec ["DB_fnc_removeClanPlayer",2];
systemChat "You left the clan";
_display closeDisplay 1;
};
_display closeDisplay 1;
};
case "setrank":{
_params params ["_buttonSetRank"];
_display = ctrlParent _buttonSetRank;
_selectedPlayer = _display getVariable ["TargetMemberData",[]];
if (_selectedPlayer isEqualTo []) exitWith {};
_selectedPlayer params ["_memberUUID","_memberSteamID","_memberName","_memberRank","_memberComment"];
_comboRank = _display getVariable "ComboRank";
_currentSelected = lbCurSel _comboRank;
_ranks = [["Owner",0],["Admin",10],["Member",100]]; // TODO DEFINE SOMEWHERE ELSE
_targetRank = (_ranks select _currentSelected) select 1;
if (_targetRank != _memberRank) then {
_clanUUID = player getVariable ["clanUUID",""];
// [[_memberUUID,_clanUUID],_targetRank] remoteExec ["DB_fnc_updateClanPlayer",2];
systemChat "Rank updated";
systemChat str(_targetRank);
};
// TODO Read current selected from cbList
// TODO if rank = 0 = owner (can change owner)
// if rank = 10 = admin, can demote admins and promote players
};
case "savecomment":{
// DONE + tested
_params params ["_buttonSaveComment"];
_display = ctrlParent _buttonSaveComment;
_editComment = _display getVariable "EditComment";
_currentText = ctrlText _editComment;
_selectedPlayer = _display getVariable ["TargetMemberData",[]];
if (_selectedPlayer isEqualTo []) exitWith {};
_selectedPlayer params ["_memberUUID","_memberSteamID","_memberName","_memberRank","_memberComment"];
// Update comment to DB if changed
if !(_currentText isEqualTo _memberComment) then {
systemChat "Comment updated!";
_clanUUID = player getVariable ["clanUUID",""];
[[_memberUUID,_clanUUID],_currentText] remoteExec ["DB_fnc_updateClanPlayer",2];
};
};
case "nextpage":{
_params params ["_rightArrowCtrl"];
......
......@@ -289,6 +289,8 @@ switch _mode do {
};
};
};
// Add points
[1] call DS_fnc_addPoints;
};
};
};
......
......@@ -434,6 +434,7 @@ class CfgFunctions
class RscDisplayDSRJournalCrafting {};
class RscDisplayDSRJournalBuilding {};
class RscDisplayDSRJournalProgression {};
class RscDisplayDSRJournalClan {};
};
class Client_Interface_Journal_Notes {
file = "Desolation\Client\Interface\Journal\Notes";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment