Jump to content
Noigel

Dialog Slider Issue, Can't Enforce the Particular Increments Desired

Recommended Posts

Hey All,

 

(I looked in the forum backlogs to see if this has been answered before but couldn't find anything similar.)

 

I've created a script that places a target a distance away in 25 meter increments for range practice.  I'm currently using a dialog with many buttons on it to change the distance.

 

It is completely functional but also looks pretty poor:

pz74AN0.png

 

I'd like to use a slider instead.  I've created a rough dialog for it and the left and right arrows work great and properly increment by 25 on each click... but when I click on or move the mouse along the slider... it completely abandons the 25 meter increments.

 

Please see the following GIF where I illustrate this: 

y6opY8a.gif

 

Can you help me force the slider to only increment by 25 no matter where the mouse clicks or moves along it?  Here's the relevant code I have:

 

defines.hpp

class RscSlider

{
idc = -1;
style = "0x400 + 0x10";
type = 43;
shadow = 0;
color[] = {1,1,1,0.4};
colorActive[] = {1,1,1,1};
colorDisabled[] = {0.5,0.5,0.5,0.2};
arrowEmpty = "\A3\ui_f\data\gui\cfg\slider\arrowEmpty_ca.paa";
arrowFull = "\A3\ui_f\data\gui\cfg\slider\arrowFull_ca.paa";
border = "\A3\ui_f\data\gui\cfg\slider\border_ca.paa";
thumb = "\A3\ui_f\data\gui\cfg\slider\thumb_ca.paa";
x = 0.304062 * safezoneW + safezoneX;
y = 0.511 * safezoneH + safezoneY;
w = 0.391875 * safezoneW;
h = 0.044 * safezoneH;
};

 

distance_dialog_slider.hpp

class range_distance_slider_wsl: RscSlider

{
idc = 1900;
//onMouseClick = "";   I've not used these but I'm betting they are somehow involved in the solution...
//onMouseMoving = "";
onSliderPosChanged = "_sliderpos = sliderPosition 1900; ctrlSetText [1901,str _sliderpos];"
};

 

call_distance_dialog_slider.sqf

_handle1 = createdialog "range_distance_slider";

 
sliderSetRange [1900, 25, 2000];
sliderSetPosition [1900, 25];
sliderSetSpeed [1900, 25, 1];

 

Thanks for reading!  

 

-Noigel

 

 

Share this post


Link to post
Share on other sites

can't you use lbSetData or something and then work on from that?

Share this post


Link to post
Share on other sites

I've almost got it figured out using straight-up math.  It works but I have a secondary problem that the slider and the text control in the dialog do not retain/remember the number where they are left.  See below for my code additions, what it looks like now, and the last error I'm trying to work out.

 

distance_dialog_slider.hpp

class range_distance_slider_wsl: RscSlider
{
idc = 1900;
onSliderPosChanged = "_sliderPos = sliderPosition 1900; _makeWhole = round _sliderPos; _divideBy25 = (_makeWhole / 25); _makeWholeAgain = round _divideBy25; _final_multiplyBy25 = _makeWholeAgain * 25; ctrlSetText [1901,str _final_multiplyBy25]; _nul = [_this] execVM ""targeting\change_rangetarget_distance_slider.sqf""";
};
 
change_rangetarget_distance_slider.sqf

_fullParameter = _this select 0;
_sliderPos  = _fullParameter select 1;
 
_makeWhole = round _sliderPos;
 
_divideBy25 = (_makeWhole / 25);
 
_makeWholeAgain = round _divideBy25;
 
_finalMultiplyBy25 = _makeWholeAgain * 25;
 
temp_Distance_Adjust = _finalMultiplyBy25;

 

call_distance_dialog_slider.sqf

_handle1 = createdialog "range_distance_slider"; 

sliderSetRange [1900, 25, 2000];
sliderSetSpeed [1900, 25, 25];
 
waitUntil { !dialog };

 

I'm doing the calculation twice... once in distance_dialog_slider.hpp to show the real-time value in the textbox control... and a second time in change_rangetarget_distance_slider.sqf to take the actual value and plug it into a setpos command later in the code.

 

It looks really good now:

H6rOl3S.gif

 

But it doesn't retain the values.  Help!   :)

COJ8p6L.gif

 

Thanks,

-Noigel

Share this post


Link to post
Share on other sites
But it doesn't retain the values.  Help!

 

 

it's not supposed to. you need to reset the values after opening the dialog.

 

Share this post


Link to post
Share on other sites

You don't really need first round. I also don't see a reason to have that change_rangetarget_distance_slider.sqf file since it only sets variable (isn't it possible from onSliderPosChanged?).

I would do something like:

 

dialog's onLoad:

// don't use first two lines in call_distance_dialog_slider.sqf
sliderSetRange [1900, 25, 2000];
sliderSetSpeed [1900, 25, 25];
sliderSetPosition [1900, temp_Distance_Adjust]
ctrlSetText [1901, str temp_Distance_Adjust];

onSliderPosChanged:

temp_Distance_Adjust = 25 * (round ((_this select 1) / 25));
ctrlSetText [1901, str temp_Distance_Adjust];
  • Like 1

Share this post


Link to post
Share on other sites

Awesome, I fixed it!

 

I added an OnLoad event to my distance_dialog_slider.hpp and an additional SQF file:

 

distance_dialog_slider.hpp

 

class range_distance_slider
{
idd=-1;
movingenable=false;
enableSimulation=true;
onLoad= "_this execVM 'onLoadInit.sqf'";
class controls 
{
 
//yadda, yadda, yadda...

 

 

onLoadInit.sqf

disableSerialization;
 
_display = _this select 0; // onload sends [display] as argument
 
ctrlSetText [1901,str temp_Distance_Adjust];
sliderSetPosition [1900, temp_Distance_Adjust];

 

Hope this helps the next scripter!   :)

 

-Noigel

 

 

Share this post


Link to post
Share on other sites

Thanks for that gc8, helped confirm what I needed to research next.

 

And thanks pedeathtrian, I really do appreciate you showing me where to tighten up code.  Everything I've learned is self-taught so it's all pretty much un-optimized... it works but it is all homemade "first iteration" code.  I'll definitely make those changes!

 

Here's the near-final product:

eSHr6s6.gif

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×