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

Build module - basic resource payment #600

Merged
merged 20 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion Missionframework/KPGUI/KPGUI_classes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: KPGUI_classes.hpp
Author: Wyqer - https://github.com/KillahPotatoes
Date: 2018-09-13
Last Update: 2019-04-22
Last Update: 2019-05-01
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html

Description:
Expand Down Expand Up @@ -1112,6 +1112,44 @@ class KPGUI_PRE_DialogButton_LeftPanel: KPGUI_PRE_Button {
w = KP_GETWPLAIN(KP_WIDTH_VAL_LP,1);
};

/*
--- Right panel sized classes ---
*/

// Title bar
class KPGUI_PRE_DialogTitle_RightPanel: KPGUI_PRE_Title {
x = KP_GETX(KP_X_VAL_RP,KP_WIDTH_VAL_RP,0,1);
y = safeZoneY + safeZoneH * KP_Y_VAL_RP;
w = KP_GETWPLAIN(KP_WIDTH_VAL_RP,1);
};

// Cross symbol
class KPGUI_PRE_DialogCross_RightPanel: KPGUI_PRE_CloseCross {
x = safeZoneX + safeZoneW * (KP_X_VAL_RP + KP_WIDTH_VAL_RP - 0.02);
y = KP_GETY_CROSS(KP_Y_VAL_RP);
};

// Version info
class KPGUI_PRE_DialogVersionIcon_RightPanel: KPGUI_PRE_VersionIcon {
x = safeZoneX + safeZoneW * (KP_X_VAL_RP + KP_WIDTH_VAL_RP - 0.04);
y = KP_GETY_CROSS(KP_Y_VAL_RP);
};

// Background
class KPGUI_PRE_DialogBackground_RightPanel: KPGUI_PRE_Background {
x = KP_GETX(KP_X_VAL_RP,KP_WIDTH_VAL_RP,0,1);
y = KP_GETY_AREA(KP_Y_VAL_RP);
w = KP_GETWPLAIN(KP_WIDTH_VAL_RP,1);
h = safeZoneH * KP_HEIGHT_VAL_RP;
};

// Button
class KPGUI_PRE_DialogButton_RightPanel: KPGUI_PRE_Button {
x = KP_GETX(KP_X_VAL_RP,KP_WIDTH_VAL_RP,0,1);
y = KP_GETY_BELOW(KP_Y_VAL_RP,KP_HEIGHT_VAL_RP);
w = KP_GETWPLAIN(KP_WIDTH_VAL_RP,1);
};

/*
--- Small sized classes ---
*/
Expand Down
12 changes: 11 additions & 1 deletion Missionframework/KPGUI/KPGUI_defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: KPGUI_defines.hpp
Author: Wyqer - https://github.com/KillahPotatoes
Date: 2018-07-10
Last Update: 2019-04-05
Last Update: 2019-05-01
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html

Description:
Expand Down Expand Up @@ -142,6 +142,16 @@
#define KP_WIDTH_VAL_LP 0.2
#define KP_HEIGHT_VAL_LP (1 - 2 * KP_Y_VAL_LP - KP_HEIGTH_TITLE - KP_HEIGTH_BUTTON - 2 * KP_SPACING_Y)

/*
--- Right panel dialog components ---
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*/
(X from 0.7975 - 0.9975, Y from 0.0025 - 0.9975)
*/

For the left panel dialog:

    (X from 0.0025 - 0.2025, Y from 0.0025 - 0.9975)


#define KP_X_VAL_RP 0.8 - 0.0025
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not 0.7975?

#define KP_Y_VAL_RP 0.0025

#define KP_WIDTH_VAL_RP 0.2
#define KP_HEIGHT_VAL_RP (1 - 2 * KP_Y_VAL_RP - KP_HEIGTH_TITLE - KP_HEIGTH_BUTTON - 2 * KP_SPACING_Y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define KP_HEIGHT_VAL_RP (1 - 2 * KP_Y_VAL_RP - KP_HEIGTH_TITLE - KP_HEIGTH_BUTTON - 2 * KP_SPACING_Y)
#define KP_HEIGHT_VAL_RP (0.905 - KP_HEIGTH_TITLE - KP_HEIGTH_BUTTON - 2 * KP_SPACING_Y)

same for left panel dialog


