Skip to content

Commit

Permalink
Added: A tooltip for the locktime (#3334)
Browse files Browse the repository at this point in the history
* INIT:

* THE NIGHTMARES ARE OVER.

* stringtable

* Added: grammar to the comments

* review changes
  • Loading branch information
killerswin2 authored Jul 6, 2024
1 parent fede1c2 commit 0bed86b
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 5 deletions.
1 change: 1 addition & 0 deletions A3A/addons/core/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ class CfgFunctions
class secondsToTimeSpan {};
class systemTime_format_S {};
class timeSpan_format {};
class systemTimeDurationToTimeSpan {};
};

class UI {
Expand Down
154 changes: 154 additions & 0 deletions A3A/addons/core/functions/Time/fn_systemTimeDurationToTimeSpan.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* File: fn_systemTimeDurationToTimeSpan.sqf
* Function:
* Author: <killerswin2>
* Function description
* converts the arma 3 timespans to antistai timespans
* Arguments:
* 0: timespan <ARRAY>
* 1: timespan <BOOL>
*
* Return Value:
* 0: timespan in antistasi format
*
* Example:
* [systemTimeUTC, _locktime] call A3A_fnc_systemTimeDurationToTimeSpan
*
* Public: No
*/

/*
I MUST PREFACE THIS HERE. I FUCKING HATE DOING THIS SHIT IN SQF.
THIS CODE WENT THROUGH ABOUT 6 DIFFERENT REVISIONS, WHETHER BY
FIXING RANDOM ERRORS THAT ONLY SQF COULD HAVE, OR THE FUCKING
STUPID FACT THAT WE ONLY HAVE FUCKING FLOATS IN THIS LANGUAGE.
THAT WOULDN'T BE A PROBLEM IF WE HAD LOWER LEVEL OPERATORS
AND FUNCTIONS, BUT AFTER 20+ YEARS THOSE NEVER MATERAILIZED.
FLOATS CAN ONLY SUPPORT INT VALUES UP TO 16,777,216. NOW THINK
WHY IS THIS A PROBLEM. ONE YEAR, NON LEAP, IS 31,536,000 SECONDS.
IT IS IMPOSSIBLE TO ENCODE UNIX TIMESTAMPS OR ANY NORMAL STAMP
WITH THIS ABYSMAL LANGUAGE. SO WHAT DO WE DO? WE FUCKING HAVE
TO MANUALLY FUCKING SUBTRACT PER TIME UNIT. WHY? WHY? WHY? THIS
IS FUCKING STUPID, I'M NOT A FUCKING EXPERT ON CALENDAR
CALCULATIONS BUT THIS LANGUAGE HAS FORCED MY HAND. I WANT THIS
LANGUAGE TO DIE A HORRIBLE DEATH. IF WE WENT TO INTERCEPT OR
JUST A PLAIN EXTENSION, I WOULDN'T HAVE HAD TO SPEND HOURS
ON THIS. I'M NOT A BETTER PROGRAMMER AFTER EXPERIENCING THIS.
MY TIME IS VALUABLE, IT IS A FINITE RESOURCE. I HAVE LOST IT
HERE, I'LL NEVER GET IT BACK. THIS LANGUAGE TREATS US LIKE
SHIT, ONLY BY SPENDING TIME AWAY FROM IT DO WE REASON HOW
TERRIBLE WE HAVE IT. IF THIS WAS ANY OTHER LANGUAGE THIS CODE
WOULD HAVE BEEN THREE LINES MAX.
MAY GOD HAVE MERCY ON THE SOULS THAT MAINTAIN THIS PIECE OF
SHIT.
*/

params ["_systemTimeFinal", "_systemTimeinit"];

#define YEARS 0
#define MONTHS 1
#define DAYS 2
#define HOURS 3
#define MINUTES 4
#define SECONDS 5
#define MILLISECS 6

// test case here [false,580,0,48,22,210,0,0]
//_systemTimeinit = [2022, 11, 30, 16, 31, 2, 685];
//_systemTimeFinal = [2024, 7, 2, 17, 19, 24, 895];

private _daysToMonths365 = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
private _daysToMonths366 = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366];

private _daysInMonths365 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
private _daysInMonths366 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];


private _fnc_isLeapYear =
{
(_this % 4) == 0 && {( _this % 100) != 0 || {_this % 400 == 0}}
};

private _fnc_daysToYear =
{
private _year = _this - 1;
private _century = floor (_year / 100);
floor (_year * (365 * 4 + 1) / 4) - _century + floor (_century / 4)
};

// make a copy of init for use in adder math stuff.
private _finalTime = +_systemTimeFinal;
private _initTime = +_systemTimeinit;

