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 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 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); }