void ShowExport() { ExportData data = ExportData.DataFromDBs(); ImportExportDialog ied = new ImportExportDialog(this, data, true); ied.Show(); ied.DialogComplete += (sender, e) => { FileDialog.CheckFilePermission(this, () => { FileDialog fd = new FileDialog(this, new List <string>() { ".cmx" }, false); fd.Text = "export.cmx"; fd.Show(); fd.DialogComplete += (object s, FileDialog.FileDialogEventArgs ea) => { string name = ea.Filename; string fullname = Path.Combine(fd.Folder, name); FileInfo file = new FileInfo(fullname); fullname = fullname.TrimEnd('.') + ".cmx"; XmlLoader <ExportData> .Save(e.Data, fullname); }; }); }; }
void ShowImport() { FileDialog fd = new FileDialog(this, new List <string>() { ".cmx" }, true); fd.Show(); fd.DialogComplete += (object s, FileDialog.FileDialogEventArgs ea) => { string name = ea.Filename; string fullname = Path.Combine(fd.Folder, name); FileInfo file = new FileInfo(fullname); ShowImportDialog(fullname); }; }
void SavePressed(LinearLayout cl, bool monsters) { FileDialog.CheckFilePermission(Activity, () => { FileDialog fd = new FileDialog(cl.Context, _Extensions, false); fd.DialogComplete += (object s, FileDialog.FileDialogEventArgs ea) => { string name = ea.Filename; if (!name.EndsWith(".cmpt", StringComparison.CurrentCultureIgnoreCase)) { name = name + ".cmpt"; } string fullname = Path.Combine(fd.Folder, name); XmlListLoader <Character> .Save(new List <Character>(_CombatState.Characters.Where((a) => a.IsMonster == monsters)), fullname); }; fd.Show(); }); }
void LoadPressed(LinearLayout cl, bool monsters) { FileDialog.CheckFilePermission(Activity, () => { FileDialog fd = new FileDialog(cl.Context, _Extensions, true); fd.Show(); fd.DialogComplete += (object s, FileDialog.FileDialogEventArgs ea) => { string name = ea.Filename; string fullname = Path.Combine(fd.Folder, name); FileInfo file = new FileInfo(fullname); if (String.Compare(".por", file.Extension, true) == 0 || String.Compare(".rpgrp", file.Extension, true) == 0) { List <Monster> importmonsters = Monster.FromFile(fullname); if (importmonsters != null) { foreach (Monster m in importmonsters) { Character ch = new Character(m, false); ch.IsMonster = monsters; _CombatState.AddCharacter(ch); } } } else { List <Character> l = XmlListLoader <Character> .Load(fullname); foreach (var c in l) { c.IsMonster = monsters; _CombatState.AddCharacter(c); } } }; }); }
private void AddCharacterList(LayoutInflater inflater, ViewGroup container, View v, int id, bool monsters) { LinearLayout cl = (LinearLayout)inflater.Inflate(Resource.Layout.CharacterList, container, false); cl.LayoutParameters = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent, 1f); ListView lv = cl.FindViewById <ListView>(Resource.Id.characterList); lv.Adapter = (new CharacterListAdapter(_CombatState, monsters)); lv.ItemSelected += (sender, e) => { Character c = ((BaseAdapter <Character>)lv.Adapter)[e.Position]; ShowCharacter(v, c); }; lv.ItemClick += (sender, e) => { Character c = ((BaseAdapter <Character>)lv.Adapter)[e.Position]; ShowCharacter(v, c); }; if (!monsters) { _PlayerList = lv; } else { _MonsterList = lv; } lv.SetOnDragListener(new ListOnDragListener(monsters, v)); cl.FindViewById <ImageButton>(Resource.Id.blankButton).Click += (object sender, EventArgs e) => { _CombatState.AddBlank(monsters); }; cl.FindViewById <ImageButton>(Resource.Id.monsterButton).Click += (object sender, EventArgs e) => { MonsterPickerDialog dl = new MonsterPickerDialog(v.Context, monsters, _CombatState); dl.Show(); }; cl.FindViewById <ImageButton>(Resource.Id.loadButton).Click += (object sender, EventArgs e) => { FileDialog fd = new FileDialog(cl.Context, _Extensions, true); fd.Show(); fd.DialogComplete += (object s, FileDialog.FileDialogEventArgs ea) => { string name = ea.Filename; string fullname = Path.Combine(fd.Folder, name); FileInfo file = new FileInfo(fullname); if (String.Compare(".por", file.Extension, true) == 0 || String.Compare(".rpgrp", file.Extension, true) == 0) { List <Monster> importmonsters = Monster.FromFile(fullname); if (importmonsters != null) { foreach (Monster m in importmonsters) { Character ch = new Character(m, false); ch.IsMonster = monsters; _CombatState.AddCharacter(ch); } } } else { List <Character> l = XmlListLoader <Character> .Load(fullname); foreach (var c in l) { c.IsMonster = monsters; _CombatState.AddCharacter(c); } } }; }; cl.FindViewById <ImageButton>(Resource.Id.saveButton).Click += (object sender, EventArgs e) => { FileDialog fd = new FileDialog(v.Context, _Extensions, false); fd.DialogComplete += (object s, FileDialog.FileDialogEventArgs ea) => { string name = ea.Filename; if (!name.EndsWith(".cmpt", StringComparison.CurrentCultureIgnoreCase)) { name = name + ".cmpt"; } string fullname = Path.Combine(fd.Folder, name); XmlListLoader <Character> .Save(new List <Character>(_CombatState.Characters.Where((a) => a.IsMonster == monsters)), fullname); }; fd.Show(); }; cl.FindViewById <Button>(Resource.Id.clearButton).Click += (object sender, EventArgs e) => { AlertDialog.Builder bui = new AlertDialog.Builder(v.Context); bui.SetMessage("Clear " + (monsters?"Monsters":"Players") + " List?"); bui.SetPositiveButton("OK", (a, x) => { List <Character> removeList = new List <Character>(from c in _CombatState.Characters where c.IsMonster == monsters select c); foreach (Character c in removeList) { _CombatState.RemoveCharacter(c); } }); bui.SetNegativeButton("Cancel", (a, x) => {}); bui.Show(); }; if (monsters) { _XPText = cl.FindViewById <TextView>(Resource.Id.xpText); ReloadXPText(); } v.FindViewById <LinearLayout>(id).AddView(cl); }