// we don't support months and years, so convert them to days
private _finalDaysFrom = _finalTime # YEARS call _fnc_daysToYear;
_finalDaysFrom = _finalDaysFrom + ([_daysToMonths365, _daysToMonths366] select ((_finalTime # YEARS) call _fnc_isLeapYear) select (_finalTime # MONTHS) - 1);
_finalTime set [DAYS, (_finalTime # DAYS) + _finalDaysFrom];

private _initDaysFrom = _initTime # YEARS call _fnc_daysToYear;
_initDaysFrom = _initDaysFrom+ ([_daysToMonths365, _daysToMonths366] select ((_initTime # YEARS) call _fnc_isLeapYear) select (_initTime # MONTHS) - 1);
_initTime set [DAYS, (_initTime # DAYS) + _initDaysFrom];

// we go one by one for readability
// I definitly do not like doing this.
private _durationMS = _finalTime # MILLISECS - _initTime # MILLISECS;
if(_durationMS < 0) then
{
// now do adder stuff
_finalTime set [SECONDS, (_finalTime # SECONDS) - 1];
_finalTime set [MILLISECS, (_finalTime # MILLISECS) + 1000];
_durationMS = _finalTime # MILLISECS - _initTime # MILLISECS;
};

private _durationSEC = _finalTime # SECONDS - _initTime # SECONDS;
if(_durationSEC < 0) then
{
_finalTime set [MINUTES, (_finalTime # MINUTES) - 1];
_finalTime set [SECONDS, (_finalTime # SECONDS) + 60];
_durationSEC = _finalTime # SECONDS - _initTime # SECONDS;
};

private _durationMIN = _finalTime # MINUTES - _initTime # MINUTES;
if(_durationMIN < 0) then
{
_finalTime set [HOURS, (_finalTime # HOURS) - 1];
_finalTime set [MINUTES, (_finalTime # MINUTES) + 60];
_durationMIN = _finalTime # MINUTES - _initTime # MINUTES;
};

private _durationHOUR = _finalTime # HOURS - _initTime # HOURS;
if(_durationHOUR < 0) then
{
_finalTime set [DAYS, (_finalTime # DAYS) - 1];
_finalTime set [HOURS, (_finalTime # HOURS) + 24];
_durationHOUR = _finalTime # HOURS - _initTime # HOURS;
};

private _durationDAYS = _finalTime # DAYS - _initTime # DAYS;
if(_durationDAYS < 0) exitwith
{
// days are not uniform, so just do this shit. WELCOME TO HELL.
[false, 0, 0, 0, 0, 0, 0, 0]
};

// DON'T FUCKING UNCOMMENT THIS SHIT BELOW
// IT'S HERE TO REMIND OF WHAT SQF TOOK FROM ME
// private _durationMONTHS = _finalTime # MONTHS - _initTime # MONTHS;
// if(_durationMONTHS < 0) then
// {
// _finalTime set [YEARS, (_finalTime # YEARS) - 1];
// _finalTime set [MONTHS, (_finalTime # MONTHS) + 12];
// _durationMONTHS = _finalTime # MONTHS - _initTime # MONTHS;
// };

// private _durationYEARS = _finalTime # YEARS - _initTime # YEARS;
// if(_durationYEARS < 0) exitWith
// {
// // well shit, you're not supposed to get here... just return a zero array
// [0,0,0,0,0,0,0]
// };


[false, _durationDAYS, _durationHOUR, _durationMIN, _durationSEC, _durationMS, 0, 0]
3 changes: 2 additions & 1 deletion A3A/addons/garage/Core/fn_reciveBroadcast.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "defines.inc"
FIX_LINE_NUMBERS()
Trace_1("Reciving broadcast: %1",_this);
params ["_lockUID", "_checkoutUID", "_catIndex", "_vehUID", "_player", "_switch"];
params ["_lockUID", "_checkoutUID", "_catIndex", "_vehUID", "_player", "_switch", "_time"];

private _cat = HR_GRG_Vehicles#_catIndex;
private _vehicle = _cat get _vehUID;
Expand All @@ -37,6 +37,7 @@ if (_switch) then { [getPlayerUID _player] call HR_GRG_fnc_releaseAllVehicles };
if (!isNil "_lockUID") then {
_vehicle set [2, _lockUID];
_vehicle set [5, if (_lockUID isEqualTo "") then { "" } else { name _player }];
_vehicle set [7, [_time, []] select (_lockUID isEqualTo "")];
};

if (!isNil "_checkoutUID") then {
Expand Down
11 changes: 9 additions & 2 deletions A3A/addons/garage/Core/fn_reloadCategory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lbClear _ctrl;
private _selected = -1;
private _HR_GRG_SelectedVehicles = [-1,-1,""];
{
_y params ["_displayName", "_class", "_lockedUID", "_checkedOut", "", ["_lockName", ""]];
_y params ["_displayName", "_class", "_lockedUID", "_checkedOut", "", ["_lockName", ""], "", ["_lockTime", []]];
private _index = _ctrl lbAdd _displayName;
_ctrl lbSetData [_index, str _x];
_ctrl lbSetValue [_index, _x];
Expand All @@ -46,14 +46,21 @@ private _HR_GRG_SelectedVehicles = [-1,-1,""];
};
_ctrl lbSetPictureRight [_index, CheckOutIcon];
_ctrl lbSetPictureRightColor [_index, _color];
_tooltipText = name (_checkedOut call BIS_fnc_getUnitByUID) +" "+( localize "STR_HR_GRG_Feedback_checkedOutToolTip" )+" ";
_tooltipText = format ["%1 %2 %3", name (_checkedOut call BIS_fnc_getUnitByUID), ( localize "STR_HR_GRG_Feedback_checkedOutToolTip" ), parseText "\n"];
};

if !( _lockedUID isEqualTo "" ) then {
private _color = if ( _lockedUID isEqualTo HR_GRG_PlayerUID ) then { [1,1,1,1] } else { [1,0.1,0.1,1] }; //white, red
_ctrl lbSetPictureRight [_index, LockIcon];
_ctrl lbSetPictureRightColor [_index, _color];
_tooltipText = _tooltipText + ( localize "STR_HR_GRG_Feedback_LockedToolTip" )+" "+ _lockName;

private _systemTime = systemTimeUTC;
if(_lockTime isEqualTo []) then {_lockTime = _systemTime;};
private _timeSpan = [_systemTime, _locktime] call A3A_fnc_systemTimeDurationToTimeSpan;
_tooltipText = format [localize "STR_HR_GRG_Feedback_LockedToolTip_Ago", _tooltipText,
[_timeSpan, 0,0,false,2] call A3A_fnc_timeSpan_format
];
};
_ctrl lbSetTooltip [_index, _tooltipText];
_ctrl lbSetPictureRightColorSelected [_index, [0.85,0.85,0.55,1]];
Expand Down
5 changes: 4 additions & 1 deletion A3A/addons/garage/Core/fn_toggleLock.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ if (_lock isEqualTo "" && !(_vehUID in flatten HR_GRG_Sources) && {[_UID] call H
["STR_HR_GRG_Feedback_toggleLock_limit"] remoteExecCall ["HR_GRG_fnc_Hint", _player];
};

private _lockTime = systemTimeUTC;

_veh set [2, _UID];
_veh set [5, [name _player, ""] select (_UID isEqualTo "")];
[_UID, nil, _catIndex, _vehUID, _player, false] call HR_GRG_fnc_broadcast;
_veh set [7, [_lockTime, 0] select (_UID isEqualTo "")];
[_UID, nil, _catIndex, _vehUID, _player, false, _lockTime] call HR_GRG_fnc_broadcast;
Info_3("Lock state toggled for Vehicle ID: %1 | By: %2 | Locked: %3", _vehUID, name _player, (_UID isNotEqualTo ""));
3 changes: 2 additions & 1 deletion A3A/addons/garage/Public/fn_addVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ private _addVehicle = {

private _stateData = [_this] call HR_GRG_fnc_getState;
private _customisation = [_this] call BIS_fnc_getVehicleCustomization;
private _lockTime = [systemTimeUTC, []] select (_lockUID isEqualTo "");

//Antistasi adaptions
_this call _transferToArsenal;
Expand All @@ -182,7 +183,7 @@ private _addVehicle = {

//Add vehicle to garage
private _vehUID = [] call HR_GRG_fnc_genVehUID;
(HR_GRG_Vehicles#_cat) set [_vehUID, [cfgDispName(_class), _class, _lockUID, "", _stateData, _lockName, _customisation]];
(HR_GRG_Vehicles#_cat) set [_vehUID, [cfgDispName(_class), _class, _lockUID, "", _stateData, _lockName, _customisation, _lockTime]];

//register vehicle as a source
if (_sourceIndex != -1) then {
Expand Down
3 changes: 3 additions & 0 deletions A3A/addons/garage/Stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@
<Turkish>Aracı kilitledi</Turkish>
<Chinesesimp>载具被上锁,它属于</Chinesesimp>
</Key>
<Key ID="STR_HR_GRG_Feedback_LockedToolTip_Ago">
<Original>%1: %2 ago</Original>
</Key>
<Key ID="STR_HR_GRG_Feedback_requestMount_Denied">
<Original>Can't mount static</Original>
<German>Kann gegenstand nicht montieren.</German>
Expand Down

0 comments on commit 0bed86b

Please sign in to comment.