Example #1
0
 public BasePage(PlayerBuildModel model)
 {
     BindingContext = Model = model;
     InitializeComponent();
     CurrentPageChanged += CarouselPage_CurrentPageChanged;
     Title = CurrentPage.Title;
 }
 public BuildPage(PlayerBuildModel model)
 {
     BindingContext = Model = model;
     InitializeComponent();
     Children.Add(
         new NavigationPage(new BasePage(Model))
     {
         Title = "Base",
         Icon  = Device.OnPlatform("tab_feed.png", null, null)
     });
     Children.Add(
         new NavigationPage(new AboutPage())
     {
         Title = "Personal",
         Icon  = Device.OnPlatform("tab_about.png", null, null)
     });
     Children.Add(
         new NavigationPage(new AboutPage())
     {
         Title = "Spell",
         Icon  = Device.OnPlatform("tab_about.png", null, null)
     });
     Children.Add(
         new NavigationPage(new ShopPage(Model))
     {
         Title = "Item",
         Icon  = Device.OnPlatform("tab_about.png", null, null)
     });
     Children.Add(
         new NavigationPage(new AboutPage())
     {
         Title = "Config",
         Icon  = Device.OnPlatform("tab_about.png", null, null)
     });
 }
Example #3
0
        async void AddItem_Clicked(object sender, EventArgs e)
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            viewModel.Items.Clear();
            BuilderContext Context = new BuilderContext(new Player()
            {
                Name = "New Player"
            });
            PluginManager manager = new PluginManager();

            manager.Add(new NoFreeEquipment());
            manager.Add(new CustomBackground());
            manager.Add(new SpellPoints());
            manager.Add(new SingleLanguage());
            Context.Plugins            = manager;
            Context.UndoBuffer         = new LinkedList <Player>();
            Context.RedoBuffer         = new LinkedList <Player>();
            Context.UnsavedChanges     = 0;
            ItemsListView.SelectedItem = null;
            LoadingProgress loader = new LoadingProgress(Context);
            LoadingPage     l      = new LoadingPage(loader);
            await Navigation.PushModalAsync(l);

            var t = l.Cancel.Token;

            try
            {
                await loader.Load(t).ConfigureAwait(false);

                t.ThrowIfCancellationRequested();
                PlayerBuildModel model = new PlayerBuildModel(Context);
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopModalAsync(false);
                    await Navigation.PushModalAsync(new NavigationPage(new FlowPage(model)));
                });
            }
            catch (OperationCanceledException)
            {
            }
            finally
            {
                IsBusy = false;
            }
            // Manually deselect item
        }
