Code: Select all
!$("head").append("<link rel='stylesheet' type='text/css' href='Data/js/messi.css' />");
Structure Player
name.s
finalres.l
EndStructure
Global Dim players.Player(4)
Global currentHand = 0
Global txtP1, txtP2, txtP3, txtP4
Procedure CloseWindowEvent()
CloseWindow(EventWindow())
EndProcedure
Procedure GadgetEvents()
Select EventGadget()
EndSelect
EndProcedure
Procedure Alert(title.s,message.s)
!new Messi(v_message, {title: v_title, width: '200px', titleClass: 'anim error', modal: true , buttons: [{id: 0, label: 'Close', val: 'X'}]});
EndProcedure
Procedure RefreshButtons()
SetGadgetText(txtP1, players(0)\name)
SetGadgetText(txtP2, players(1)\name)
SetGadgetText(txtP3, players(2)\name)
SetGadgetText(txtP4, players(3)\name)
EndProcedure
Runtime Procedure doNewDlg()
If GetGadgetText(DialogGadget(0, "player1")) = "" Or
GetGadgetText(DialogGadget(0, "player2")) = "" Or
GetGadgetText(DialogGadget(0, "player3")) = "" Or
GetGadgetText(DialogGadget(0, "player4")) = ""
Alert("New","Names cannot be empty")
Else
; Set names and initialize scores
players(0)\name = UCase(GetGadgetText(DialogGadget(0, "player1")))
players(0)\finalres = 0
players(1)\name = UCase(GetGadgetText(DialogGadget(0, "player2")))
players(1)\finalres = 0
players(2)\name = UCase(GetGadgetText(DialogGadget(0, "player3")))
players(2)\finalres = 0
players(3)\name = UCase(GetGadgetText(DialogGadget(0, "player4")))
players(3)\finalres = 0
currentHand = 1
FreeDialog(0)
EndIf
EndProcedure
Runtime Procedure cancelNewDlg()
FreeDialog(0)
EndProcedure
Procedure newDlg()
#Dialog = 0
#Xml = 0
XML$ = "<window id='#PB_Any' name='new' text='New game' minwidth='auto' minheight='auto' maxheight='auto' flags='#PB_Window_ScreenCentered | #PB_Window_SizeGadget'>" +
" <vbox expand='no'>" +
" <text text='Player #1' />" +
" <string name='player1' text='' width='200' />" +
" <text text='Player #2' />" +
" <string name='player2' text='' width='200' />" +
" <text text='Player #3' />" +
" <string name='player2' text='' width='200' />" +
" <text text='Player #4' />" +
" <string name='player3' text='' width='200' />" +
" <empty /> " +
" <empty /> " +
" <hbox expand='equal'>" +
" <button text='Ok' onevent='doNewDlg()' height='30' />" +
" <button text='Cancel' onevent='cancelNewDlg()' height='30' />" +
" </hbox>" +
" </vbox>" +
" </window>"
If ParseXML(#Xml, XML$) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "new")
Debug "Dialog created"
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf
EndProcedure
Procedure MenuEvents()
Select EventMenu()
Case 0 ; New
newDlg()
Case 1 ; Load
Case 2 ; Save
Case 3 ; Undo
Case 4 ; Draw
Case 4 ; Show
EndSelect
EndProcedure
Procedure Start()
ExamineDesktops()
WindowWidth = DesktopWidth(0)
WindowHeight = DesktopHeight(0)
Top = 10
GadgetHeight = 24
If OpenWindow(0, 0, 0, WindowWidth, WindowHeight, "Mahjong Score", #PB_Window_Background)
; Toolbar
If CreateToolBar(0, WindowID(0))
Global newBtn = ToolBarImageButton(0, ImageID(0))
ToolBarToolTip(0, newBtn, "New game")
Global loadBtn = ToolBarImageButton(1, ImageID(1))
ToolBarToolTip(0, loadBtn, "Load game")
Global saveBtn = ToolBarImageButton(2, ImageID(2))
ToolBarToolTip(0, saveBtn, "Save game")
ToolBarSeparator()
Global undoBtn = ToolBarImageButton(3, ImageID(3))
ToolBarToolTip(0, undoBtn, "Undo annotation")
Global drawBtn = ToolBarImageButton(4, ImageID(4))
ToolBarToolTip(0, drawBtn, "Draw hand")
ToolBarSeparator()
Global showBtn = ToolBarImageButton(5, ImageID(5))
ToolBarToolTip(0, showBtn, "Show annotations")
BindEvent(#PB_Event_Menu, @MenuEvents())
EndIf
; Four big buttons
height = WindowHeight - ToolBarHeight(0)
If (height > WindowWidth)
width = (WindowWidth - 20) / 2
Else
width = (height - 20) / 2
EndIf
ContainerGadget(#PB_Any,10, ToolBarHeight +10, width, width, #PB_Container_Raised )
txtP1 = TextGadget(#PB_Any, width / 2 - 20, width / 2 - 60, 40, 40, "East", #PB_Text_Center | #PB_Text_VerticalCenter)
ButtonImageGadget(#PB_Any, width / 2 - 30, width / 2 - 30, 60, 60, ImageID(6))
CloseGadgetList()
ContainerGadget(#PB_Any, 10 + width, ToolBarHeight +10, width, width, #PB_Container_Raised )
txtP2 = TextGadget(#PB_Any, width / 2 - 20, width / 2 - 60, 40, 40, "South", #PB_Text_Center | #PB_Text_VerticalCenter)
ButtonImageGadget(#PB_Any, width / 2 - 30, width / 2 - 30, 60, 60, ImageID(7))
CloseGadgetList()
ContainerGadget(#PB_Any, 10, ToolBarHeight + 10 + width, width, width, #PB_Container_Raised )
txtP3 = TextGadget(#PB_Any, width / 2 - 20, width / 2 - 60, 40, 40, "West", #PB_Text_Center | #PB_Text_VerticalCenter)
ButtonImageGadget(#PB_Any, width / 2 - 30, width / 2 - 30, 60, 60, ImageID(8))
CloseGadgetList()
ContainerGadget(#PB_Any, 10 + width, ToolBarHeight + 10 + width, width, width, #PB_Container_Raised )
txtP4 = TextGadget(#PB_Any, width / 2 - 20, width / 2 - 60, 40, 40, "North", #PB_Text_Center | #PB_Text_VerticalCenter)
ButtonImageGadget(#PB_Any, width / 2 - 30, width / 2 - 30, 60, 60, ImageID(9))
CloseGadgetList()
; Actions on gadgets
BindEvent(#PB_Event_Gadget, @GadgetEvents())
BindEvent(#PB_Event_CloseWindow, @CloseWindowEvent())
CompilerIf #PB_Compiler_OS <> #PB_OS_Web
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
CompilerEndIf
EndIf
EndProcedure
Procedure Loading(Type, Filename$)
Static NbLoadedElements
NbLoadedElements+1
If NbLoadedElements = 10 ; Finished the loading of all images, we can start the application
Start()
EndIf
EndProcedure
Procedure LoadingError(Type, Filename$)
Debug Filename$ + ": loading error"
EndProcedure
; Resizing or rotating
Procedure SizeWindowHandler()
CloseWindow(0)
Start()
EndProcedure
Procedure LoadImages()
;CloseDebugOutput()
; Resizing or rotation
BindEvent(#PB_Event_SizeWindow, @SizeWindowHandler(),0)
; Load images
LoadImage(0, "Data/ToolBar/add.png")
LoadImage(1, "Data/ToolBar/load.png")
LoadImage(2, "Data/ToolBar/save.png")
LoadImage(3, "Data/ToolBar/undo.png")
LoadImage(4, "Data/ToolBar/draw.png")
LoadImage(5, "Data/ToolBar/table.png")
LoadImage(6, "Data/Buttons/east.png")
LoadImage(7, "Data/Buttons/south.png")
LoadImage(8, "Data/Buttons/west.png")
LoadImage(9, "Data/Buttons/north.png")
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
!$.getScript("Data/js/messi.js", loadok);
!function loadok()
!{
LoadImages()
!}
Greetings ... Peter