//Updates the GUI with latest info whilst maintaining current state
        public void Refresh(bool pageLoad = false)
        {
            if (facade == null)
            {
                return;
            }

            clearGUIProperties();
            int index = pageLoad ? facadeIndex : facade.SelectedListItemIndex;

            itemSelected(lastItem, index, lastitemIndex, true, pageLoad, false);
            if (currentView == ViewState.Details)
            {
                ExtendedGUIListItem item = facade.SelectedListItem as ExtendedGUIListItem;
                if (item != null && item.AssociatedGame != null && detailsItem != null && detailsItem.AssociatedGame.GameID == item.AssociatedGame.GameID)
                {
                    detailsItem = item;
                }

                if (pageLoad)
                {
                    gameSelected(detailsItem, true);
                }
                else
                {
                    onFacadeItemSelected(detailsItem, facade, true);
                }
            }
        }
        public void ItemSelected()
        {
            ExtendedGUIListItem selectedListItem = facade.SelectedListItem as ExtendedGUIListItem;
            int parentIndex = facade.SelectedListItemIndex;

            itemSelected(selectedListItem, 0, parentIndex);
        }
        public void ShowContextMenu()
        {
            ExtendedGUIListItem item = null;
            bool detailsUpdate       = false;

            if (currentView == ViewState.Details)
            {
                item          = detailsItem;
                detailsUpdate = true;
            }
            else if (facade.Focus)
            {
                item = (ExtendedGUIListItem)facade.SelectedListItem;
            }

            if (MenuPresenter.ShowContext(item, this))
            {
                if (detailsUpdate)
                {
                    gameSelected(item, true);
                }
                else
                {
                    onFacadeItemSelected(item, facade, detailsUpdate); //Update GUI
                }
            }
        }
        void toggleDetails(ExtendedGUIListItem detailsItem, bool hide = false)
        {
            int controlId;

            setFacadeVisibility(hide);
            if (hide)
            {
                currentView = ViewState.Items;
                controlId   = facade.GetID;
                ExtendedGUIListItem item = (ExtendedGUIListItem)facade.SelectedListItem;
                if (this.detailsItem != null && item != null && item.AssociatedGame != null && this.detailsItem.AssociatedGame.GameID == item.AssociatedGame.GameID)
                {
                    item.UpdateGameInfo(this.detailsItem.AssociatedGame);
                }
                this.detailsItem = null;
                onFacadeItemSelected(facade.SelectedListItem, facade);
            }
            else
            {
                currentView      = ViewState.Details;
                controlId        = detailsDefaultControl;
                this.detailsItem = detailsItem;
                if (detailsItem != null)
                {
                    onFacadeItemSelected(detailsItem, facade, true);
                }
            }
            GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SETFOCUS, Plugin.WINDOW_ID, 0, controlId, 0, 0, null);

            GUIGraphicsContext.SendMessage(msg);
        }
        public bool LaunchGame(bool auto = false)
        {
            Game game = null;

            if (currentView == ViewState.Details && detailsItem != null)
            {
                game = detailsItem.AssociatedGame;
            }
            else if (facade.Focus)
            {
                ExtendedGUIListItem item = facade.SelectedListItem as ExtendedGUIListItem;
                if (item != null)
                {
                    game = item.AssociatedGame;
                }
            }
            if (game != null)
            {
                if (auto)
                {
                    game.GoodmergeFiles = null;
                }
                launchGame(game);
                return(true);
            }

            return(false);
        }
Exemple #6
0
        public override ExtendedGUIListItem CreateGUIListItem()
        {
            ExtendedGUIListItem listItem = new ExtendedGUIListItem(title);

            listItem.AssociatedGame = this;
            listItem.ThumbnailImage = listItem.ThumbGroup.FrontCoverDefaultPath;
            return(listItem);
        }
