Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V0.96.8] cratefiller integration #814

Open
wants to merge 11 commits into
base: v0.96.8
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.96.8 (TBD)
* Added: Czech translation. Thanks to [MJVEVERUSKA](https://github.com/MJVEVERUSKA)
* Added: KP cratefiller available at the logistic station.
* Added: Ability to carry ressource crates.
* Added: Scripts/configs to setup and run development environment from VSCode tasks
* Updated: Italian localization. Thanks to [k4s0](https://github.com/k4s0)
Expand Down
2 changes: 2 additions & 0 deletions Missionframework/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ class KPLIB {
};
#include "scripts\client\CfgFunctions.hpp"
#include "scripts\server\CfgFunctions.hpp"

#include "KP\KPCF\functions.hpp"
};
86 changes: 86 additions & 0 deletions Missionframework/KP/KPCF/fnc/fn_cratefiller_addEquipment.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "..\ui\defines.hpp"
#include "script_component.hpp"
/*
KPLIB_fnc_cratefiller_addEquipment

File: fn_cratefiller_addEquipment.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-04-06
Last Update: 2020-09-23
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html


Description:
Adds the given amount of the selected item to the inventory.

Parameter(s):
_controlId - Id of the control which is selected [NUMBER, defaults to 0]

Returns:
Function reached the end [BOOL]
*/

params [
["_controlId", 0, [0]]
];

// Dialog controls
private _dialog = findDisplay KPLIB_IDC_CRATEFILLER_DIALOG;
private _ctrlActive = _dialog displayCtrl _controlId;

// Read controls
private _indexActive = lbCurSel _ctrlActive;

// Check for empty selection
if (_indexActive isEqualTo -1 || ((lnbSize _ctrlActive) select 0) isEqualTo 0) exitWith {
[localize "STR_KPLIB_HINT_SELECTION"] call CBA_fnc_notify;
};

// Get the storage object
private _storage = [] call KPLIB_fnc_cratefiller_getStorage;
private _nearFOB = player getVariable ["KPLIB_fobName", ""];
private _inventory = [] call KPLIB_fnc_cratefiller_getInventory;

// Check if the storage is in range
if ((_storage distance2D (getMarkerPos _nearFOB)) > KPLIB_range_fob) exitWith {
[localize "STR_KPLIB_HINT_RANGE"] call CBA_fnc_notify;
[] remoteExecCall ["KPLIB_fnc_cratefiller_getNearStorages", (allPlayers - entities "HeadlessClient_F")];
};

// Variables
private _item = "";

if (_controlId isEqualTo KPLIB_IDC_CRATEFILLER_INVENTORYLIST) then {
// Item selection
_item = (_inventory select _indexActive) select 1;
} else {
private _cat = CCGVAR("activeCat", "");
private _catStuff = CGVAR(_cat, []);
_item = (_catStuff select _indexActive) select 1;
};

// Check for enough inventory capacity
if (!(_storage canAdd _item)) exitWith {
CBA_ui_notifyQueue = [];
[localize "STR_KPLIB_HINT_FULL"] call CBA_fnc_notify;
};

// Add the given item
if (_item isKindOf "Bag_Base") then {
_storage addBackpackCargoGlobal [_item, 1];
} else {
_storage addItemCargoGlobal [_item, 1];
};

[] remoteExecCall ["KPLIB_fnc_cratefiller_showInventory", (allPlayers - entities "HeadlessClient_F")];

private _config = [_item] call KPLIB_fnc_cratefiller_getConfigPath;
private _name = (getText (_config >> "displayName"));
private _picture = (getText (_config >> "picture"));
CBA_ui_notifyQueue = [];
[
[_picture, 2],
[format [localize "STR_KPLIB_HINT_ADDED", _name, 1]]
] call CBA_fnc_notify;

true
127 changes: 127 additions & 0 deletions Missionframework/KP/KPCF/fnc/fn_cratefiller_createEquipmentList.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include "..\ui\defines.hpp"
#include "script_component.hpp"
/*
KPLIB_fnc_cratefiller_createEquipmentList

File: fn_cratefiller_createEquipmentList.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-04-06
Last Update: 2020-09-23
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html


Description:
Changes the shown equipment category.

Parameter(s):
NONE

Returns:
Function reached the end [BOOL]
*/

// Dialog controls
private _dialog = findDisplay KPLIB_IDC_CRATEFILLER_DIALOG;
private _ctrlCat = _dialog displayCtrl KPLIB_IDC_CRATEFILLER_COMBOEQUIPMENT;
private _ctrlWeapon = _dialog displayCtrl KPLIB_IDC_CRATEFILLER_COMBOWEAPONS;
private _ctrlSearch = _dialog displayCtrl KPLIB_IDC_CRATEFILLER_SEARCHBAR;
private _ctrlEquipment = _dialog displayCtrl KPLIB_IDC_CRATEFILLER_EQUIPMENTLIST;

// Clear the lists
lbClear _ctrlWeapon;
lbClear _ctrlEquipment;

// Hide controls
_ctrlWeapon ctrlShow false;
_ctrlSearch ctrlShow false;

// Read controls
private _catIndex = lbCurSel _ctrlCat;

// Check for empty selection
if (_catIndex isEqualTo -1) exitWith {};

// Variables
private _config = "";

switch (_catIndex) do {

// Weapons
case 0 : {
{
_config = [_x select 1] call KPLIB_fnc_cratefiller_getConfigPath;
_ctrlEquipment lnbAddRow ["", _x select 0];
_ctrlEquipment lnbSetPicture [[_foreachIndex, 0], getText (_config >> "picture")];
} forEach (CGVAR("weapons", []));
CCSVAR("activeCat", "weapons", false);
};

// Magazines
case 1 : {
_ctrlWeapon ctrlShow true;
_ctrlSearch ctrlShow true;
{
_index = _ctrlWeapon lbAdd (_x select 0);
_ctrlWeapon lbSetData [_index , _x select 1];
_config = [_x select 1] call KPLIB_fnc_cratefiller_getConfigPath;
_ctrlWeapon lbSetPicture [_index, getText (_config >> "picture")];
} forEach (CGVAR("weapons", []));
CCSVAR("activeCat", "magazines", false);
};

// Attachments
case 2 : {
_ctrlWeapon ctrlShow true;
_ctrlSearch ctrlShow true;
{
_index = _ctrlWeapon lbAdd (_x select 0);
_ctrlWeapon lbSetData [_index , _x select 1];
_config = [_x select 1] call KPLIB_fnc_cratefiller_getConfigPath;
_ctrlWeapon lbSetPicture [_index, getText (_config >> "picture")];
} forEach (CGVAR("weapons", []));
CCSVAR("activeCat", "attachments", false);
};

// Grenades
case 3 : {
{
_config = [_x select 1] call KPLIB_fnc_cratefiller_getConfigPath;
_ctrlEquipment lnbAddRow ["", _x select 0];
_ctrlEquipment lnbSetPicture [[_foreachIndex, 0], getText (_config >> "picture")];
} forEach (CGVAR("grenades", []));
CCSVAR("activeCat", "grenades", false);
};

// Explosives
case 4 : {
{
_config = [_x select 1] call KPLIB_fnc_cratefiller_getConfigPath;
_ctrlEquipment lnbAddRow ["", _x select 0];
_ctrlEquipment lnbSetPicture [[_foreachIndex, 0], getText (_config >> "picture")];
} forEach (CGVAR("explosives", []));
CCSVAR("activeCat", "explosives", false);
};

// Items
case 5 : {
{
_config = [_x select 1] call KPLIB_fnc_cratefiller_getConfigPath;
_ctrlEquipment lnbAddRow ["", _x select 0];
_ctrlEquipment lnbSetPicture [[_foreachIndex, 0], getText (_config >> "picture")];
} forEach (CGVAR("items", []));
CCSVAR("activeCat", "items", false);
};

// Backpacks
case 6 : {
{
_config = [_x select 1] call KPLIB_fnc_cratefiller_getConfigPath;
_ctrlEquipment lnbAddRow ["", _x select 0];
_ctrlEquipment lnbSetPicture [[_foreachIndex, 0], getText (_config >> "picture")];
} forEach (CGVAR("backpacks", []));
CCSVAR("activeCat", "backpacks", false);
};

};

true
80 changes: 80 additions & 0 deletions Missionframework/KP/KPCF/fnc/fn_cratefiller_createSubList.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "..\ui\defines.hpp"
#include "script_component.hpp"
/*
KPLIB_fnc_cratefiller_createSubList

File: fn_cratefiller_createSubList.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-04-06
Last Update: 2020-10-01
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html


Description:
Creates a list with valueable magazines or attachments.

Parameter(s):
NONE

Returns:
Function reached the end [BOOL]
*/

// Dialog controls
private _dialog = findDisplay KPLIB_IDC_CRATEFILLER_DIALOG;
private _ctrlCat = _dialog displayCtrl KPLIB_IDC_CRATEFILLER_COMBOEQUIPMENT;
private _ctrlWeapon = _dialog displayCtrl KPLIB_IDC_CRATEFILLER_COMBOWEAPONS;
private _ctrlEquipment = _dialog displayCtrl KPLIB_IDC_CRATEFILLER_EQUIPMENTLIST;

// Clear the lists
lbClear _ctrlEquipment;

// Read controls
private _catIndex = lbCurSel _ctrlCat;
private _weaponIndex = lbCurSel _ctrlWeapon;

// Check for empty selection
if (_weaponIndex isEqualTo -1) exitWith {};

// Weapon selection
private _weaponType = _ctrlWeapon lbData _weaponIndex;

// Variables
private _config = "";

switch (_catIndex) do {

// Magazines
case 1 : {
// Get compatible magazines
private _glType = (getArray (configfile >> "CfgWeapons" >> _weaponType >> "muzzles")) select 1;
private _magazines = [_weaponType] call CBA_fnc_compatibleMagazines;
_magazines append ([configfile >> "CfgWeapons" >> _weaponType >> _glType] call CBA_fnc_compatibleMagazines);
private _sortedMagazines = [_magazines] call KPLIB_fnc_cratefiller_sortList;
CSVAR("magazines", _sortedMagazines);

// Fill controls
{
_config = [_x select 1] call KPLIB_fnc_cratefiller_getConfigPath;
_ctrlEquipment lnbAddRow ["", _x select 0];
_ctrlEquipment lnbSetPicture [[_foreachIndex, 0], getText (_config >> "picture")];
} forEach _sortedMagazines;
};

// Attachments
case 2 : {
// Get compatible attachments
private _attachments = [_weaponType] call BIS_fnc_compatibleItems;
private _sortedAttachments = [_attachments] call KPLIB_fnc_cratefiller_sortList;
CSVAR("attachments", _sortedAttachments);

// Fill controls
{
_config = [_x select 1] call KPLIB_fnc_cratefiller_getConfigPath;
_ctrlEquipment lnbAddRow ["", _x select 0];
_ctrlEquipment lnbSetPicture [[_foreachIndex, 0], getText (_config >> "picture")];
} forEach _sortedAttachments;
};
};

true
46 changes: 46 additions & 0 deletions Missionframework/KP/KPCF/fnc/fn_cratefiller_deletePreset.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "..\ui\defines.hpp"
/*
KPLIB_fnc_cratefiller_deletePreset

File: fn_cratefiller_deletePreset.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-04-07
Last Update: 2020-09-23
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html


Description:
Deletes the selected preset.

Parameter(s):
NONE

Returns:
Function reached the end [BOOL]
*/

// Dialog controls
private _dialog = findDisplay KPLIB_IDC_CRATEFILLER_DIALOG;
private _ctrlImport = _dialog displayCtrl KPLIB_IDC_CRATEFILLER_IMPORTNAME;

// Read the import name
private _index = lbCurSel _ctrlImport;
private _importName = _ctrlImport lbText _index;

// Check for empty selection
if (_index isEqualTo -1) exitWith {
[localize "STR_KPLIB_HINT_SELECTION"] call CBA_fnc_notify;
};

// Read the presets from profileNamespace
private _import = profileNamespace getVariable ["KPLIB_cratefiller_preset", []];

_import deleteAt (_import findIf {(_x select 0) isEqualTo _importName});

// Save the inventory into profileNamespace
profileNamespace setVariable ["KPLIB_cratefiller_preset", _import];
saveProfileNamespace;

[] call KPLIB_fnc_cratefiller_showPresets;

true
Loading