Exemplo n.º 1
0
        private void newGroupItemButton_Click(object sender, EventArgs e)
        {
            updateSelectedGroupItem();
            if (selectedGroup == null)
            {
                return;
            }

            string        title = "SQL";
            GroupItemInfo info  = new GroupItemInfo("");

            if (newItemTypeComboBox.Text == "Dynamic")
            {
                title       = "Dynamic";
                info.Column = dynamicColumns[0];
            }
            TreeNode newNode = new TreeNode(title)
            {
                Tag = info
            };

            newNode.Nodes.Add("Loading...");
            groupItemsTreeView.Nodes.Add(newNode);
            groupItemsTreeView.SelectedNode = newNode;
        }
Exemplo n.º 2
0
        private void groupItemsTreeView_AfterExpand(object sender, TreeViewEventArgs e)
        {
            updateSelectedGroupItem();
            if (selectedGroup == null)
            {
                return;
            }

            TreeNode selectedNode = e.Node;

            if (selectedNode == null)
            {
                return;
            }

            GroupItemInfo info = selectedNode.Tag as GroupItemInfo;

            if (info == null)
            {
                return;
            }

            if (selectedNode.Nodes.Count == 1 && selectedNode.Nodes[0].Text == "Loading...")
            {
                addChildNodes(selectedNode, info);
            }
        }
Exemplo n.º 3
0
        void updateSelectedGroup()
        {
            if (selectedGroup == null)
            {
                return;
            }

            selectedGroup.Title = txt_Title.Text;
            if (selectedListItem != null)
            {
                selectedListItem.Text = txt_Title.Text;
            }

            if (sortDropdownItems.ContainsKey(sortComboBox.Text))
            {
                selectedGroup.SortProperty = sortDropdownItems[sortComboBox.Text];
            }
            selectedGroup.SortDescending = sortDescCheckBox.Checked;
            if (layoutDropdownItems.ContainsKey(layoutComboBox.Text))
            {
                selectedGroup.Layout = layoutDropdownItems[layoutComboBox.Text];
            }

            selectedGroup.GroupItemInfos.Clear();
            foreach (TreeNode node in groupItemsTreeView.Nodes)
            {
                GroupItemInfo info = node.Tag as GroupItemInfo;
                if (info != null)
                {
                    selectedGroup.GroupItemInfos.Add(info);
                }
            }
        }
Exemplo n.º 4
0
        void addChildNodes(TreeNode selectedNode, GroupItemInfo info)
        {
            selectedNode.Nodes.Clear();

            if (info.SQL != null)
            {
                if (string.IsNullOrEmpty(info.Column))
                {
                    foreach (Game game in DB.Instance.GetGames(info.SQL, false))
                    {
                        selectedNode.Nodes.Add(new TreeNode(game.Title)
                        {
                            BackColor = Color.DarkGray
                        });
                    }
                }
                else
                {
                    foreach (RomGroup group in selectedGroup.GetSubGroups(info))
                    {
                        selectedNode.Nodes.Add(new TreeNode(group.Title)
                        {
                            BackColor = Color.DarkGray
                        });
                    }
                }
            }
            else if (info.Id == -2)
            {
                if (info.Emulator)
                {
                    foreach (Emulator emu in DB.Instance.GetEmulators())
                    {
                        selectedNode.Nodes.Add(new TreeNode(emu.Title)
                        {
                            BackColor = Color.LightGray
                        });
                    }
                }
                else
                {
                    foreach (Game game in DB.Instance.GetGames())
                    {
                        selectedNode.Nodes.Add(new TreeNode(game.Title)
                        {
                            BackColor = Color.LightGray
                        });
                    }
                }
            }

            if (selectedNode.Nodes.Count < 1)
            {
                selectedNode.Nodes.Add("No items");
            }
        }
Exemplo n.º 5
0
        private void groupItemsTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            updateGroupItemButtons();
            allowGroupItemUpdate = false;
            updateSelectedGroupItem();
            resetSQLGroup();
            resetDynamicGroup();

            if (selectedGroup == null)
            {
                return;
            }

            TreeNode selectedNode = groupItemsTreeView.SelectedNode;

            if (selectedNode == null)
            {
                return;
            }

            selectedGroupItem = selectedNode.Tag as GroupItemInfo;
            if (selectedGroupItem == null)
            {
                selectedTreeNode = null;
                return;
            }
            selectedTreeNode = selectedNode;

            if (selectedGroupItem.SQL != null)
            {
                if (string.IsNullOrEmpty(selectedGroupItem.Column))
                {
                    sqlGroupBox.Enabled = true;
                    txt_SQL.Text        = selectedGroupItem.SQL;
                }
                else
                {
                    dynamicGroupBox.Enabled         = true;
                    dyn_ColumnComboBox.SelectedItem = selectedGroupItem.Column;
                    if (selectedGroupItem.Order == "DESC")
                    {
                        dyn_OrderComboBox.SelectedIndex = 1;
                    }
                    else
                    {
                        dyn_OrderComboBox.SelectedIndex = 0;
                    }
                }
            }
            allowGroupItemUpdate = true;
        }
Exemplo n.º 6
0
 private void addToGroupButton_Click(object sender, EventArgs e)
 {
     updateSelectedGroupItem();
     foreach (ListViewItem item in allItemsListView.SelectedItems)
     {
         GroupItemInfo info = item.Tag as GroupItemInfo;
         if (info == null)
         {
             continue;
         }
         TreeNode newNode = new TreeNode(item.Text)
         {
             Tag = info
         };
         if (info.Id == -2)
         {
             newNode.Nodes.Add("Loading...");
         }
         groupItemsTreeView.Nodes.Add(newNode);
     }
 }