Exemple #7
0
 public static bool ShowContext(ExtendedGUIListItem item, GUIPresenter presenter)
 {
     if (item == null || item.AssociatedGame == null)
     {
         return(showSimpleContext(presenter));
     }
     else
     {
         return(ShowGameDialog(item.AssociatedGame, presenter));
     }
 }
        bool loadStartupItems(int index)
        {
            lastItem      = null;
            lastitemIndex = 0;

            if (startupItem != null)
            {
                return(handleStartupItem(index));
            }

            List <DBItem> items = new List <DBItem>();
            int           layout;

            if (startupState == StartupState.FAVOURITES)
            {
                items.AddRange(DB.Instance.GetGames("WHERE favourite='True' ORDER BY title ASC", false));
                layout = Options.Instance.GetIntOption("viewfavourites");
            }
            else if (startupState == StartupState.PCGAMES)
            {
                items.AddRange(DB.Instance.GetGames(Emulator.GetPC()));
                layout = Options.Instance.GetIntOption("viewpcgames");
            }
            else if (startupState == StartupState.GROUPS)
            {
                foreach (RomGroup group in GroupHandler.Instance.Groups)
                {
                    group.RefreshThumbs();
                    items.Add(group);
                }
                layout = groupsLayout;
            }
            else
            {
                foreach (Emulator emu in DB.Instance.GetEmulators())
                {
                    items.Add(emu);
                }
                layout = Options.Instance.GetIntOption("viewemus");
            }

            if (!setItemsToFacade(items.ToArray(), null, 0, index))
            {
                return(false);
            }

            setLayout(layout);
            return(true);
        }
        void clearGUIProperties()
        {
            //Image handlers
            if (backdrop != null)
            {
                backdrop.Filename = string.Empty;
            }

            cover.Filename        = string.Empty;
            backCover.Filename    = string.Empty;
            titleScreen.Filename  = string.Empty;
            inGameScreen.Filename = string.Empty;

            GUIPropertyManager.SetProperty("#Emulators2.currentfilter", "");
            ExtendedGUIListItem.ClearGUIProperties();
        }
Exemple #10
0
        bool emulatorSelected(ExtendedGUIListItem selectedListItem, int index, int parentIndex)
        {
            if (selectedListItem.AssociatedEmulator == null)
            {
                return(false);
            }

            if (!setItemsToFacade(DB.Instance.GetGames(selectedListItem.AssociatedEmulator), selectedListItem, parentIndex, index))
            {
                return(false);
            }
            lastItem      = selectedListItem;
            lastitemIndex = parentIndex;

            //setLayout must be called after setting facade items and lastItem info
            setLayout(selectedListItem.AssociatedEmulator.View);
            return(true);
        }
Exemple #11
0
 public bool ToggleDetails()
 {
     if (currentView == ViewState.Details)
     {
         toggleDetails(null, true);
         return(true);
     }
     else if (facade.Focus)
     {
         ExtendedGUIListItem item = facade.SelectedListItem as ExtendedGUIListItem;
         if (item != null)
         {
             gameSelected(item, true);
             return(true);
         }
     }
     return(false);
 }
Exemple #12
0
        void itemSelected(ExtendedGUIListItem selectedListItem, int index, int parentIndex, bool reverse = false, bool changeLayout = true, bool allowSortChange = true)
        {
            bool handled = false;

            allowLayoutChange = changeLayout;
            setImageDelay(0);

            if (selectedListItem == null)
            {
                handled = loadStartupItems(index);
            }
            else if (selectedListItem.IsGroup)
            {
                handled = groupSelected(selectedListItem, index, parentIndex, allowSortChange);
            }
            else if (selectedListItem.AssociatedEmulator != null)
            {
                handled = emulatorSelected(selectedListItem, index, parentIndex);
            }
            else if (selectedListItem.AssociatedGame != null)
            {
                gameSelected(selectedListItem);
                handled = true;
            }

            allowLayoutChange = true;

            if (!handled)                                                                                                 //if no items to display,
            {
                if (reverse && selectedListItem != null)                                                                  //if we're going back and not already on top level
                {
                    itemSelected(selectedListItem.Parent, parentIndex, selectedListItem.ParentIndex, true, changeLayout); //go back another level
                    return;
                }
                else
                {
                    Emulators2Settings.Instance.ShowMPDialog(Translator.Instance.noitemstodisplay); //else show message to user
                }
            }
            setFacadeVisibility(currentView != ViewState.Details);
            setImageDelay(imageLoadingDelay);
        }
Exemple #13
0
        bool groupSelected(ExtendedGUIListItem selectedListItem, int index, int parentIndex, bool allowSortChange)
        {
            RomGroup romGroup = selectedListItem.RomGroup;

            if (romGroup == null)
            {
                return(false);
            }

            romGroup.Refresh();
            if (romGroup.GroupItems.Count < 1)
            {
                return(false);
            }

            if (allowSortChange)
            {
                SortProperty = romGroup.SortProperty;
                if (sortAsc == romGroup.SortDescending)
                {
                    sortAsc = !romGroup.SortDescending;
                    if (OnSortAscendingChanged != null)
                    {
                        OnSortAscendingChanged(sortAsc);
                    }
                }
            }

            setItemsToFacade(romGroup.GroupItems, selectedListItem, parentIndex, index);

            lastItem      = selectedListItem;
            lastitemIndex = parentIndex;
            if (romGroup.Layout < 0)
            {
                romGroup.Layout = currentLayout;
            }
            else
            {
                setLayout(romGroup.Layout);
            }
            return(true);
        }
