Skip to content

Commit

Permalink
game refreshes/updates itself correctly after changing settings from …
Browse files Browse the repository at this point in the history
…within game
  • Loading branch information
seveerekaj committed Jun 8, 2022
1 parent 85113af commit b67d397
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
18 changes: 14 additions & 4 deletions resources/lib/quizlib/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def onInit(self):
self.getControl(1000 + idx).setImage(posters[idx % len(posters)])

# Check preconditions
self.validateSettings()

def validateSettings(self):
hasMovies = library.hasMovies()
hasTVShows = library.hasTVShows()
hasMusic = library.hasMusic()
Expand Down Expand Up @@ -107,7 +110,7 @@ def onInit(self):

self.moviesEnabled = bool(hasMovies and question.isAnyMovieQuestionsEnabled())
self.tvShowsEnabled = bool(hasTVShows and question.isAnyTVShowQuestionsEnabled())
self.musicEnabled = bool(hasMusic) and question.isAnyMusicQuestionsEnabled()
self.musicEnabled = bool(hasMusic and question.isAnyMusicQuestionsEnabled())

if not question.isAnyMovieQuestionsEnabled():
xbmcgui.Dialog().ok(strings(E_WARNING), strings(E_ALL_MOVIE_QUESTIONS_DISABLED, E_QUIZ_TYPE_NOT_AVAILABLE))
Expand Down Expand Up @@ -185,6 +188,7 @@ def onClick(self, controlId):
imdb.downloadData()
elif action == MenuGui.ACTION_OPEN_SETTINGS:
ADDON.openSettings()
self.validateSettings()
self.quizGui.onSettingsChanged()
elif action == MenuGui.ACTION_EXIT:
self.quizGui.close()
Expand Down Expand Up @@ -244,8 +248,14 @@ def onSettingsChanged(self):
minPercent = ADDON.getSettingInt('question.whatmovieisthis.min_percent')
maxPercent = ADDON.getSettingInt('question.whatmovieisthis.max_percent')
duration = ADDON.getSettingInt('question.whatmovieisthis.duration')
logger.log(f"setting new player with min:{minPercent} max:{maxPercent}, duration:{duration}")
self.player = player.TimeLimitedPlayer(min(minPercent, maxPercent), max(minPercent, maxPercent), duration)
if self.player is None:
self.player = player.TimeLimitedPlayer(min(minPercent, maxPercent), max(minPercent, maxPercent), duration)
else:
# note: I could create a new instance of self.player with the new parameters here, but when I tried that, weird stuff happened -
# the player's threading timer was getting called twice: with both old and new duration. I also tried "del self.player" before creating a new player,
# but the destructor was never actually invoked. So I just use the setBounds function on the existing player instead of creating a new one
logger.log(f"setting new player with min:{minPercent} max:{maxPercent}, duration:{duration}")
self.player.setBounds(min(minPercent, maxPercent), max(minPercent, maxPercent), duration)

@buggalo.buggalo_try_except()
def onInit(self):
Expand Down Expand Up @@ -286,7 +296,7 @@ def newGame(self, gameInstance):
self.defaultLibraryFilters.extend(iter(library.buildRatingsFilters('rating', CONTENT_RATINGS[:idx])))

if ADDON.getSetting(SETT_ONLY_WATCHED_MOVIES) == 'true':
self.defaultLibraryFilters.extend(library.buildOnlyWathcedFilter())
self.defaultLibraryFilters.extend(library.buildOnlyWatchedFilter())

self.questionCandidates = question.getEnabledQuestionCandidates(self.gameInstance)

Expand Down
2 changes: 1 addition & 1 deletion resources/lib/quizlib/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def buildRatingsFilters(field, ratings):
return filters


def buildOnlyWathcedFilter():
def buildOnlyWatchedFilter():
return [{
'operator': 'greaterthan',
'field': 'playcount',
Expand Down
19 changes: 11 additions & 8 deletions resources/lib/quizlib/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ class TimeLimitedPlayer(xbmc.Player):
def __init__(self, minPercent, maxPercent, duration):
super().__init__()
logger.log(">> TimeLimitedPlayer.__init__()")
self.minPercent = minPercent
self.maxPercent = maxPercent
self.duration = duration
self.setBounds(minPercent, maxPercent, duration)
self.eventTimer = None
self.startingPlayback = False
self.lastItem = None
self.lastStartPercentage = None
self.playBackEventReceived = False

def setBounds(self, minPercent, maxPercent, duration):
self.minPercent = minPercent
self.maxPercent = maxPercent
self.duration = duration

def replay(self):
logger.log(">> TimeLimitedPlayer.replay()")
if self.lastItem is not None:
Expand Down Expand Up @@ -106,7 +109,7 @@ def playWindowed(self, item, replay=False):

retries = 0
while not self.playBackEventReceived and retries < 20:
xbmc.sleep(250) # keep sleeping to get onPlayBackStarted() event
xbmc.sleep(250) # keep sleeping to get onAVStarted() event
retries += 1

logger.log(">> TimeLimitedPlayer.playWindowed() - end")
Expand Down Expand Up @@ -142,18 +145,18 @@ def onTimerComplete(self):
xbmc.sleep(250) # keep sleeping to get onPlayBackStopped() event
retries += 1

def onPlayBackStarted(self):
logger.log(">> TimeLimitedPlayer.onPlayBackStarted()")
def onAVStarted(self):
logger.log(">> TimeLimitedPlayer.onAVStarted()")
self.playBackEventReceived = True

if self.eventTimer is not None:
self.eventTimer.cancel()
logger.log(f"IMPORTANT setting timer for {self.duration} seconds")
logger.log(f">> TimeLimitedPlayer.onAVStarted() - setting timer for {self.duration} seconds")
self.eventTimer = threading.Timer(self.duration, self.onTimerComplete)
self.eventTimer.start()

self.startingPlayback = False
logger.log(">> TimeLimitedPlayer.onPlayBackStarted() - end")
logger.log(">> TimeLimitedPlayer.onAVStarted() - end")

def onPlayBackStopped(self):
logger.log(">> TimeLimitedPlayer.onPlayBackStopped()")
Expand Down
5 changes: 2 additions & 3 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ Jake's TODOs:
or maybe grab several frames, each from a different random position of the film, and show each to the user? have the number of frames grabbed configurable
where is cinema vision getting their quotes, trivia from?
have name the movie be full screen, and show all posters as choices
pause instead of stop movie at end of movie quiz, then have replay button show up
pause instead of stop at end of "what movie is this?" then have banner show "time's up! (change the length of time to play in settings)"
change hard-coded numbers to string constants
for settings strings accessed in code, use const variables rather than hard-coding the strings
add 5th or maybe even 6th answer option
bug: changing from short to longer time in settings launched from in-game, does not work.
apparently fanart is required?
ask about onfocus for listitem
put random in util module along with logger
get movie quotes from subtitle tracks of locally-stored movies?
delete old image resources
add readme with link to forum?

twinther's TODOs:
- Error message when we are unable to find additional questions
Expand Down

0 comments on commit b67d397

Please sign in to comment.