public void RenderNormalDialog(float x, float y, Vector4 color) { GL.DepthFunc(DepthFunction.Always); OrthoRenderEngine.DrawExtendedColoredTexturedBox(TextureCollection.DialogBG, color, x - 16, y - 16, Writer.Width + 32, Writer.Height + 32); OrthoRenderEngine.DrawTexturedBox(Writer.GetTextureID(), x, y, Writer.Width, Writer.Height); GL.DepthFunc(DepthFunction.Lequal); }
public void Init() { Console.WriteLine("GL version: " + GL.GetString(StringName.Version)); TextureCollection.Load(); MeshCollection.Load(); BasicShader.MakeInstance(); ForAmbientShader.MakeInstance(); ForDirectionalShader.MakeInstance(); ForShadowDirShader.MakeInstance(); ForPointShader.MakeInstance(); ShadowGenShader.MakeInstance(); ColorShader.MakeInstance(); TextureShader.MakeInstance(); LiquidShader.MakeInstance(new Texture(Util.PATH + "res/textures/liquid.png")); BladeShader.MakeInstance(); OrthoRenderEngine.Init(); TooltipHelper = new TooltipHelper(); ErrortipHelper = new ErrorTooltipHelper(); Localization.LoadFromFile(Util.PATH + "res/localization/no_NO.txt"); MainMenu = new MainMenuView(this); PauseMenu = new PauseMenuView(this); CurrentScene = MakeMenuScene(); CurrentView = MainMenu; CurrentView.OnViewUsed(null); }
public void HandleInput() { int pressedBox = -1; if (Input.OrthoMouseX <OrthoRenderEngine.GetCanvasWidth() - overscan& Input.OrthoMouseX> OrthoRenderEngine.GetCanvasWidth() - iconSize - overscan & Input.OrthoMouseY <OrthoRenderEngine.GetCanvasHeight() - overscan& Input.OrthoMouseY> OrthoRenderEngine.GetCanvasHeight() - iconSize * SIZE - overscan) { hoveredBox = (int)((OrthoRenderEngine.GetCanvasHeight() - Input.OrthoMouseY - overscan) / iconSize); } else { hoveredBox = -1; } if (Input.PressedItemKey != -1) { pressedBox = Input.PressedItemKey; } else if (Input.MousePressed && hoveredBox > -1) { pressedBox = hoveredBox; } int usedBox = pressedBox == -1 ? hoveredBox : pressedBox; if (usedBox == -1) { hoveredItem = -1; return; } uint box = 0; int index = 0; for (; index < GetItemAmount(); index++) { box += GetItem(index).GetSize(); if (box > usedBox) { break; } } int usedItem = (index < GetItemAmount()) ? index : -1; if (pressedBox != -1) { if (selectedItem == usedItem) { selectedItem = -1; } else { selectedItem = usedItem; } } else { hoveredItem = usedItem; } }
public void RenderView(Matrix4 VP, Scene s) { if (PrevView != null) { PrevView.RenderView(VP, s); } OrthoRenderEngine.DrawColorOnEntireScreen(gradiantColor); OrthoRenderEngine.DrawColoredBox(Vector4.UnitW, barXPos, 0, barWidth, OrthoRenderEngine.GetCanvasHeight()); float maxY = OrthoRenderEngine.GetCanvasHeight() * 0.55f; float x = Input.OrthoMouseX - barXPos; float y = maxY + optionHeight - Input.OrthoMouseY; if (x > 0 & x < barWidth & y > 0 & y < writers.Length * optionHeight) { hovering = (int)y / optionHeight; } else { hovering = -1; } for (int i = 0; i < writers.Length; i++) { OrthoRenderEngine.DrawColoredTexturedBox(hovering == i ? Util.White : Util.White60, writers[i].GetTextureID(), barXPos, maxY - optionHeight * i, writers[i].Width, writers[i].Height); } }
public override void RenderItem(float x, float y, float width, float height) { BladeShader Instance = BladeShader.Instance; Instance.Bind(); Instance.SetMVP(OrthoRenderEngine.GetMVPForMesh(Type.CenteredScaledMeshMatirx * ItemMatrix, x + 4, y + 4, width - 8, height - 8)); Instance.SetModelspaceMatrix(OrthoRenderEngine.DefaultModelspace); Instance.SetColor(KnownMetal.GetColor(Metal)); Instance.SetMaps(sharpnessMap); Type.Mesh.Draw(); }
public void Render() { if (Time.CurrentTime() > time) { return; } GL.DepthFunc(DepthFunction.Always); OrthoRenderEngine.DrawExtendedColoredTexturedBox(TextureCollection.DialogBG, Util.LightRed60, x - 16, y - 16, Writer.Width + 32, Writer.Height + 32); OrthoRenderEngine.DrawTexturedBox(Writer.GetTextureID(), x, y, Writer.Width, Writer.Height); GL.DepthFunc(DepthFunction.Lequal); }
public void RenderView(Matrix4 VP, Scene s) { Inventory playerInv = game.GameStats.PlayerInventory; playerInv.Render(game); if (!transition.IsDone()) { return; } HatchInventory hatchInv = game.GameStats.HatchInv; float x = inventoryXPos; float y = inventoryYPos; OrthoRenderEngine.DrawTexturedBox(TextureCollection.Button, x, y, iconSize * iconsPerRow, iconSize * iconsPerRow, 0, 0, iconsPerRow, iconsPerRow); float itemX = 0; float itemY = 0; for (int i = 0; i < hatchInv.GetItemAmount(); i++) { Item item = hatchInv.GetItem(i); if (itemY + item.GetSize() > iconsPerRow) { itemY = 0; itemX++; if (itemX >= iconsPerRow) { } //TODO add multiple pages or something } item.RenderItem(x + itemX * iconSize, y + itemY * iconSize, iconSize, iconSize * item.GetSize()); itemY += item.GetSize(); } if (hoveredItem >= 0 & hoveredItem < hatchInv.GetItemAmount()) { Item item = hatchInv.GetItem(hoveredItem); game.TooltipHelper.ClaimIfPossible(this); if (game.TooltipHelper.GetOwner() == this) { game.TooltipHelper.RenderItemTooltip(item, Input.OrthoMouseX - 30, Input.OrthoMouseY); } } else if (game.TooltipHelper.GetOwner() == this) { game.TooltipHelper.UnClaim(); } }
public void Render(Smith2DGame game) { var cW = OrthoRenderEngine.GetCanvasWidth(); var cH = OrthoRenderEngine.GetCanvasHeight(); uint l = 0; for (int i = 0; i < GetItemAmount(); i++) { Item item = GetItem(i); Vector4 boxColor = i == selectedItem ? selected : Util.White; OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Button, cW - iconSize - overscan, cH - iconSize * (l + 0.5f) - overscan, iconSize, iconSize / 2, 0, 0, 1, 0.5f); OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Numbers, cW - iconSize - overscan + 2, cH - iconSize * l - overscan - 12, 10, 10, l / 4f, 0, 0.25f, 1); uint oldL = l; for (l++; l < oldL + item.GetSize(); l++) { OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Button, cW - iconSize - overscan, cH - iconSize * l - overscan, iconSize, iconSize / 2, 0, 0.25f, 1, 0.5f); OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Button, cW - iconSize - overscan, cH - iconSize * (l + 0.5f) - overscan, iconSize, iconSize / 2, 0, 0.25f, 1, 0.5f); } OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Button, cW - iconSize - overscan, cH - iconSize * l - overscan, iconSize, iconSize / 2, 0, 0.5f, 1, 0.5f); float bob = i == selectedItem ? (float)Math.Sin(Time.CurrentTime() * 5) * 4 + 2 : 0; item.RenderItem(cW - iconSize - overscan - bob, cH - iconSize * l - overscan - bob, iconSize + bob * 2, iconSize * item.GetSize() + bob * 2); } for (uint i = l; i < Inventory.SIZE; i++) { OrthoRenderEngine.DrawTexturedBox(TextureCollection.Button, cW - iconSize - 20, cH - iconSize * (i + 1) - 20, iconSize, iconSize, 0, 0, 1, 1); OrthoRenderEngine.DrawTexturedBox(TextureCollection.Numbers, cW - iconSize - 20 + 2, cH - iconSize * i - 20 - 12, 10, 10, i / 4f, 0, 0.25f, 1); } if (hoveredItem > -1 & hoveredItem < items.Count && items [hoveredItem] != null) { game.TooltipHelper.ClaimIfPossible(this); if (game.TooltipHelper.GetOwner() == this) { game.TooltipHelper.RenderItemTooltip(items [hoveredItem], OrthoRenderEngine.GetCanvasWidth() - overscan - iconSize - 32, Input.OrthoMouseY); } } else if (game.TooltipHelper.GetOwner() == this) { game.TooltipHelper.UnClaim(); } if (tooFull) { game.ErrortipHelper.ShowError(Localization.GetLocalization("ui.error.inventoryfull"), OrthoRenderEngine.GetCanvasWidth() - overscan, OrthoRenderEngine.GetCanvasHeight() - overscan - iconSize * SIZE - 32 - 30, 1.5f, true); tooFull = false; } }
public void UpdateView(Scene s) { transition.UpdateTransition(Time.Delta() * 2f); if (Input.CloseKeyPressed) { OnTableNotUsed(); game.SetView(parentView); return; } if (Input.InteractKeyPressed | Input.MousePressed & Input.OrthoMouseX > OrthoRenderEngine.GetCanvasWidth() - 300 & Input.OrthoMouseX < OrthoRenderEngine.GetCanvasWidth() - 50 & Input.OrthoMouseY > 50 & Input.OrthoMouseY < 300) { game.SetView(anvil); anvil.OnAnvilUsed(parentView, blade, heat, diamond); OnTableNotUsed(); return; } if (Input.UpKeyPressed & diamond < blade.Type.Points.Length - 1) { diamond++; } else if (Input.DownKeyPressed & diamond >= 0) { diamond--; } if (Input.LeftKey) { panAngle -= (panAngle + 0.4f) * Time.Delta() * 3; } else if (Input.RightKey) { panAngle -= (panAngle - 0.4f) * Time.Delta() * 3; } else { panAngle -= panAngle * Time.Delta() * 3; } for (int i = 0; i < heat.Length; i++) { if (i != diamond & heat [i] > 25) { heat [i] -= Time.Delta() * 200; } else if (heat [i] < 1927) { heat [i] += Time.Delta() * 100; } } }
public void RenderItemTooltip(Item i, float x, float y) { if (i != currentItem) { i.DrawTooltip(Writer); } x -= Writer.Width; y -= Writer.Height / 2; GL.DepthFunc(DepthFunction.Always); OrthoRenderEngine.DrawExtendedColoredTexturedBox(TextureCollection.DialogBG, Util.White60, x - 16, y - 16, Writer.Width + 32, Writer.Height + 32); OrthoRenderEngine.DrawTexturedBox(Writer.GetTextureID(), x, y, Writer.Width, Writer.Height); GL.DepthFunc(DepthFunction.Lequal); currentItem = i; }
public void RenderView(Matrix4 VP, Scene s) { blade.RenderBlade(VP, Pos.X, Pos.Y - (diamond < 0?-0.6f:blade.Type.Points[diamond] * blade.Type.MeshScale), height, Util.PI / 2, heat, GetEyePos()); BasicShader shader = BasicShader.Instance; shader.Bind(); Matrix4 modelspace = Matrix4.CreateTranslation(0, 1, 0) * Matrix4.CreateRotationX(-hammerMove) * Matrix4.CreateTranslation(0, 2.5f + hammerY * hammerMove / 4, 0) * Matrix4.CreateRotationX(0.9f - hammerMove) * Matrix4.CreateRotationZ(0.7f + hammerX * hammerMove / 4) * Matrix4.CreateTranslation(1.9f, -2.4f, height + 1) * Modelspace; shader.SetMVP(modelspace * VP); shader.SetModelspaceMatrix(modelspace); shader.ResetColor(); hammer.Draw(); OrthoRenderEngine.DrawExtendedColoredTexturedBox(TextureCollection.DialogBG, Util.White, 50, 50, 250, 250); OrthoRenderEngine.DrawColoredMesh(table.Mesh, projection, Util.White, 50, 50, 250, 250); OrthoRenderEngine.DrawColoredMesh(table.Coal, projection, Util.White, 50, 50, 250, 250); }
public void OnResize(int width, int height) { GL.Viewport(0, 0, width, height); ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView(fov, width / (float)height, 0.1f, 50); OrthoRenderEngine.OnResize(width, height); }
public void RenderView(Matrix4 VP, Scene s) { blade.RenderBlade(VP, Pos.X + (diamond < 0?-0.6f:blade.Type.Points[diamond] * blade.Type.MeshScale), Pos.Y, height, Util.PI, heat, GetEyePos()); OrthoRenderEngine.DrawExtendedColoredTexturedBox(TextureCollection.DialogBG, Util.White, OrthoRenderEngine.GetCanvasWidth() - 300, 50, 250, 250); OrthoRenderEngine.DrawColoredMesh(anvil.Mesh, projection, Util.White, OrthoRenderEngine.GetCanvasWidth() - 300, 50, 250, 250); }
public static void AddToWindow(GameWindow window) { window.KeyDown += (sender, e) => { if (e.IsRepeat) { return; } switch (e.Key) { case CLOSEKEY: closeKeyBuffered = true; break; case LEFTKEY: LeftKey = true; break; case RIGHTKEY: RightKey = true; break; case UPKEY: UpKey = true; upKeyBuffered = true; break; case DOWNKEY: DownKey = true; downKeyBuffered = true; break; case INTERACTKEY: interactKeyBuffered = true; break; case POURKEY: pourKeyBuffered = true; break; } for (int i = 0; i < ITEMKEYS.Length; i++) { if (e.Key == ITEMKEYS[i]) { bufferedItemKey = i; break; } } }; window.Keyboard.KeyUp += (sender, e) => { switch (e.Key) { case LEFTKEY: LeftKey = false; break; case RIGHTKEY: RightKey = false; break; case UPKEY: UpKey = false; break; case DOWNKEY: DownKey = false; break; default: break; } }; window.Mouse.ButtonDown += (sender, e) => { if (e.Button == MouseButton.Left) { MouseDown = true; mousePressBuffered = true; } else if (e.Button == MouseButton.Right) { interactKeyBuffered = true; } }; window.Mouse.ButtonUp += (sender, e) => { if (e.Button == MouseButton.Left) { MouseDown = false; } }; window.Mouse.Move += (sender, e) => { RelativeMouseX = e.X * 2f / window.Width - 1; RelativeMouseY = e.Y * 2f / window.Height - 1; OrthoMouseX = (float)e.X / window.Width * OrthoRenderEngine.GetCanvasWidth(); OrthoMouseY = (1 - (float)e.Y / window.Height) * OrthoRenderEngine.GetCanvasHeight(); }; }
public override void RenderItem(float x, float y, float width, float height) { OrthoRenderEngine.DrawColoredMesh(MeshCollection.Ingot, ItemMatrix, Metal.Color, x + 4, y + 4, width - 8, height - 8); }
public override void RenderItem(float x, float y, float width, float height) { OrthoRenderEngine.DrawColoredMesh(Info.Mesh, Info.ItemMatrix, Info.Color, x + 4, y + 4, width - 8, height - 8); }
public void UpdateView(Scene s) { transition.UpdateTransition(Time.Delta() * 2); if (Input.CloseKeyPressed) { OnAnvilNotUsed(); game.SetView(parentView); return; } if (Input.InteractKeyPressed | Input.MousePressed & Input.OrthoMouseX > 50 & Input.OrthoMouseX < 300 & Input.OrthoMouseY > 50 & Input.OrthoMouseY < 300) { game.SetView(table); table.OnTableUsed(heat, blade); OnAnvilNotUsed(); return; } for (int i = 0; i < heat.Length; i++) { if (heat[i] > 25) { heat [i] -= Time.Delta() * (i == diamond? 100 : 200); } } if (!hammerDown && Input.MousePressed & hammerMove <0.3f& Input.OrthoMouseX> OrthoRenderEngine.GetCanvasWidth() / 2 - 100 & Input.OrthoMouseX <OrthoRenderEngine.GetCanvasWidth() / 2 + 100 & Input.OrthoMouseY> OrthoRenderEngine.GetCanvasHeight() / 2 - 70 & Input.OrthoMouseY < OrthoRenderEngine.GetCanvasHeight() / 2 + 70) { hammerDown = true; hammerX = Util.NextFloat() - 0.5f; hammerY = Util.NextFloat() - 0.5f; } if (hammerDown) { if (hammerMove < 1) { hammerMove += Time.Delta() * 10; if (hammerMove >= 1) { hammerDown = false; hammerMove = 1; if (diamond >= 0) { blade.Sharpness [diamond] = Math.Min(1, blade.Sharpness [diamond] + KnownMetal.GetRedEmmission(blade.Metal, heat[diamond]) * 0.01f * (1 - blade.Sharpness [diamond])); blade.UpdateSharpnessMap(); } } } } else if (hammerMove > 0) { hammerMove = Math.Max(0, hammerMove - Time.Delta() * 4); } if (Input.LeftKey) { panAngle -= (panAngle + 0.6f) * Time.Delta() * 3; } else if (Input.RightKey) { panAngle -= (panAngle - 0.6f) * Time.Delta() * 3; } else { panAngle -= panAngle * Time.Delta() * 3; } if (Input.DownKey) { panAngleY -= (panAngleY + 0.3f) * Time.Delta() * 3; } else if (Input.UpKey) { panAngleY -= (panAngleY - 0.28f) * Time.Delta() * 3; } else { panAngleY -= panAngleY * Time.Delta() * 3; } }