Skip to content

Commit

Permalink
add searchbar to mission browser (#974)
Browse files Browse the repository at this point in the history
* add searchbar to mission browser

* implement filter functions

* select first element whenever lb items are changed

* exit box outline positioning

* exit box outline positioning
  • Loading branch information
commy2 committed Sep 13, 2018
1 parent 9ad30cc commit e13258f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addons/ui/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ class Extended_DisplayLoad_EventHandlers {
class RscDisplayPassword {
ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayPassword)'));
};
class RscDisplayRemoteMissions {
ADDON = QUOTE(_this call (uiNamespace getVariable 'FUNC(initDisplayRemoteMissions)'));
};
};
1 change: 1 addition & 0 deletions addons/ui/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
PREP(initDisplayInterrupt);
PREP(initDisplayMultiplayerSetup);
PREP(initDisplayPassword);
PREP(initDisplayRemoteMissions);
93 changes: 93 additions & 0 deletions addons/ui/fnc_initDisplayRemoteMissions.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineResinclDesign.inc" // can't have this in config, because it redefines some entries, and that makes Mikero's shits its pants

params ["_display"];
private _ctrlMaps = _display displayCtrl IDC_SERVER_ISLAND;
private _ctrlMissions = _display displayCtrl IDC_SERVER_MISSION;

ctrlPosition _ctrlMissions params ["_left", "_top", "_width", "_height"];

private _ctrlSearch = _display ctrlCreate ["RscEdit", IDC_SEARCH];
_ctrlSearch ctrlSetPosition [
_left + 0.1 * GUI_GRID_W,
_top,
_width - 1.2 * GUI_GRID_W,
GUI_GRID_H
];
_ctrlSearch ctrlCommit 0;

private _ctrlSearchButton = _display ctrlCreate ["RscButtonSearch", IDC_SEARCH_BUTTON];
_ctrlSearchButton ctrlSetPosition [
_left + _width - GUI_GRID_W,
_top,
GUI_GRID_W,
GUI_GRID_H
];
_ctrlSearchButton ctrlCommit 0;

_ctrlMissions ctrlSetPosition [
_left,
_top + 1.1 * GUI_GRID_H,
_width,
_height - 1.1 * GUI_GRID_H
];
_ctrlMissions ctrlCommit 0;

// store all missions of the currently selected map
private _fnc_storeMapMissions = {_this spawn {isNil { // delay a frame
params ["_ctrlMaps"];
private _display = ctrlParent _ctrlMaps;
private _ctrlMissions = _display displayCtrl IDC_SERVER_MISSION;

private _missions = [];
for "_i" from 0 to (lbSize _ctrlMissions - 1) do {
private _name = _ctrlMissions lbText _i;
private _value = _ctrlMissions lbValue _i;
private _data = _ctrlMissions lbData _i;
private _color = _ctrlMissions lbColor _i;

_missions pushBack [_name, _value, _data, _color];
};

_ctrlMissions setVariable [QGVAR(missions), _missions];
_display call (_display getVariable QFUNC(filter));
}}};

_ctrlMaps call _fnc_storeMapMissions;
_ctrlMaps ctrlAddEventHandler ["lbSelChanged", _fnc_storeMapMissions];

// filter out missions we don't want
_display setVariable [QFUNC(filter), {
params ["_display"];
private _ctrlSearch = _display displayCtrl IDC_SEARCH;
private _ctrlMissions = _display displayCtrl IDC_SERVER_MISSION;

private _filter = toLower ctrlText _ctrlSearch;
private _missions = _ctrlMissions getVariable QGVAR(missions);

lbClear _ctrlMissions;

{
_x params ["_name", "_value", "_data", "_color"];

if (toLower _name find _filter != -1) then {
private _index = _ctrlMissions lbAdd _name;
_ctrlMissions lbSetValue [_index, _value];
_ctrlMissions lbSetData [_index, _data];
_ctrlMissions lbSetColor [_index, _color];
};
} forEach _missions;

_ctrlMissions lbSetCurSel 0;
}];

// update every time search parameters are changed
private _fnc_update = {_this spawn {isNil { // delay a frame
params ["_ctrlSearch"];
private _display = ctrlParent _ctrlSearch;
_display call (_display getVariable QFUNC(filter));
}}};

_ctrlSearch ctrlAddEventHandler ["KeyDown", _fnc_update];
_ctrlSearch ctrlAddEventHandler ["KeyUp", _fnc_update];
_ctrlSearchButton ctrlAddEventHandler ["ButtonClick", _fnc_update];

0 comments on commit e13258f

Please sign in to comment.