protected override void LoadContent() { _inited = true; if (_mainView == null) { return; } _drawBatch = new AdvancedDrawBatch(GraphicsDevice); ContentLoading?.Invoke(this); IDefinitionClass obj = _mainView.CreateInstance(null, null); MainView = (UiContainer)obj; MainView.RecalculateAll(); MainView.RegisterView(); MainView.ViewAdded(); ViewLoaded?.Invoke(this); MainView.Bounds = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); }
/// <summary> /// Loads <see cref="Animation"/> from package /// </summary> /// <param name="name">Name of <see cref="Animation"/></param> /// <returns><see cref="Animation"/></returns> public Animation LoadAnimation(string name) { ContentLoading?.Invoke(this, new ContentLoadingEventArgs() { ContentFileName = name, ContentType = ContentType.Animation, PackageName = this.PackageName }); try { Texture texture = LoadTexture(name, TextureLayout.Stretch); using (ZipFile pak = ZipFile.Read(PackagePath)) { MemoryStream ms = new MemoryStream(); ms.Position = 0; pak[name + ".amd"].Extract(ms); byte[] raw = ms.ToArray(); string[] animationMetadata = Encoding.Default.GetString(raw).Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); int animFrmDuration = 0; int animFrmCount = 0; int frameWidth = 0; foreach (var ln in animationMetadata) { string[] split = ln.Split('='); switch (split[0].ToLower()) { case "frameticktrigger": if (!int.TryParse(split[1], out animFrmDuration)) { throw new ContentLoadException("Unable to load animation metadata of " + name + " from " + this.PackageName + "! Invalid metadata parameter value: \"" + split[0] + "=" + split[1] + "\" must be numerical Int32 value"); } break; case "framecount": if (!int.TryParse(split[1], out animFrmCount)) { throw new ContentLoadException("Unable to load animation metadata of " + name + " from " + this.PackageName + "! Invalid metadata parameter value: \"" + split[0] + "=" + split[1] + "\" must be numerical Int32 value"); } break; case "framewidth": if (!int.TryParse(split[1], out frameWidth)) { throw new ContentLoadException("Unable to load animation metadata of " + name + " from " + this.PackageName + "! Invalid metadata parameter value: \"" + split[0] + "=" + split[1] + "\" must be numerical Int32 value"); } break; } } Animation animation = new Animation(texture, animFrmCount, animFrmDuration, frameWidth); return(animation); } } catch (Exception ex) { throw new ContentLoadException("Unable to load \"" + name + "\" animation from " + this.PackageName + "! Inner exception message: " + ex.Message, ex); } }
public Font LoadFont(string name, float fontSize) { ContentLoading?.Invoke(this, new ContentLoadingEventArgs() { ContentFileName = name, ContentType = ContentType.Font, PackageName = this.PackageName }); try { //byte[] fontDataRaw = pak.ReadBytes(name + ".fnt"); //FontFamily fml = FontFromBytesConverter.FontFamilyFromBytes(fontDataRaw); //Font font = new Font(fml, fontSize); //return font; throw new NotImplementedException("Font loading from packages currently broken! Please create issue on GitHub if you want to help to fix this"); } catch (Exception ex) { throw new ContentLoadException("Unable to load \"" + name + "\" font from " + this.PackageName + "! Inner exception message: " + ex.Message, ex); } }
public int crimeCity(string city, string state) { city = UppercaseFirst(city); //Check for format state = UppercaseFirst(state); //Check for format RootObject agencyObject = JsonConvert.DeserializeObject <RootObject>(ContentLoading.GetJsonContent()); int size = agencyObject.agency.Count; string ori = agencyObject.agency[0].ori; for (int i = 0; i < size; i++)//Find ORI number for City and State { if (agencyObject.agency[i].agency == city) { if (agencyObject.agency[i].state == state) { ori = agencyObject.agency[i].ori; i = size; } } } string url1 = "https://api.usa.gov/crime/fbi/sapi/api/summarized/agencies/" + ori; string url2 = "/offenses/2017/2017?api_key=" + cdeKey; string url = String.Concat(url1, url2); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);//Querey CDE database according to ORI number WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader sreader = new StreamReader(dataStream); string responsereader = sreader.ReadToEnd(); response.Close(); //Use algorithim to compare Violent crime to property crime and homicides CrimeObject crimeobject = JsonConvert.DeserializeObject <CrimeObject>(responsereader); int violent = crimeobject.results[11].actual; int property = crimeobject.results[7].actual; int homicide = crimeobject.results[3].actual; float rate = (float)violent / (float)property; rate = rate + (((float)homicide / (float)violent) * 2); rate = rate * 100; return((int)rate); }
/// <summary> /// Loads <see cref="Texture"/> from package /// </summary> /// <param name="name">Name of <see cref="Texture"/></param> /// <param name="textureLayout">Layout of texture</param> /// <returns><see cref="Texture"/></returns> public Texture LoadTexture(string name, TextureLayout textureLayout) { ContentLoading?.Invoke(this, new ContentLoadingEventArgs() { ContentFileName = name, ContentType = ContentType.Texture, PackageName = this.PackageName }); try { using (ZipFile pak = ZipFile.Read(PackagePath)) { MemoryStream ms = new MemoryStream(); ms.Position = 0; pak[name + ".tex"].Extract(ms); Texture tex = new Texture(Image.FromStream(ms), textureLayout); return(tex); } } catch (Exception ex) { throw new ContentLoadException("Unable to load \"" + name + "\" texture from " + this.PackageName + "! Inner exception message: " + ex.Message, ex); } }
/// <summary> /// Loads <see cref="String"/> array of lines from package /// </summary> /// <param name="name">Name of strings file</param> /// <returns><see cref="string"/> array</returns> public string[] LoadStrings(string name) { ContentLoading?.Invoke(this, new ContentLoadingEventArgs() { ContentFileName = name, ContentType = ContentType.Strings, PackageName = this.PackageName }); try { using (ZipFile pak = ZipFile.Read(PackagePath)) { MemoryStream ms = new MemoryStream(); ms.Position = 0; pak[name + ".strings"].Extract(ms); byte[] raw = ms.ToArray(); string[] outputStrings = Encoding.Default.GetString(raw).Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); return(outputStrings); } } catch (Exception ex) { throw new ContentLoadException("Unable to load \"" + name + "\" strings from " + this.PackageName + "! Inner exception message: " + ex.Message, ex); } }
/// <summary> /// Loads <see cref="Audio"/> from package /// </summary> /// <param name="name">Name of <see cref="Audio"/></param> /// <returns><see cref="Audio"/></returns> public Audio LoadAudio(string name) { ContentLoading?.Invoke(this, new ContentLoadingEventArgs() { ContentFileName = name, ContentType = ContentType.Audio, PackageName = this.PackageName }); try { using (ZipFile pak = ZipFile.Read(PackagePath)) { MemoryStream ms = new MemoryStream(); ms.Position = 0; pak[name + ".wad"].Extract(ms); byte[] raw = ms.ToArray(); Audio audio = new Audio(WaveFileReaderFromBytesConverter.ByteArrayToWaveFileReader(raw)); return(audio); } } catch (Exception ex) { throw new ContentLoadException("Unable to load \"" + name + "\" audio from " + this.PackageName + "! Inner exception message: " + ex.Message, ex); } }
private void doneButton_Click(object sender, System.EventArgs e) { ContentLoading.LoadScreen(MainFormStateSingleton.Instance.LastLoadedScreen); }
private void OnBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e) { NavigationStarting?.Invoke(sender, e); ContentLoading?.Invoke(sender, e); }
/// <summary> /// To Check the seat availability on the dates for no of pax /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="pax"></param> /// <returns></returns> public bool CheckAvailability(DateTime start, DateTime end, int pax) { if (!CheckDataValidity(start, end, pax)) { return(false); } FlightData flightData = new FlightData(); string inputData = ContentLoading.GetFlightDataContent(); try { flightData = JsonConvert.DeserializeObject <FlightData>(inputData); } catch (Exception e) { _errors.Add($"Fattle error in Data extraction. Exception {e.InnerException}"); return(false); } var isFlightOperatesOnStartDate = IsFlightOperatesOnDate(start, flightData); if (!isFlightOperatesOnStartDate) { _errors.Add($"There are no service on Start date: {start.ToShortDateString()} or End date: {end.ToShortDateString()}"); return(false); } var isFlightOperatesOnEndDate = IsFlightOperatesOnDate(end, flightData); if (!isFlightOperatesOnEndDate) { _errors.Add($"There are no service on End date: {end.ToShortDateString()}"); return(false); } AvailableSeats(start, flightData, out int outAvailable, out int inAvailable); if (outAvailable == 0) { _errors.Add($"There are no seats available on Start date: {start.ToShortDateString()}"); return(false); } AvailableSeats(end, flightData, out int outAvailableEnd, out int inAvailableEnd); if (inAvailableEnd == 0) { _errors.Add($"There are no seats available on End date: {end.ToShortDateString()}"); return(false); } if (pax > outAvailable) { _errors.Add($"On start date: {start.ToShortDateString()}, Only available seats are {outAvailable}, but you are looking for {pax}."); return(false); } if (pax > inAvailableEnd) { _errors.Add($"On end date: {end.ToShortDateString()}, Only available seats are {inAvailableEnd}, but you are looking for {pax}."); return(false); } return(true); }