def infoDialog(title, subtitle, callback): from info_dialog_canvas import InfoDialogCanvas dialog = getPopupMenu(InfoDialogCanvas()) Text(dialog.canvas.titleTxtObj, text=title.strip(), limit=15, width=20) Text(dialog.canvas.subtitleTxtObj, text=subtitle.strip(), limit=250, width=35) confirmBtn = Button(dialog.canvas.confirmBtnObj) confirmBtn.setOnclickAction(lambda: dialog.close(callback)) dialog.open()
def onHover(controller): hover = controller.sensors['hover'] button = Button(controller.owner) if button.isEnabled() and hover.positive: hoverSound = button.getOnhoverSound() if hoverSound: Audio(hoverSound).play() button.applyHoverColor() button.runOnHoverAction() else: button.applyDefaultColor()
def setBenchmarkMenu(menu, playerId, challengeName, challengeId): from pcache import Stats, Scores from puzzle_main import startPuzzleScene from button_widget import Button from text_widget import Text score = Scores(playerId, challengeId) stats = Stats(playerId, challengeId) playBtn = Button(menu.canvas.playBtnObj) returnBtn = Button(menu.canvas.exitBtnObj) returnBtn.setOnclickAction(menu.close) playBtn.setOnclickAction(lambda: menu.close(startPuzzleScene)) Text(menu.canvas.titleTxtObj, challengeName) if score.fetch(): Text(menu.canvas.timeTxtObj, frmtTime(score.timeCompleted)) Text(menu.canvas.movesTxtObj, score.moves) Text(menu.canvas.streakCountTxtObj, score.streaks) if stats.fetch(): Text(menu.canvas.playCountTxtObj, stats.playCount) Text(menu.canvas.playTimeTxtObj, frmtTime(stats.totalTime)) Text(menu.canvas.winsTxtObj, stats.wins) Text(menu.canvas.losesTxtObj, stats.loses)
def setMainCanvas(scene, paginator, positionNodes): from challenge_menu_listerners import OnChallengeListChangeListerner from button_widget import Button from text_widget import Text canvas = ListCanvas() canvas.add(scene.objects['main_canvas_position_node'], False) nextButton = Button(canvas.nextBtnObj) previousButton = Button(canvas.previousBtnObj) Text(canvas.pageNumTxtObj, paginator.curIndex + 1) nextButton.setOnclickAction( lambda: nextChallengeList(paginator, positionNodes)) previousButton.setOnclickAction( lambda: previousChallengeList(paginator, positionNodes)) OnChallengeListChangeListerner().attach( 'update_page_number', lambda index, challenges: Text(canvas.pageNumTxtObj, index + 1)) OnChallengeListChangeListerner().attach( 'update_challenge_list', lambda index, challenges: showChallengeList( scene, challenges, positionNodes)) fadeIn(canvas)
def confirmDialog(title, subtitle, onConfirm, onCancel=lambda: ()): from confirm_dialog_canvas import ConfirmDialogCanvas dialog = getPopupMenu(ConfirmDialogCanvas()) Text(dialog.canvas.titleTxtObj, title) Text(dialog.canvas.subtitleTxtObj, subtitle) confirmBtn = Button(dialog.canvas.confirmBtnObj) cancelBtn = Button(dialog.canvas.cancelBtnObj) confirmBtn.setOnclickAction(lambda: dialog.close(onConfirm)) cancelBtn.setOnclickAction(dialog.close) dialog.open()
def getPopupMenu(canvas): from menu import PopUpMenu, CENTER_POSITION_NODE from game import reshuffle, quit menu = PopUpMenu(canvas, CENTER_POSITION_NODE) reshuffleBtn = Button(menu.canvas.reshuffleBtnObj) exitBtn = Button(menu.canvas.exitBtnObj) reshuffleBtn.setOnclickAction(reshuffle) exitBtn.setOnclickAction(quit) return menu
def onClick(controller): from button_effects import clickAnimation hover = controller.sensors['hover'] click = controller.sensors['click'] button = Button(controller.owner) if button.isButtonEnabled() and hover.positive and click.positive: button.disable() def onClick(): onClickSound = button.getOnclickSound() if not onClickSound: onClickSound = BUTTON_CLICK Audio(onClickSound).play() button.enable() button.runOnClickAction() # animate animation click and after the last frame, # run onclick action clickAnimation(button.buttonObj, onClick)
def setChallengeMenu(canvas, challenge): from hud_resources import loadPuzzlePatternViewer from utils import frmtTime from pcache import Scores from navigator import startPuzzleScene, overlayChallengeViewer from player import getPlayerId from button_widget import Button from text_widget import Text playerId = getPlayerId() challengeId = challenge['id'] challengeName = challenge['name'] score = Scores(playerId, challengeId) scene = logic.getCurrentScene() moves = 0 time = '00:00:00' streaks = 0 if score.fetch(): moves = score.moves streaks = score.streaks time = frmtTime(score.timeCompleted) Text(canvas.titleTxtObj, challengeName) Text(canvas.timeTxtObj, time) Text(canvas.movesTxtObj, moves) Text(canvas.streaksTxtObj, streaks) Button(canvas.playBtnObj).setOnclickAction( lambda: startPuzzleScene(challenge)) Button(canvas.patternBtnObj).setOnclickAction( lambda: loadPuzzlePatternViewer(challenge)) dialogPopIn(canvas)