Exemplo n.º 7
0
        void groupsListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (!e.IsSelected)
            {
                return;
            }

            updateButtons();
            updateSelectedGroupItem();
            selectedGroupItem = null;
            updateSelectedGroup();
            selectedGroup    = null;
            selectedListItem = null;

            allowGroupItemUpdate = false;
            resetSQLGroup();
            resetDynamicGroup();

            if (groupsListView.SelectedItems.Count > 1)
            {
                return;
            }

            selectedListItem = e.Item;
            selectedGroup    = e.Item.Tag as RomGroup;
            if (selectedGroup == null)
            {
                selectedListItem = null;
                return;
            }

            txt_Title.Text = selectedGroup.Title;

            sortDescCheckBox.Checked = selectedGroup.SortDescending;
            bool found = false;

            foreach (KeyValuePair <string, ListItemProperty> keyVal in sortDropdownItems)
            {
                if (keyVal.Value == selectedGroup.SortProperty)
                {
                    found = true;
                    sortComboBox.SelectedItem = keyVal.Key;
                    break;
                }
            }
            if (!found)
            {
                sortComboBox.SelectedIndex = 0;
            }

            found = false;
            foreach (KeyValuePair <string, int> keyVal in layoutDropdownItems)
            {
                if (keyVal.Value == selectedGroup.Layout)
                {
                    found = true;
                    layoutComboBox.SelectedItem = keyVal.Key;
                    break;
                }
            }
            if (!found)
            {
                layoutComboBox.SelectedIndex = 0;
            }

            groupItemsTreeView.Nodes.Clear();

            foreach (GroupItemInfo item in selectedGroup.GroupItemInfos)
            {
                TreeNode newNode = new TreeNode()
                {
                    Tag = item
                };
                if (item.SQL != null)
                {
                    if (string.IsNullOrEmpty(item.Column))
                    {
                        newNode.Text = "SQL";
                    }
                    else
                    {
                        newNode.Text = "Dynamic";
                    }

                    newNode.Nodes.Add("Loading...");
                }
                else if (item.Emulator)
                {
                    Emulator emu;
                    if (item.Id == -2)
                    {
                        newNode.Text = "All Emulators";
                        newNode.Nodes.Add("Loading...");
                    }
                    else if (allEmulators.TryGetValue(item.Id, out emu))
                    {
                        newNode.Text = emu.Title;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    Game game;
                    if (item.Id == -2)
                    {
                        newNode.Text = "All Games";
                        newNode.Nodes.Add("Loading...");
                    }
                    else if (allGames.TryGetValue(item.Id, out game))
                    {
                        newNode.Text = game.Title;
                    }
                    else
                    {
                        continue;
                    }
                }
                groupItemsTreeView.Nodes.Add(newNode);
            }

            allowGroupItemUpdate = true;
        }
Exemplo n.º 8
0
        public DBItem GetRandomThumbItem(GroupItemInfo info)
        {
            DBItem thumbItem = null;

            if (!string.IsNullOrEmpty(info.Column))
            {
                return(null);
            }
            else if (info.SQL != null)
            {
                lock (artworkCacheSync)
                {
                    if (sqlRandomArtwork.ContainsKey(info.SQL))
                    {
                        return(sqlRandomArtwork[info.SQL]);
                    }
                }
                string sql          = info.SQL;
                int    orderbyIndex = orderByRegEx.Match(sql).Index;
                if (orderbyIndex > -1)
                {
                    sql = sql.Substring(0, orderbyIndex).Trim();
                }
                sql += " ORDER BY RANDOM() LIMIT 1";
                List <Game> games = DB.Instance.GetGames(sql, false);
                if (games.Count > 0)
                {
                    thumbItem = games[0];
                    lock (artworkCacheSync)
                        sqlRandomArtwork[info.SQL] = thumbItem;
                }
            }
            else if (info.Emulator)
            {
                lock (artworkCacheSync)
                    if (emuRandomArtwork.ContainsKey(info.Id))
                    {
                        return(emuRandomArtwork[info.Id]);
                    }

                if (info.Id == -2)
                {
                    List <Emulator> emus = DB.Instance.GetEmulators();
                    if (emus.Count > 0)
                    {
                        thumbItem = emus[new Random().Next(emus.Count)];
                    }
                }
                else
                {
                    thumbItem = DB.Instance.GetEmulator(info.Id);
                }
                if (thumbItem != null)
                {
                    lock (artworkCacheSync)
                        emuRandomArtwork[info.Id] = thumbItem;
                }
            }
            else
            {
                lock (artworkCacheSync)
                    if (gameRandomArtwork.ContainsKey(info.Id))
                    {
                        return(gameRandomArtwork[info.Id]);
                    }

                if (info.Id == -2)
                {
                    List <Game> games = DB.Instance.GetGames("ORDER BY RANDOM() LIMIT 1", false);
                    if (games.Count > 0)
                    {
                        thumbItem = games[0];
                    }
                }
                else
                {
                    thumbItem = DB.Instance.GetGame(info.Id);
                }
                if (thumbItem != null)
                {
                    lock (artworkCacheSync)
                        gameRandomArtwork[info.Id] = thumbItem;
                }
            }
            return(thumbItem);
        }