Results 1 to 9 of 9

Thread: OSD and Submenu

  1. #1
    Join Date
    Dec 2006
    Posts
    5

    Post OSD and Submenu

    Hi,

    I'm trying to make my OSD with submenu works.
    I've followed the example with the AutoMenu and AutoCallback way. I can't get it work.
    I've read all the post concerning OSD but that didn't help me. I must have forgotten something obvious.
    Here is my code (from the Demo.gml OSD Menu example).


    local SubMenu1 = {
    Title='My First Submenu',
    [1]='SubMenu Option 1',
    [2]='SubMenu Option 2',
    }

    local MyMenu = {
    Title='Toplevel Menu',
    [1]='Menu Option 1',
    [2]='Menu Option 2',
    [3]=SubMenu1,
    [4]={
    Name='Menu Option 3 - Extended',
    EventString='Nice!!',
    EventDevice=100, -- Really you can add whatever you like here except for 'Title'.
    },
    }

    table.insert(SubMenu1, MyMenu)

    --[[ this one gets called when a user clicks on a menu item
    the item clicked can be one of three types as defined above.
    --]]
    local function MyAutoCB(Number, Text, Item, Closing)

    osd.StatusMessage ("Here in MyAutoCB function ")

    if type(Item) == 'string' then
    -- a regular menu item was clicked.
    gir.TriggerEvent(Text, 18,0)
    end

    if type(Item) == 'table' then

    -- Figure out if it was a submenu or an extended item.
    if not Item.Title then
    -- alright this is an extended entry.
    gir.TriggerEvent(Item.EventString, Item.EventDevice,0)
    else
    -- Sub Menu Item Clicked

    end

    end

    end

    -- Recycle the menu, do not keep creating new ones, you will run out of resources.
    if not AutoMenu then

    -- On the AutoMenu class DO NOT OVERRIDE THE Callback! Instead
    -- Override the AutoCallback, if the AutoCallback is not overriden
    -- the default is to Send the following Event:
    -- EventString: "<MENU TITLE>.<MENU ITEM>"
    -- EventDevice: 18
    -- EventModifier: 1
    -- Payload 1: <MENU ITEM>
    -- Payload 2: <MENU ITEM NUMBER>

    AutoMenu = osd.Classes.AutoMenu:New ({AutoCallback = MyAutoCB, Fade=true, TimeOut=5000})
    --AutoMenu = osd.Classes.AutoMenu:New ({Fade=true})
    AutoMenu:Initialize()

    AutoMenu.MaxItems=20
    end

    -- Toggle visibility.
    if not AutoMenu.Visible then
    AutoMenu:Show (true, MyMenu)
    else
    AutoMenu:Hide()
    end



    It is like the MyAutoCB is never called as none of the osd.StatusMessage is displayed.

    Please, any help would be really appreciated.
    By the way, a simple OSD menu (with no submenu) works great.

    Thanks.
    Last edited by tevaf; December 27th, 2006 at 03:23 PM.

  2. #2
    Join Date
    Dec 2006
    Posts
    5

    Default

    Hi again,

    Do I have to install the OSD menu plugin with Girder 4 to make submenu work ?

    Could someone show me an other working example of OSD menu with submenu that I can try ?

    Thanks for any clue.

  3. #3
    Join Date
    Dec 2006
    Posts
    5

    Default

    Please, anyone as a code sample to share ?

    Thanks.

  4. #4
    Join Date
    Dec 2006
    Posts
    1

    Default

    I had the same problem, I put the line "AutoMenu = osd.Classes......" out of the "if not" clause and that seems to work

  5. #5
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,541

    Default

    I justed tested the example in the Demo.gml and it seems to work.

    Code:
    --[[ 	AutoMenu Example, Girder 4.0
    		By Ron Bessems / January 25 2006
    		
    		If you need to make more elaborate menus, with submenus and
    		being able to do things besides triggering events this class
    		will be of great help to you.
    		
    		It uses a table to store the layout of the menu, see the table
    		'MyMenu'. The entries on the menu are stored in the table by index.
    		(The [1]=... and [2]=...)
    		
    		To give a submenu a name use the 'Title' Entry.
    		
    		Here is an example of a very simple menu:
    		-----------------------------------------
            
    		local MyMenu = {
    			Title='Simple Example',
    			[1]='Menu Option 1',
    			[2]='Menu Option 2',
    		}
    		
    		This will display two menu items "Menu Option 1" and "Menu Option 2" with the
    		menu Title of "Simple Example".
    		
            Menu with SubMenu:
            ------------------------------------------
    
            local SubMenu1 = {
                Title='My First Submenu',
                [1]='SubMenu Option 1',
                [2]='SubMenu Option 2',      
            }
            
            local MyMenu = {
    			Title='Toplevel Menu',
    			[1]='Menu Option 1',
    			[2]='Menu Option 2',
                [3]=SubMenu1,            
            }
            
            Which adds a submenu to our menu system.
            
            
            Menu with SubMenu and reference to Top Menu:
            --------------------------------------------
            
            Say you wanted to go back to the previous menu, this is done by
            adding a link to the table above into the subtable. Sounds complicated? It's not!
    
            SubMenu1 = {
                Title='My First Submenu',
                [1]='SubMenu Option 1',
                [2]='SubMenu Option 2',      
            }
            
            MyMenu = {
    			Title='Toplevel Menu',
    			[1]='Menu Option 1',
    			[2]='Menu Option 2',
                [3]=SubMenu1,            
            }
    		
    		table.insert(SubMenu1, MyMenu)
    		
    		That last line added a new menu item to our submenu that links back to the toplevel menu.
            Some people like it more compact and would want to do this in one table:
            
    		MyMenu = {
    			Title='Toplevel Menu',
    			[1]='Menu Option 1',
    			[2]='Menu Option 2',
                [3]= {
                    Title='My First Submenu',
                    [1]='SubMenu Option 1',
                    [2]='SubMenu Option 2',                
                },
    		}
    
            table.insert(MyMenu[3], MyMenu)
                    
            
            
            
            Menu with Extended Entries:
            ------------------------------------------------
            
            Sometimes you might not want to trigger an event with the eventstring being the same
            as the label on the menu or you would want to do something totally different. In that case
            you'll need to able to store extra information in the menu so you can retrieve it. This is
            done with an extended entry.
            
            MyMenu = {
    			Title='Toplevel Menu',
    			[1]='Menu Option 1',
    			[2]='Menu Option 2',
                [3]= {
                    Name='Menu Option 3 - Extended',
    		        EventString='Nice!!',
    		        EventDevice=100,        -- Really you can add whatever you like here except for 'Title'.
                },
                
            }
            
            You'll also need some way of being notified of the menu click that is done by a callback.
            
            when you create the object specify your callback:
            
            
            local function MyAutoCB(Number, Text, Item)
                -- do something here.
            end
            
            AutoMenu = osd.Classes.AutoMenu:New ({AutoCallback = MyAutoCB})
    
            
            The function should be able to deal with 3 menu types
            
             1. A regular item, Item will be of the type string
             
             2. An extended item, Item will be of the type table and Item.Title will not exist.
             
             3. An Sub Menu, Item will be of the type table and Item.Title will exists. This is called
                when the user clicks on a submenu.	
    
            the function MyAutoCB below gives an example of this.            
    
    --]]
    
    local SubMenu1 = {
        Title='My First Submenu',
        [1]='SubMenu Option 1',
        [2]='SubMenu Option 2',      
    }
    
    local MyMenu = {
        Title='Toplevel Menu',
        [1]='Menu Option 1',
        [2]='Menu Option 2',
        [3]=SubMenu1,  
        [4]={
            Name='Menu Option 3 - Extended',
            EventString='Nice!!',
            EventDevice=100,        -- Really you can add whatever you like here except for 'Title'.
        },    
    }
    
    table.insert(SubMenu1, MyMenu)
    
    --[[ this one gets called when a user clicks on a menu item
    	 the item clicked can be one of three types as defined above.    
    --]]
    local function MyAutoCB(Number, Text, Item, Closing)
    	print(Number, Text, Item, Closing)
    	
    	if type(Item) == 'string' then
    		-- a regular menu item was clicked.
    		gir.TriggerEvent(Text, 18,0)
    	end
    	
    	if type(Item) == 'table' then
    		
    		-- Figure out if it was a submenu or an extended item.
    		if not Item.Title then
    			-- alright this is an extended entry.			
    			gir.TriggerEvent(Item.EventString, Item.EventDevice,0)		
    		else		
    			-- Sub Menu Item Clicked
    			
    		end	
    	
    	end
    
    end
    
    -- Recycle the menu, do not keep creating new ones, you will run out of resources.
    if not AutoMenu then
    	
    	-- On the AutoMenu class DO NOT OVERRIDE THE Callback! Instead
    	-- Override the AutoCallback, if the AutoCallback is not overriden
    	-- the default is to Send the following Event:
    	-- EventString: "<MENU TITLE>.<MENU ITEM>"
    	-- EventDevice: 18
    	-- EventModifier: 1
    	-- Payload 1: <MENU ITEM>
    	-- Payload 2: <MENU ITEM NUMBER>
    	
    	AutoMenu = osd.Classes.AutoMenu:New ({AutoCallback = MyAutoCB, Fade=true, TimeOut=5000})
    	--AutoMenu = osd.Classes.AutoMenu:New ({Fade=true})
    	AutoMenu:Initialize()
    
    	AutoMenu.MaxItems=20 
    end
    
    -- Toggle visibility.
    if not AutoMenu.Visible then	
    	AutoMenu:Show (true, MyMenu)
    else
    	AutoMenu:Hide()
    end
    I added the print line to the MyAutoCB to see if it is called every time and it does seem to. Can you start from the code above and modify it?
    Ron
    No support through PM

  6. #6
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,541

    Default

    Actually for starts do not modify it just try it out as is.
    Ron
    No support through PM

  7. #7
    Join Date
    Dec 2006
    Posts
    5

    Default

    Thanks for your replies.
    I will try it as soon as I get home and let you know the results.

  8. #8
    Join Date
    Dec 2006
    Posts
    5

    Default

    Thanks RON for your help.
    Your example works fine.

    I found my mistake.
    When adding print command to the script or osd.StatusMessage, it seems that I have to reset the LUA script engine (<F11>) to apply the change. Otherwise, none of my code modification is executed.

  9. #9
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    Quote Originally Posted by tevaf View Post
    Thanks RON for your help.
    Your example works fine.

    I found my mistake.
    When adding print command to the script or osd.StatusMessage, it seems that I have to reset the LUA script engine (<F11>) to apply the change. Otherwise, none of my code modification is executed.
    correct

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •