Jump to content

Radio B-Zone recrutează noi DJ. Aplică aici

Radio Legend recrutează noi DJ. Aplică aici

Recrutăm designeri audio și video. Puteți aplica aici

 

Sign in to follow this  
D J C

[CLEO] Dialog.AddCheckBox / Dialog.AddSlider

Recommended Posts

Hello there, I need an example of how can I use Dialog.AddCheckBox / Dialog.AddSlider function in my loop:

Dialog.Create(20@, "Test")
0AF0: 21@ = get_int_from_ini_file "CLEO\Test.ini" section "HUD" key "maindiX"    
0AF0: 22@ = get_int_from_ini_file "CLEO\Test.ini" section "HUD" key "maindiY"  
Dialog.SetRECT(20@, 21@, 22@, 200, 250)  
dialog.SetVisible(20@, 0)                                                                               
Dialog.AddCheckBox(20@, 38, " ", 8, 12, 50, 25)    
dialog.AddStatic(20@, 39, "{00FF00}Auto-Save", 35, 15, 300, 20)
Dialog.AddButton(20@, 40, "?", 165, 13, 25, 25) 
  
dialog.AddStatic(20@, 51, "{00FF00}Auto-Save-2", 10, 40, 200, 20)
dialog.AddSlider(20@, 52, 110, 45, 40, 18, 1)
dialog.AddStatic(20@, 53, "Off", 85, 40, 20, 20)
dialog.AddStatic(20@, 54, "On", 165, 40, 20, 20)

 

This is my whole code:

{$CLEO .cs}

0000:

repeat
    wait 0
until 0AFA:

gosub @Create
0B34: samp register_client_command "show" to_label @Show
0B34: samp register_client_command "hide" to_label @Hide

WHILE TRUE
WAIT 0

if 0C89:  key_just_pressed 0x1B //ESC
then
    Dialog.SetVisible(20@, False)
    SAMP.SetCursorMode(0)
end

if dialog.IsMinimized(20@)
then
    0B5E: get_cursor_pos 21@ 22@
    Dialog.SetRECT(20@, 21@, 22@, 200, 250)
    0AF1: write_int 21@ to_ini_file "CLEO\Test.ini" section "HUD" key "X" 
    0AF1: write_int 22@ to_ini_file "CLEO\Test.ini" section "HUD" key "Y" 
end 

if Dialog.IsVisible(20@)
then
    SAMP.SetCursorMode(2)    
    if 0B81: dialog 20@ pop_event_to 17@ control_id_to 18@
    then
        if 18@ == 40 
        then
            chatmsg "? Button works" -1
        end
    end
end   


END



:Create

Dialog.Create(20@, "Test")
0AF0: 21@ = get_int_from_ini_file "CLEO\Test.ini" section "HUD" key "X"    
0AF0: 22@ = get_int_from_ini_file "CLEO\Test.ini" section "HUD" key "Y"  
Dialog.SetRECT(20@, 21@, 22@, 200, 250)  
dialog.SetVisible(20@, 0)                                                                               
Dialog.AddCheckBox(20@, 38, " ", 8, 12, 50, 25)    
dialog.AddStatic(20@, 39, "{00FF00}Auto-Save", 35, 15, 300, 20)
Dialog.AddButton(20@, 40, "?", 165, 13, 25, 25)

dialog.AddStatic(20@, 51, "{00FF00}Auto-Save-2", 10, 40, 200, 20)
dialog.AddSlider(20@, 52, 110, 45, 40, 18, 1)
dialog.AddStatic(20@, 53, "Off", 85, 40, 20, 20)
dialog.AddStatic(20@, 54, "On", 165, 40, 20, 20) 

return

:Show
Dialog.SetVisible(20@, True)
0B43: samp cmd_ret

:Hide
Dialog.SetVisible(20@, False)
SAMP.SetCursorMode(0)
0B43: samp cmd_ret

 

In addition, if boxes are checked, how does possible to load it back when I restart the game? by using INI files (Same to Slider too.)

Example:

if $box == 1 //checked
then
	dialog.SetCheckBoxChecked(20@, 39, 0)
    chatmsg "You have disabled this thing." -1
    0AF1: write_int 0 to_ini_file "CLEO\Test.ini" section "Config" key "Test"
end
if $box == 0 //Un-Checked
then
    dialog.SetCheckBoxChecked(20@, 39, 1)
    chatmsg "You have enabled this thing." -1
    0AF1: write_int 0 to_ini_file "CLEO\Test.ini" section "Config" key "Test"
end

 

Share this post


Link to post
Share on other sites

Topic inactiv.

:topic_closed:

 

Share this post


Link to post
Share on other sites
On 9/24/2021 at 4:07 PM, Tupi said:

Topic inactiv.

:topic_closed:

 

Topic redeschis. Dacă nu vrei să ajuţi omul, lasă topicul deschis, poate alţii vor dori. Sper că înţelegi unde bat.

Share this post


Link to post
Share on other sites
Posted (edited)

Hello DJC!

I don't know how good can i explain this, but i will try with examples from my mod.

1) First, how you done, you need to create the dialog

    Dialog.Create([email protected], "name")

next, from what i seen you can do it to sure that the dialog will not be out of user screen, some may have 16:9 screen, some may 4:3

    0B5A: get_screen_resolution [email protected] [email protected] 
    [email protected] /=2                                                                                                                                                 
    [email protected] /=2                            
    Dialog.SetRECT([email protected], [email protected], [email protected], 300, 500)    // 300 & 500 from what i remeber are for dialog size.
    dialog.SetVisible([email protected], 0) // here you hide the dialog after create it to not be shown when enter the game

 

