Add size parameter to displayTextPicture, Improve parameter checking in displayText functions, Cleanup magazine repack (privates, deprecated macros, style)

This commit is contained in:
jonpas 2016-06-04 20:40:55 +02:00
parent 48ab81ad87
commit 8ff4a2ecaf
7 changed files with 90 additions and 101 deletions

View File

@ -5,17 +5,22 @@
* Arguments: * Arguments:
* 0: Text <ANY> * 0: Text <ANY>
* 1: Image <STRING> * 1: Image <STRING>
* 2: Image color (default: [0, 0, 0, 0]) <ARRAY> * 2: Image color <ARRAY> (default: [1, 1, 1])
* 3: Target Unit. Will only display if target is the player controlled object (default: ACE_player) <OBJECT> * 3: Target Unit. Will only display if target is the player controlled object <OBJECT> (default: ACE_player)
* 4: Size <NUMBER> (default: 2)
* *
* Return Value: * Return Value:
* None * None
* *
* Example:
* ["text", "image", [1, 1, 1], ACE_player, 2] call ace_common_fnc_displayTextPicture
* ["text", "image", nil, nil, 3] call ace_common_fnc_displayTextPicture
*
* Public: Yes * Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params ["_text", "_image", ["_imageColor", [1,1,1]], ["_target", ACE_player]]; params [["_text", ""], ["_image", "", [""]], ["_imageColor", [1,1,1], [[]]], ["_target", ACE_player, [objNull]], ["_size", 2, [0]]];
if (_target != ACE_player) exitWith {}; if (_target != ACE_player) exitWith {};
@ -39,6 +44,6 @@ if (typeName _text != "TEXT") then {
_text = parseText format ["<t align='center'>%1</t>", _text]; _text = parseText format ["<t align='center'>%1</t>", _text];
}; };
_text = composeText [parseText format ["<img size='2' align='center' color='%2' image='%1'/>", _image, _imageColor call BIS_fnc_colorRGBtoHTML], lineBreak, _text]; _text = composeText [parseText format ["<img size='2' align='center' color='%2' image='%1'/>", _image, _imageColor call BIS_fnc_colorRGBtoHTML], lineBreak, _text];
[_text, 2] call FUNC(displayTextStructured); [_text, _size] call FUNC(displayTextStructured);

View File

@ -4,17 +4,20 @@
* *
* Arguments: * Arguments:
* 0: Text <ANY> * 0: Text <ANY>
* 1: Size of the textbox (default: 1.5) <NUMBER> * 1: Size of the textbox <NUMBER> (default: 1.5)
* 2: Target Unit. Will only display if target is the player controlled object (default: ACE_player) <OBJECT> * 2: Target Unit. Will only display if target is the player controlled object <OBJECT> (default: ACE_player)
* *
* Return Value: * Return Value:
* None * None
* *
* Example:
*
*
* Public: Yes * Public: Yes
*/ */
#include "script_component.hpp" #include "script_component.hpp"
params ["_text", ["_size", 1.5], ["_target", ACE_player]]; params [["_text", ""], ["_size", 1.5, [0]], ["_target", ACE_player, [objNull]]];
if (_target != ACE_player) exitWith {}; if (_target != ACE_player) exitWith {};

View File

@ -1,6 +1,6 @@
/* /*
* Author: PabstMirror,commy2, esteldunedain, Ruthberg * Author: PabstMirror, commy2, esteldunedain, Ruthberg
* Gets magazine children for interaciton menu * Gets magazine children for interaciton menu.
* *
* Argument: * Argument:
* 0: Target <OBJECT> * 0: Target <OBJECT>
@ -16,13 +16,11 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_unitMagazines", "_unitMagCounts", "_index", "_actions", "_displayName", "_picture", "_action"];
params ["_target", "_player"]; params ["_target", "_player"];
// get all mags and ammo count // get all mags and ammo count
_unitMagazines = []; private _unitMagazines = [];
_unitMagCounts = []; private _unitMagCounts = [];
{ {
private "_xFullMagazineCount"; private "_xFullMagazineCount";
_x params ["_xClassname", "_xCount", "_xLoaded", "_xType"]; _x params ["_xClassname", "_xCount", "_xLoaded", "_xType"];
@ -31,7 +29,7 @@ _unitMagCounts = [];
//for every partial magazine, that is either in inventory or can be moved there //for every partial magazine, that is either in inventory or can be moved there
if ((_xCount < _xFullMagazineCount) && {_xCount > 0} && {(!_xLoaded) || {_player canAdd _xClassname}}) then { if ((_xCount < _xFullMagazineCount) && {_xCount > 0} && {(!_xLoaded) || {_player canAdd _xClassname}}) then {
_index = _unitMagazines find _xClassname; private _index = _unitMagazines find _xClassname;
if (_index == -1) then { if (_index == -1) then {
_unitMagazines pushBack _xClassname; _unitMagazines pushBack _xClassname;
_unitMagCounts pushBack [_xCount]; _unitMagCounts pushBack [_xCount];
@ -42,13 +40,13 @@ _unitMagCounts = [];
} forEach (magazinesAmmoFull _player); } forEach (magazinesAmmoFull _player);
//Create the action children for all appropriate magazines //Create the action children for all appropriate magazines
_actions = []; private _actions = [];
{ {
if ((count (_unitMagCounts select _forEachIndex)) >= 2) then {// Ignore invalid magazines types (need 2+ partial mags to do anything) if ((count (_unitMagCounts select _forEachIndex)) >= 2) then {// Ignore invalid magazines types (need 2+ partial mags to do anything)
_displayName = getText (configFile >> "CfgMagazines" >> _x >> "displayName"); private _displayName = getText (configFile >> "CfgMagazines" >> _x >> "displayName");
_picture = getText (configFile >> "CfgMagazines" >> _x >> "picture"); private _picture = getText (configFile >> "CfgMagazines" >> _x >> "picture");
_action = [_x, _displayName, _picture, {_this call FUNC(startRepackingMagazine)}, {true}, {}, _x] call EFUNC(interact_menu,createAction); private _action = [_x, _displayName, _picture, {_this call FUNC(startRepackingMagazine)}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player]; _actions pushBack [_action, [], _player];
}; };
} forEach _unitMagazines; } forEach _unitMagazines;

View File

@ -19,39 +19,36 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_structuredOutputText", "_picture", "_fullMags", "_partialMags", "_fullMagazineCount"];
params ["_args", "_elapsedTime", "_totalTime", "_errorCode"]; params ["_args", "_elapsedTime", "_totalTime", "_errorCode"];
_args params ["_magazineClassname", "_lastAmmoCount"]; _args params ["_magazineClassname", "_lastAmmoCount"];
_fullMagazineCount = getNumber (configFile >> "CfgMagazines" >> _magazineClassname >> "count"); private _fullMagazineCount = getNumber (configFile >> "CfgMagazines" >> _magazineClassname >> "count");
//Don't show anything if player can't interact: // Don't show anything if player can't interact
if (!([ACE_player, objNull, ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith))) exitWith {}; if (!([ACE_player, objNull, ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith))) exitWith {};
_structuredOutputText = if (_errorCode == 0) then { // Count mags
format ["<t align='center'>%1</t><br/>", (localize LSTRING(RepackComplete))]; private _fullMags = 0;
private _partialMags = 0;
{
_x params ["_classname", "_count"];
if (_classname == _magazineClassname && {_count > 0}) then {
if (_count == _fullMagazineCount) then {
_fullMags = _fullMags + 1;
} else {
_partialMags = _partialMags + 1;
};
};
} forEach (magazinesAmmoFull ACE_player);
private _repackedMagsText = format [localize LSTRING(RepackedMagazinesCount), _fullMags, _partialMags];
private _structuredOutputText = if (_errorCode == 0) then {
format ["<t align='center'>%1</t><br/>%2", localize LSTRING(RepackComplete), _repackedMagsText];
} else { } else {
format ["<t align='center'>%1</t><br/>", (localize LSTRING(RepackInterrupted))]; format ["<t align='center'>%1</t><br/>%2", localize LSTRING(RepackInterrupted), _repackedMagsText];
}; };
_picture = getText (configFile >> "CfgMagazines" >> _magazineClassname >> "picture"); private _picture = getText (configFile >> "CfgMagazines" >> _magazineClassname >> "picture");
_structuredOutputText = _structuredOutputText + format ["<img align='center' size='1.8' color='#ffffff' image='%1'/> <br/>", _picture]; [_structuredOutputText, _picture, nil, nil, 2.5] call EFUNC(common,displayTextPicture);
//EFUNC(common,displayTextStructured) doesn't have room for this, and I don't think it's nessacary, can fix in the future if wanted:
// _fullMags = 0;
// _partialMags = 0;
// {
// EXPLODE_2_PVT(_x,_xClassname,_xCount);
// if ((_xClassname == _magazineClassname) && {_xCount > 0}) then {
// if (_xCount == _fullMagazineCount) then {
// _fullMags = _fullMags + 1;
// } else {
// _partialMags = _partialMags + 1;
// };
// };
// } forEach (magazinesAmmoFull ACE_player);
// _structuredOutputText = _structuredOutputText + format [("<t align='center'>" + (localize LSTRING(RepackedMagazinesCount)) + "</t>"), _fullMags, _partialMags];
[parseText _structuredOutputText, 2] call EFUNC(common,displayTextStructured);

View File

@ -18,19 +18,16 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_currentAmmoCount", "_addedMagazines", "_missingAmmo", "_index", "_updateMagazinesOnPlayerFnc"];
params ["_ars", "_elapsedTime", "_totalTime"]; params ["_ars", "_elapsedTime", "_totalTime"];
_args params ["_magazineClassname", "_lastAmmoCount", "_simEvents"]; _args params ["_magazineClassname", "_lastAmmoCount", "_simEvents"];
if !((_simEvents select 0) params ["_nextEventTime", "_nextEventIsBullet", "_nextEventMags"]) exitWith { ERROR("No Event"); false }; if !((_simEvents select 0) params ["_nextEventTime", "_nextEventIsBullet", "_nextEventMags"]) exitWith { ERROR("No Event"); false };
if (_nextEventTime > _elapsedTime) exitWith { true };//waiting on next event if (_nextEventTime > _elapsedTime) exitWith { true };//waiting on next event
//Verify we aren't missing any ammo //Verify we aren't missing any ammo
_currentAmmoCount = []; private _currentAmmoCount = [];
{ {
_x params ["_xClassname", "_xCount"]; _x params ["_xClassname", "_xCount"];
if (_xClassname == _magazineClassname) then { if (_xClassname == _magazineClassname) then {
@ -39,11 +36,11 @@ _currentAmmoCount = [];
} forEach (magazinesAmmo ACE_player); //only inventory mags } forEach (magazinesAmmo ACE_player); //only inventory mags
//Go through mags we currently have and check off the ones we should have //Go through mags we currently have and check off the ones we should have
_addedMagazines = +_currentAmmoCount; private _addedMagazines = +_currentAmmoCount;
_missingAmmo = false; private _missingAmmo = false;
{ {
if (_x > 0) then { if (_x > 0) then {
_index = _addedMagazines find _x; private _index = _addedMagazines find _x;
if (_index != -1) then { if (_index != -1) then {
_addedMagazines deleteAt _index; _addedMagazines deleteAt _index;
} else { } else {
@ -54,7 +51,7 @@ _missingAmmo = false;
if (_missingAmmo) exitWith { false }; //something removed ammo that was being repacked (could be other players or scripts) if (_missingAmmo) exitWith { false }; //something removed ammo that was being repacked (could be other players or scripts)
_updateMagazinesOnPlayerFnc = { private _updateMagazinesOnPlayerFnc = {
ACE_player removeMagazines _magazineClassname; //remove inventory magazines ACE_player removeMagazines _magazineClassname; //remove inventory magazines
{ {
if (_x > 0) then { if (_x > 0) then {

View File

@ -19,47 +19,26 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_fnc_newMag", "_time", "_events", "_fnc_swapAmmo", "_ammoSwaped", "_lowIndex", "_highIndex", "_ammoToTransfer", "_ammoAvailable", "_ammoNeeded", "_swapProgress"];
params ["_fullMagazineCount", "_arrayOfAmmoCounts", "_isBelt"]; params ["_fullMagazineCount", "_arrayOfAmmoCounts", "_isBelt"];
// Sort Ascending - Don't modify original // Sort Ascending - Don't modify original
_arrayOfAmmoCounts = +_arrayOfAmmoCounts; _arrayOfAmmoCounts = +_arrayOfAmmoCounts;
_arrayOfAmmoCounts sort true; _arrayOfAmmoCounts sort true;
_fnc_newMag = { private _fnc_newMag = {
_time = _time + GVAR(TimePerMagazine); _time = _time + GVAR(TimePerMagazine);
_events pushBack [_time, false, +_arrayOfAmmoCounts]; _events pushBack [_time, false, +_arrayOfAmmoCounts];
}; };
_fnc_swapAmmo = if (_isBelt) then { private _lowIndex = 0;
{ private _highIndex = (count _arrayOfAmmoCounts) - 1;
_time = _time + GVAR(TimePerBeltLink); private _ammoToTransfer = 0;
_arrayOfAmmoCounts set [_lowIndex, ((_arrayOfAmmoCounts select _lowIndex) - _ammoSwaped)]; private _ammoAvailable = 0;
_arrayOfAmmoCounts set [_highIndex, ((_arrayOfAmmoCounts select _highIndex) + _ammoSwaped)]; private _time = 0;
_events pushBack [_time, true, +_arrayOfAmmoCounts]; private _events = [];
}
} else {
{
for "_swapProgress" from 0 to (_ammoSwaped - 1) do {
_time = _time + GVAR(TimePerAmmo);
_arrayOfAmmoCounts set [_lowIndex, ((_arrayOfAmmoCounts select _lowIndex) - 1)];
_arrayOfAmmoCounts set [_highIndex, ((_arrayOfAmmoCounts select _highIndex) + 1)];
_events pushBack [_time, true, +_arrayOfAmmoCounts];
};
}
};
_lowIndex = 0;
_highIndex = (count _arrayOfAmmoCounts) - 1;
_ammoToTransfer = 0;
_ammoAvailable = 0;
_time = 0;
_events = [];
while {_lowIndex < _highIndex} do { while {_lowIndex < _highIndex} do {
_ammoNeeded = _fullMagazineCount - (_arrayOfAmmoCounts select _highIndex); private _ammoNeeded = _fullMagazineCount - (_arrayOfAmmoCounts select _highIndex);
_ammoAvailable = _arrayOfAmmoCounts select _lowIndex; _ammoAvailable = _arrayOfAmmoCounts select _lowIndex;
if (_ammoAvailable == 0) then { if (_ammoAvailable == 0) then {
@ -70,8 +49,20 @@ while {_lowIndex < _highIndex} do {
_highIndex = _highIndex - 1; _highIndex = _highIndex - 1;
call _fnc_newMag; call _fnc_newMag;
} else { } else {
_ammoSwaped = _ammoAvailable min _ammoNeeded; private _ammoSwaped = _ammoAvailable min _ammoNeeded;
call _fnc_swapAmmo; if (_isBelt) then {
_time = _time + GVAR(TimePerBeltLink);
_arrayOfAmmoCounts set [_lowIndex, (_arrayOfAmmoCounts select _lowIndex) - _ammoSwaped];
_arrayOfAmmoCounts set [_highIndex, (_arrayOfAmmoCounts select _highIndex) + _ammoSwaped];
_events pushBack [_time, true, +_arrayOfAmmoCounts];
} else {
for "_swapProgress" from 0 to (_ammoSwaped - 1) do {
_time = _time + GVAR(TimePerAmmo);
_arrayOfAmmoCounts set [_lowIndex, (_arrayOfAmmoCounts select _lowIndex) - 1];
_arrayOfAmmoCounts set [_highIndex, (_arrayOfAmmoCounts select _highIndex) + 1];
_events pushBack [_time, true, +_arrayOfAmmoCounts];
};
};
}; };
}; };
}; };

View File

@ -13,39 +13,37 @@
* Nothing * Nothing
* *
* Example: * Example:
* ["30Rnd_65x39_caseless_mag"] call ace_magazinerepack_fnc_startRepackingMagazine * [player, player, "30Rnd_65x39_caseless_mag"] call ace_magazinerepack_fnc_startRepackingMagazine
* *
* Public: No * Public: No
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_magazineCfg", "_fullMagazineCount", "_isBelt", "_startingAmmoCounts", "_simEvents", "_totalTime"];
params ["_target", "_player", "_magazineClassname"]; params ["_target", "_player", "_magazineClassname"];
if (isNil "_magazineClassname" || {_magazineClassname == ""}) exitWith {ERROR("Bad Mag Classname");}; if (isNil "_magazineClassname" || {_magazineClassname == ""}) exitWith {ERROR("Bad Mag Classname");};
_magazineCfg = configFile >> "CfgMagazines" >> _magazineClassname; private _magazineCfg = configFile >> "CfgMagazines" >> _magazineClassname;
// Calculate actual ammo to transfer during repack // Calculate actual ammo to transfer during repack
_fullMagazineCount = getNumber (_magazineCfg >> "count"); private _fullMagazineCount = getNumber (_magazineCfg >> "count");
//Is linked belt magazine: //Is linked belt magazine:
_isBelt = (isNumber (_magazineCfg >> "ACE_isBelt")) && {(getNumber (_magazineCfg >> "ACE_isBelt")) == 1}; private _isBelt = isNumber (_magazineCfg >> "ACE_isBelt") && {(getNumber (_magazineCfg >> "ACE_isBelt")) == 1};
//Check canInteractWith: //Check canInteractWith:
if (!([_player, objNull, ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith))) exitWith {}; if !([_player, objNull, ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {};
[_player] call EFUNC(common,goKneeling); [_player] call EFUNC(common,goKneeling);
_startingAmmoCounts = []; private _startingAmmoCounts = [];
{ {
EXPLODE_4_PVT(_x,_xClassname,_xCount,_xLoaded,_xType); _x params ["_xClassname", "_xCount", "_xLoaded", "_xType"];
if ((_xClassname == _magazineClassname) && {(_xCount != _fullMagazineCount) && {_xCount > 0}}) then { if (_xClassname == _magazineClassname && {_xCount != _fullMagazineCount && {_xCount > 0}}) then {
if (_xLoaded) then { if (_xLoaded) then {
//Try to Remove from weapon and add to inventory, otherwise ignore //Try to Remove from weapon and add to inventory, otherwise ignore
if (_player canAdd _magazineClassname) then { if (_player canAdd _magazineClassname) then {
switch (_xType) do { switch (_xType) do {
case (1): {_player removePrimaryWeaponItem _magazineClassname;}; case (1): {_player removePrimaryWeaponItem _magazineClassname};
case (2): {_player removeHandgunItem _magazineClassname;}; case (2): {_player removeHandgunItem _magazineClassname};
case (4): {_player removeSecondaryWeaponItem _magazineClassname;}; case (4): {_player removeSecondaryWeaponItem _magazineClassname};
default {ERROR("Loaded Location Invalid");}; default {ERROR("Loaded Location Invalid");};
}; };
_player addMagazine [_magazineClassname, _xCount]; _player addMagazine [_magazineClassname, _xCount];
@ -57,10 +55,10 @@ _startingAmmoCounts = [];
}; };
} forEach (magazinesAmmoFull _player); } forEach (magazinesAmmoFull _player);
if ((count _startingAmmoCounts) < 2) exitWith {ERROR("Not Enough Mags to Repack");}; if (count _startingAmmoCounts < 2) exitWith {ERROR("Not Enough Mags to Repack");};
_simEvents = [_fullMagazineCount, _startingAmmoCounts, _isBelt] call FUNC(simulateRepackEvents); private _simEvents = [_fullMagazineCount, _startingAmmoCounts, _isBelt] call FUNC(simulateRepackEvents);
_totalTime = (_simEvents select ((count _simEvents) - 1) select 0); private _totalTime = _simEvents select (count _simEvents - 1) select 0;
[ [
_totalTime, _totalTime,