Jump to content

[CLEO] Dialog.AddCheckBox / Dialog.AddSlider


D J C
 Share

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

 

Link to comment
Share on other sites

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(1@, "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 2@ 3@ 
    2@ /=2                                                                                                                                                 
    3@ /=2                            
    Dialog.SetRECT(1@, 2@, 3@, 300, 500)    // 300 & 500 from what i remeber are for dialog size.
    dialog.SetVisible(1@, 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(1@, 1, "{28afe0}Zona", 5, 11, 100, 20) // 1@ - add to this dialog - "1" item id - "{28afe0}Zona" - the text - "5, 11" coords, x, y  - "100, 20" text size

Dialog.AddEditBox(1@, 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(1@, 3, "Set", 260, 4, 37, 35)  // same story, "set" will appear on the middle of the button

Dialog.AddCheckBox(1@, 10, " ", 5, 50, 50, 25) // nothing new

dialog.AddSlider(1@, 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(1@)

then

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

if 0B81: dialog 1@ pop_event_to 17@ control_id_to 18@ // 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 18@ == 3 // if we have an action to item id 3, in our case, if the button is pressed

then

alloc 4@ 200 // if you will have text, you need to alloc memory

Dialog.GetControlText(1@, 2, 4@) // like that we take text from editbox id 2 to variable 4@

0AF5: write_string_to_ini_file 4@ 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 4@

end

 

- checkbox

if 18@ == 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 18@ == 52 // same story, 52 item id

then

Dialog.SliderGetValue(1@, 52, 4@) // 52 item id, 4@ 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 4@ value 4

 

- closing dialog

if 18@ == 4 // button id 4

dialog.SetVisible(1@, 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: 4@ = get_int_from_ini_file "CLEO\PDHelperV7.ini" section "PDHelper" key "somatie" // get value from ini
   if 4@ == 1 // if it was checked (by ini value) 
   then                                           
    dialog.SetCheckBoxChecked(1@, 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 4@ 200                                   
   0AF4: 4@ = read_string_from_ini_file "CLEO\PDHelperV7.ini" section "radar" key "zona" // read text for editbox
   Dialog.SetControlText(1@, 2, 4@) // set text 4@ to editbox id 2
   free 4@  

 

// 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(1@, 52, 1)   // if it's value one it will be set to one
   else
    Dialog.SliderSetValue(1@, 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
Link to comment
Share on other sites

  • Tupi locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

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.