/*
--- Small dialog components ---
(X from 0.3 - 0.7, Y from 0.05 - 0.8)
Expand Down
2 changes: 1 addition & 1 deletion Missionframework/description.ext
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ allowFunctionsLog = 0;

// As a security measure, functions are by default protected against rewriting during mission.
// This restriction does not apply in missions previewed from the editor.
allowFunctionsRecompile = 0;
allowFunctionsRecompile = __EVAL([0, 1] select (is3DENMultiplayer || is3DEN));
Wyqer marked this conversation as resolved.
Show resolved Hide resolved

// Disable specific channels for voice and text communication.
// MOTD and admin say have exception and will show in global.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: KPLIB_fnc_build_addBuildables.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2018-12-09
Last Update: 2019-04-23
Last Update: 2019-04-29
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No

Expand All @@ -13,7 +13,7 @@

Parameter(s):
_category - Display name of category [DATATYPE, defaults to DEFAULTVALUE]
_buildables - Buildable items [DATATYPE, defaults to DEFAULTVALUE]
_buildables - Buildable items [ARRAY or CODE, defaults to []]

Returns:
Index of items inside category [NUMBER]
Expand Down
22 changes: 16 additions & 6 deletions Missionframework/modules/15_build/fnc/fn_build_changeQueueMode.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
File: fn_build_changeQueueMode.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2018-11-29
Last Update: 2019-04-23
Last Update: 2019-05-04
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No

Expand All @@ -25,25 +25,35 @@ params [

private _display = ctrlParent _control;
private _confirmBtnControl = _display displayCtrl KPLIB_IDC_BUILD_CONFIRM;
private _buildList = _display displayCtrl KPLIB_IDC_BUILD_ITEM_LIST;

// !TODO! preserve and restore current build queue
switch (LGVAR_D(buildMode, 0)) do {
case 0: {
_control ctrlSetText "Move mode";
_control ctrlSetText localize "STR_KPLIB_DIALOG_BUILD_MODE_MOVE";
LSVAR("buildMode", 1);
LSVAR("buildItem", []);
_confirmBtnControl ctrlEnable false;
_buildList ctrlEnable false;

private _currentItems = LGVAR(buildQueue);

private _playerFob = player getVariable "KPLIB_fob";
private _currentItems = (KPLIB_persistence_objects select {(_x getVariable "KPLIB_fob") isEqualTo _playerFob}) select {!isNull _x};
LSVAR("buildQueue", _currentItems);
private _movableItems = (KPLIB_persistence_objects select {(_x getVariable "KPLIB_fob") isEqualTo _playerFob}) select {!isNull _x};
LSVAR("buildQueue_buy", _currentItems);
LSVAR("buildQueue", _movableItems);
};

case 1: {
_control ctrlSetText "Build mode";
_control ctrlSetText localize "STR_KPLIB_DIALOG_BUILD_MODE_BUILD";
LSVAR("buildMode", 0);
_confirmBtnControl ctrlEnable true;
_buildList ctrlEnable true;

private _buyableItems = LGVAR(buildQueue_buy);
LSVAR("buildQueue_buy", nil);

LSVAR("buildQueue", []);
LSVAR("buildQueue", _buyableItems);
};
};

Expand Down
8 changes: 4 additions & 4 deletions Missionframework/modules/15_build/fnc/fn_build_confirmAll.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
File: fn_build_confirmAll.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2018-11-28
Last Update: 2019-04-23
Last Update: 2019-05-04
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No

Expand All @@ -22,16 +22,16 @@
private _validItems = LGVAR(buildQueue) select {_x getVariable ["KPLIB_validPos", true]};
LSVAR("buildQueue", LGVAR(buildQueue) - _validItems);

// !TODO! implement build queue handling (resource check etc.)
systemChat "buildConfirm: Resource check not implemented yet!";
{
private _dirAndUp = [vectorDir _x, vectorUp _x];
private _pos = getPosATL _x;
private _class = typeOf _x;

private _price = _x getVariable "KPLIB_build_price";

deleteVehicle _x;

[[_class, _pos, 0, true], _dirAndUp, player] remoteExecCall ["KPLIB_fnc_build_confirmSingle", 2];
[[_class, _pos, 0, true], _dirAndUp, _price, player] remoteExecCall ["KPLIB_fnc_build_confirmSingle", 2];

} forEach _validItems;

Expand Down
13 changes: 10 additions & 3 deletions Missionframework/modules/15_build/fnc/fn_build_confirmSingle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: fn_build_confirmSingle.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2018-11-29
Last Update: 2019-04-23
Last Update: 2019-05-04
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No

Expand All @@ -14,6 +14,7 @@
Parameter(s):
_createParams - Parameters for common_createVehicle [ARRAY, defaults to nil]
_vectorDirAndUp - Vector dir and up for created object [ARRAY, defaults to nil]
_price - Supplies price [ARRAY, defaults to nil]
_player - Player that initiated the building of object [OBJECT, defaults to objNull]

Returns:
Expand All @@ -22,13 +23,20 @@
params [
["_createParams", nil, [[]]],
["_vectorDirAndUp", nil, [[]], 2],
["_price", nil, [[]], 3],
["_player", objNull, [objNull]]
];
_createParams params ["_className", "_pos", "_dir", "_justBuild"];

private _fob = _player getVariable ["KPLIB_fob", ""];

if !(([_fob] + _price) call KPLIB_fnc_resources_pay) exitWith {
[format ["Not enough resources to build: %1 at: %2", _className, _fob], "BUILD"] call KPLIB_fnc_common_log;
["KPLIB_build_not_enough_resources", [_className], _player] call CBA_fnc_targetEvent;
};

private ["_obj"];

// !TODO! save only builings via Build module, units and vehicles should be moved to persistence module
switch true do {
case (_className isKindOf "Man"): {
_obj = [createGroup KPLIB_preset_sideF, _className] call KPLIB_fnc_common_createUnit;
Expand All @@ -51,7 +59,6 @@ switch true do {
};
};

private _fob = _player getVariable ["KPLIB_fob", ""];

["KPLIB_build_item_built", [_obj, _fob]] call CBA_fnc_globalEvent;
["KPLIB_build_item_built_local", [_obj, _fob], _player] call CBA_fnc_targetEvent;
40 changes: 21 additions & 19 deletions Missionframework/modules/15_build/fnc/fn_build_displayFillList.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,35 @@
File: fn_build_displayFillList.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2018-09-09
Last Update: 2019-04-23
Last Update: 2019-04-30
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No

Description:
Sets display build mode
Fill list of buildable items

Parameter(s):
_mode - Build mode index [NUMBER, defaults to 0]
NONE

Returns:
Mode was changed [BOOL]
*/
params [
["_categoryIdx", 0, [0]],
["_searchQuery", "", [""]]
];