Exemple #14
0
        public void LaunchDocument()
        {
            if (facade == null)
            {
                return;
            }
            if (facade.SelectedListItem == null)
            {
                return;
            }

            ExtendedGUIListItem item = (ExtendedGUIListItem)facade.SelectedListItem;

            Logger.LogDebug("Opening {0} manual", item.Label);
            if (item.AssociatedEmulator != null)
            {
                Executor.LaunchDocument(item.AssociatedEmulator);
            }
            else if (item.AssociatedGame != null)
            {
                Executor.LaunchDocument(item.AssociatedGame);
            }
        }
Exemple #15
0
        public void UpdateGame(Game game)
        {
            if (game == null)
            {
                return;
            }

            ExtendedGUIListItem item = null;

            lock (gameItemLock)
                if (gameItems == null || !gameItems.TryGetValue(game.GameID, out item))
                {
                    return;
                }

            GUIWindowManager.SendThreadCallback((a, b, c) =>
            {
                item.UpdateGameInfo(game);
                if (facade != null && facade.SelectedListItem == item)
                {
                    if (currentView == ViewState.Details)
                    {
                        if (detailsItem != null && detailsItem.AssociatedGame != null && item.AssociatedGame != null && detailsItem.AssociatedGame.GameID == item.AssociatedGame.GameID)
                        {
                            toggleDetails(item);
                        }
                    }
                    else
                    {
                        item.ItemSelected(facade);
                    }
                }

                return(0);
            }, 0, 0, null);
        }
Exemple #16
0
 void gameSelected(ExtendedGUIListItem selectedItem)
 {
     gameSelected(selectedItem, clickToDetails);
 }
Exemple #17
0
        void gameSelected(ExtendedGUIListItem selectedItem, bool lClickToDetails)
        {
            if (selectedItem == null)
            {
                return;
            }
            Game selectedGame = selectedItem.AssociatedGame;

            if (selectedGame == null)
            {
                return;
            }

            int           itemCount         = 0;
            int           selectedGoodmerge = -1;
            List <string> goodMergeGames    = null;

            if (selectedGame.IsGoodmerge)
            {
                try
                {
                    goodMergeGames = Extractor.Instance.ViewFiles(selectedGame, out selectedGoodmerge);
                }
                catch (ExtractException) { }

                if (goodMergeGames != null)
                {
                    if (goodMergeGames.Count < 1)
                    {
                        goodMergeGames = null;
                    }
                    else
                    {
                        itemCount = goodMergeGames.Count;
                    }
                }

                selectedGame.GoodmergeFiles = goodMergeGames;
            }


            if (goodmergeList != null)
            {
                GUIControl.ClearControl(Plugin.WINDOW_ID, goodmergeList.GetID);
            }

            if (goodMergeGames != null)
            {
                if (selectedGoodmerge < 0 || selectedGoodmerge >= goodMergeGames.Count)
                {
                    selectedGoodmerge = 0;
                }

                if (lClickToDetails && goodmergeList != null)
                {
                    selectedGame.CurrentDisc.LaunchFile = goodMergeGames[selectedGoodmerge];
                    bool selected = false;
                    for (int x = 0; x < goodMergeGames.Count; x++)
                    {
                        GUIListItem item = new GUIListItem(goodMergeGames[x].Replace(selectedGame.Filename, "").Trim())
                        {
                            DVDLabel = goodMergeGames[x]
                        };
                        GUIControl.AddListItemControl(Plugin.WINDOW_ID, goodmergeList.GetID, item);
                        if (!selected && x == selectedGoodmerge)
                        {
                            selected      = true;
                            item.Selected = true;
                            goodmergeList.SelectedListItemIndex = x;
                        }
                    }
                }
                else if (selectedGame.CurrentDisc.LaunchFile != goodMergeGames[selectedGoodmerge])
                {
                    selectedGame.CurrentDisc.LaunchFile = "";
                }
            }

            GUIPropertyManager.SetProperty("#Emulators2.CurrentItem.goodmergecount", itemCount.ToString());
            if (lClickToDetails)
            {
                toggleDetails(selectedItem);
            }
            else
            {
                launchGame(selectedGame);
            }
        }
