private void UpdateMesh() { if (Builder == null || Filter == null || Renderer == null) { return; } Builder.Reset(); Rect internalRect = new Rect(0, 0, 1, 1); Builder.AddQuad(0, 0, 0, 480, 85); // int loc = RemapFromSpell(ActiveSpell); if (loc >= 0) { int spx = loc % 12; int spy = loc / 12; Rect irSpellBlock = Utils.DivRect(new Rect(5 + spx * 38, 5 + spy * 38, 37, 37), new Vector2(SpbFrame.width, SpbFrame.height)); Builder.AddQuad(0, 5 + spx * 38 + 1, 5 + spy * 38 + 1, 37, 37, irSpellBlock, new Color(0.5f, 0.5f, 0.5f, 1)); } for (int i = 0; i < 24; i++) { if ((SpellsMask & (1u << (int)RemapToSpell(i))) != 0) { continue; } int spx = i % 12; int spy = i / 12; Builder.AddQuad(1, 5 + spx * 38 + 1, 5 + spy * 38 + 1, 36, 36); } Builder.CurrentMesh = 1; Filter.mesh = Builder.ToMesh(MeshTopology.Quads, MeshTopology.Quads); }
public void UpdateMesh() { if (Filter.mesh != null && LastWidth == Width && LastHeight == Height && LastClicked == _Clicked && LastChecked == Checked) { return; } LastChecked = Checked; LastClicked = _Clicked; LastWidth = Width; LastHeight = Height; if (Builder == null) { Builder = new Utils.MeshBuilder(); } // Color col_inactive = new Color(1, 1, 1, 1); Color col_active = new Color(1, 1, 1, 0); if (_Clicked) { col_active = new Color(1, 1, 1, 0.5f); } else if (Checked) { col_active = new Color(1, 1, 1, 1); col_inactive = new Color(0, 0, 0, 1); } Builder.AddQuad(0, 0, 0, imgRadiob.Sprites[2].rect.width, imgRadiob.Sprites[2].rect.height, imgRadiob.AtlasRects[2], col_inactive); // disabled Builder.AddQuad(0, 0, 0, imgRadiob.Sprites[3].rect.width, imgRadiob.Sprites[3].rect.height, imgRadiob.AtlasRects[3], col_active); // disabled Filter.mesh = Builder.ToMesh(MeshTopology.Quads); }
public void SetTooltip(string text) { if (Tooltip == null) { TooltipRendererA = new AllodsTextRenderer(Fonts.Font2, Font.Align.Left, 0, 0, false, 12); Tooltip = Utils.CreateObject(); Tooltip.transform.parent = transform; TooltipRenderer = Tooltip.AddComponent <MeshRenderer>(); TooltipFilter = Tooltip.AddComponent <MeshFilter>(); TooltipBall = Images.LoadImage("graphics/interface/ball.bmp", 0, Images.ImageType.AllodsBMP); Material[] materials = new Material[] { new Material(MainCamera.MainShader), new Material(MainCamera.MainShader) }; materials[0].mainTexture = TooltipBall; TooltipRenderer.materials = materials; GameObject TooltipText = TooltipRendererA.GetNewGameObject(0.01f, Tooltip.transform, 100); TooltipRendererA.Material.color = new Color32(165, 121, 49, 255); TooltipText.transform.localPosition = new Vector3(6, 6, -0.02f); } Tooltip.SetActive(true); float topX = lastMouseX; float topY = lastMouseY; text = text.Replace('#', '\n').Replace("~", ""); TooltipRendererA.Text = text; // ideal position for the tooltip is top/right of the mouse. // but if it doesn't fit, should be moved around. topX = lastMouseX; topY = lastMouseY - TooltipRendererA.Height - 12; float fw = TooltipRendererA.ActualWidth + 12; float fh = TooltipRendererA.Height + 12; if (topX + fw > MainCamera.Width) { topX = MainCamera.Width - fw; } if (topY + fh > MainCamera.Height) { topY = MainCamera.Height - fh; } if (topX < 0) { topX = 0; } if (topY < 0) { topY = 0; } Tooltip.transform.localPosition = new Vector3(topX, topY, MainCamera.MouseZ + 0.01f); TooltipBuilder.Reset(); TooltipBuilder.AddQuad(0, 0, 0, 4, 4); TooltipBuilder.AddQuad(0, TooltipRendererA.ActualWidth + 8, 0, 4, 4); TooltipBuilder.AddQuad(0, TooltipRendererA.ActualWidth + 8, TooltipRendererA.Height + 6, 4, 4); TooltipBuilder.AddQuad(0, 0, TooltipRendererA.Height + 6, 4, 4); // now render border quads float bw = TooltipRendererA.ActualWidth + 6; float bh = TooltipRendererA.Height + 6 - 2; // 2 = difference between "LineHeight" and our custom LineHeight of 12 // top border bright TooltipBuilder.CurrentMesh = 1; TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3, 1); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 1); TooltipBuilder.NextVertex(); // top border dark TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 1 + 2); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3, 1 + 2); TooltipBuilder.NextVertex(); // bottom border bright TooltipBuilder.CurrentMesh = 1; TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3, 3 + bh); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 3 + bh); TooltipBuilder.NextVertex(); // bottom border dark TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 3 + bh + 2); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3, 3 + bh + 2); TooltipBuilder.NextVertex(); // left border bright TooltipBuilder.CurrentMesh = 1; TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(1, 3); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(1, 3 + bh); TooltipBuilder.NextVertex(); // left border dark TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(1 + 2, 3 + bh); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(1 + 2, 3); TooltipBuilder.NextVertex(); // right border bright TooltipBuilder.CurrentMesh = 1; TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 3); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 3 + bh); TooltipBuilder.NextVertex(); // right border dark TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw + 2, 3 + bh); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw + 2, 3); TooltipBuilder.NextVertex(); // BACKGROUND QUAD TooltipBuilder.AddQuad(TooltipBuilder.CurrentMesh, 3, 3, bw, bh, new Color32(33, 44, 33, 255)); TooltipFilter.mesh = TooltipBuilder.ToMesh(MeshTopology.Quads, MeshTopology.Quads); }
public void Start() { UiManager.Instance.Subscribe(this); if (InvFrame == null) { InvFrame = Images.LoadImage("graphics/interface/invframe.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow1 == null) { InvArrow1 = Images.LoadImage("graphics/interface/invarrow1.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow2 == null) { InvArrow2 = Images.LoadImage("graphics/interface/invarrow2.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow3 == null) { InvArrow3 = Images.LoadImage("graphics/interface/invarrow3.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow4 == null) { InvArrow4 = Images.LoadImage("graphics/interface/invarrow4.bmp", 0, Images.ImageType.AllodsBMP); } // Renderer = gameObject.AddComponent <MeshRenderer>(); Filter = gameObject.AddComponent <MeshFilter>(); Renderer.materials = new Material[] { new Material(MainCamera.MainShader), new Material(MainCamera.MainShader), new Material(MainCamera.MainShader) }; Renderer.materials[0].mainTexture = InvFrame; Renderer.materials[1].color = Renderer.materials[2].color = new Color(0, 0, 0, 0); // generate mesh. Utils.MeshBuilder mb = new Utils.MeshBuilder(); // 3 submeshes: left arrow, right arrow, and background. I'm NOT using the full original inventory view. for (int i = 0; i < View.InvWidth; i++) { int internalPosition; if (i == 0) { internalPosition = 0; } else if (i == View.InvWidth - 1) { internalPosition = 4; } else { internalPosition = (i % 3) + 1; } Rect internalRect = Utils.DivRect(new Rect(32 + internalPosition * 80, 0, 80, 90), new Vector2(InvFrame.width, InvFrame.height)); mb.AddQuad(0, 32 + i * 80, 0, 80, 90, internalRect); } // add two quads for unpressed buttons mb.AddQuad(0, 0, 0, 32, 90, Utils.DivRect(new Rect(0, 0, 32, 90), new Vector2(InvFrame.width, InvFrame.height))); mb.AddQuad(0, 32 + View.InvWidth * 80, 0, 32, 90, Utils.DivRect(new Rect(432, 0, 32, 90), new Vector2(InvFrame.width, InvFrame.height))); mb.AddQuad(1, 0, 2, 32, 88); mb.AddQuad(2, 32 + View.InvWidth * 80, 2, 32, 88); Filter.mesh = mb.ToMesh(MeshTopology.Quads, MeshTopology.Quads, MeshTopology.Quads); transform.localScale = new Vector3(1, 1, 0.01f); transform.localPosition = new Vector3((Screen.width - 176) / 2 - (View.InvWidth * 80 + 64) / 2, Screen.height - 90, MainCamera.InterfaceZ + 0.99f); // on this layer all map UI is drawn }
public void Update() { // update text if (TextObjects.Count != InvWidth * InvHeight || TextRenderers.Count != InvWidth * InvHeight) { for (int i = 0; i < TextRenderers.Count; i++) { TextRenderers[i].DestroyImmediate(); } TextObjects.Clear(); TextRenderers.Clear(); for (int ly = 0; ly < InvHeight; ly++) { for (int lx = 0; lx < InvWidth; lx++) { AllodsTextRenderer atr = new AllodsTextRenderer(Fonts.Font2); atr.Text = ""; atr.Material.color = new Color32(0xBD, 0x9E, 0x4A, 0xFF); GameObject go = atr.GetNewGameObject(0.01f, transform, 100, 0.01f); TextObjects.Add(go); TextRenderers.Add(atr); go.transform.localPosition = new Vector3((lx * 80 + 6) * InvScale, (ly * 80 + 80 - 4) * InvScale - atr.Font.LineHeight, -0.2f); } } } // first submesh = quads, item background // second submesh = lines, item magic glow // third submesh = quads, item pictures if (Pack == null) { Filter.mesh.Clear(); return; } Builder.Reset(); int start = Math.Max(Math.Min(Scroll, Pack.Count - InvWidth * InvHeight), 0); int end = Math.Min(start + InvWidth * InvHeight, Pack.Count); int x = 0; int y = 0; for (int i = start; i < end; i++) { Builder.AddQuad(y * InvWidth + x, (x * 80) * InvScale, (y * 80) * InvScale, 80 * InvScale, 80 * InvScale, new Rect(0, 0, 1, 1)); // check texture. // for now, just put generic background Renderer.materials[y * InvWidth + x].mainTexture = img_BackInv; x++; if (x >= InvWidth) { x = 0; y++; } } for (int i = 0; i < TextObjects.Count; i++) { TextObjects[i].SetActive(false); } // now add magic glow where it should be x = 0; y = 0; UpdateMGlow(); // per-widget unique animation is used. int rnd = 0; for (int i = start; i < end; i++) { // check if item has special effects Item item = Pack[i]; if (item.MagicEffects.Count > 0) { float baseX = x * 80 * InvScale; float baseY = y * 80 * InvScale; Builder.CurrentMesh = InvWidth * InvHeight * 2; foreach (MGlowPart part in MGlowParts) { // draw all glow parts // left Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y); Builder.CurrentColor = new Color32(208, 0, 208, 255); Builder.NextVertex(); Builder.CurrentPosition = new Vector3(baseX + part.x - 2f * part.state, baseY + part.y); Builder.CurrentColor = new Color32(64, 0, 64, 255); Builder.NextVertex(); // right Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y); Builder.CurrentColor = new Color32(208, 0, 208, 255); Builder.NextVertex(); Builder.CurrentPosition = new Vector3(baseX + part.x + 2f * part.state, baseY + part.y); Builder.CurrentColor = new Color32(64, 0, 64, 255); Builder.NextVertex(); // top Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y); Builder.CurrentColor = new Color32(208, 0, 208, 255); Builder.NextVertex(); Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y - 2f * part.state); Builder.CurrentColor = new Color32(64, 0, 64, 255); Builder.NextVertex(); // bottom Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y); Builder.CurrentColor = new Color32(208, 0, 208, 255); Builder.NextVertex(); Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y + 2f * part.state); Builder.CurrentColor = new Color32(64, 0, 64, 255); Builder.NextVertex(); } } int dcount = item.Count; if (UiManager.Instance.DragItem == item) { dcount -= UiManager.Instance.DragItemCount; } if (dcount > 1) { TextRenderers[rnd].Text = dcount.ToString(); TextObjects[rnd].SetActive(true); } rnd++; x++; if (x >= InvWidth) { x = 0; y++; } } // add item pictures x = 0; y = 0; for (int i = start; i < end; i++) { Item item = Pack[i]; item.Class.File_Pack.UpdateSprite(); // check texture. // for now, just put generic background Renderer.materials[InvWidth * InvHeight + y * InvWidth + x].mainTexture = item.Class.File_Pack.File.Atlas; Renderer.materials[InvWidth * InvHeight + y * InvWidth + x].SetTexture("_Palette", item.Class.File_Pack.File.OwnPalette); Color color = new Color(1, 1, 1, (item == UiManager.Instance.DragItem) ? 0.25f : 1); // draw dragged items half transparent Builder.AddQuad(InvWidth * InvHeight + y * InvWidth + x, (x * 80) * InvScale, (y * 80) * InvScale, 80 * InvScale, 80 * InvScale, item.Class.File_Pack.File.AtlasRects[0], color); x++; if (x >= InvWidth) { x = 0; y++; } } MeshTopology[] topologies = new MeshTopology[InvWidth * InvHeight * 2 + 1]; for (int i = 0; i < InvWidth * InvHeight; i++) { topologies[i] = MeshTopology.Quads; topologies[InvWidth * InvHeight + i] = MeshTopology.Quads; } topologies[InvWidth * InvHeight * 2] = MeshTopology.Lines; Builder.CurrentMesh = topologies.Length - 1; Filter.mesh = Builder.ToMesh(topologies); }
public void Start() { ItemCount = (MainCamera.Width - 176 - 64) / 80; // each arrow is 32 in width View.InvScale = 1; View.InvWidth = (int)(ItemCount / View.InvScale); View.InvHeight = (int)(1 / View.InvScale); View.ShowMoney = true; if (InvFrame == null) { InvFrame = Images.LoadImage("graphics/interface/invframe.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow1 == null) { InvArrow1 = Images.LoadImage("graphics/interface/invarrow1.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow2 == null) { InvArrow2 = Images.LoadImage("graphics/interface/invarrow2.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow3 == null) { InvArrow3 = Images.LoadImage("graphics/interface/invarrow3.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow4 == null) { InvArrow4 = Images.LoadImage("graphics/interface/invarrow4.bmp", 0, Images.ImageType.AllodsBMP); } // Renderer = gameObject.AddComponent <MeshRenderer>(); Filter = gameObject.AddComponent <MeshFilter>(); Renderer.materials = new Material[] { new Material(MainCamera.MainShader), new Material(MainCamera.MainShader), new Material(MainCamera.MainShader) }; Renderer.materials[0].mainTexture = InvFrame; Renderer.materials[1].color = Renderer.materials[2].color = new Color(0, 0, 0, 0); // generate mesh. Utils.MeshBuilder mb = new Utils.MeshBuilder(); // 3 submeshes: left arrow, right arrow, and background. I'm NOT using the full original inventory view. for (int j = 1; j >= 0; j--) { for (int i = 0; i < View.InvWidth; i++) { int internalPosition; if (i == 0) { internalPosition = 0; } else if (i == View.InvWidth - 1) { internalPosition = 4; } else { internalPosition = (i % 3) + 1; } int yoffs = 0; if (View.InvScale < 1) { yoffs = (int)(1.5f / View.InvScale); } Rect internalRect = Utils.DivRect(new Rect(32 + internalPosition * 80, 0, 80, 90), new Vector2(InvFrame.width, InvFrame.height)); mb.AddQuad(0, 32 + i * 80 * View.InvScale, j * 80 * View.InvScale + yoffs, 80 * View.InvScale, 90 * View.InvScale, internalRect); } } // add two quads for unpressed buttons mb.AddQuad(0, 0, 0, 32, 90, Utils.DivRect(new Rect(0, 0, 32, 90), new Vector2(InvFrame.width, InvFrame.height))); mb.AddQuad(0, 32 + View.InvWidth * 80 * View.InvScale, 0, 32, 90, Utils.DivRect(new Rect(432, 0, 32, 90), new Vector2(InvFrame.width, InvFrame.height))); mb.AddQuad(1, 0, 2, 32, 88); mb.AddQuad(2, 32 + View.InvWidth * 80 * View.InvScale, 2, 32, 88); Filter.mesh = mb.ToMesh(MeshTopology.Quads, MeshTopology.Quads, MeshTopology.Quads); transform.localScale = new Vector3(1, 1, 0.01f); transform.localPosition = new Vector3((MainCamera.Width - 176) / 2 - (View.InvWidth * 80 * View.InvScale + 64) / 2, MainCamera.Height - 90, MainCamera.InterfaceZ + 0.99f); // on this layer all map UI is drawn }