2) how to add checkbox, slider, text, etc

Dialog.AddStatic([email protected], 1, "{28afe0}Zona", 5, 11, 100, 20) // [email protected] - add to this dialog - "1" item id - "{28afe0}Zona" - the text - "5, 11" coords, x, y  - "100, 20" text size

Dialog.AddEditBox([email protected], 2, "", 37, 3, 135, 36)  // same story as upper, i think you can add text here too, but i recommand you to create a static with text and put it where you want

Dialog.AddButton([email protected], 3, "Set", 260, 4, 37, 35)  // same story, "set" will appear on the middle of the button

Dialog.AddCheckBox([email protected], 10, " ", 5, 50, 50, 25) // nothing new

dialog.AddSlider([email protected], 52, 198, 358, 40, 18, 1) // here the same as upper but we don't have a text section, the last number "1" is for the maximum position of the slider, ex from 0 to 1 here, if you will put 100 it will be from 0 to 100

 

3) how to give functions to checkbox, slider, etc

first, here will be in a loop, what we done until now it's out of a repeat loop and it's loaded just one time.

we will start with the visible dialog condition, as we will not have it running if it's not necessary.

if Dialog.IsVisible([email protected])

then

0B8D: samp set_cursor_mode 2 // like that we can move the mouse in dialog

if 0B81: dialog [email protected] pop_event_to [email protected] control_id_to [email protected] // this will search for some actions done by things added before

 

- static 

it's just a text that you place, i don't think it can have any function

 

- editbox & button (i will put it in sections like that to be easely to find, but this is continue of the upper code)

// i will put them in one place becouse idk at what can you use editbox without a button, it may make lag to save it each secound.

if [email protected] == 3 // if we have an action to item id 3, in our case, if the button is pressed

then

alloc [email protected] 200 // if you will have text, you need to alloc memory

Dialog.GetControlText([email protected], 2, [email protected]) // like that we take text from editbox id 2 to variable [email protected]

0AF5: write_string_to_ini_file [email protected] path "CLEO\PDHelperV7.ini" section "radar" key "zona" // just an example from my mod

chatmsg "done" -1 // if you want a text confirmation for action

free [email protected]

end

 

- checkbox

if [email protected] == 10 // again, if we have action to item id 10

then

//what you want to do if it's checked, example for uncheck situation:

    0AF0: $radar = get_int_from_ini_file "CLEO\PDHelperV7.ini" section "PDHelper" key "radar"
           if $radar == 1
                then
                    chatmsg "{28afe0}PDHelper Sistemele Radar{ffffff} au fost oprite." -1 
                    0AF1: write_int 0 to_ini_file "CLEO\PDHelperV7.ini" section "PDHelper" key "radar"
                else
                    chatmsg "{28afe0}PDHelper Sistemele Radar{ffffff} au fost porite." -1 
                    0AF1: write_int 1 to_ini_file "CLEO\PDHelperV7.ini" section "PDHelper" key "radar"
                end 

end

 

- slider

if [email protected] == 52 // same story, 52 item id

then

Dialog.SliderGetValue([email protected], 52, [email protected]) // 52 item id, [email protected] will be the variable who take the value from slider, example if you have it from 1 to 10 and it it's set to 4 it will give the var [email protected] value 4

 

- closing dialog

if [email protected] == 4 // button id 4

dialog.SetVisible([email protected], 0) // hide dialog

0B8D: samp set_cursor_mode 0 // set cursor to can be used in game as normal, not for dialog.

 

4) taking the value setted before

from start i will say that you need to store them after any action to work corectly

now, after you create the dialog (at number 1)

let's say you want to see if a checkbox was checked or not last time you exit the game

//example 1

   AF0: [email protected] = get_int_from_ini_file "CLEO\PDHelperV7.ini" section "PDHelper" key "somatie" // get value from ini
   if [email protected] == 1 // if it was checked (by ini value) 
   then                                           
    dialog.SetCheckBoxChecked([email protected], 6, 1) // 6 checkbox id, 1 = checked

else it's by default unchecked from what i remember

 

and like that you can do for any thing, i'll leave you some examples:

//example 2

   alloc [email protected] 200                                   
   0AF4: [email protected] = read_string_from_ini_file "CLEO\PDHelperV7.ini" section "radar" key "zona" // read text for editbox
   Dialog.SetControlText([email protected], 2, [email protected]) // set text [email protected] to editbox id 2
   free [email protected]  

 

// example 3

   0AF0: $limba = get_int_from_ini_file "CLEO\PDHelperV7.ini" section "PDHelper" key "limba" // get value, in this case 1 or 0
   if $limba == 1            
   then                                          
    Dialog.SliderSetValue([email protected], 52, 1)   // if it's value one it will be set to one
   else
    Dialog.SliderSetValue([email protected], 52, 0)    // otherwise if it's 0, it will be set to 0

   end    

 

 

 

That's all, i hope that i helped you, if i miss something you can ask me. Have a nice day!

Edited by TheTom

Share this post


Link to post
Share on other sites
Posted (edited)

@TheTom I really appreciate all the help you did right now. The problem is solved and everything works well.

Thanks.

Edited by D J C

Share this post


Link to post
Share on other sites

If you need help again, open other topic.

 

:topic_closed:

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.