REM ------------------------------------------------------ REM RPGDice - A RPG's Dice for Series 60 OPL REM (C) 2006 by Roberto Colistete Jr. REM Email : Roberto.Symbian@terra.com.br REM WWW : www.RobertoColistete.net/RPGDice/ REM This is free software distributed under the terms of REM the Open Source License. REM REM Credits also go to: REM Ramón Giostri Campos - for the idea of RPGDice and his REM advice about RPG dices. REM Ewan Spence - S60 Event Core (used as reference) REM Adrian Pemsel - S60 Phocal (used as reference) REM ------------------------------------------------------ INCLUDE "Const.oph" INCLUDE "AppFrame.oxh" INCLUDE "RPGDice.oph" PROC Main: GLOBAL dirdata$(255),iniFile$(255),flagSaveINI% GLOBAL screenW%,screenH%,frameW%,frameH%,frameId% GLOBAL evStat%,ev&(16),breakout% REM Dice variables GLOBAL nFaces%(10),inFaces%,nRolls% Init_RPGDice: DO Event_Loop: UNTIL breakout% Exit_RPGDice: ENDP PROC Init_RPGDice: breakout%=KFalse% SETFLAGS KSendSwitchOnMessage& REM Enable auto switch off REM Values for dice variables nFaces%(1)=4 : nFaces%(2)=6 : nFaces%(3)=8 nFaces%(4)=10 : nFaces%(5)=12 : nFaces%(6)=14 nFaces%(7)=16 : nFaces%(8)=18 : nFaces%(9)=20 nFaces%(10)=100 : inFaces%=2 nRolls%=1 REM Configure main window screenW%=gWIDTH : screenH%=gHEIGHT frameW%=screenW% : frameH%=screenH%-KStatusBarHeight% frameId%=gIDENTITY gSETWIN 0,KStatusBarHeight%,FrameW%,FrameH% AfSetStatusVisible%:(1) REM Set paths dirdata$="\System\Apps\"+K_App_File_Name$+"\" iniFile$="C:"+dirdata$+K_App_File_Name$+".ini" flagSaveINI%=KTrue% IniLoadFile: REM Random seed for the random rolls of the dice RANDOMIZE DAY*SECOND+inFaces%*nRolls% DrawDiceStatus:(KTrue%) ENDP PROC IniLoadFile: LOCAL ver$(10) ONERR errHandler:: IF EXIST (iniFile$) OPEN iniFile$,A,a$,b$ ver$=A.a$ inFaces%=INT(VAL(MID$(A.b$,1,3))) nRolls%=INT(VAL(MID$(A.b$,4,3))) CLOSE flagSaveINI%=KFalse% ENDIF RETURN errHandler:: ONERR OFF TRAP CLOSE ENDP PROC IniSaveFile: ONERR errHandler:: TRAP MKDIR "C:"+dirdata$ TRAP DELETE iniFile$ CREATE iniFile$,A,a$,b$ INSERT A.a$=K_App_Ver$ A.b$=GEN$(inFaces%,-3)+GEN$(nRolls%,-3) PUT CLOSE RETURN errHandler:: ONERR OFF TRAP CLOSE ENDP PROC Exit_RPGDice: ONERR JustStop:: IF flagSaveINI% IniSaveFile: ENDIF JustStop:: ONERR OFF STOP ENDP PROC Event_Loop: LOCAL c$(255) DO GETEVENT32 ev&() REM Check system messages c$=GETCMD$ IF LEFT$(c$,1)=KGetCmdLetterExit$ : Exit_RPGDice: ELSEIF LEFT$(c$,1)=KGetCmdLetterBackup$ : Exit_RPGDice: ELSEIF LEFT$(c$,1)=KGetCmdLetterBroughtToFGround$ : rem Brought To Focus ENDIF REM Check keyboard IF (ev&(KEvAType%)<>KEvKeyDown& AND ev&(KEvAType%)<>KEvKeyUp&) KbdDrv:(ev&(KEvAType%),ev&(KEvAKMod%),ev&(KEvAScan%)) ENDIF UNTIL breakout% ENDP PROC KbdDrv:(aKey&,aMod&,aScanCode&) LOCAL key& key&=aKey& REM "Options" left soft key of Series 60 IF key&=KKeyLeftSoftKey& key&=ShowMenu&: IF (key&>=ASC("A")) AND (key&<=ASC("Z")) key&=key&-ASC("A")+ASC("a") ENDIF IF key&=%r RollDice: ELSEIF (key&>=K4Faces%) AND (key&<=K100Faces%) inFaces%=key&-K4Faces%+1 flagSaveINI%=KTrue% DrawDiceStatus:(KFalse%) ELSEIF (key&>=K1Roll%) AND (key&<=K10Rolls%) nRolls%=key&-K1Roll%+1 flagSaveINI%=KTrue% DrawDiceStatus:(KFalse%) ELSEIF key&=%h ShowHelp: ELSEIF key&=%a ShowAbout: ELSEIF key&=%x breakout%=KTrue% ENDIF REM "Exit" right soft key of Series 60 ELSEIF key&=KKeyRightSoftKey& breakout%=KTrue% REM Cursor up (or "2") increases the number of faces of the dice ELSEIF (key&=KKeyUpArrow32&) OR (key&=ASC("2")) IF inFaces% < KNumDiceTypes% inFaces%=inFaces%+1 ELSE inFaces%=1 ENDIF flagSaveINI%=KTrue% DrawDiceStatus:(KFalse%) REM Cursor down (or "8") decreases the number of faces of the dice ELSEIF (key&=KKeyDownArrow32&) OR (key&=ASC("8")) IF inFaces% > 1 inFaces%=inFaces%-1 ELSE inFaces%=KNumDiceTypes% ENDIF flagSaveINI%=KTrue% DrawDiceStatus:(KFalse%) REM Cursor right (or "6") increases the number of rolls of the dice ELSEIF (key&=KKeyRightArrow32&) OR (key&=ASC("6")) IF nRolls% < 10 nRolls%=nRolls%+1 ELSE nRolls%=1 ENDIF flagSaveINI%=KTrue% DrawDiceStatus:(KFalse%) REM Cursor left (or "4") decreases the number of rolls of the dice ELSEIF (key&=KKeyLeftArrow32&) OR (key&=ASC("4")) IF nRolls% > 1 nRolls%=nRolls%-1 ELSE nRolls%=10 ENDIF flagSaveINI%=KTrue% DrawDiceStatus:(KFalse%) REM Cursor select (or "5") makes the dice to roll ELSEIF (key&=KKeyCursorSelectKey&) OR (key&=ASC("5")) RollDice: ENDIF ENDP PROC DrawDiceStatus:(flagDrawSoftKeys%) gUPDATE OFF IF flagDrawSoftKeys% gCLS ENDIF gFONT KOplFontLatinBold17& gAT 2,17 gPRINTB GEN$(nFaces%(inFaces%),3)+"-Dice",frameW%/2,KgPrintBLeftAligned% gAT frameW%/2+1,17 IF nRolls%=1 gPRINTB GEN$(nRolls%,3)+"-Roll",frameW%/2-2,KgPrintBRightAligned% ELSE gPRINTB GEN$(nRolls%,3)+"-Rolls",frameW%/2-2,KgPrintBRightAligned% ENDIF IF flagDrawSoftKeys% SetLeftSoftKey:("Options") SetRightSoftKey:("Exit") ENDIF gUPDATE ON ENDP PROC RollDice: LOCAL iRoll%,diceResult% gUPDATE OFF IF nRolls% < 5 gFONT KOplFontLatinBold17& ELSE gFONT KOplFontLatinBold12& ENDIF iRoll%=0 DO iRoll%=iRoll%+1 diceResult%=1+INT(RND*nFaces%(inFaces%)) gAT 0,20+((iRoll%*136)/(nRolls%+1)) IF (nRolls% < 5) OR (iRoll% = nRolls%) gPRINTB "Roll #"+GEN$(iRoll%,2)+" : "+GEN$(diceResult%,3),frameW%,KgPrintBCenteredAligned% ELSE gPRINTB "Roll #"+GEN$(iRoll%,2)+" : "+GEN$(diceResult%,3),frameW%/2-1,KgPrintBLeftAligned% diceResult%=1+INT(RND*nFaces%(inFaces%)) gAT frameW%/2,20+((iRoll%*136)/(nRolls%+1)) iRoll%=iRoll%+1 gPRINTB "Roll #"+GEN$(iRoll%,2)+" : "+GEN$(diceResult%,3),frameW%/2-1,KgPrintBRightAligned% ENDIF UNTIL iRoll% >= nRolls% SetLeftSoftKey:("Ok") SetRightSoftKey:("") gUPDATE ON GET DrawDiceStatus:(KTrue%) ENDP PROC ShowMenu&: mINIT mCASC "Number of Faces","4",K4Faces%,"6",K6Faces%,"8",K8Faces%,"10",K10Faces%,"12",K12Faces%,"14",K14Faces%,"16",K16Faces%,"18",K18Faces%,"20",K20Faces%,"100",K100Faces% mCASC "Number of Rolls","1",K1Roll%,"2",K2Rolls%,"3",K3Rolls%,"4",K4Rolls%,"5",K5Rolls%,"6",K6Rolls%,"7",K7Rolls%,"8",K8Rolls%,"9",K9Rolls%,"10",K10Rolls% mCARD "Options","Roll [5]",%r,"Number of Faces>",%f,"Number of Rolls>",%n,"Help",%h,"About",%a,"Exit",%x RETURN MENU ENDP PROC ShowHelp: gUPDATE OFF gCLS gAT 0,15 gFONT KOplFontLatinPlain12& gPRINTB " Roll/Throw dice : press '5' or",frameW%,KgPrintBLeftAligned% gAT 0,30 gPRINTB " the 'Select' joypad key or the",frameW%,KgPrintBLeftAligned% gAT 0,45 gPRINTB " 'Options/Roll' menu.",frameW%,KgPrintBLeftAligned% gAT 0,63 gPRINTB " Number of faces : press '2'/'8' or",frameW%,KgPrintBLeftAligned% gAT 0,78 gPRINTB " the up/down joypad key or the",FrameW%,KgPrintBLeftAligned% gAT 0,93 gPRINTB " 'Options/Number of Faces' menu.",frameW%,KgPrintBLeftAligned% gAT 0,111 gPRINTB " Number of rolls : press '6'/'4' or",frameW%,KgPrintBLeftAligned% gAT 0,126 gPRINTB " the right/left joypad key or the",FrameW%,KgPrintBLeftAligned% gAT 0,141 gPRINTB " 'Options/Number of Rolls' menu.",frameW%,KgPrintBLeftAligned% SetLeftSoftKey:("Ok") SetRightSoftKey:("") gUPDATE gUPDATE ON GET DrawDiceStatus:(KTrue%) ENDP PROC ShowAbout: gUPDATE OFF gCLS gAT 3,20 gFONT KOplFontLatinBold17& gPRINTB K_App_Name$,frameW%-6,KgPrintBCenteredAligned% gAT 3,35 gFONT KOplFontLatinPlain12& gPRINTB "v"+K_App_Ver$,frameW%-6,KgPrintBCenteredAligned% gAT 0,55 gPRINTB "A freeware and open source OPL",FrameW%,KgPrintBCenteredAligned% gAT 0,70 gPRINTB "program for Symbian & Series 60",FrameW%,KgPrintBCenteredAligned% gAT 0,95 gPRINTB "(C) "+K_App_Year$+" "+K_Author_Name$,FrameW%,KgPrintBCenteredAligned% gAT 0,115 gPRINTB K_Author_WWW$,FrameW%,KgPrintBCenteredAligned% gAT 0,135 gPRINTB K_Author_Email$,FrameW%,KgPrintBCenteredAligned% SetLeftSoftKey:("Ok") SetRightSoftKey:("") gUPDATE gUPDATE ON GET DrawDiceStatus:(KTrue%) ENDP PROC SetLeftSoftKey:(caption$) gFONT KOplFontLatinBold17& gAT 2,frameH%-4 gPRINTB caption$,frameW%/2-1,KgPrintBLeftAligned% ENDP PROC SetRightSoftKey:(caption$) gFONT KOplFontLatinBold17& gAT frameW%/2+1,frameH%-4 gPRINTB caption$,frameW%/2-2,KgPrintBRightAligned% ENDP