Example #4
0
        async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            //viewModel.Items.Clear();
            var item = args.SelectedItem as Models.Character;

            if (item == null)
            {
                return;
            }
            BuilderContext Context = new BuilderContext(item.Player);
            PluginManager  manager = new PluginManager();

            manager.Add(new SpellPoints());
            manager.Add(new SingleLanguage());
            Context.Plugins = manager;

            //Task.Run(async () =>
            //     {
            //         if (Context.Player.FilePath is IFile file)
            //         {
            //             string name = file.Name;
            //             IFile target = await (await App.Storage.CreateFolderAsync("Backups", CreationCollisionOption.OpenIfExists).ConfigureAwait(false)).CreateFileAsync(name, CreationCollisionOption.ReplaceExisting).ConfigureAwait(false);
            //             using (Stream fout = await target.OpenAsync(FileAccess.ReadAndWrite))
            //             {
            //                 using (Stream fin = await file.OpenAsync(FileAccess.Read))
            //                 {
            //                     await fin.CopyToAsync(fout);
            //                 }
            //             };
            //         }
            //     }).Forget();
            Context.UndoBuffer         = new LinkedList <Player>();
            Context.RedoBuffer         = new LinkedList <Player>();
            Context.UnsavedChanges     = 0;
            ItemsListView.SelectedItem = null;
            LoadingProgress loader = new LoadingProgress(Context);
            LoadingPage     l      = new LoadingPage(loader);
            await Navigation.PushModalAsync(l);

            var t = l.Cancel.Token;

            try
            {
                await loader.Load(t).ConfigureAwait(false);

                t.ThrowIfCancellationRequested();
                PlayerBuildModel model = new PlayerBuildModel(Context);
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopModalAsync(false);
                    await Navigation.PushModalAsync(new NavigationPage(new FlowPage(model)));
                });
            }
            catch (OperationCanceledException)
            {
            }
            finally
            {
                IsBusy = false;
                (sender as ListView).SelectedItem = null;
            }
            // Manually deselect item
        }
        public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
        {
            Task.Run(async() =>
            {
                if ("Inbox".Equals(Path.GetDirectoryName(url.Path)))
                {
                    IFolder incoming = await App.Storage.CreateFolderAsync("Inbox", CreationCollisionOption.OpenIfExists);
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(incoming));
                    });
                }
                else if (url.Path?.EndsWith(".cb5") ?? false)
                {
                    try {
                        using (Stream f = File.OpenRead(url.Path)) {
                            Player player          = Player.Serializer.Deserialize(f) as Player;
                            BuilderContext Context = new BuilderContext(player);
                            PluginManager manager  = new PluginManager();
                            manager.Add(new SpellPoints());
                            manager.Add(new SingleLanguage());
                            manager.Add(new CustomBackground());
                            manager.Add(new NoFreeEquipment());
                            Context.Plugins = manager;


                            Context.UndoBuffer     = new LinkedList <Player>();
                            Context.RedoBuffer     = new LinkedList <Player>();
                            Context.UnsavedChanges = 0;

                            Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                            {
                                LoadingProgress loader   = new LoadingProgress(Context);
                                LoadingPage l            = new LoadingPage(loader, false);
                                App.MainTab.SelectedItem = App.MainTab.Children[2];
                                await App.MainTab.Children[2].Navigation.PushModalAsync(l);
                                var t = l.Cancel.Token;
                                try
                                {
                                    await loader.Load(t).ConfigureAwait(false);
                                    t.ThrowIfCancellationRequested();
                                    PlayerBuildModel model = new PlayerBuildModel(Context);
                                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                                    {
                                        await App.MainTab.Children[2].Navigation.PopModalAsync(false);
                                        await App.MainTab.Children[2].Navigation.PushModalAsync(new NavigationPage(new FlowPage(model)));
                                    });
                                } catch (Exception e) {
                                    ConfigManager.LogError(e);
                                }
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        ConfigManager.LogError(e);
                    }
                }
                else
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        if (url.Path.StartsWith(App.Storage.Path, System.StringComparison.Ordinal))
                        {
                            await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(await FileSystem.Current.GetFolderFromPathAsync(Path.GetDirectoryName(url.Path))));
                        }
                    });
                }
            }).Forget();
            return(true);
        }
        public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
        {
            Task.Run(async() =>
            {
                if ("Inbox".Equals(Path.GetFileName(Path.GetDirectoryName(url.Path))))
                {
                    IFolder incoming = await App.Storage.CreateFolderAsync("Incoming", CreationCollisionOption.OpenIfExists);
                    IFile f          = await FileSystem.Current.GetFileFromPathAsync(url.Path);
                    await f.MoveAsync(Path.Combine(incoming.Path, f.Name), NameCollisionOption.GenerateUniqueName);
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(incoming));
                    });
                }
                else if (url.Path?.EndsWith(".cb5") ?? false)
                {
                    url.StartAccessingSecurityScopedResource();
                    try {
                        //using (MemoryStream s = new MemoryStream()) {
                        //    NSInputStream stream = NSInputStream.FromUrl(url);
                        //    byte[] buffer = new byte[1024];
                        //    while (stream.HasBytesAvailable()) {
                        //        int read = (int)stream.Read(buffer, 1024);
                        //        s.Write(buffer, 0, read);
                        //    }
                        //    s.Seek(0, SeekOrigin.Begin);
                        //NSFileHandle fs = NSFileHandle.OpenReadUrl(url, out NSError err);
                        //NSData data = fs.ReadDataToEndOfFile();
                        //fs.CloseFile();
                        //using (Stream f = data.AsStream()) {AsStream
                        //new MyInputStream(NSInputStream.FromUrl(url))) {
                        //NSData d = await url.LoadDataAsync("text/xml");
                        //File.OpenRead(url.Path)
                        using (Stream s = File.OpenRead(url.Path)) {
                            Player player          = Player.Serializer.Deserialize(s) as Player;
                            BuilderContext Context = new BuilderContext(player);
                            PluginManager manager  = new PluginManager();
                            manager.Add(new SpellPoints());
                            manager.Add(new SingleLanguage());
                            manager.Add(new CustomBackground());
                            manager.Add(new NoFreeEquipment());
                            Context.Plugins = manager;


                            Context.UndoBuffer     = new LinkedList <Player>();
                            Context.RedoBuffer     = new LinkedList <Player>();
                            Context.UnsavedChanges = 0;

                            Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                            {
                                LoadingProgress loader   = new LoadingProgress(Context);
                                LoadingPage l            = new LoadingPage(loader, false);
                                App.MainTab.SelectedItem = App.MainTab.Children[1];
                                await App.MainTab.Children[2].Navigation.PushModalAsync(l);
                                var t = l.Cancel.Token;
                                try
                                {
                                    await loader.Load(t).ConfigureAwait(false);
                                    t.ThrowIfCancellationRequested();
                                    PlayerBuildModel model = new PlayerBuildModel(Context);
                                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                                    {
                                        await App.MainTab.Children[1].Navigation.PopModalAsync(false);
                                        await App.MainTab.Children[1].Navigation.PushModalAsync(new NavigationPage(new FlowPage(model)));
                                    });
                                } catch (Exception e) {
                                    ConfigManager.LogError(e);
                                }
                            });
                        }
                        url.StopAccessingSecurityScopedResource();
                    }
                    catch (Exception e)
                    {
                        ConfigManager.LogError(e);
                    }
                }
                else if (url.Path.StartsWith(App.Storage.Path, System.StringComparison.Ordinal))
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(await FileSystem.Current.GetFolderFromPathAsync(Path.GetDirectoryName(url.Path))));
                    });
                }
                else
                {
                    url.StartAccessingSecurityScopedResource();
                    IFolder incoming = await App.Storage.CreateFolderAsync("Incoming", CreationCollisionOption.OpenIfExists);
                    IFile target     = await incoming.CreateFileAsync(url.LastPathComponent, CreationCollisionOption.GenerateUniqueName);
                    using (Stream f = File.OpenRead(url.Path))
                    {
                        using (Stream o = await target.OpenAsync(PCLStorage.FileAccess.ReadAndWrite))
                        {
                            await f.CopyToAsync(o);
                        }
                    }
                    url.StopAccessingSecurityScopedResource();
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(incoming));
                    });
                }
            }).Forget();
            return(true);
        }