While "True"
UpdateProgram()
UpdateFrame()
FrameRate()
EndWhile
'=======================================================
'FIRST ORDER SUBROUTINES
'=======================================================
Sub UpdateProgram
start = Clock.ElapsedMilliseconds
If mouseMove Then
GetMousePosition()
Menu_UpdateOnMouseMove()
mouseMove = "False"
EndIf
If mouseDown Then
Menu_UpdateOnMouseDown() 'creates a non async OnMenuClicked Event
'GetMousePosition() 'not used here for menu
mouseDown = "False"
EndIf
If menuClicked Then 'OnMenuClicked
' For Multi-Language
For i = 1 To nLang
If subMenu[menuSelection][subMenuSelection] = lang1[ixLang[i]] Then
lang = ixLang[i]
i = nLang ' exit For
EndIf
EndFor
If lang <> langLast Then
Shapes.SetText(hello, msg[1][lang])
Shapes.SetText(l1, lang1[lang])
Shapes.SetText(l2, lang2[lang])
langLast = lang
EndIf
'============================================================
'SECOND ORDER SUBROUTINES - except for Menu Module
'============================================================
Sub GetMousePosition
mseX = GraphicsWindow.MouseX
mseY = GraphicsWindow.MouseY
EndSub
'=========================================================
'Event Handlers
'=========================================================
Sub OnMouseMove
mouseMove = "True"
EndSub
Sub OnMouseDown
mouseDown = "True"
EndSub
'************************************************************************************************************
'============================================================
'DROP DOWN MENU SUBROUTINES
'============================================================
'Customise & Dynamic Subs - Second Order
'-----------------------------------------------------------------------------------------------------
Sub Menu_DataTable 'USE THIS SUB TO CUSTOMISE MENU
'MENU
'Data Table
menu = "1=Language;" 'ADD DATA
menuWidth = "1=100;" 'MATCH WIDTH WITH DATA
For i = 1 To nLang
subMenu[1][i] = lang1[ixLang[i]]
subMenuWidth[i] = 150 'MATCH WIDTH WITH DATA
EndFor
EndSub
Sub Menu_DrawMenuBar 'USE THIS SUB TO REDRAW MENU BAR on Resize 'UNTESTED
'Add Menu Bar - Sub {redraw for new window size}
If weHaveSprites Then
GraphicsWindow.DrawResizedImage(menuBarTexture, 0, 0, gw, menuHeight)
Else
GraphicsWindow.BrushColor = "LightGray"
GraphicsWindow.FillRectangle(0, 0, gw, menuHeight)
EndIf
EndSub
'-----------------------------------------------------------------------------------------------------------
'Initialise Menu - First Order
'-----------------------------------------------------------------------------------------------------------
Sub Menu_Initialise
Menu_DataTable() 'USED TO CUSTOMISE THE MENU
'If there are no PNG files then we don't have sprites
weHaveSprites = "True"
For i = Array.GetItemCount(menuFileName) To 1 Step -1
If Text.IsSubText(getMenuFiles, menuFileName[i]) <> "True" Then
weHaveSprites = "False"
EndIf
EndFor
menuFocusOpacityIndex = 0
'Get posX for menuFocus
For i = 1 To Array.GetItemCount(menuWidth) 'to be reversed
totalMenuWidth = totalMenuWidth + menuWidth[i]
menuFocusX[i] = totalMenuWidth - menuWidth[i]
EndFor
If totalMenuWidth > gw Then
TextWindow.WriteLine("ERROR: total menu widths exceeds GW")
TextWindow.Pause()
EndIf
For i = Array.GetItemCount(menu) To 1 Step -1
menuText[i] = Shapes.AddText(menu[i])
Shapes.Move(menuText[i], menuFocusX[i] + menuTextOffset, menuTextOffsetY)
EndFor
'Error Check subMenu Width. NEEDS MORE TESTING
If menuFocusX[Array.GetItemCount(menu)] + subMenuWidth[Array.GetItemCount(menu)] > gw Then
TextWindow.WriteLine("ERROR: sum of all subMenu widths exceeds GW")
TextWindow.Pause()
EndIf
'Add Sub Menus - FIXING B/GROUND SPRITE *******************************
If weHaveSprites Then
subMenuBackground = Shapes.AddImage(subMenuBackgroundSprite)
Else
GraphicsWindow.BrushColor = "LightGray"
subMenuBackground = Shapes.AddRectangle(menuFocusWidth, menuHeight)
EndIf
Shapes.SetOpacity(subMenuBackground, 0)
For j = Array.GetItemCount(subMenu) To 1 Step -1
left = menuFocusX[j] + subMenuTextOffset
For i = Array.GetItemCount(subMenu[j]) To 1 Step -1
GraphicsWindow.BrushColor = "Black"
subMenuText[j][i] = Shapes.AddText(subMenu[j][i])
Shapes.Move(subMenuText[j][i], left, menuHeight * i + menuTextOffsetY)
Shapes.SetOpacity(subMenuText[j][i], 0)
EndFor
EndFor
EndSub
'------------------------------------------------------------------------------------------------------------
'Menu Updates - Second Order
'------------------------------------------------------------------------------------------------------------
Sub Menu_UpdateOnMouseMove
'Update Menu Focus onMouseMove
menuFocusedOn = 0
menuFocusOpacityIndex = 0
If mseY <= menuHeight And mseX <= totalMenuWidth Then
For i = Array.GetItemCount(menu) To 1 Step -1
If mseX >= menuFocusX[i] And mseX <= menuFocusX[i] + menuWidth[i] Then
menuFocusOpacityIndex = isMenuSelected 'isMenuSelected toggles onMouseDown 1/-1
menuFocusZoomX = menuWidth[i] / menuFocusWidth
menuFocusedOn = i 'determines which SubMenu[i] to open If isMenuSelected = 1
nextMenuFocus = menuFocusedOn
EndIf
EndFor
If isMenuSelected = 1 And nextMenuFocus <> currentMenuFocus Then 'change selected Menu focus
priorMenuFocus = currentMenuFocus
currentMenuFocus = nextMenuFocus
EndIf
ElseIf isMenuSelected = 1 Then 'lock the selected Menu and its opacity to show related SubMenu
menuFocusedOn = currentMenuFocus '...so that SubMenu stays open when mouse is off location
menuFocusOpacityIndex = 1
EndIf
'Update SubMenu Focus onMouseMove
subMenuFocusedOn = 0 'WIP
If isMenuSelected = 1 Then
subMenuFocusOpacity = 0
'Loop thru sub menu, as required. Sets subMenuFocus Top, Opacity & ZoomX. And sets subMenuBackgroundZoomY
If mseX >= menuFocusX[menuFocusedOn] And mseX <= menuFocusX[menuFocusedOn] + subMenuWidth[menuFocusedOn] Then
If mseY > menuHeight And mseY <= menuHeight * (Array.GetItemCount(subMenu[menuFocusedOn]) + 1) Then
For i = Array.GetItemCount(subMenu[menuFocusedOn]) To 1 Step -1
If mseY >= menuHeight * i And mseY <= menuHeight * (i+1) Then
subMenuFocusTop = menuHeight * i
subMenuFocusedOn = i
EndIf
EndFor
subMenuFocusOpacity = 100
EndIf
subMenuFocusZoomX = subMenuWidth[menuFocusedOn] / menuFocusWidth
subMenuBackgroundZoomY = (Array.GetItemCount(subMenu[menuFocusedOn]) * menuHeight) / menuHeight
EndIf
Else
subMenuFocusOpacity = 0
EndIf
EndSub
Sub Menu_UpdateOnMouseDown
'Update Menu onMouseDown
If menuFocusedOn <> 0 Then
isMenuSelected = -isMenuSelected 'toggle on Click 1/-1
menuFocusOpacityIndex = isMenuSelected
EndIf
priorMenuFocus = 0
If isMenuSelected = -1 Then
If mseY > menuHeight Or mseX > totalMenuWidth Then
menuFocusOpacityIndex = 0
priorMenuFocus = menuFocusedOn
EndIf
EndIf
'OnMenuClicked event {non async Event} - pass the selection to If menuClicked
If isMenuSelected = -1 And subMenuFocusedOn > 0 Then
menuSelection = menuFocusedOn
subMenuSelection = subMenuFocusedOn
If menuSelection > 0 And subMenuSelection > 0 Then '***OnMenuClicked Event***
menuClicked = "True" 'non async event. Sequential
EndIf
menuFocusedOn = 0
subMenuFocusedOn = 0
'Unlock the selected Menu after no mouseMove between clicks
ElseIf isMenuSelected = -1 And mseY > menuHeight Or isMenuSelected = -1 And mseX > totalMenuWidth Then '****wip here
menuFocusedOn = 0
EndIf
EndSub
Sub Menu_UpdateFrame
'Update Menu Focus - Main Bar
Shapes.SetOpacity(menuFocus, menuFocusOpacity[menuFocusOpacityIndex])
Shapes.Zoom(menuFocus, menuFocusZoomX, 1)
Shapes.Move(menuFocus, menuFocusX[menuFocusedOn] + (menuWidth[menuFocusedOn] - menuFocusWidth) /2, 0)
Y = menuHeight + ((Array.GetItemCount(subMenu[menuFocusedOn]) * menuHeight) - menuHeight) / 2 'wip put in update program
Shapes.Move(subMenuBackground, menuFocusX[menuFocusedOn] + (subMenuWidth[menuFocusedOn] - menuFocusWidth) /2, Y)
For i = Array.GetItemCount(subMenu[menuFocusedOn]) To 1 Step -1
Shapes.SetOpacity(subMenuText[menuFocusedOn][i], subMenuOpacity)
EndFor
'Update SubMenu - Lost Focus
Shapes.SetOpacity(subMenuBackground[priorMenuFocus], 0) 'check if index needed
For i = Array.GetItemCount(subMenu[priorMenuFocus]) To 1 Step -1
Shapes.SetOpacity(subMenuText[priorMenuFocus][i], 0)
EndFor