public AddTypeControler(View.NewType w) { wind = w; if (contAdd()) { string img = wind.icoPath.Text; e = new Model.Type(wind.IDbox.Text, wind.nameBox.Text.Trim(' '), wind.descBox.Text, img); } else { success = false; return; } if (chckTag()) { addTag(); success = true; GlowingEarth.getInstance().getMaster().notifyChange(); return; } else { wind.Error.Content = "Type with this ID already exists"; success = false; return; } }
public AddEtiqControler(View.NewTag w) { wind = w; if (contAdd()) { e = new Etiquette(wind.IDbox.Text, wind.colorp.SelectedColor.ToString(), wind.descBox.Text); } else { success = false; return; } if (chckTag()) { addTag(); success = true; GlowingEarth.getInstance().getMaster().notifyChange(); return; } else { wind.Errl.Content = "Tag with this ID already exists"; success = false; return; } }
public DeleteControler(Model.Etiquette e) { foreach (Model.Etiquette d in GlowingEarth.getInstance().getMaster().getTags()) { if (d.getID().Equals(e.getID())) { GlowingEarth.getInstance().getMaster().getTags().Remove(d); break; } } foreach (Model.Resource r in GlowingEarth.getInstance().getMaster().getResources()) { foreach (Model.Etiquette et in r.getTags()) { if (et.getID().Equals(e.getID())) { r.getTags().Remove(et); break; } } r.setTags(r.getTags()); //Cudna greska bez ovoga -.- } success = true; }
private void IDbox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { String curText = IDbox.Text; bool found = false; foreach (Model.Etiquette r in GlowingEarth.getInstance().getMaster().tags) { if (r.getID().Equals(curText)) { found = true; Error.Content = "Tag with this ID already exists"; IDbox.BorderBrush = System.Windows.Media.Brushes.Red; break; } } if (!found || curText.Equals("")) { BrushConverter bc = new BrushConverter(); IDbox.BorderBrush = (System.Windows.Media.Brush)bc.ConvertFrom("#C7DFFC"); if (Error.Content.Equals("Tag with this ID already exists") || Error.Content.Equals("Invalid ID character")) { Error.Content = ""; } } }
public ModifyControler(View.ResEditor resed) { re = resed; res = makeRes(); if (res != null) { for (int i = 0; i < GlowingEarth.getInstance().getMaster().getResources().Count; i++) { if (res.getMark().Equals(GlowingEarth.getInstance().getMaster().getResources()[i].getMark())) { GlowingEarth.getInstance().getMaster().getResources()[i] = res; break; } } } else { success = false; return; } foreach (Model.MapItem mi in GlowingEarth.getInstance().getMaster().getMapItems()) { if (mi.getID().Equals(res.getMark())) { mi.setName(res.getName()); mi.setPath(res.getIco()); } } success = true; GlowingEarth.getInstance().getMaster().notifyChange(); }
public DeleteProjectControler() { GlowingEarth.getInstance().getMaster().getResources().Clear(); GlowingEarth.getInstance().getMaster().getTypes().Clear(); GlowingEarth.getInstance().getMaster().getTags().Clear(); GlowingEarth.getInstance().getMaster().getMapItems().Clear(); GlowingEarth.getInstance().getMaster().setTitle(GlowingEarth.getInstance().getMaster().getTitle().Replace("*", string.Empty)); }
private void ok_Click(object sender, RoutedEventArgs e) { resC = new Controler.AddRessControler(this); if (resC.getSuccess()) { System.Windows.MessageBox.Show("Resource added successfully!", "Success!", MessageBoxButton.OK); resetWindow(); GlowingEarth.getInstance().getMaster().notifyChange(); } }
private void delete_Click(object sender, RoutedEventArgs e) { MessageBoxResult mbr = System.Windows.MessageBox.Show("Are you sure?", "Confirm Deletion", MessageBoxButton.YesNo); if (mbr == MessageBoxResult.Yes) { Controler.DeleteControler dc = new Controler.DeleteControler(_selectedTag); GlowingEarth.getInstance().getMaster().notifyChange(); } }
public LoadProjectControler() { if (GlowingEarth.getInstance().getMaster().getTitle().Contains("*")) { DialogResult dr = MessageBox.Show("Do you want to save changes?", "Save changes", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { OpenFileDialog fid = new OpenFileDialog(); fid.DefaultExt = ".gemap"; fid.Filter = "Glowing Earth Map (*.gemap)|*.gemap"; DialogResult diir = fid.ShowDialog(); if (diir == System.Windows.Forms.DialogResult.OK) { SaveProjectControler spc = new SaveProjectControler(); } } } OpenFileDialog fd = new OpenFileDialog(); fd.DefaultExt = ".gemap"; fd.Filter = "Glowing Earth Map (*.gemap)|*.gemap"; DialogResult dir = fd.ShowDialog(); if (dir == System.Windows.Forms.DialogResult.OK) { path = fd.FileName; BinaryFormatter fm = new BinaryFormatter(); FileStream sm = null; try { sm = File.OpenRead(path); Model.MasterClass x = (Model.MasterClass)fm.Deserialize(sm); GlowingEarth.getInstance().getMaster().setTags(x.getTags()); GlowingEarth.getInstance().getMaster().setTypes(x.getTypes()); GlowingEarth.getInstance().getMaster().setResources(x.getResources()); GlowingEarth.getInstance().getMaster().setTitle(x.getTitle()); GlowingEarth.getInstance().getMaster().setSerPath(x.getSerPath()); GlowingEarth.getInstance().getMaster().setMapItems(x.getMapItems()); ThisWasLastController tc = new ThisWasLastController("save"); } catch (Exception e) { MessageBox.Show("Loading went wrong. Please, try again. If the problem persists, contact your administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (sm != null) { sm.Dispose(); sm.Close(); } } } }
private void delete_Click(object sender, RoutedEventArgs e) { Error.Content = ""; MessageBoxResult mbr = System.Windows.MessageBox.Show("Are you sure you want to delete this type? This could lead to deletion of resources that contain this type.", "Confirm Deletion", MessageBoxButton.YesNo); if (mbr == MessageBoxResult.Yes) { Controler.DeleteControler dec = new Controler.DeleteControler(_selType); GlowingEarth.getInstance().getMaster().notifyChange(); } }
private bool chckRes() { foreach (Model.Resource r in GlowingEarth.getInstance().getMaster().getResources()) { if (res.getMark().Equals(r.getMark())) { return(false); } } return(true); }
public bool chckTag() { foreach (Model.Type t in GlowingEarth.getInstance().getMaster().getTypes()) { if (t.getMark().Equals(e.getMark())) { success = false; return(false); } } return(true); }
public bool chckTag() { foreach (Etiquette t in GlowingEarth.getInstance().getMaster().getTags()) { if (t.getID().Equals(e.getID())) { success = false; return(false); } } return(true); }
private void modify_Click(object sender, RoutedEventArgs e) { Controler.ModifyControler mc = new Controler.ModifyControler(this); if (mc.getSucc()) { System.Windows.MessageBox.Show("Resource modified successfully!", "Success!", MessageBoxButton.OK); GlowingEarth.getInstance().getMaster().notifyChange(); } else { Error.Content = "Something went wrong :("; } }
public ModifyControler(View.TypeEditor resed) { te = resed; if ((type = makeType()) != null) { for (int i = 0; i < GlowingEarth.getInstance().getMaster().getTypes().Count; i++) { if (type.getMark().Equals(GlowingEarth.getInstance().getMaster().getTypes()[i].getMark())) { GlowingEarth.getInstance().getMaster().getTypes()[i] = type; break; } } } else { success = false; return; } GlowingEarth.getInstance().itemList.Items.Refresh(); ObservableCollection <Model.Resource> temp = GlowingEarth.getInstance().getMaster().getResources(); for (int i = 0; i < temp.Count; i++) { if (GlowingEarth.getInstance().getMaster().getResources()[i].getType().getMark().Equals(type.getMark())) { Model.Resource r = temp[i]; r.setType(type); if (r.getHasTypeImg()) { r.setIcon(type.getImg()); } ObservableCollection <Model.MapItem> mapitems = GlowingEarth.getInstance().getMaster().getMapItems(); for (int j = 0; j < mapitems.Count; j++) { if (mapitems[j].getID().Equals(r.getMark())) { mapitems[j].setPath(r.getIco()); } } GlowingEarth.getInstance().getMaster().setMapItems(mapitems); } } GlowingEarth.getInstance().getMaster().setResources(temp); success = true; GlowingEarth.getInstance().map.Items.Refresh(); GlowingEarth.getInstance().getMaster().notifyChange(); }
public SaveProjectAsControler() { SaveFileDialog fd = new SaveFileDialog(); fd.DefaultExt = ".gemap"; fd.Filter = "Glowing Earth Map (*.gemap)|*.gemap"; DialogResult dr = fd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { GlowingEarth.getInstance().getMaster().setSerPath(fd.FileName); saveProject(fd.FileName); } }
private void ok_Click(object sender, RoutedEventArgs e) { if (cont()) { ec = new Controler.AddEtiqControler(this); if (ec.getSuccess()) { System.Windows.MessageBox.Show("Tag added successfully!", "Success!", MessageBoxButton.OK); IDbox.Text = ""; descBox.Text = ""; Errl.Content = ""; GlowingEarth.getInstance().getMaster().notifyChange(); } } }
private void modify_Click(object sender, RoutedEventArgs e) { Controler.ModifyControler mc = new Controler.ModifyControler(this); if (mc.getSucc()) { for (int i = 0; i < copy.Count; i++) { if (copy[i].getMark().Equals(mc.getRes().getMark())) { copy[i] = mc.getRes(); res[i] = mc.getRes(); break; } } System.Windows.MessageBox.Show("Resource modified successfully!", "Success!", MessageBoxButton.OK); Error.Content = ""; } GlowingEarth.getInstance().getMaster().notifyChange(); }
/*KRAJ VALIDACIJE PRICEBOXA*/ private void typeBox_Copy_SelectionChanged(object sender, SelectionChangedEventArgs e) { ObservableCollection <Model.Resource> resez = new ObservableCollection <Model.Resource>(); _selectedResource = null; picpath = ""; filt = (Model.Type)filter.SelectedItem; if (filt != null && (searchBox.Text.Equals("") || searchBox.Text.Equals("Search for resources..."))) { foreach (Model.Resource r in GlowingEarth.getInstance().getMaster().getResources()) { if (r.getType().getMark().Equals(filt.getMark())) { resez.Add(r); } } res.Clear(); foreach (Model.Resource r in resez) { res.Add(r); } } else if (filt != null && !(searchBox.Text.Equals("") || searchBox.Text.Equals("Search for resources..."))) { foreach (Model.Resource r in GlowingEarth.getInstance().getMaster().getResources()) { if (r.getType().getMark().Equals(filt.getMark()) && r.getMark().Equals(searchBox.Text)) { resez.Add(r); } } res.Clear(); foreach (Model.Resource r in resez) { res.Add(r); } } else { restartResez(); } }
public NewProjectControler(string name) { if (GlowingEarth.getInstance().getMaster().getTitle().Contains("*")) { if (MessageBox.Show("You have some unsaved changes on current map. Do you want to save those changes?", "Save changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes) { SaveFileDialog fd = new SaveFileDialog(); fd.DefaultExt = ".gemap"; fd.Filter = "Glowing Earth Map (*.gemap)|*.gemap"; DialogResult dr = fd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { GlowingEarth.getInstance().getMaster().setSerPath(fd.FileName); saveProject(fd.FileName); } } } projName = "Glowing Earth - " + name; GlowingEarth.getInstance().getMaster().getResources().Clear(); GlowingEarth.getInstance().getMaster().getTypes().Clear(); GlowingEarth.getInstance().getMaster().getTags().Clear(); GlowingEarth.getInstance().getMaster().getMapItems().Clear(); GlowingEarth.getInstance().getMaster().setTitle(projName); if (MessageBox.Show("To see this project next time you open Glowing Earth, you should save this project.\nDo you want to save this project?", "Save new project", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { SaveFileDialog fd = new SaveFileDialog(); fd.DefaultExt = ".gemap"; fd.Filter = "Glowing Earth Map (*.gemap)|*.gemap"; DialogResult dr = fd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { GlowingEarth.getInstance().getMaster().setSerPath(fd.FileName); saveProject(fd.FileName); ThisWasLastController tc = new ThisWasLastController("save"); } } }
public DeleteControler(Model.Resource r) { foreach (Model.Resource d in GlowingEarth.getInstance().getMaster().getResources()) { if (d.getMark().Equals(r.getMark())) { GlowingEarth.getInstance().getMaster().getResources().Remove(d); break; } } ObservableCollection <Model.MapItem> mati = new ObservableCollection <Model.MapItem>(); foreach (Model.MapItem mi in GlowingEarth.getInstance().getMaster().getMapItems()) { if (!mi.getID().Equals(r.getMark())) { mati.Add(mi); } } GlowingEarth.getInstance().getMaster().setMapItems(mati); success = true; }
public bool saveProject(string path) { BinaryFormatter fm = new BinaryFormatter(); FileStream sm = null; try { sm = File.OpenWrite(path); fm.Serialize(sm, GlowingEarth.getInstance().getMaster()); GlowingEarth.getInstance().getMaster().setTitle(GlowingEarth.getInstance().getMaster().getTitle().Replace("*", string.Empty)); sm.Dispose(); sm.Close(); return(true); } catch (Exception e) { MessageBox.Show("Saving went wrong. Please, try again. If the problem persists, contact your administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine(e.StackTrace); sm.Dispose(); sm.Close(); return(false); } }
public void save() { BinaryFormatter fm = new BinaryFormatter(); FileStream sm = null; try { sm = File.OpenWrite(path); fm.Serialize(sm, GlowingEarth.getInstance().getMaster().getSerPath()); } catch (Exception e) { Console.WriteLine(e.StackTrace); } finally { if (sm != null) { sm.Dispose(); sm.Close(); } } }
public DeleteControler(Model.Type e) { foreach (Model.Type d in GlowingEarth.getInstance().getMaster().getTypes()) { if (d.getMark().Equals(e.getMark())) { GlowingEarth.getInstance().getMaster().getTypes().Remove(d); break; } } ObservableCollection <Model.Resource> temp = new ObservableCollection <Model.Resource>(); foreach (Model.Resource r in GlowingEarth.getInstance().getMaster().resources) { temp.Add(r); } for (int i = 0; i < temp.Count; i++) { if (e.getMark().Equals(temp[i].getType().getMark())) { Model.Resource rz = temp[i]; ObservableCollection <Model.MapItem> mati = new ObservableCollection <Model.MapItem>(); foreach (Model.MapItem mi in GlowingEarth.getInstance().getMaster().getMapItems()) { if (!mi.getID().Equals(rz.getMark())) { mati.Add(mi); } } GlowingEarth.getInstance().getMaster().setMapItems(mati); GlowingEarth.getInstance().getMaster().getResources().Remove(temp[i]); } } success = true; }
public ModifyControler(View.TagEditor resed) { tage = resed; if ((tag = makeTag()) != null) { for (int i = 0; i < GlowingEarth.getInstance().getMaster().getTags().Count; i++) { if (tag.getID().Equals(GlowingEarth.getInstance().getMaster().getTags()[i].getID())) { GlowingEarth.getInstance().getMaster().getTags()[i] = tag; break; } } } else { success = false; return; } foreach (Model.Resource r in GlowingEarth.getInstance().getMaster().getResources()) { List <Model.Etiquette> temp = r.getTags(); int j = 0; foreach (Model.Etiquette et in temp) { if (et.getID().Equals(tag.getID())) { temp[j] = tag; break; } j++; } r.setTags(temp); } success = true; GlowingEarth.getInstance().getMaster().notifyChange(); }
public AddRessControler(View.NewRes refer) { wind = refer; res = new Resource(); if (contAdd()) { foreach (Model.Etiquette b in wind.tagovi) { if (b.isPartOfRes) { res.taglist.Add(b); } } res.setName(wind.nameBox.Text.Trim(' ')); res.setMark(wind.IDBox.Text); res.setDesc(wind.descBox.Text); if (wind.radioFreq.IsChecked == true) { res.setFreq(Resource.FreqType.FREQUENT); } else if (wind.radioRare.IsChecked == true) { res.setFreq(Resource.FreqType.RARE); } else if (wind.radioUniv.IsChecked == true) { res.setFreq(Resource.FreqType.UNIVERSAL); } res.setType((Model.Type)wind.typeBox.SelectedItem); res.setPrice(Double.Parse(wind.priceBox.Text)); if (wind.radioScoop.IsChecked == true) { res.setUnit(Resource.Units.SCOOP); } else if (wind.radioBarrel.IsChecked == true) { res.setUnit(Resource.Units.BAREL); } else if (wind.radioT.IsChecked == true) { res.setUnit(Resource.Units.T); } else if (wind.radioKG.IsChecked == true) { res.setUnit(Resource.Units.KG); } res.setOb(wind.ren.IsChecked.Value); res.setStr(wind.Strt.IsChecked.Value); res.setExp(wind.exp.IsChecked.Value); res.setDate(wind.Date.SelectedDate.Value); if (wind.icoPath.Text.Equals("")) { res.setIcon(res.getType().getImg()); res.setHasTypeImg(true); } else { res.setIcon(wind.icoPath.Text); res.setHasTypeImg(false); } } else { success = false; return; } //Resource created <----------------------------------- if (chckRes()) { addRes(); GlowingEarth.getInstance().getMaster().notifyChange(); success = true; } else { wind.Error.Content = "Resource with this ID already exists"; success = false; } }
public void addTag() { GlowingEarth.getInstance().getMaster().getTags().Add(e); success = true; }
private void addRes() { GlowingEarth.getInstance().getMaster().getResources().Add(res); }
public void addTag() { GlowingEarth.getInstance().getMaster().types.Add(e); }
public Model.Resource makeRes() { res = new Model.Resource(); if (contAddRes()) { res.setName(re.nameBox.Text.Trim(' ')); res.setMark(re.IDBox.Text); res.setDesc(re.descBox.Text); if (re.radioFreq.IsChecked == true) { res.setFreq(Model.Resource.FreqType.FREQUENT); } else if (re.radioRare.IsChecked == true) { res.setFreq(Model.Resource.FreqType.RARE); } else if (re.radioUniv.IsChecked == true) { res.setFreq(Model.Resource.FreqType.UNIVERSAL); } res.setType((Model.Type)re.typeBox.SelectedItem); res.setPrice(Double.Parse(re.priceBox.Text)); if (re.radioScoop.IsChecked == true) { res.setUnit(Model.Resource.Units.SCOOP); } else if (re.radioBarrel.IsChecked == true) { res.setUnit(Model.Resource.Units.BAREL); } else if (re.radioT.IsChecked == true) { res.setUnit(Model.Resource.Units.T); } else if (re.radioKG.IsChecked == true) { res.setUnit(Model.Resource.Units.KG); } res.setOb(re.ren.IsChecked.Value); res.setStr(re.Strt.IsChecked.Value); res.setExp(re.exp.IsChecked.Value); res.setDate(re.Date.SelectedDate.Value); res.setHasTypeImg(re.selectedResource.getHasTypeImg()); bool this_is_type = false; foreach (Model.Type t in re.types) { if (t.getImg().Equals(re.picpath)) { this_is_type = true; break; } } if (re.icoPath.Text.Equals("") || (res.getHasTypeImg())) { bool novo = false; foreach (Model.Type t in GlowingEarth.getInstance().getMaster().types) { String path = t.getImg(); if ((path.Equals(((Model.Type)re.typeBox.SelectedItem).getImg()) || path.Equals("")) && this_is_type) { res.setIcon(res.getType().getImg()); res.setHasTypeImg(true); novo = true; break; } } if (!novo) { res.setIcon(re.icoPath.Text); res.setHasTypeImg(false); } } else { res.setIcon(re.icoPath.Text); res.setHasTypeImg(false); } bool dontModify = true; List <Model.Etiquette> et = new List <Model.Etiquette>(); foreach (Model.Etiquette e in re.tags) { if (e.isPartOfRes) { dontModify = false; et.Add(e); } } bool dontAdd = false; if (!dontModify) { foreach (Model.Etiquette e in GlowingEarth.getInstance().getMaster().getTags()) { if (e.isPartOfRes) { List <Model.Etiquette> etz = re.selectedResource.getTags(); foreach (Model.Etiquette z in etz) { if (z.getID().Equals(e.getID())) { dontAdd = true; break; } } if (!dontAdd) { et.Add(e); } } } res.setTags(et); } } else { success = false; return(null); } return(res); }