// CfgVehicles config for shorter/faster access
private _cfg = configFile >> "CfgVehicles";
// Get category items
(LGVAR(buildables) select _categoryIdx) params ["", "_categoryItems"];

// Get categories list
private _categoriesList = LGVAR(display) displayCtrl KPLIB_IDC_BUILD_CATEGORY_LIST;
private _categoryIdx = lbCurSel _categoriesList;
// Get search query box
private _searchBox = LGVAR(display) displayCtrl KPLIB_IDC_BUILD_SEARCH;
private _searchQuery = toLower ctrlText _searchBox;
// Get list box with buildables
private _listBox = LGVAR(display) displayCtrl KPLIB_IDC_BUILD_ITEM_LIST;
_listBox lbSetCurSel -1; // Unselect current row as it sticks between clearing
lnbClear _listBox;

private _fnc_addItems = {

};
// Get category items
(LGVAR(buildables) select _categoryIdx) params ["", "_categoryItems"];

// Fill the item list
{
Expand All @@ -49,15 +48,18 @@ private _fnc_addItems = {
_x params ["_className", "_priceSupp", "_priceAmmo", "_priceFuel"];

private _name = getText (_cfg >> _className >> "displayName");
// Filter list
if !((toLower _name find _searchQuery) isEqualTo -1) then {

_listBox lnbAddRow [_name, str _priceSupp, str _priceAmmo, str _priceFuel];
private _currentIdx = ((lnbSize _listBox) select 0) - 1;
_listBox lnbAddRow [_name, str _priceSupp, str _priceAmmo, str _priceFuel];
private _currentIdx = ((lnbSize _listBox) select 0) - 1;

// Serialize classname and price
_listBox lnbSetData [[_currentIdx, 0], str _x];
// Serialize classname and price
_listBox lnbSetData [[_currentIdx, 0], str _x];

private _icon = _className call KPLIB_fnc_common_getIcon;
_listBox lnbSetPicture [[_currentIdx, 0], _icon];
private _icon = _className call KPLIB_fnc_common_getIcon;
_listBox lnbSetPicture [[_currentIdx, 0], _icon];
};
} forEach _x;

} foreach _categoryItems;
Expand Down
11 changes: 4 additions & 7 deletions Missionframework/modules/15_build/fnc/fn_build_displayLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
File: fn_build_displayLoad.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2018-09-09
Last Update: 2019-04-23
Last Update: 2019-04-30
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No

Expand Down Expand Up @@ -46,13 +46,10 @@ _itemsList ctrlAddEventHandler ["LBSelChanged", {

private _categoriesList = _display displayCtrl KPLIB_IDC_BUILD_CATEGORY_LIST;
_categoriesList ctrlAddEventHandler ["LBSelChanged", {
params ["_control", "_selectedIndex"];

// Clear the search on category change
LSVAR("search", "");
params ["_control"];

// Fill the items list
[_selectedIndex, ""] call KPLIB_fnc_build_displayFillList;
// Clear search and fill the items list
[] call KPLIB_fnc_build_searchClear;

// Unfocus the listbox to prevent camera controls from changing the selection
ctrlSetFocus ((ctrlParent _control) displayCtrl KPLIB_IDC_BUILD_CONFIRM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
File: fn_build_displayPlaceObject.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2018-09-09
Last Update: 2019-04-23
Last Update: 2019-05-04
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No

Expand Down Expand Up @@ -37,6 +37,8 @@ if !(_className isEqualTo "") exitWith {
_obj setPosASL _cursorWorldPosASL;
_obj setVectorUp _cursorSurfaceNormal;

_obj setVariable ["KPLIB_build_price", [_priceSupplies, _priceAmmo, _priceFuel]];

LGVAR(buildQueue) pushBack _obj;

// Clear current item upon placement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: fn_build_drawBoundingBox.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2018-09-29
Last Update: 2019-04-23
Last Update: 2019-05-01
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No

Expand All @@ -24,7 +24,7 @@ params [
];

// Get left bottom and right top corners
(boundingBoxReal _object) params ["_c1", "_c2"];
(0 boundingBoxReal _object) params ["_c1", "_c2"];

// Draw the bounding box
{
Expand Down
Loading