diff --git a/assets/fonts/Gotham-Medium.otf b/assets/fonts/Gotham-Medium.otf new file mode 100644 index 0000000..144fd8e Binary files /dev/null and b/assets/fonts/Gotham-Medium.otf differ diff --git a/images/dialog-back.png b/images/dialog-back.png new file mode 100644 index 0000000..50e1314 Binary files /dev/null and b/images/dialog-back.png differ diff --git a/images/dialog-bar.png b/images/dialog-bar.png new file mode 100644 index 0000000..6b5d231 Binary files /dev/null and b/images/dialog-bar.png differ diff --git a/images/dialog-bottom.png b/images/dialog-bottom.png new file mode 100644 index 0000000..727f8f5 Binary files /dev/null and b/images/dialog-bottom.png differ diff --git a/images/dialog-bullet.png b/images/dialog-bullet.png new file mode 100644 index 0000000..0f431e6 Binary files /dev/null and b/images/dialog-bullet.png differ diff --git a/images/dialog-top.png b/images/dialog-top.png new file mode 100644 index 0000000..83f5265 Binary files /dev/null and b/images/dialog-top.png differ diff --git a/images/dialog.png b/images/dialog.png new file mode 100644 index 0000000..eaface9 Binary files /dev/null and b/images/dialog.png differ diff --git a/images/keyboard-back.png b/images/keyboard-back.png new file mode 100644 index 0000000..4826942 Binary files /dev/null and b/images/keyboard-back.png differ diff --git a/images/keyboard-backspace.png b/images/keyboard-backspace.png new file mode 100644 index 0000000..c62a1cd Binary files /dev/null and b/images/keyboard-backspace.png differ diff --git a/images/keyboard-bullet-on.png b/images/keyboard-bullet-on.png new file mode 100644 index 0000000..ad8b699 Binary files /dev/null and b/images/keyboard-bullet-on.png differ diff --git a/images/keyboard-bullet-sel-on.png b/images/keyboard-bullet-sel-on.png new file mode 100644 index 0000000..c5f8b21 Binary files /dev/null and b/images/keyboard-bullet-sel-on.png differ diff --git a/images/keyboard-caps.png b/images/keyboard-caps.png new file mode 100644 index 0000000..9499800 Binary files /dev/null and b/images/keyboard-caps.png differ diff --git a/images/keyboard-check.png b/images/keyboard-check.png new file mode 100644 index 0000000..ac0826f Binary files /dev/null and b/images/keyboard-check.png differ diff --git a/images/keyboard-clear.png b/images/keyboard-clear.png new file mode 100644 index 0000000..f80bc21 Binary files /dev/null and b/images/keyboard-clear.png differ diff --git a/images/keyboard-cursor.png b/images/keyboard-cursor.png new file mode 100644 index 0000000..c880a1b Binary files /dev/null and b/images/keyboard-cursor.png differ diff --git a/images/keyboard-field.png b/images/keyboard-field.png new file mode 100644 index 0000000..4a0cd9b Binary files /dev/null and b/images/keyboard-field.png differ diff --git a/images/keyboard-key.png b/images/keyboard-key.png new file mode 100644 index 0000000..33510e2 Binary files /dev/null and b/images/keyboard-key.png differ diff --git a/images/keyboard-long.png b/images/keyboard-long.png new file mode 100644 index 0000000..d21cce9 Binary files /dev/null and b/images/keyboard-long.png differ diff --git a/images/keyboard-shift.png b/images/keyboard-shift.png new file mode 100644 index 0000000..35866f0 Binary files /dev/null and b/images/keyboard-shift.png differ diff --git a/images/keyboard-space.png b/images/keyboard-space.png new file mode 100644 index 0000000..3e43e87 Binary files /dev/null and b/images/keyboard-space.png differ diff --git a/images/paragraph-bar.png b/images/paragraph-bar.png new file mode 100644 index 0000000..347cc5e Binary files /dev/null and b/images/paragraph-bar.png differ diff --git a/images/paragraph-bullet.png b/images/paragraph-bullet.png new file mode 100644 index 0000000..0fff2d3 Binary files /dev/null and b/images/paragraph-bullet.png differ diff --git a/source/gameMain.brs b/source/gameMain.brs index 841c4ba..3ce9d29 100644 --- a/source/gameMain.brs +++ b/source/gameMain.brs @@ -31,24 +31,28 @@ Sub Main() m.files = CreateObject("roFileSystem") m.fonts = {reg:CreateObject("roFontRegistry")} m.fonts.reg.Register("pkg:/assets/fonts/PoP.ttf") + m.fonts.reg.Register("pkg:/assets/fonts/Gotham-Medium.otf") + m.fonts.KeysFont = m.fonts.reg.getFont("Gotham Medium", 30, false, false) m.bitmapFont = LoadBitmapFont() m.prandom = CreatePseudoRandom() m.manifest = GetManifestArray() m.status = [] 'Check Roku model for performance alert if not IsOpenGL() - m.mainScreen = CreateObject("roScreen") - m.mainScreen.SetMessagePort(m.port) - MessageDialog("Prince of Persia", "Warning: Your Roku device doesn't support accelerated graphics, this game will not perform well.") + m.mainScreen = CreateObject("roScreen", true, 1280, 720) + canvas = CreateCanvas() + MessageDialog(m.port, "Prince of Persia", "Warning: Your Roku device doesn't support accelerated" + chr(10) + "graphics, this game will not perform well.") else if IsRokuStick() - m.mainScreen = CreateObject("roScreen") - m.mainScreen.SetMessagePort(m.port) - MessageDialog("Prince of Persia", "Warning: Your Roku Stick device has limited memory, this game only works properly on the 4 rooms mode.") + m.mainScreen = CreateObject("roScreen", true, 1280, 720) + canvas = CreateCanvas() + MessageDialog(m.port, "Prince of Persia", "Warning: Your Roku Stick device has limited memory," + chr(10) + "this game only works properly on the 4 rooms mode.") end if 'Initialize Screen if isHD() + print "HD Mode" m.mainScreen = CreateObject("roScreen", true, 854, 480) else + print "SD Mode" m.mainScreen = CreateObject("roScreen", true, 640, 480) end if m.mainScreen.SetMessagePort(m.port) diff --git a/source/gameMenu.brs b/source/gameMenu.brs index f099ff9..c58cfd5 100644 --- a/source/gameMenu.brs +++ b/source/gameMenu.brs @@ -12,28 +12,27 @@ ' ******************************************************************************************************** ' ******************************************************************************************************** -Function StartMenu() as integer - screen = m.mainScreen - screen.Clear(0) - scale = Int(GetScale(screen, 640, 432)) - centerX = Cint((screen.GetWidth()-(640*scale))/2) - centerY = Cint((screen.GetHeight()-(432*scale))/2) +function StartMenu() as integer + m.mainScreen.Clear(0) + scale = Int(GetScale(m.mainScreen, 640, 432)) + centerX = Cint((m.mainScreen.GetWidth() - (640 * scale)) / 2) + centerY = Cint((m.mainScreen.GetHeight() - (432 * scale)) / 2) backImage = ScaleBitmap(CreateObject("roBitmap", "pkg:/images/start_menu.jpg"), scale) - CrossFade(screen, centerX, centerY, GetPaintedBitmap(m.colors.black, 640 * scale, 432 * scale, true), backImage, 4) + CrossFade(m.mainScreen, centerX, centerY, GetPaintedBitmap(m.colors.black, 640 * scale, 432 * scale, true), backImage, 4) menuFont = m.fonts.reg.getFont("Prince of Persia Game Font", 26, false, false) button = -1 selected = 0 while true if button <> selected - screen.Clear(0) - screen.DrawObject(centerX, centerY, backImage) - faceColors = [ m.colors.white, m.colors.white, m.colors.white, m.colors.white ] + m.mainScreen.Clear(0) + m.mainScreen.DrawObject(centerX, centerY, backImage) + faceColors = [m.colors.white, m.colors.white, m.colors.white, m.colors.white] faceColors[selected] = &hFF0000FF - screen.DrawText("Play Classic Mode", centerX + 225, centerY + 162, faceColors[0], menuFont) - screen.DrawText("Play 4 Rooms Mode", centerX + 215, centerY + 215, faceColors[1], menuFont) - screen.DrawText("Play 9 Rooms Mode", centerX + 215, centerY + 267, faceColors[2], menuFont) - screen.DrawText("Game Settings", centerX + 240, centerY + 319, faceColors[3], menuFont) - screen.SwapBuffers() + m.mainScreen.DrawText("Play Classic Mode", centerX + 225, centerY + 162, faceColors[0], menuFont) + m.mainScreen.DrawText("Play 4 Rooms Mode", centerX + 215, centerY + 215, faceColors[1], menuFont) + m.mainScreen.DrawText("Play 9 Rooms Mode", centerX + 215, centerY + 267, faceColors[2], menuFont) + m.mainScreen.DrawText("Game Settings", centerX + 240, centerY + 319, faceColors[3], menuFont) + m.mainScreen.SwapBuffers() button = selected end if key = wait(0, m.port) @@ -60,36 +59,36 @@ Function StartMenu() as integer if button < 3 return button + 1 else - SettingsMenu(screen) + SettingsMenu() button = -1 end if end if end if end while -End Function +end function -Sub SettingsMenu(screen as object) - scale = Int(GetScale(screen, 640, 432)) - centerX = Cint((screen.GetWidth()-(640*scale))/2) - centerY = Cint((screen.GetHeight()-(432*scale))/2) +sub SettingsMenu() + scale = Int(GetScale(m.mainScreen, 640, 432)) + centerX = Cint((m.mainScreen.GetWidth() - (640 * scale)) / 2) + centerY = Cint((m.mainScreen.GetHeight() - (432 * scale)) / 2) menuFont = m.fonts.reg.getFont("Prince of Persia Game Font", 30, false, false) colorWhite = &hFFFFFFFF colorRed = &hFF0000FF button = -1 selected = m.settings.controlMode - backImage = ScaleBitmap(CreateObject("roBitmap", "pkg:/images/settings_menu.jpg"),scale) + backImage = ScaleBitmap(CreateObject("roBitmap", "pkg:/images/settings_menu.jpg"), scale) while true if button <> selected - screen.Clear(0) - screen.DrawObject(centerX, centerY, backImage) - faceColors = [ m.colors.white, m.colors.white, m.colors.white, m.colors.white, m.colors.white ] + m.mainScreen.Clear(0) + m.mainScreen.DrawObject(centerX, centerY, backImage) + faceColors = [m.colors.white, m.colors.white, m.colors.white, m.colors.white, m.colors.white] faceColors[selected] = &hFF0000FF - screen.DrawText("Control Mode", centerX + 93, centerY + 108, faceColors[0], menuFont) - screen.DrawText("Graphics Mode", centerX + 93, centerY + 161, faceColors[1], menuFont) - screen.DrawText("Mods & Cheats", centerX + 93, centerY + 213, faceColors[2], menuFont) - screen.DrawText("High Scores", centerX + 93, centerY + 265, faceColors[3], menuFont) - screen.DrawText("Game Credits", centerX + 93, centerY + 318, faceColors[4], menuFont) - screen.SwapBuffers() + m.mainScreen.DrawText("Control Mode", centerX + 93, centerY + 108, faceColors[0], menuFont) + m.mainScreen.DrawText("Graphics Mode", centerX + 93, centerY + 161, faceColors[1], menuFont) + m.mainScreen.DrawText("Mods & Cheats", centerX + 93, centerY + 213, faceColors[2], menuFont) + m.mainScreen.DrawText("High Scores", centerX + 93, centerY + 265, faceColors[3], menuFont) + m.mainScreen.DrawText("Game Credits", centerX + 93, centerY + 318, faceColors[4], menuFont) + m.mainScreen.SwapBuffers() button = selected end if key = wait(0, m.port) @@ -117,13 +116,13 @@ Sub SettingsMenu(screen as object) else if key = m.code.BUTTON_SELECT_PRESSED m.sounds.select.Trigger(50) if selected = 0 - option = OptionsMenu(screen, [{text: "Vertical Control", image:"control_vertical"},{text:"Horizontal Control", image:"control_horizontal"}], m.settings.controlMode) + option = OptionsMenu([{ text: "Vertical Control", image: "control_vertical" }, { text: "Horizontal Control", image: "control_horizontal" }], m.settings.controlMode) if option >= 0 and option <> m.settings.controlMode m.settings.controlMode = option SaveSettings(m.settings) end if else if selected = 1 - option = OptionsMenu(screen, [{text: "IBM-PC MS-DOS", image:"graphics_dos"},{text:"Macintosh Classic", image:"graphics_mac"}], m.settings.spriteMode) + option = OptionsMenu([{ text: "IBM-PC MS-DOS", image: "graphics_dos" }, { text: "Macintosh Classic", image: "graphics_mac" }], m.settings.spriteMode) if option >= 0 and option <> m.settings.spriteMode m.settings.spriteMode = option m.settings.modId = invalid @@ -131,41 +130,47 @@ Sub SettingsMenu(screen as object) end if else if selected = 2 ModsAndCheatsScreen() - m.mainScreen.SwapBuffers() + if isHD() + m.mainScreen = CreateObject("roScreen", true, 854, 480) + else + m.mainScreen = CreateObject("roScreen", true, 640, 480) + end if + m.mainScreen.SetMessagePort(m.port) + m.mainScreen.SetAlphaEnable(true) else if selected = 3 - HighscoresScreen(screen) + HighscoresScreen() else if selected = 4 - CreditsScreen(screen) + CreditsScreen() end if button = -1 end if end if end while -End Sub +end sub -Function OptionsMenu(screen as object, options as object, default as integer) as integer - scale = Int(GetScale(screen, 640, 432)) - centerX = Cint((screen.GetWidth()-(640*scale))/2) - centerY = Cint((screen.GetHeight()-(432*scale))/2) +function OptionsMenu(options as object, default as integer) as integer + scale = Int(GetScale(m.mainScreen, 640, 432)) + centerX = Cint((m.mainScreen.GetWidth() - (640 * scale)) / 2) + centerY = Cint((m.mainScreen.GetHeight() - (432 * scale)) / 2) menuFont = m.fonts.reg.getFont("Prince of Persia Game Font", 26, false, false) colorWhite = &hFFFFFFFF colorRed = &hFF0000FF button = -1 if default <= 1 then selected = default else selected = 0 - backImage = ScaleBitmap(CreateObject("roBitmap", "pkg:/images/options_menu.jpg"),scale) + backImage = ScaleBitmap(CreateObject("roBitmap", "pkg:/images/options_menu.jpg"), scale) while true if button <> selected - screen.Clear(0) - screen.DrawObject(centerX, centerY, backImage) + m.mainScreen.Clear(0) + m.mainScreen.DrawObject(centerX, centerY, backImage) if selected = 0 - screen.DrawText(options[0].text, centerX + 88, centerY + 57, colorRed, menuFont) - screen.DrawText(options[1].text, centerX + 80, centerY + 109, colorWhite, menuFont) + m.mainScreen.DrawText(options[0].text, centerX + 88, centerY + 57, colorRed, menuFont) + m.mainScreen.DrawText(options[1].text, centerX + 80, centerY + 109, colorWhite, menuFont) else - screen.DrawText(options[0].text, centerX + 88, centerY + 57, colorWhite, menuFont) - screen.DrawText(options[1].text, centerX + 80, centerY + 109, colorRed, menuFont) + m.mainScreen.DrawText(options[0].text, centerX + 88, centerY + 57, colorWhite, menuFont) + m.mainScreen.DrawText(options[1].text, centerX + 80, centerY + 109, colorRed, menuFont) end if - screen.DrawObject(centerX, centerY, ScaleBitmap(CreateObject("roBitmap", "pkg:/images/" + options[selected].image + ".png"),scale)) - screen.SwapBuffers() + m.mainScreen.DrawObject(centerX, centerY, ScaleBitmap(CreateObject("roBitmap", "pkg:/images/" + options[selected].image + ".png"), scale)) + m.mainScreen.SwapBuffers() button = selected end if key = wait(0, m.port) @@ -191,59 +196,59 @@ Function OptionsMenu(screen as object, options as object, default as integer) as end if end while return selected -End Function +end function -Sub HighScoresScreen(screen as object) - scale = Int(GetScale(screen, 640, 432)) - centerX = Cint((screen.GetWidth()-(640*scale))/2) - centerY = Cint((screen.GetHeight()-(432*scale))/2) +sub HighScoresScreen() + scale = Int(GetScale(m.mainScreen, 640, 432)) + centerX = Cint((m.mainScreen.GetWidth() - (640 * scale)) / 2) + centerY = Cint((m.mainScreen.GetHeight() - (432 * scale)) / 2) backImage = ScaleBitmap(CreateObject("roBitmap", "pkg:/images/highscores_back.jpg"), scale) - while true - screen.Clear(0) - screen.DrawObject(centerX, centerY, backImage) - xn = centerX + 72 * 2 - xt = centerX + 217 * 2 - ys = centerY + 85 * 2 - c = 0 - for each score in m.highScores - m.bitmapFont.write(screen, score.name, xn, ys, 2.0) - m.bitmapFont.write(screen, FormatTime(score.time), xt, ys, 2.0) - ys += (12 * 2) - c++ - if c = 7 then exit for - next + while true + m.mainScreen.Clear(0) + m.mainScreen.DrawObject(centerX, centerY, backImage) + xn = centerX + 72 * 2 + xt = centerX + 217 * 2 + ys = centerY + 85 * 2 + c = 0 + for each score in m.highScores + m.bitmapFont.write(m.mainScreen, score.name, xn, ys, 2.0) + m.bitmapFont.write(m.mainScreen, FormatTime(score.time), xt, ys, 2.0) + ys += (12 * 2) + c++ + if c = 7 then exit for + next if m.highScores.Count() > 0 - m.bitmapFont.write(screen, "[ Press * to reset the High Scores ]", xn - 52, 370, 2.0) + m.bitmapFont.write(m.mainScreen, "[ Press * to reset the High Scores ]", xn - 52, 370, 2.0) else - m.bitmapFont.write(screen, "< No High Scores are recorded yet >", xn - 52, ys + 8, 2.0) + m.bitmapFont.write(m.mainScreen, "< No High Scores are recorded yet >", xn - 52, ys + 8, 2.0) end if - screen.SwapBuffers() - key = wait(0, m.port) - if key <> invalid + m.mainScreen.SwapBuffers() + key = wait(0, m.port) + if key <> invalid if type(key) = "roUniversalControlEvent" key = key.getInt() end if - if key = m.code.BUTTON_INFO_PRESSED and m.highScores.Count() > 0 - m.sounds.select.Trigger(50) - saveOpt = MessageBox(screen, 230, 100, "Reset Scores?", 2) + if key = m.code.BUTTON_INFO_PRESSED and m.highScores.Count() > 0 + m.sounds.select.Trigger(50) + saveOpt = MessageBox(m.mainScreen, 230, 100, "Reset Scores?", 2) if saveOpt = m.const.BUTTON_YES m.highScores = [] SaveHighScores(m.highScores) end if - else if key < 100 - m.sounds.navSingle.Trigger(50) - exit while - end if - end if - end while -End Sub + else if key < 100 + m.sounds.navSingle.Trigger(50) + exit while + end if + end if + end while +end sub -Sub CreditsScreen(screen as object) - scale = Int(GetScale(screen, 640, 432)) - centerX = Cint((screen.GetWidth()-(640*scale))/2) - centerY = Cint((screen.GetHeight()-(432*scale))/2) - screen.Clear(0) - screen.DrawObject(centerX, centerY, ScaleBitmap(CreateObject("roBitmap", "pkg:/images/game_credits.jpg"), scale)) +sub CreditsScreen() + scale = Int(GetScale(m.mainScreen, 640, 432)) + centerX = Cint((m.mainScreen.GetWidth() - (640 * scale)) / 2) + centerY = Cint((m.mainScreen.GetHeight() - (432 * scale)) / 2) + m.mainScreen.Clear(0) + m.mainScreen.DrawObject(centerX, centerY, ScaleBitmap(CreateObject("roBitmap", "pkg:/images/game_credits.jpg"), scale)) m.mainScreen.SwapBuffers() while true key = wait(0, m.port) @@ -252,11 +257,11 @@ Sub CreditsScreen(screen as object) end if if key <> invalid and key < 100 then exit while end while -End Sub +end sub -Function MessageBox(screen as object, width as integer, height as integer, text as string, options = 3 as integer) as integer - leftX = Cint((screen.GetWidth()-width)/2) - topY = Cint((screen.GetHeight()-height)/2) +function MessageBox(screen as object, width as integer, height as integer, text as string, options = 3 as integer) as integer + leftX = Cint((screen.GetWidth() - width) / 2) + topY = Cint((screen.GetHeight() - height) / 2) xt = leftX + int(width / 2) - ((Len(text) + 1) * 14) / 2 xb = leftX + int(width / 2) - (13 * 14) / 2 yt = topY + height / 2 - 25 @@ -268,8 +273,8 @@ Function MessageBox(screen as object, width as integer, height as integer, text screen.DrawRect(leftX, topY, width, height, m.colors.black) m.bitmapFont.write(screen, text, xt, yt, 2.0) DrawBorder(screen, width, height, m.colors.white, 0) - boff = [0,60,100] - line = [42,28,84] + boff = [0, 60, 100] + line = [42, 28, 84] m.bitmapFont.write(screen, "Yes", xb + boff[0], yt + 30, 2.0) m.bitmapFont.write(screen, "No", xb + boff[1], yt + 30, 2.0) if options = 3 @@ -307,11 +312,11 @@ Function MessageBox(screen as object, width as integer, height as integer, text end if end if end while -End Function +end function -Sub TextBox(screen as object, width as integer, height as integer, text as string, border = false as boolean) - leftX = Cint((screen.GetWidth()-width)/2) - topY = Cint((screen.GetHeight()-height)/2) +sub TextBox(screen as object, width as integer, height as integer, text as string, border = false as boolean) + leftX = Cint((screen.GetWidth() - width) / 2) + topY = Cint((screen.GetHeight() - height) / 2) xt = leftX + int(width / 2) - (Len(text) * 13) / 2 yt = topY + height / 2 - 15 m.mainScreen.SwapBuffers() @@ -319,4 +324,4 @@ Sub TextBox(screen as object, width as integer, height as integer, text as strin m.bitmapFont.write(screen, text, xt, yt, 2.0) if border then DrawBorder(screen, width, height, m.colors.white, 0) m.mainScreen.SwapBuffers() -End Sub +end sub diff --git a/source/gameMods.brs b/source/gameMods.brs index cdfb86a..f2e501a 100644 --- a/source/gameMods.brs +++ b/source/gameMods.brs @@ -119,12 +119,14 @@ Function GetModImage(modId as dynamic) as string End Function Sub ModsAndCheatsScreen() + m.mainScreen = CreateObject("roScreen", true, 1280, 720) + m.mainScreen.SetMessagePort(m.port) this = { screen: CreateListScreen() port: m.port } this.screen.SetMessagePort(this.port) - this.screen.SetHeader("Mods and Cheats") + this.screen.SetHeader("Mods an d Cheats") this.modArray = [{name: "(none)", author:"", levels: false, sprites: false, sounds: false}] this.modIndex = 0 for each modId in m.mods.Keys() @@ -300,7 +302,6 @@ Sub ModsAndCheatsScreen() end if end if end while - return End Sub Function GetMenuItems(menu as object) diff --git a/source/gameSound.brs b/source/gameSound.brs index 966a942..b14640a 100644 --- a/source/gameSound.brs +++ b/source/gameSound.brs @@ -18,6 +18,7 @@ Function LoadSounds(enable as boolean) as object wav: {clip:"", priority:0, cycles:0}, metadata : ParseJson(ReadAsciiFile("pkg:/assets/sounds/sounds.json")), navSingle : CreateObject("roAudioResource", "navsingle"), + roll : CreateObject("roAudioResource", "navmulti"), deadend : CreateObject("roAudioResource", "deadend"), select : CreateObject("roAudioResource", "select") } diff --git a/source/gameUtil.brs b/source/gameUtil.brs index 304955a..6c7eeb7 100644 --- a/source/gameUtil.brs +++ b/source/gameUtil.brs @@ -371,12 +371,12 @@ End Function Function IsHD() di = CreateObject("roDeviceInfo") - return (di.GetUIResolution().name <> "sd") + return (di.GetUIResolution().height >= 720) End Function Function IsfHD() di = CreateObject("roDeviceInfo") - return(di.GetUIResolution() = "fhd") + return(di.GetUIResolution().name.lcase() = "fhd") End Function Function ConvertX(x) @@ -488,16 +488,16 @@ Function FormatTime(seconds as integer) as string end if ' Hours if seconds >= 3600 - textTime = textTime + (seconds / 3600).toStr() + ":" + textTime = textTime + int(seconds / 3600).toStr() + ":" hasHours = true seconds = seconds Mod 3600 end if ' Minutes if seconds >= 60 if hasHours - textTime = textTime + ZeroPad((seconds / 60).toStr()) + ":" + textTime = textTime + ZeroPad(int(seconds / 60).toStr()) + ":" else - textTime = textTime + (seconds / 60).toStr() + ":" + textTime = textTime + int(seconds / 60).toStr() + ":" end if seconds = seconds Mod 60 else @@ -592,31 +592,44 @@ Function seq_prandom(seed as integer, n as integer, p as integer, max as integer return r1 End Function -'------- Roku Screens Functions ---- -Sub MessageDialog(title, text, port = invalid) As Integer - if port = invalid then port = CreateObject("roMessagePort") - d = CreateObject("roMessageDialog") - d.SetTitle(title) - d.SetText(text) - d.SetMessagePort(port) - d.AddButton(1, "Okay") - d.Show() +Function MessageDialog(port, title, text, buttons = ["OK"], default = 0, overlay = false) As Integer + if port = invalid + if m.port = invalid + port = CreateObject("roMessagePort") + else + port = m.port + end if + end if + s = CreateMessageDialog() + s.SetTitle(title) + s.SetText(text) + s.SetMessagePort(port) + s.EnableOverlay(overlay) + for b = 0 to buttons.Count()-1 + s.AddButton(b, buttons[b]) + next + s.SetFocusedMenuItem(default) + s.Show() + result = 99 'nothing pressed while true - msg = wait(0, port) - if msg.isScreenClosed() - exit while - else if msg.isButtonPressed() + msg = s.wait(port) + if msg.isButtonPressed() result = msg.GetIndex() exit while + else if msg.isScreenClosed() + exit while end if end while -End Sub + return result +End Function Function KeyboardScreen(title = "", prompt = "", text = "", button1 = "Okay", button2= "Cancel", secure = false, port = invalid) as string + m.mainScreen = CreateObject("roScreen", true, 1280, 720) + m.mainScreen.SetMessagePort(m.port) + m.mainScreen.SetAlphaEnable(true) if port = invalid then port = CreateObject("roMessagePort") result = "" - port = CreateObject("roMessagePort") - screen = CreateObject("roKeyboardScreen") + screen = CreateKeyBoardScreen() screen.SetMessagePort(port) screen.SetTitle(title) screen.SetDisplayText(prompt) @@ -626,22 +639,27 @@ Function KeyboardScreen(title = "", prompt = "", text = "", button1 = "Okay", bu screen.SetSecureText(secure) screen.Show() while true - msg = wait(0, port) - if type(msg) = "roKeyboardScreenEvent" - if msg.isScreenClosed() + msg = screen.wait(port) + if msg.isScreenClosed() + exit while + else if msg.isButtonPressed() + if msg.GetIndex() = 1 and screen.GetText().Trim() <> "" 'Ok + result = screen.GetText() + exit while + else if msg.GetIndex() = 2 'Cancel + result = "" exit while - else if msg.isButtonPressed() - if msg.GetIndex() = 1 and screen.GetText().Trim() <> "" 'Ok - result = screen.GetText() - exit while - else if msg.GetIndex() = 2 'Cancel - result = "" - exit while - end if end if end if end while screen.Close() + if isHD() + m.mainScreen = CreateObject("roScreen", true, 854, 480) + else + m.mainScreen = CreateObject("roScreen", true, 640, 480) + end if + m.mainScreen.SetMessagePort(m.port) + m.mainScreen.SetAlphaEnable(true) return result End function diff --git a/source/libCanvas.brs b/source/libCanvas.brs index 35a13a9..0cb66b9 100644 --- a/source/libCanvas.brs +++ b/source/libCanvas.brs @@ -37,6 +37,9 @@ Function CreateCanvas() as object m.fonts.AddReplace("big", m.fonts.reg.GetDefaultFont(40 * this.scale, false, false)) m.fonts.AddReplace("huge", m.fonts.reg.GetDefaultFont(46 * this.scale, false, false)) end if + ' Initialize Cache + InitCache() + this.stackId = m.stack.Count() m.stack.Push(this) return this diff --git a/source/libKeyboardScreen.brs b/source/libKeyboardScreen.brs new file mode 100644 index 0000000..5282964 --- /dev/null +++ b/source/libKeyboardScreen.brs @@ -0,0 +1,444 @@ +' ******************************************************************************************************** +' ******************************************************************************************************** +' ** Roku Prince of Persia Channel - http://github.com/lvcabral/Prince-of-Persia-Roku +' ** +' ** libKeyboardScreen.brs - Library to implement a Keyboard Screen +' ** Created: October 2019 +' ** Updated: October 2019 +' ** +' ** Copyright (C) Marcelo Lv Cabral < https://lvcabral.com > +' ******************************************************************************************************** +' ******************************************************************************************************** + +Function CreateKeyBoardScreen() as object + ' Objects + this = {buttons:[], canvas: CreateCanvas(), focused: {r:0,c:1}} + this.screen = this.canvas.screen + this.codes = m.code + this.sounds = m.sounds + this.theme = m.theme + this.fonts = m.fonts + this.textFont = m.fonts.reg.GetDefaultFont(25, false, false) + this.modes = [] + this.currentMode = 0 + this.capsLock = false + this.shift = false + ' Properties + this.title = "" + this.text = "" + this.displayText = "" + this.blinkCursor = false + this.maxLength = 20 + this.secure = false + this.focus = -1 + this.visible = false + ' Methods + this.SetMessagePort = set_msg_port + this.SetTitle = set_title + this.SetText = set_text + this.SetDisplayText = set_display_text + this.SetMaxLength = set_max_length + this.SetSecureText = set_secure_text + this.GetText = get_text + this.AddButton = add_button + ' this.ClearButtons ' Not Implemented + this.Show = show_keyboard_screen + this.Wait = wait_keyboard_screen + this.Close = close_screen + this.SetModes = set_keyboard_modes + + ' Initialize Canvas + this.SetModes() + this.canvas.SetLayer(0, GetOverhang()) + + return this +End Function + +Sub show_keyboard_screen() + txtArray = [] + imgArray = [] + keybPos = {x: 255, y: 280} + cursorPos = { x: keybPos.x + 770, y: keybPos.y - 96 } + txtArray.Push({ Text: m.title + TextAttrs: {color: m.theme.BreadcrumbTextLeft, font: "Large", HAlign: "Right"} + TargetRect: {x: 578, y: 72, w:650, h:36}}) + imgArray.Push({ url: "pkg:/images/keyboard-field.png" + CompositionMode: "Source" + TargetRect: {x:keybPos.x, y:keybPos.y-110}}) + imgArray.Push({ url: "pkg:/images/keyboard-back.png" + CompositionMode: "Source" + TargetRect: {x:keybPos.x, y:keybPos.y}}) + if m.secure then text = String(Len(m.text), "*") else text = m.text + txtArray.Push({ + Text: text + TextAttrs: {color: "#A7A7A7FF", font: "Medium", HAlign: "Right", elipsis: true} + TargetRect: {x:keybPos.x+20, y:keybPos.y-90, w:747, h:36}}) + if m.blinkCursor + m.canvas.SetLayer(3, { url: "pkg:/images/keyboard-cursor.png", TargetRect: cursorPos }) + else + m.canvas.ClearLayer(3) + end if + m.blinkCursor = not m.blinkCursor + txtArray.Push({ + Text: m.displayText + TextAttrs: {color: "#666D70FF", font: "Medium", HAlign: "Right"} + TargetRect: {x:keybPos.x+15, y:keybPos.y-36, w:770, h:36}}) + ' Setup Keyboard + m.keys = [[],[],[],[]] + for c = 0 to 11 + for r = 0 to 3 + char = m.modes[m.currentMode].Mid(c+12*r,1) + if c > 0 and c < 11 + if c <= 7 + xc = c-1 + x = keybPos.x+199 + (46*xc) + y = keybPos.y+21 + (46*r) + else + xc = c-8 + x = keybPos.x+537 + (46*xc) + y = keybPos.y+21 + (46*r) + end if + if char <> m.K_SKIP + if c = m.focused.c and r = m.focused.r + color = "#0094FFFF" + imgArray.Push({ url: "pkg:/images/keyboard-key.png" + CompositionMode: "Source" + TargetRect: {x:x, y:y-7}}) + else + color = "#A7A7A7FF" + end if + txtArray.Push({ + Text: char + TextAttrs: {color: color, font: m.fonts.KeysFont, HAlign: "Center"} + TargetRect: {x:x, y:y, w:42, h:32}}) + else + txtArray.Push({ color: "#585858FF" + TargetRect: {x:x, y:y-6, w:42, h:42}}) + end if + else if c = 0 + x = keybPos.x+13 + y = keybPos.y+14 + (46*r) + if c = m.focused.c and r = m.focused.r + if r = 0 + img = "pkg:/images/keyboard-caps.png" + else + img = "pkg:/images/keyboard-long.png" + end if + color = "#0094FFFF" + imgArray.Push({ url: img + CompositionMode: "Source" + TargetRect: {x:x, y:y}}) + else + color = "#3C3C3CFF" + end if + if r > 0 + if r = 1 + caption = "abc123" + else if r = 2 + caption = "&%#?" + else if r = 3 + caption = "åÅñÑ" + end if + txtArray.Push({ + Text: caption + TextAttrs: {color: color, font: m.fonts.KeysFont, HAlign: "Center"} + TargetRect: {x:x + 40, y:y + 6, w:106, h:32}}) + end if + else if c > 10 + if c = m.focused.c and r = m.focused.r + x = keybPos.x+692 + y = keybPos.y+15 + (46*r) + color = "#0094FFFF" + if r = 0 + img = "pkg:/images/keyboard-shift.png" + else if r = 1 + img = "pkg:/images/keyboard-space.png" + else if r = 2 + img = "pkg:/images/keyboard-clear.png" + else if r = 3 + img = "pkg:/images/keyboard-backspace.png" + end if + imgArray.Push({ url: img + CompositionMode: "Source" + TargetRect: {x:x, y:y}}) + end if + end if + m.keys[r].Push(char) + next + next + ' Setup Left Keys + if m.capsLock + imgArray.Push({ url: "pkg:/images/keyboard-check.png" + TargetRect: {x:keybPos.x+24, y:keybPos.y+25}}) + end if + img = "pkg:/images/keyboard-bullet-on.png" + if m.currentMode < 2 + modePos = {x:keybPos.x+17, y:keybPos.y+66} + if m.focused.c = 0 and m.focused.r = 1 + img = "pkg:/images/keyboard-bullet-sel-on.png" + end if + else if m.currentMode < 4 + modePos = {x:keybPos.x+17, y:keybPos.y+112} + if m.focused.c = 0 and m.focused.r = 2 + img = "pkg:/images/keyboard-bullet-sel-on.png" + end if + else + modePos = {x:keybPos.x+17, y:keybPos.y+158} + if m.focused.c = 0 and m.focused.r = 3 + img = "pkg:/images/keyboard-bullet-sel-on.png" + end if + end if + + imgArray.Push({ url: img + TargetRect: modePos}) + + ' Setup Buttons + if m.buttons.Count() > 0 + menuPos = {x: 224, y: m.screen.GetHeight() - 70 - (36 * m.buttons.Count())} + for i = 0 to m.buttons.Count() - 1 + if i = m.focus + imgArray.Push({ url: "pkg:/images/paragraph-bar.png" + TargetRect: {x:menuPos.x , y:menuPos.y}}) + txtColor = m.theme.ListItemHighlightText + if txtColor = invalid + txtColor = "#FFFFFFFF" + end if + else + imgArray.Push({ url: "pkg:/images/paragraph-bullet.png" + TargetRect: {x:1016 , y:menuPos.y}}) + txtColor = "#666D70FF" + end if + txtArray.Push({ + Text: m.buttons[i].text + TextAttrs: {color: txtColor, font: m.textFont, HAlign: "Right"} + TargetRect: {x:menuPos.x + 28, y:menuPos.y + 2, w:750, h:30}}) + menuPos.y = menuPos.y + 36 + next + end if + m.canvas.SetLayer(1, imgArray) + m.canvas.SetLayer(2, txtArray) + m.canvas.Show() + m.visible = true +End Sub + +Function wait_keyboard_screen(port) as object + if port = invalid then port = m.canvas.screen.port + while true + event = wait(500, port) + if type(event) = "roUniversalControlEvent" and event.IsPress() + index = event.GetInt() + char = event.GetChar() + if index = m.codes.BUTTON_LEFT_PRESSED and m.focused.r < 4 + cols = m.keys[m.focused.r].Count()-1 + m.focused.c-- + if m.focused.c < 0 then m.focused.c = cols + key = m.keys[m.focused.r][m.focused.c] + while key = m.K_SKIP + m.focused.c-- + if m.focused.c < 0 then m.focused.c = cols + key = m.keys[m.focused.r][m.focused.c] + end while + m.sounds.navSingle.Trigger(50) + else if index = m.codes.BUTTON_RIGHT_PRESSED and m.focused.r < 4 + cols = m.keys[m.focused.r].Count()-1 + m.focused.c++ + if m.focused.c > cols then m.focused.c = 0 + key = m.keys[m.focused.r][m.focused.c] + while key = m.K_SKIP + m.focused.c++ + if m.focused.c > cols then m.focused.c = 0 + key = m.keys[m.focused.r][m.focused.c] + end while + m.sounds.navSingle.Trigger(50) + else if index = m.codes.BUTTON_UP_PRESSED + m.focused.r-- + if m.focused.r < 0 + m.focused.r = 3 + m.buttons.Count() + else if m.focused.r < 4 + key = m.keys[m.focused.r][m.focused.c] + while key = m.K_SKIP + m.focused.r-- + key = m.keys[m.focused.r][m.focused.c] + end while + end if + m.focus = m.focused.r - 4 + m.sounds.navSingle.Trigger(50) + else if index = m.codes.BUTTON_DOWN_PRESSED + m.focused.r++ + if m.focused.r > 3 + m.buttons.Count() + m.focused.r = 0 + else if m.focused.r < 4 + key = m.keys[m.focused.r][m.focused.c] + if key = m.K_SKIP then m.focused.r = 4 + end if + m.focus = m.focused.r - 4 + m.sounds.navSingle.Trigger(50) + else if index = m.codes.BUTTON_BACK_PRESSED + m.sounds.navSingle.Trigger(50) + m.Close() + msg = GetScreenMessage(m.focus, "closed") + exit while + else if index = m.codes.BUTTON_REWIND_PRESSED or index = 11 + if Len(m.text) > 0 + m.sounds.roll.Trigger(50) + m.text = Left(m.text, Len(m.text)-1) + else + m.sounds.deadend.Trigger(50) + end if + else if index = m.codes.BUTTON_SELECT_PRESSED + if m.focus >= 0 + m.sounds.select.Trigger(50) + msg = GetScreenMessage(m.buttons[m.focus].id, "button") + exit while + else + key = m.keys[m.focused.r][m.focused.c] + if key = m.K_CAPS ' Caps Lock + m.shift = false + m.capsLock = not m.capsLock + if m.currentMode = 0 and m.capsLock + m.currentMode = 1 + else if m.currentMode = 1 and not m.capsLock + m.currentMode = 0 + else if m.currentMode = 2 and m.capsLock + m.currentMode = 3 + else if m.currentMode = 3 and not m.capsLock + m.currentMode = 2 + else if m.currentMode = 4 and m.capsLock + m.currentMode = 5 + else if m.currentMode = 5 and not m.capsLock + m.currentMode = 4 + end if + m.sounds.select.Trigger(50) + else if key = m.K_SHFT ' Shift + if m.currentMode = 0 + m.currentMode = 1 + else if m.currentMode = 2 + m.currentMode = 3 + else if m.currentMode = 4 + m.currentMode = 5 + end if + m.shift = true + m.sounds.select.Trigger(50) + else if key = m.K_ABC1 ' Letters and Numbers + if m.capsLock or m.shift + m.currentMode = 1 + else + m.currentMode = 0 + end if + m.sounds.select.Trigger(50) + else if key = m.K_SYMB ' Symbols + if m.capsLock or m.shift + m.currentMode = 3 + else + m.currentMode = 2 + end if + m.sounds.select.Trigger(50) + else if key = m.K_ACNT ' Accents + if m.capsLock or m.shift + m.currentMode = 5 + else + m.currentMode = 4 + end if + m.sounds.select.Trigger(50) + else if key = m.K_WIPE ' Clear + if Len(m.text) > 0 + m.sounds.roll.Trigger(50) + m.text = "" + else + m.sounds.deadend.Trigger(50) + end if + else if key = m.K_BKSP ' Backspace + if Len(m.text) > 0 + m.sounds.roll.Trigger(50) + m.text = Left(m.text, Len(m.text)-1) + else + m.sounds.deadend.Trigger(50) + end if + else if key >= m.K_SPAC ' Printable character + if Len(m.text) < m.maxLength + m.sounds.select.Trigger(50) + m.text += key + else + m.sounds.deadend.Trigger(50) + end if + if m.shift and not m.capsLock + if m.currentMode = 1 + m.currentMode = 0 + else if m.currentMode = 3 + m.currentMode = 2 + else if m.currentMode = 5 + m.currentMode = 4 + end if + end if + m.shift = false + end if + end if + else if char >= 32 and char <= 126 ' Basic printable ASCII characters + m.sounds.select.Trigger(50) + m.text += Chr(char) + else if char >= 128 and char <= 255 ' Extended printable ASCII characters + m.sounds.select.Trigger(50) + m.text += Chr(char) + end if + end if + m.Show() + end while + return msg +End Function + +Sub set_keyboard_modes() + 'Constants + m.K_CAPS = Chr(14) + m.K_SHFT = Chr(15) + m.K_ABC1 = Chr(1) + m.K_SYMB = Chr(2) + m.K_ACNT = Chr(3) + m.K_SPAC = Chr(32) + m.K_WIPE = Chr(4) + m.K_SKIP = Chr(9) + m.K_BKSP = Chr(127) + m.K_DBQT = Chr(34) + ' Keyboard Modes + lowerCase = m.K_CAPS + "abcdefg123" + m.K_SHFT + lowerCase += m.K_ABC1 + "hijklmn456" + m.K_SPAC + lowerCase += m.K_SYMB + "opqrstu789" + m.K_WIPE + lowerCase += m.K_ACNT + "vwxyz-_@0." + m.K_BKSP + m.modes.Push(lowerCase) + upperCase = m.K_CAPS + "ABCDEFG123" + m.K_SHFT + upperCase += m.K_ABC1 + "HIJKLMN456" + m.K_SPAC + upperCase += m.K_SYMB + "OPQRSTU789" + m.K_WIPE + upperCase += m.K_ACNT + "VWXYZ-_@0." + m.K_BKSP + m.modes.Push(upperCase) + lowerSymb = m.K_CAPS + "!?*#$%^´ˆ˜" + m.K_SHFT + lowerSymb += m.K_ABC1 + "&,:;`'" + m.K_DBQT + "¨¯¸ " + lowerSymb += m.K_SYMB + "(){}[]~=+×" + m.K_WIPE + lowerSymb += m.K_ACNT + "¡¿<>|\/÷±‰" + m.K_BKSP + m.modes.Push(lowerSymb) + upperSymb = m.K_CAPS + "•·¢£¤¥€¼½¾" + m.K_SHFT + upperSymb += m.K_ABC1 + "®©™«»‹›“”„" + m.K_SPAC + upperSymb += m.K_SYMB + "¦†‡§ƒµ¶‘’‚" + m.K_WIPE + upperSymb += m.K_ACNT + "¹²³º°ª…–—" + m.K_SKIP + m.K_BKSP + m.modes.Push(upperSymb) + lowerAcnt = m.K_CAPS + "àáâãäåæýÿš" + m.K_SHFT + lowerAcnt += m.K_ABC1 + "èéêëìíîžðþ" + m.K_SPAC + lowerAcnt += m.K_SYMB + "ïòóôõöøß" + m.K_SKIP + m.K_SKIP + m.K_WIPE + lowerAcnt += m.K_ACNT + "œùúûüçñ" + m.K_SKIP + m.K_SKIP + m.K_SKIP + m.K_BKSP + m.modes.Push(lowerAcnt) + upperAcnt = m.K_CAPS + "ÀÁÂÃÄÅÆÝŸŠ" + m.K_SHFT + upperAcnt += m.K_ABC1 + "ÈÉÊËÌÍÎŽÐÞ" + m.K_SPAC + upperAcnt += m.K_SYMB + "ÏÒÓÔÕÖØ" + m.K_SKIP + m.K_SKIP + m.K_SKIP + m.K_WIPE + upperAcnt += m.K_ACNT + "ŒÙÚÛÜÇÑ" + m.K_SKIP + m.K_SKIP + m.K_SKIP + m.K_BKSP + m.modes.Push(upperAcnt) +End Sub + +Sub set_display_text(text as string) + m.displayText = text +End Sub + +Sub set_max_length(length as integer) + m.maxLength = length +End Sub + +Sub set_secure_text(secure as boolean) + m.secure = secure +End Sub \ No newline at end of file diff --git a/source/libListScreen.brs b/source/libListScreen.brs index 4193223..dd1e171 100644 --- a/source/libListScreen.brs +++ b/source/libListScreen.brs @@ -4,7 +4,7 @@ ' ** ' ** libListScreen.brs - Library to implement generic List Screen ' ** Created: June 2018 -' ** Updated: September 2019 +' ** Updated: October 2019 ' ** ' ** Copyright (C) Marcelo Lv Cabral < https://lvcabral.com > ' ******************************************************************************************************** @@ -33,14 +33,12 @@ Function CreateListScreen(ignoreBackKey = false as boolean) as object this.SetHeader = set_list_header this.SetContent = set_list_content this.SetItem = set_content_item - this.SetFocusedListItem = set_focused_item + this.SetFocusedListItem = set_focused_list_item + ' this.SetTitle ' Not Implemented this.Show = show_list_screen this.Wait = wait_list_screen this.Close = close_screen - ' Initialize Cache - InitCache() - ' Initialize Canvas this.canvas.SetLayer(0, GetOverhang()) @@ -48,6 +46,7 @@ Function CreateListScreen(ignoreBackKey = false as boolean) as object End Function Sub show_list_screen() + print "Show List:"; m.headerText txtArray = [] imgArray = [] txtArray.Append(m.breadCrumb) @@ -55,7 +54,10 @@ Sub show_list_screen() Text: m.headerText TextAttrs: {color: m.theme.ListScreenHeaderText, font: "Large", HAlign: "Left"} TargetRect: {x:170, y:156, w:524, h:32}}) - if m.content.Count() > 0 + if m.content.Count() > 0 + if m.focus >= m.content.Count() + m.focus = 0 + end if imgArray.Push({ url: m.content[m.focus].HDPosterUrl 'CachedFile(m.content[m.focus].HDPosterUrl + "250x250") TargetRect: {x: 782, y: 200}}) @@ -73,6 +75,14 @@ Sub show_list_screen() url: "pkg:/images/arrow-up.png" TargetRect: {x: 380, y: menuPos.y-40}}) end if + if m.first < 0 or m.last >= m.content.Count() + m.first = 0 + if m.content.Count() > 9 + m.last = 7 + else + m.last = m.content.Count() - 1 + end if + end if for i = m.first to m.last if i = m.focus if m.theme.ListItemHighlightHD <> invalid and m.theme.ListItemHighlightHD <> "" @@ -86,13 +96,20 @@ Sub show_list_screen() else textColor = m.theme.ListItemText end if - txtArray.Push({ - Text: m.content[i].Title - TextAttrs: {color: textColor, font: "Medium", HAlign: "Left"} - TargetRect: {x:menuPos.x, y:menuPos.y, w:420, h:30}}) - imgArray.Push({ - url: m.content[i].HDSmallIconUrl - TargetRect: {x: 654, y: menuPos.y}}) + if m.content[i].HDSmallIconUrl <> invalid + txtArray.Push({ + Text: m.content[i].Title + TextAttrs: {color: textColor, font: "Medium", HAlign: "Left", elipsis: true} + TargetRect: {x:menuPos.x, y:menuPos.y, w:420, h:30}}) + imgArray.Push({ + url: m.content[i].HDSmallIconUrl + TargetRect: {x: 654, y: menuPos.y}}) + else + txtArray.Push({ + Text: m.content[i].Title + TextAttrs: {color: textColor, font: "Medium", HAlign: "Left", elipsis: true} + TargetRect: {x:menuPos.x, y:menuPos.y, w:470, h:30}}) + end if menuPos.y = menuPos.y + 54 next if m.last < m.content.Count() - 1 @@ -107,7 +124,7 @@ Sub show_list_screen() m.visible = true End Sub -Sub set_list_content(list as object) +Sub set_list_content(list as object, refresh = true as boolean) m.content = list for i = 0 to m.content.Count() - 1 m.content[i].HDPosterUrl = CenterImage(m.content[i].HDPosterUrl, 300, 300) @@ -119,7 +136,7 @@ Sub set_list_content(list as object) else m.last = m.content.Count() - 1 end if - if m.visible then m.Show() + if m.visible and refresh then m.Show() End Sub Sub set_content_item(index as integer, item as object, refresh = true as boolean) @@ -128,6 +145,21 @@ Sub set_content_item(index as integer, item as object, refresh = true as boolean if m.visible and refresh then m.Show() End Sub +Sub set_focused_list_item(index as integer) + m.focus = index + if m.content.Count() < 8 + m.first = 0 + m.last = m.content.Count() - 1 + else if index + 8 < m.content.Count() + m.first = index + m.last = index + 7 + else if index - m.content.Count() < 8 + m.first = m.content.Count() - 8 + m.last = m.content.Count() - 1 + end if + if m.visible then m.Show() +End Sub + Function wait_list_screen(port) as object if port = invalid then port = m.canvas.screen.port while true diff --git a/source/libMessageDialog.brs b/source/libMessageDialog.brs new file mode 100644 index 0000000..7770d58 --- /dev/null +++ b/source/libMessageDialog.brs @@ -0,0 +1,142 @@ +' ******************************************************************************************************** +' ******************************************************************************************************** +' ** Roku Prince of Persia Channel - http://github.com/lvcabral/Prince-of-Persia-Roku +' ** +' ** libListScreen.brs - Library to implement generic List Screen +' ** Created: September 2019 +' ** Updated: October 2019 +' ** +' ** Copyright (C) Marcelo Lv Cabral < https://lvcabral.com > +' ******************************************************************************************************** +' ******************************************************************************************************** + +Function CreateMessageDialog() as object + ' Objects + this = {buttons:[], canvas: GetTopCanvas()} + this.screen = this.canvas.screen + this.codes = m.code + this.sounds = m.sounds + this.theme = m.theme + this.titleFont = this.canvas.fonts.reg.GetDefaultFont(32, true, false) + this.textFont = this.canvas.fonts.reg.GetDefaultFont(25, false, false) + + this.title = "" + this.text = "" + this.focus = 0 + this.overlay = false + this.visible = false + this.backCache = false + this.lineHeight = this.textFont.GetOneLineHeight() + + ' Methods + this.SetMessagePort = set_msg_port + this.SetTitle = set_title + this.SetText = set_text + this.AddButton = add_button + this.EnableOverlay = enable_overlay + this.SetFocusedMenuItem = set_focused_item + this.Show = show_msg_dialog + this.Wait = wait_msg_dialog + + return this +End Function + +Sub show_msg_dialog() + print "Show Dialog" + txtArray = [] + imgArray = [] + imgArray.Push({ url: "pkg:/images/dialog-top.png" + TargetRect: {x:254, y:171}}) + imgArray.Push({ url: "tmp:/dialog-back.png" + TargetRect: {x:254, y:203}}) + txtArray.Push({ + Text: m.title + TextAttrs: {color: "#4F5962FF", font: m.titleFont, HAlign: "Center"} + TargetRect: {x:275, y:208, w:730, h:32}}) + lines = m.text.Split(Chr(10)) + textHeight = m.lineHeight * lines.Count() + for l = 0 to lines.Count() - 1 + txtArray.Push({ + Text: lines[l] + TextAttrs: {color: "#666D70FF", font: m.textFont, HAlign: "Left"} + TargetRect: {x:294, y:260 + (l * m.lineHeight), w:680, h:m.lineHeight}}) + next + menuPos = {x: 290, y: 280 + (l * m.lineHeight)} + if m.buttons.Count() > 0 + for i = 0 to m.buttons.Count() - 1 + if i = m.focus + imgArray.Push({ url: "pkg:/images/dialog-bar.png" + TargetRect: {x:menuPos.x , y:menuPos.y}}) + textColor = m.theme.ListItemHighlightText + else + imgArray.Push({ url: "pkg:/images/dialog-bullet.png" + TargetRect: {x:948 , y:menuPos.y}}) + textColor = "#666D70FF" + end if + txtArray.Push({ + Text: m.buttons[i].text + TextAttrs: {color: textColor, font: m.textFont, HAlign: "Right"} + TargetRect: {x:menuPos.x + 28, y:menuPos.y + 2, w:622, h:30}}) + menuPos.y = menuPos.y + 36 + next + end if + if not m.backCache + bmp = ScaleToSize(CreateObject("roBitmap", "pkg:/images/dialog-back.png"), 771, menuPos.y-203, false) + png = bmp.GetPng(0, 0, bmp.GetWidth(), bmp.GetHeight()) + png.WriteFile("tmp:/dialog-back.png") + m.backCache = true + end if + imgArray.Push({ url: "pkg:/images/dialog-bottom.png" + TargetRect: {x:254, y:menuPos.y}}) + m.canvas.SetLayer(91, imgArray) + m.canvas.SetLayer(92, txtArray) + m.canvas.Show() + m.visible = true +End Sub + +Function wait_msg_dialog(port) as object + if port = invalid then port = m.canvas.screen.port + while true + event = wait(0, port) + if type(event) = "roUniversalControlEvent" + index = event.GetInt() + if index = m.codes.BUTTON_UP_PRESSED + if m.buttons.Count() > 0 + if m.focus = 0 + m.sounds.dead.Trigger(50) + else + m.focus-- + m.sounds.navi.Trigger(50) + m.Show() + end if + end if + else if index = m.codes.BUTTON_DOWN_PRESSED + if m.buttons.Count() > 0 + if m.focus = m.buttons.Count() - 1 + m.sounds.dead.Trigger(50) + else + m.focus++ + m.sounds.navi.Trigger(50) + m.Show() + end if + end if + else if index = m.codes.BUTTON_BACK_PRESSED + m.sounds.navi.Trigger(50) + msg = GetScreenMessage(m.focus, "closed") + exit while + else if index = m.codes.BUTTON_SELECT_PRESSED + m.sounds.select.Trigger(50) + msg = GetScreenMessage(m.buttons[m.focus].id, "button") + exit while + end if + end if + end while + m.canvas.ClearLayer(91) + m.canvas.ClearLayer(92) + m.canvas.Show() + return msg +End Function + +Sub enable_overlay(enable as boolean) + m.overlay = enable +End Sub diff --git a/source/libScreens.brs b/source/libScreens.brs index 699c96c..acdbcd2 100644 --- a/source/libScreens.brs +++ b/source/libScreens.brs @@ -4,7 +4,7 @@ ' ** ' ** libCanvas.brs - Library with generic methods for Screen objects ' ** Created: June 2018 -' ** Updated: September 2019 +' ** Updated: October 2019 ' ** ' ** Copyright (C) Marcelo Lv Cabral < https://lvcabral.com > ' ******************************************************************************************************** @@ -36,13 +36,21 @@ Sub set_breadcrumb_text(leftText as string, rightText as string) m.breadCrumb = [] m.breadCrumb.Push({ Text: leftText TextAttrs: {color: m.theme.BreadcrumbTextLeft, font: font, HAlign: "Left"} - TargetRect: {x:xl, y:72, w:wl, h:24}}) + TargetRect: {x:xl, y:72, w:wl, h:30}}) m.breadCrumb.Push({ Text: "•" TextAttrs: {color: m.theme.BreadcrumbDelimiter, font: font, HAlign: "Left"} - TargetRect: {x:xb, y:72, w:20, h:24}}) + TargetRect: {x:xb, y:72, w:20, h:30}}) m.breadCrumb.Push({ Text: rightText TextAttrs: {color: m.theme.BreadcrumbTextRight, font: font, HAlign: "Left"} - TargetRect: {x:xr, y:72, w:wr, h:24}}) + TargetRect: {x:xr, y:72, w:wr, h:30}}) +End Sub + +Sub set_title(title as string) + m.title = title +End Sub + +Sub set_text(text as string) + m.text = text End Sub Sub set_focused_item(index as integer) @@ -50,10 +58,18 @@ Sub set_focused_item(index as integer) if m.visible then m.Show() End Sub +Function get_text() as string + return m.text +End Function + Function get_content_list() as object return m.content End Function +Sub add_button(id as integer, text as string) + m.buttons.Push({id: id, text: text}) +End Sub + '------ ' Generic Functions @@ -117,7 +133,7 @@ End Function Function CachedFile(fileName as string) as string g = GetGlobalAA() tmpFile = g.cache.Lookup(fileName) - if tmpFile = invalid then tmpFile = fileName + if tmpFile = invalid then tmpFile = "" return tmpFile End Function