예제 #1
0
        public static void initLoadCharList()
        {
            log("Refreshing Character List View");
            List <CharList>       lst  = loadCharList();
            List <CharListImages> lsti = new List <CharListImages>();
            TH1Helper             ca   = new TH1Helper();

            lst.Sort(delegate(CharList c1, CharList c2) { return(c1.importedon.CompareTo(c2.importedon)); });
            lst.Reverse();
            foreach (CharList cl in lst)
            {
                CharListImages il = new CharListImages();
                il.name       = cl.name;
                il.level      = cl.level;
                il.importedon = cl.importedon;
                il.exp        = cl.exp;
                il.hash       = cl.hash;
                il.path       = cl.path;
                il.cclass     = cl.cclass;
                il.bounty     = cl.bounty;
                il.image      = classToImage(Array.IndexOf(ca.classNamesArray, cl.cclass));
                il.calign     = cl.calign;
                il.lastplayed = cl.lastplayed;
                lsti.Add(il);
            }

            ObservableCollection <CharListImages> obsicol = new ObservableCollection <CharListImages>(lsti);

            obsicol.CollectionChanged += lstCharacter_OnChange;
            MainWindow._CharactersUC.lstCharacters.ItemsSource = obsicol;
        }
예제 #2
0
        public static void importCharSave(TH1SaveStructure save)
        {
            bool alreadylisted = false;

            Directory.CreateDirectory("saves");

            if (save.lastError == 0)
            {
                // Generate list
                ObservableCollection <CharListImages> list = (ObservableCollection <CharListImages>)MainWindow._CharactersUC.lstCharacters.ItemsSource;
                CharListImages item = new CharListImages();
                TH1Helper      ca   = new TH1Helper();

                // Generate item
                item.hash       = BitConverter.ToString(save.hash).Replace("-", "");
                item.name       = save.character.name;
                item.exp        = save.character.exp.ToString("N0");
                item.level      = save.character.level;
                item.importedon = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                item.bounty     = save.character.bounty.ToString("N0");
                item.cclass     = ca.classNamesArray[save.character.charClass];
                item.calign     = ca.alignmentNamesArray[save.character.alignment];
                item.image      = classToImage(save.character.charClass);
                item.lastplayed = save.character.lastSave.ToString();

                // Backup save
                item.path = @"saves\" + item.hash + ".th1";
                save.writeSaveFile(item.path);

                // Check if already in the list
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].hash == item.hash)
                    {
                        alreadylisted = true;
                        list[i]       = item;
                    }
                }

                // Save list
                if (!alreadylisted)
                {
                    list.Insert(0, item);
                }
            }
        }