1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Solved HELP...Different pictures pop up when select different text from a drop down menu

Discussion in 'Scripting Workshop' started by Brian Wong, Jul 30, 2019.

  1. Brian Wong

    Brian Wong New Member

    Messages:
    4
    Hi there, I'm a beginner just start learning KSP and I'm have a question about drop down menu, is it possible to make different pictures pop up when select different text from a drop down menu? How can I link them together?

    For example:
    $shoes_pic1_id show up something when drop down menu "shoes1" selected?
    $shoes_pic2_id show up something when drop down menu "shoes2" selected?


    Code:
    on init
      
        make_perfview
        set_ui_height(632)
        
      declare ui_switch $Shoes_on_off_switch
        move_control_px($Shoes_on_off_switch,40,40)
        make_persistent($Shoes_on_off_switch)
        set_control_par_str(get_ui_id($Shoes_on_off_switch),$CONTROL_PAR_TEXT,"")
        set_control_par(get_ui_id($Shoes_on_off_switch),$CONTROL_PAR_WIDTH,60)
        set_control_par(get_ui_id($Shoes_on_off_switch),$CONTROL_PAR_HEIGHT,60)
        set_control_par_str(get_ui_id($Shoes_on_off_switch),$CONTROL_PAR_HELP,"Shoes On Off Switch.")
        set_control_par_str(get_ui_id($Shoes_on_off_switch),$CONTROL_PAR_PICTURE,"switch_on_off")
     
        declare $shoes_pic_1_id
        set_control_par_str($shoes_pic_1_id ,$CONTROL_PAR_PICTURE,"SHOES_1")
        move_control_px($Shoes_on_off_switch,150,150)
        declare $shoes_pic_2_id
        set_control_par_str($shoes_pic_2_id ,$CONTROL_PAR_PICTURE,"SHOES_2")
        move_control_px($Shoes_on_off_switch,150,150)
        declare $shoes_pic_3_id
        set_control_par_str($shoes_pic_3_id ,$CONTROL_PAR_PICTURE,"SHOES_3")
        move_control_px($Shoes_on_off_switch,150,150)
    
      declare ui_menu $ShoesDropDownMenu
       add_menu_item ($ShoesDropDownMenu, "Selection", 0)
       add_menu_item ($ShoesDropDownMenu, "Shoes1", 1)
       add_menu_item ($ShoesDropDownMenu, "Shoes2", 2)
       add_menu_item ($ShoesDropDownMenu, "Shoes3", 3)
    
         $Shoes_on_off_switch := 0 {$Shoes_on_off_switch is off by default, so hide $ShoesDropDownMenu}
         move_control ($ShoesDropDownMenu,0,0)
         move_control_px($Shoes_on_off_switch,40,40)
         make_persistent($Shoes_on_off_switch)
         make_persistent ($ShoesDropDownMenu)
    
    
        read_persistent_var ($Shoes_on_off_switch)
          if ($Shoes_on_off_switch = 1)
            move_control_px ($ShoesDropDownMenu,40,80)
          else
            move_control ($ShoesDropDownMenu,0,0)   
          end if
    end on
    
    on ui_control ($Shoes_on_off_switch)
        if ($Shoes_on_off_switch = 1)
          move_control_px ($ShoesDropDownMenu,40,80)
        else
          move_control ($ShoesDropDownMenu,0,0)   
        end if
    end on 
     

    Attached Files:

  2. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    You have to call a single picture that will be shared by as many Menu selections .

    An example is present in the KONTAKT Factory Library with the Master FX selection menu.
     
    Last edited: Jul 31, 2019
  3. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You're going about this in a wrong way.

    First, you cannot use set_control_par_str() on a variable that is not a UI control. Ideally you would have an ui_label on which you can either change the picture by using $CONTROL_PAR_PICTURE (and you would do it in ui_control callback of the menu, AND persistence_changed callback), or you would have one PNG with multiple frames, which you would then switch with $CONTROL_PAR_PICTURE_STATE.
     
  4. Brian Wong

    Brian Wong New Member

    Messages:
    4
    Hi,

    Would you mind make a code example please?
    I'm still a bit confused how to make it work, but I would love to find it out and make more understanding that helps with my study.

    Thank you so much!:)
     
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Code:
    on init
        declare ui_menu $Menu
        declare ui_label $Pic (1, 1)
    
        make_persistent($Menu)
    
        set_text($Pic, "")
    
        add_menu_item($Menu, "First", 0)
        add_menu_item($Menu, "Second", 1)
        add_menu_item($Menu, "Third", 2)
    end on
    
    function UpdatePic()
        set_control_par(get_ui_id($Pic), $CONTROL_PAR_PICTURE_STATE, $Menu)
    end function
    
    on persistence_changed
        call UpdatePic()
    end on
    
    on ui_control ($Menu)
        call UpdatePic()
    end on
    Of course use $CONTROL_PAR_WIDTH/HEIGHT on the label to resize it according to your picture. This code assumes all the pictures are in one PNG with multiple frames.
     
  6. Brian Wong

    Brian Wong New Member

    Messages:
    4
    Thats kl lol Thank you so much for your help, cheers

    Sent from my MI NOTE Pro using Tapatalk