/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (fEngine.InputManager.KeyPressed(Keys.P)) { fEngine.UpdatePaused = !fEngine.UpdatePaused; } if (fEngine.InputManager.KeyPressed(Keys.M)) { fEngine.ToggleFullscreen(); } fLabelDisplayMode.Text = $"Mode={fEngine.DisplayMode}"; fAdapterSize.Text = $"Adapter={fEngine.AdapterSize.Width}x{fEngine.AdapterSize.Height}"; fWindowSize.Text = $"Window={fEngine.WindowSize.Width}x{fEngine.WindowSize.Height}"; fAspectRatio.Text = $"AspectRatio={fEngine.AspectRatio}"; fFPS.Text = $"FPS={fEngine.FPS.FrameRate}"; fInfo.Text = $"Lines={fLines.Lines}"; if (fEngine.MouseOverElement == null) { fCurrentElement.Text = "..."; } else { GuiElement element = fEngine.MouseOverElement; string name = String.Empty; bool isFirst = true; while (element != null) { if (!isFirst) { name = name + "/"; } isFirst = false; string n = element.GetType().Name; if (n.StartsWith("Gui")) { name = name + n.Substring(3); } else { name = name + n; } element = element.Parent; } fCurrentElement.Text = name; } //fAngle = Convert.ToSingle(PI2 * gameTime.TotalGameTime.TotalSeconds * 0.1f); fAngle += Convert.ToSingle(gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f); base.Update(gameTime); }
public static GuiElement Get(dynamic control) { if (control is NullExceptionPreventer) { return(null); } GuiElement guiElement = null; if (control.Type is NullExceptionPreventer) { throw new ArgumentException("Type of control is not defined in control Layout"); } Type T = Assembly.Load("CGui").GetTypes().First(t => t.Name == control.Type); if (typeof(GuiElement).IsAssignableFrom(T)) { if (T.ContainsGenericParameters) { Type X = Assembly.GetCallingAssembly().GetTypes().First(t => t.Name == control.ItemType); Type Y = T.MakeGenericType(X); guiElement = Activator.CreateInstance(Y, new object[] { }) as GuiElement; } else { guiElement = Activator.CreateInstance(T, new object[] { }) as GuiElement; } foreach (var propertyName in control.Keys) { if (propertyName == "Type") { continue; } PropertyInfo prop = guiElement.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance); if (null != prop && prop.CanWrite) { if (prop.PropertyType == typeof(ConsoleColor)) { prop.SetValue(guiElement, Configuration.GetColor(control[propertyName]), null); } else { prop.SetValue(guiElement, Convert.ChangeType(control[propertyName], prop.PropertyType), null); } } } } return(guiElement); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { fCamera.Update(gameTime); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (fEngine.InputManager.KeyPressed(Keys.P)) { fEngine.UpdatePaused = !fEngine.UpdatePaused; } if (fEngine.InputManager.KeyPressed(Keys.M)) { fEngine.ToggleFullscreen(); } fLabelDisplayMode.Text = $"Mode={fEngine.DisplayMode}"; fAdapterSize.Text = $"Adapter={fEngine.AdapterSize.Width}x{fEngine.AdapterSize.Height}"; fWindowSize.Text = $"Window={fEngine.WindowSize.Width}x{fEngine.WindowSize.Height}"; fAspectRatio.Text = $"AspectRatio={fEngine.AspectRatio}"; fFPS.Text = $"FPS={fEngine.FPS.FrameRate}"; int count = fPlane.NumberOfTriangles; foreach (var plane in fPlanes) { count += plane.NumberOfTriangles; } count += fObject1.NumberOfTriangles; fInfo.Text = $"#Triangles={count}"; lblDrawMode.Text = $"Draw Mode = {fDrawMode}"; lblShaderMode.Text = $"Shader Mode = {fShaderMode}"; lblRenderObjects.Text = $"Render Objects = {fRenderObjects}"; if (fEngine.MouseOverElement == null) { fCurrentElement.Text = "..."; } else { GuiElement element = fEngine.MouseOverElement; string name = String.Empty; bool isFirst = true; while (element != null) { if (!isFirst) { name = name + "/"; } isFirst = false; string n = element.GetType().Name; if (n.StartsWith("Gui")) { name = name + n.Substring(3); } else { name = name + n; } element = element.Parent; } fCurrentElement.Text = name; } if (fUpdatePlane) { SetPlane(); } int max = fPlane.Segments; double seconds = gameTime.TotalGameTime.TotalSeconds; for (int x = 0; x <= max; x++) { float nX = 2.0f * (float)x / max - 1.0f;// -1 to +1 for (int z = 0; z <= max; z++) { float nZ = 2.0f * (float)z / max - 1.0f; double r = Math.Sqrt(nX * nX + nZ * nZ); //double y = nX * Math.Cos(r * 12.0f - seconds * 4.2f) + nZ * Math.Sin((r - 0.5) * 3.1f - seconds * 1.9f); double y = Math.Cos(r * 10.0f - seconds * 2.0f) + Math.Sin(r * 10.0f - seconds * 2.1f); float height = 200.0f * (float)y; fPlane.SetHeight(x, z, height); } } fPlane.GenerateNormals(); base.Update(gameTime); }
public static void Draw(GuiElement ds, Context ctx, Rectangle dirtyRect) { switch (ds.GetType().ToString()) { case "Krot.GUI.DrawScript+dsTextLayout": DrawScript.dsTextLayout dtl = (ds as DrawScript.dsTextLayout); ctx.DrawTextLayout(dtl.TextLayout, dtl.Point0); break; case "Krot.GUI.DrawScript+dsSetColor": DrawScript.dsSetColor dsc = ds as DrawScript.dsSetColor; ctx.SetColor(dsc.Colour); break; case "Krot.GUI.DrawScript+dsSetLineWidth": DrawScript.dsSetLineWidth dlw = ds as DrawScript.dsSetLineWidth; ctx.SetLineWidth(dlw.Width); break; case "Krot.GUI.DrawScript+dsSetLineDash": DrawScript.dsSetLineDash dld = ds as DrawScript.dsSetLineDash; ctx.SetLineDash(dld.Offset, dld.Pattern); break; case "Krot.GUI.DrawScript+dsFill": DrawScript.dsFill df = ds as DrawScript.dsFill; if (df.Preserve) { ctx.FillPreserve(); } else { ctx.Fill(); } break; case "Krot.GUI.DrawScript+dsStroke": DrawScript.dsStroke dss = ds as DrawScript.dsStroke; if (dss.Preserve) { ctx.StrokePreserve(); } else { ctx.Stroke(); } break; case "Krot.GUI.DrawScript+dsRectangle": DrawScript.dsRectangle dr = ds as DrawScript.dsRectangle; ctx.Rectangle(dr.Point0, dr.Size.Width, dr.Size.Height); break; case "Krot.GUI.DrawScript+dsRestore": ctx.Restore(); break; default: try { MessageDialog.ShowWarning("Данный тип элемента GUI ещё не поддерживается\n" + ds.GetType().ToString()); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Тип элемента DrawScript {0} не поддерживается!\nНевозможно вывести окно ошибки: {1} в {2}.", ds.GetType().ToString(), ex.GetType().ToString(), ex.Source); Console.ForegroundColor = ConsoleColor.Gray; } throw new NotImplementedException("Данный тип элемента GUI ещё не поддерживается"); } }