Exemple #18
0
        bool setItemsToFacade <T>(IEnumerable <T> items, ExtendedGUIListItem parent, int parentIndex, int selectedIndex) where T : DBItem
        {
            bool sortable = false;

            facadeItems = new List <ExtendedGUIListItem>();
            lock (gameItemLock)
            {
                gameItems = new Dictionary <int, ExtendedGUIListItem>();
                int listPosition = 0;
                foreach (DBItem item in items)
                {
                    ExtendedGUIListItem facadeItem = item.CreateGUIListItem();
                    if (facadeItem.AssociatedGame != null)
                    {
                        gameItems[facadeItem.AssociatedGame.GameID] = facadeItem;
                    }
                    sortable = sortable || facadeItem.Sortable;
                    facadeItem.OnItemSelected += new GUIListItem.ItemSelectedHandler(onFacadeItemSelected);
                    facadeItem.Parent          = parent;
                    facadeItem.ParentIndex     = parentIndex;
                    facadeItem.ListPosition    = listPosition;
                    listPosition++;
                    facadeItems.Add(facadeItem);
                }
            }

            if (facadeItems.Count < 1)
            {
                return(false);
            }

            if (sortable)
            {
                SortEnabled = true;
                if (sortProperty != ListItemProperty.DEFAULT)
                {
                    facadeItems.Sort(new ListItemComparer(sortProperty, !sortAsc));
                }
                else
                {
                    sortable = false;
                }
            }
            else
            {
                SortProperty = ListItemProperty.DEFAULT;
                SortEnabled  = false;
            }

            GUIPropertyManager.SetProperty("#Emulators2.currentfilter", parent != null ? parent.Label : startupState.Translate());
            sortable = sortable && showSortValue;

            GUIControl.ClearControl(Plugin.WINDOW_ID, facade.GetID);
            for (int i = 0; i < facadeItems.Count; i++)
            {
                if (sortable)
                {
                    facadeItems[i].SetLabel2(sortProperty);
                }
                GUIControl.AddListItemControl(Plugin.WINDOW_ID, facade.GetID, facadeItems[i]);
            }

            setFacadeIndex(selectedIndex);

            if (currentView != ViewState.Details)
            {
                onFacadeItemSelected(facade.SelectedListItem, facade);
            }

            return(true);
        }
Exemple #19
0
        void onFacadeItemSelected(GUIListItem item, GUIControl parent, bool detailsUpdate)
        {
            if (currentView == ViewState.Details)
            {
                if (!detailsUpdate)
                {
                    return;
                }
            }

            ExtendedGUIListItem selectedItem = item as ExtendedGUIListItem;

            if (selectedItem == null)
            {
                return;
            }

            ThumbGroup thumbs;
            string     lVideoId;
            string     lVideoPath;

            lock (selectedItem.SyncRoot)
            {
                selectedItem.SetGUIProperties();
                thumbs     = selectedItem.ThumbGroup;
                lVideoId   = selectedItem.VideoPreviewId;
                lVideoPath = selectedItem.VideoPreview;
            }

            if (thumbs != null)
            {
                cover.Filename        = thumbs.FrontCoverDefaultPath;
                backdrop.Filename     = thumbs.FanartDefaultPath;
                backCover.Filename    = thumbs.BackCover.Path;
                titleScreen.Filename  = thumbs.TitleScreen.Path;
                inGameScreen.Filename = thumbs.InGame.Path;
            }
            else
            {
                cover.Filename        = defaultCover;
                backdrop.Filename     = defaultFanart;
                backCover.Filename    = string.Empty;
                titleScreen.Filename  = string.Empty;
                inGameScreen.Filename = string.Empty;
            }

            if (!previewVidEnabled)
            {
                return;
            }

            //preview videos
            lock (videoPreviewSync)
            {
                if (!string.IsNullOrEmpty(currentVideoId) && currentVideoId == lVideoId)
                {
                    return;
                }
                //keep reference to current list item
                currentVideoId   = lVideoId;
                currentVideoPath = lVideoPath;

                //stop any playing media
                if (previewVidPlaying)
                {
                    previewVidPlaying = false;
                    if (OnPreviewVideoStatusChanged != null)
                    {
                        OnPreviewVideoStatusChanged(null, false);
                    }
                }

                if (videoPreviewTimer != null)
                {
                    videoPreviewTimer.Dispose();
                }

                if (!string.IsNullOrEmpty(currentVideoPath))
                {
                    videoPreviewTimer = new System.Threading.Timer(videoPreviewTimer_Elapsed, lVideoId, videoPreviewDelay, System.Threading.Timeout.Infinite);
                }
            }
        }