Esempio n. 1
0
        private void OnChatMessage(int groupId, string message, EnumChatType chattype, string data)
        {
            if (data != null && data.StartsWith("From:") && entity.Pos.SquareDistanceTo(capi.World.Player.Entity.Pos.XYZ) < 20 * 20 && message.Length > 0)
            {
                int entityid = 0;
                int.TryParse(data.Split(new string[] { ":" }, StringSplitOptions.None)[1], out entityid);
                if (entity.EntityId == entityid)
                {
                    string name = GetNameTagName();
                    if (name != null && message.StartsWith(name + ": "))
                    {
                        message = message.Substring((name + ": ").Length);
                    }

                    LoadedTexture tex = capi.Gui.Text.GenTextTexture(
                        message,
                        capi.Render.GetFont(30, ElementGeometrics.StandardFontName, ColorUtil.WhiteArgbDouble),
                        350,
                        new TextBackground()
                    {
                        color = ElementGeometrics.DialogLightBgColor, padding = 3, radius = ElementGeometrics.ElementBGRadius
                    },
                        EnumTextOrientation.Center
                        );

                    messageTextures.Insert(0, new MessageTexture()
                    {
                        tex          = tex,
                        message      = message,
                        receivedTime = capi.World.ElapsedMilliseconds
                    });
                }
            }
        }
Esempio n. 2
0
        private ClydeTexture GenTexture(GLHandle glHandle, Vector2i size, string?name, long memoryPressure = 0)
        {
            if (name != null)
            {
                ObjectLabelMaybe(ObjectLabelIdentifier.Texture, glHandle, name);
            }

            var(width, height) = size;

            var id       = AllocRid();
            var instance = new ClydeTexture(id, size, this);
            var loaded   = new LoadedTexture
            {
                OpenGLObject   = glHandle,
                Width          = width,
                Height         = height,
                Name           = name,
                MemoryPressure = memoryPressure
                                 // TextureInstance = new WeakReference<ClydeTexture>(instance)
            };

            _loadedTextures.Add(id, loaded);
            //GC.AddMemoryPressure(memoryPressure);

            return(instance);
        }
Esempio n. 3
0
        protected void OnDebugInfoChanged()
        {
            bool showDebuginfo = capi.Settings.Bool["showEntityDebugInfo"];

            if (showDebuginfo && !entity.DebugAttributes.AllDirty && !entity.DebugAttributes.PartialDirty && debugTagTexture != null) return;

            if (debugTagTexture != null)
            {
                // Don't refresh if player is more than 10 blocks away, so its less laggy
                if (showDebuginfo && capi.World.Player.Entity.Pos.SquareDistanceTo(entity.Pos) > 15 * 15 && debugTagTexture.Width > 10)
                {
                    return;
                }

                debugTagTexture.Dispose();
                debugTagTexture = null;
            }

            if (!showDebuginfo) return;


            StringBuilder text = new StringBuilder();
            foreach (KeyValuePair<string, IAttribute> val in entity.DebugAttributes)
            {
                text.AppendLine(val.Key +": " + val.Value.ToString());
            }

            debugTagTexture = capi.Gui.TextTexture.GenUnscaledTextTexture(
                text.ToString(), 
                new CairoFont(20, GuiStyle.StandardFontName, ColorUtil.WhiteArgbDouble), 
                new TextBackground() { FillColor = GuiStyle.DialogDefaultBgColor, Padding = 3, Radius = GuiStyle.ElementBGRadius }
            );

            lastDebugInfoChangeMs = entity.World.ElapsedMilliseconds;
        }
Esempio n. 4
0
        public override void Dispose()
        {
            if (meshRefOpaque != null)
            {
                meshRefOpaque.Dispose();
                meshRefOpaque = null;
            }

            if (meshRefOit != null)
            {
                meshRefOit.Dispose();
                meshRefOit = null;
            }

            if (nameTagTexture != null)
            {
                nameTagTexture.Dispose();
                nameTagTexture = null;
            }

            if (debugTagTexture != null)
            {
                debugTagTexture.Dispose();
                debugTagTexture = null;
            }

            capi.Event.ReloadShapes -= TesselateShape;
        }
Esempio n. 5
0
        private LoadedTexture GenerateOverlayTexture()
        {
            var colorTexture = new LoadedTexture(_clientApi, 0, _chunksize, _chunksize);
            var colorArray   = Enumerable.Repeat(_config.TextureColor.RGBA, _chunksize * _chunksize).ToArray();

            if (_config.RenderBorder)
            {
                for (int x = 0; x < _chunksize; x++)
                {
                    for (int y = 0; y < _chunksize; y++)
                    {
                        if (x < _config.BorderThickness || x > _chunksize - 1 - _config.BorderThickness)
                        {
                            colorArray[y * _chunksize + x] = ColorUtil.ColorOver(colorArray[y * _chunksize + x], _config.BorderColor.RGBA);
                        }
                        else if (y < _config.BorderThickness || y > _chunksize - 1 - _config.BorderThickness)
                        {
                            colorArray[y * _chunksize + x] = ColorUtil.ColorOver(colorArray[y * _chunksize + x], _config.BorderColor.RGBA);
                        }
                    }
                }
            }

            _clientApi.Render.LoadOrUpdateTextureFromRgba(colorArray, false, 0, ref colorTexture);
            _clientApi.Render.BindTexture2d(colorTexture.TextureId);

            return(colorTexture);
        }
        public void setChunk(int dx, int dz, int[] pixels)
        {
            if (dx < 0 || dx >= ChunkLen || dz < 0 || dz >= ChunkLen)
            {
                throw new ArgumentOutOfRangeException("dx/dz must be within [0," + (ChunkLen - 1) + "]");
            }

            if (tmpTexture == null || tmpTexture.Disposed)
            {
                tmpTexture = new LoadedTexture(capi, 0, chunksize, chunksize);
            }

            if (Texture == null || Texture.Disposed)
            {
                int size = ChunkLen * chunksize;
                Texture = new LoadedTexture(capi, 0, size, size);
                capi.Render.LoadOrUpdateTextureFromRgba(new int[size * size], false, 0, ref Texture);
            }

            capi.Render.LoadOrUpdateTextureFromRgba(pixels, false, 0, ref tmpTexture);

            capi.Render.GlToggleBlend(false);
            capi.Render.GLDisableDepthTest();
            capi.Render.RenderTextureIntoTexture(tmpTexture, 0, 0, chunksize, chunksize, Texture, chunksize * dx, chunksize * dz);

            capi.Render.BindTexture2d(Texture.TextureId);
            capi.Render.GlGenerateTex2DMipmaps();

            chunkSet[dx, dz] = true;
        }
Esempio n. 7
0
        public override void OnMapOpenedClient()
        {
            int size = (int)GuiElement.scaled(32);

            if (ownTexture == null)
            {
                ImageSurface surface = new ImageSurface(Format.Argb32, size, size);
                Context      ctx     = new Context(surface);
                ctx.SetSourceRGBA(0, 0, 0, 0);
                ctx.Paint();
                capi.Gui.Icons.DrawMapPlayer(ctx, 0, 0, size, size, new double[] { 0, 0, 0, 1 }, new double[] { 1, 1, 1, 1 });

                ownTexture = new LoadedTexture(capi, capi.Gui.LoadCairoTexture(surface, false), size / 2, size / 2);
                ctx.Dispose();
                surface.Dispose();
            }

            if (otherTexture == null)
            {
                ImageSurface surface = new ImageSurface(Format.Argb32, size, size);
                Context      ctx     = new Context(surface);
                ctx.SetSourceRGBA(0, 0, 0, 0);
                ctx.Paint();
                capi.Gui.Icons.DrawMapPlayer(ctx, 0, 0, size, size, new double[] { 0.3, 0.3, 0.3, 1 }, new double[] { 0.7, 0.7, 0.7, 1 });
                otherTexture = new LoadedTexture(capi, capi.Gui.LoadCairoTexture(surface, false), size / 2, size / 2);
                ctx.Dispose();
                surface.Dispose();
            }



            foreach (IPlayer player in capi.World.AllOnlinePlayers)
            {
                EntityMapComponent cmp;

                if (MapComps.TryGetValue(player, out cmp))
                {
                    cmp?.Dispose();
                    MapComps.Remove(player);
                }


                if (player.Entity == null)
                {
                    capi.World.Logger.Warning("Can't add player {0} to world map, missing entity :<", player.PlayerUID);
                    continue;
                }

                if (capi.World.Config.GetBool("mapHideOtherPlayers", false) && player.PlayerUID != capi.World.Player.PlayerUID)
                {
                    continue;
                }


                cmp = new EntityMapComponent(capi, player == capi.World.Player ? ownTexture : otherTexture, player.Entity);

                MapComps[player] = cmp;
            }
        }
Esempio n. 8
0
        public override void OnMapOpenedClient()
        {
            int chunksize = api.World.BlockAccessor.ChunkSize;

            if (ownTexture == null)
            {
                ImageSurface surface = new ImageSurface(Format.Argb32, 32, 32);
                Context      ctx     = new Context(surface);
                ctx.SetSourceRGBA(0, 0, 0, 0);
                ctx.Paint();
                capi.Gui.Icons.DrawMapPlayer(ctx, 0, 0, 32, 32, new double[] { 0, 0, 0, 1 }, new double[] { 1, 1, 1, 1 });

                ownTexture = new LoadedTexture(capi, capi.Gui.LoadCairoTexture(surface, false), 16, 16);
                ctx.Dispose();
                surface.Dispose();
            }

            if (otherTexture == null)
            {
                ImageSurface surface = new ImageSurface(Format.Argb32, 32, 32);
                Context      ctx     = new Context(surface);
                ctx.SetSourceRGBA(0, 0, 0, 0);
                ctx.Paint();
                capi.Gui.Icons.DrawMapPlayer(ctx, 0, 0, 32, 32, new double[] { 0.3, 0.3, 0.3, 1 }, new double[] { 0.7, 0.7, 0.7, 1 });
                otherTexture = new LoadedTexture(capi, capi.Gui.LoadCairoTexture(surface, false), 16, 16);
                ctx.Dispose();
                surface.Dispose();
            }



            foreach (IPlayer player in capi.World.AllOnlinePlayers)
            {
                EntityMapComponent cmp = null;

                if (MapComps.TryGetValue(player, out cmp))
                {
                    cmp?.Dispose();
                    MapComps.Remove(player);
                }

                if (cmp != null)
                {
                    mapSink.RemoveMapData(cmp);
                }


                if (player.Entity == null)
                {
                    capi.World.Logger.Warning("Can't add player {0} to world map, missing entity :<", player.PlayerUID);
                    continue;
                }

                cmp = new EntityMapComponent(capi, player == capi.World.Player ? ownTexture : otherTexture, player.Entity);

                MapComps[player] = cmp;
                mapSink.AddMapData(cmp);
            }
        }
Esempio n. 9
0
        public WaypointMapComponent(Waypoint waypoint, LoadedTexture texture, ICoreClientAPI capi) : base(capi)
        {
            this.waypoint = waypoint;
            this.Texture  = texture;
            ColorUtil.ToRGBAVec4f(waypoint.Color, ref color);

            quadModel = capi.Render.UploadMesh(QuadMeshUtil.GetQuad());
        }
Esempio n. 10
0
        public void Recompose(ICoreClientAPI capi)
        {
            Texture?.Dispose();
            Texture = new TextTextureUtil(capi).GenTextTexture(Stack.GetName(), CairoFont.WhiteSmallText());

            scissorBounds = ElementBounds.FixedSize(50, 50);
            scissorBounds.ParentBounds = capi.Gui.WindowBounds;
        }
 public ProspectorOverlayMapComponent(ICoreClientAPI clientApi, int chunkX, int chunkZ, string message, LoadedTexture colorTexture) : base(clientApi)
 {
     this.ChunkX       = chunkX;
     this.ChunkZ       = chunkZ;
     this._message     = message;
     this._chunksize   = clientApi.World.BlockAccessor.ChunkSize;
     this.worldPos     = new Vec3d(chunkX * _chunksize, 0, chunkZ * _chunksize);
     this.colorTexture = colorTexture;
 }
        public virtual void SetNewText(string[] textByCardinal, int color)
        {
            this.textByCardinal = textByCardinal;
            font.WithColor(ColorUtil.ToRGBADoubles(color));
            font.UnscaledFontsize = fontSize / RuntimeEnv.GUIScale;

            int lines = 0;

            for (int i = 0; i < textByCardinal.Length; i++)
            {
                if (textByCardinal[i].Length > 0)
                {
                    lines++;
                }
            }

            if (lines == 0)
            {
                loadedTexture?.Dispose();
                loadedTexture = null;
                return;
            }

            ImageSurface surface = new ImageSurface(Format.Argb32, TextWidth, TextHeight * lines);
            Context      ctx     = new Context(surface);

            font.SetupContext(ctx);

            int line = 0;

            for (int i = 0; i < textByCardinal.Length; i++)
            {
                if (textByCardinal[i].Length > 0)
                {
                    double linewidth = font.GetTextExtents(textByCardinal[i]).Width;

                    ctx.MoveTo((TextWidth - linewidth) / 2, line * TextHeight + ctx.FontExtents.Ascent);
                    ctx.ShowText(textByCardinal[i]);
                    line++;
                }
            }


            if (loadedTexture == null)
            {
                loadedTexture = new LoadedTexture(api);
            }
            api.Gui.LoadOrUpdateCairoTexture(surface, true, ref loadedTexture);


            surface.Dispose();
            ctx.Dispose();


            genMesh();
        }
Esempio n. 13
0
 public GuiElementSubtitleList(ICoreClientAPI capi, ElementBounds bounds)
     : base(capi, bounds)
 {
     textTexture = new LoadedTexture(capi);
     Font        = CairoFont.WhiteSmallText();
     textUtil    = new TextDrawUtil();
     for (int i = 0; i < MAX_SOUNDS; i++)
     {
         soundList[i] = new Sound();
     }
 }
Esempio n. 14
0
        public virtual void SetNewText(string text, int color)
        {
            font.WithColor(ColorUtil.ToRGBADoubles(color));
            loadedTexture?.Dispose();
            loadedTexture = null;

            if (text.Length > 0)
            {
                font.UnscaledFontsize = fontSize / RuntimeEnv.GUIScale;
                loadedTexture         = api.Gui.TextTexture.GenTextTexture(text, font, TextWidth, TextHeight, null, EnumTextOrientation.Center, false);
            }
        }
Esempio n. 15
0
        public override void Dispose()
        {
            foreach (var val in MapComps)
            {
                val.Value?.Dispose();
            }

            ownTexture?.Dispose();
            ownTexture = null;
            otherTexture?.Dispose();
            otherTexture = null;
        }
Esempio n. 16
0
 public void Unload(string path)
 {
     if (LoadedTextures.ContainsKey(path))
     {
         LoadedTexture texture = LoadedTextures[path];
         texture.UsedCount--;
         if (texture.UsedCount <= 0)
         {
             texture.Texture.Dispose();
             LoadedTextures.Remove(path);
         }
     }
 }
Esempio n. 17
0
        protected void OnNameChanged()
        {
            var bh = entity.GetBehavior<EntityBehaviorNameTag>();
            if (nameTagRenderHandler == null || bh == null) return;
            if (nameTagTexture != null)
            {
                nameTagTexture.Dispose();
                nameTagTexture = null;
            }

            renderRange = bh.RenderRange;
            showNameTagOnlyWhenTargeted = bh.ShowOnlyWhenTargeted;
            nameTagTexture = nameTagRenderHandler.Invoke(capi, entity);
        }
Esempio n. 18
0
        public MapComponent LoadMapData(Vec2i chunkCoord, int[] pixels)
        {
            ICoreClientAPI capi      = api as ICoreClientAPI;
            int            chunksize = api.World.BlockAccessor.ChunkSize;
            LoadedTexture  tex       = new LoadedTexture(capi, 0, chunksize, chunksize);

            capi.Render.LoadOrUpdateTextureFromRgba(pixels, false, 0, ref tex);

            ChunkMapComponent cmp = new ChunkMapComponent(capi, chunkCoord.Copy());

            cmp.Texture = tex;

            return(cmp);
        }
Esempio n. 19
0
        public override void OnMapClosedClient()
        {
            foreach (var val in MapComps)
            {
                val.Value?.Dispose();
            }

            ownTexture.Dispose();
            ownTexture = null;
            otherTexture.Dispose();
            otherTexture = null;

            MapComps.Clear();
        }
Esempio n. 20
0
        public EyesOverlayRenderer(ICoreClientAPI capi, IShaderProgram eyeShaderProg)
        {
            this.capi          = capi;
            this.eyeShaderProg = eyeShaderProg;

            MeshData quadMesh = QuadMeshUtil.GetCustomQuadModelData(-1, -1, -20000 + 151 + 1, 2, 2);

            quadMesh.Rgba = null;

            quadRef = capi.Render.UploadMesh(quadMesh);

            string hotkey = capi.Input.HotKeys["sneak"].CurrentMapping.ToString();

            exitHelpTexture = capi.Gui.TextTexture.GenTextTexture(Lang.Get("bed-exithint", hotkey), CairoFont.WhiteSmallishText());
        }
Esempio n. 21
0
        public GuiElementFlatList(ICoreClientAPI capi, ElementBounds bounds, Action <int> onLeftClick, List <IFlatListItem> elements = null) : base(capi, bounds)
        {
            hoverOverlayTexture = new LoadedTexture(capi);

            insideBounds = new ElementBounds().WithFixedPadding(unscaledCellSpacing).WithEmptyParent();
            insideBounds.CalcWorldBounds();

            this.onLeftClick = onLeftClick;
            if (elements != null)
            {
                Elements = elements;
            }

            CalcTotalHeight();
        }
Esempio n. 22
0
        public override void Dispose()
        {
            if (meshRefOpaque != null)
            {
                meshRefOpaque.Dispose();
                meshRefOpaque = null;
            }

            if (meshRefOit != null)
            {
                meshRefOit.Dispose();
                meshRefOit = null;
            }

            if (nameTagTexture != null)
            {
                nameTagTexture.Dispose();
                nameTagTexture = null;
            }

            if (debugTagTexture != null)
            {
                debugTagTexture.Dispose();
                debugTagTexture = null;
            }

            capi.Event.ReloadShapes -= TesselateShape;

            if (DisplayChatMessages)
            {
                capi.Event.ChatMessage -= OnChatMessage;
            }


            if (eagent?.GearInventory != null)
            {
                eagent.GearInventory.SlotModified -= gearSlotModified;
            }

            if (entity is EntityPlayer eplr)
            {
                IInventory inv = eplr.Player?.InventoryManager.GetOwnInventory(GlobalConstants.backpackInvClassName);
                if (inv != null)
                {
                    inv.SlotModified -= backPackSlotModified;
                }
            }
        }
        public Texture LoadTextureFromImage <T>(Image <T> image, string name = null) where T : struct, IPixel <T>
        {
            DebugTools.Assert(_mainThread == Thread.CurrentThread);

            if (typeof(T) != typeof(Rgba32))
            {
                throw new NotImplementedException("Cannot load images other than Rgba32");
            }

            var texture = new OGLHandle(GL.GenTexture());

            GL.BindTexture(TextureTarget.Texture2D, texture.Handle);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                            (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
                            (int)TextureMagFilter.Nearest);

            var span = ((Image <Rgba32>)(object) image).GetPixelSpan();

            unsafe
            {
                fixed(Rgba32 *ptr = &MemoryMarshal.GetReference(span))
                {
                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, image.Width, image.Height, 0,
                                  PixelFormat.Rgba, PixelType.UnsignedByte, (IntPtr)ptr);
                }
            }

            if (name != null)
            {
                _objectLabelMaybe(ObjectLabelIdentifier.Texture, texture, name);
            }

            var loaded = new LoadedTexture
            {
                OpenGLObject = texture,
                Width        = image.Width,
                Height       = image.Height,
                Name         = name,
            };

            var id = ++_nextTextureId;

            _loadedTextures.Add(id, loaded);

            return(new OpenGLTexture(id, image.Width, image.Height));
        }
Esempio n. 24
0
        protected void OnChatMessage(int groupId, string message, EnumChatType chattype, string data)
        {
            if (data != null && data.Contains("from:") && entity.Pos.SquareDistanceTo(capi.World.Player.Entity.Pos.XYZ) < 20 * 20 && message.Length > 0)
            {
                int      entityid;
                string[] parts = data.Split(new char[] { ',' }, 2);
                if (parts.Length < 2)
                {
                    return;
                }

                string[] partone = parts[0].Split(new char[] { ':' }, 2);
                string[] parttwo = parts[1].Split(new char[] { ':' }, 2);
                if (partone[0] != "from")
                {
                    return;
                }

                int.TryParse(partone[1], out entityid);
                if (entity.EntityId == entityid)
                {
                    message = parttwo[1];

                    // Crappy fix
                    message = message.Replace("&lt;", "<").Replace("&gt;", ">");

                    LoadedTexture tex = capi.Gui.TextTexture.GenTextTexture(
                        message,
                        new CairoFont(25, GuiStyle.StandardFontName, ColorUtil.WhiteArgbDouble),
                        350,
                        new TextBackground()
                    {
                        FillColor = GuiStyle.DialogLightBgColor, Padding = 3, Radius = GuiStyle.ElementBGRadius
                    },
                        EnumTextOrientation.Center
                        );

                    messageTextures.Insert(0, new MessageTexture()
                    {
                        tex          = tex,
                        message      = message,
                        receivedTime = capi.World.ElapsedMilliseconds
                    });
                }
            }
        }
Esempio n. 25
0
        public override void OnMapOpenedClient()
        {
            if (texturesByIcon == null)
            {
                if (texturesByIcon != null)
                {
                    foreach (var val in texturesByIcon)
                    {
                        val.Value.Dispose();
                    }
                }

                texturesByIcon = new Dictionary <string, LoadedTexture>();

                double scale = RuntimeEnv.GUIScale;
                int    size  = (int)(27 * scale);

                ImageSurface surface = new ImageSurface(Format.Argb32, size, size);
                Context      ctx     = new Context(surface);

                string[]       icons = new string[] { "circle", "bee", "cave", "home", "ladder", "pick", "rocks", "ruins", "spiral", "star1", "star2", "trader", "vessel" };
                ICoreClientAPI capi  = api as ICoreClientAPI;

                foreach (var val in icons)
                {
                    ctx.Operator = Operator.Clear;
                    ctx.SetSourceRGBA(0, 0, 0, 0);
                    ctx.Paint();
                    ctx.Operator = Operator.Over;

                    capi.Gui.Icons.DrawIcon(ctx, "wp" + val.UcFirst(), 1, 1, size - 2, size - 2, new double[] { 0, 0, 0, 1 });

                    capi.Gui.Icons.DrawIcon(ctx, "wp" + val.UcFirst(), 2, 2, size - 4, size - 4, ColorUtil.WhiteArgbDouble);

                    //surface.WriteToPng("icon-" + val+".png");

                    texturesByIcon[val] = new LoadedTexture(api as ICoreClientAPI, (api as ICoreClientAPI).Gui.LoadCairoTexture(surface, false), (int)(20 * scale), (int)(20 * scale));
                }

                ctx.Dispose();
                surface.Dispose();
            }


            RebuildMapComponents();
        }
Esempio n. 26
0
        protected void OnNameChanged()
        {
            if (nameTagRenderHandler == null)
            {
                return;
            }
            if (nameTagTexture != null)
            {
                nameTagTexture.Dispose();
                nameTagTexture = null;
            }

            int?range = entity.GetBehavior <EntityBehaviorNameTag>()?.RenderRange;

            renderRange = range == null ? 999 : (int)range;
            showNameTagOnlyWhenTargeted = entity.GetBehavior <EntityBehaviorNameTag>()?.ShowOnlyWhenTargeted == true;
            nameTagTexture = nameTagRenderHandler.Invoke(capi, entity);
        }
        public AuctionCellEntry(ICoreClientAPI capi, ElementBounds bounds, Auction auction, Action <int> onClick) : base(capi, bounds)
        {
            iconSize = (float)scaled(unscaledIconSize);

            dummySlot    = new DummySlot(auction.ItemStack);
            this.onClick = onClick;
            this.auction = auction;

            CairoFont font = CairoFont.WhiteDetailText();
            double    offY = (unScaledCellHeight - font.UnscaledFontsize) / 2;

            scissorBounds = ElementBounds.FixedSize(unscaledIconSize, unscaledIconSize).WithParent(Bounds);
            var stackNameTextBounds = ElementBounds.Fixed(0, offY, 270, 25).WithParent(Bounds).FixedRightOf(scissorBounds, 10);
            var priceTextBounds     = ElementBounds.Fixed(0, offY, 75, 25).WithParent(Bounds).FixedRightOf(stackNameTextBounds, 10);
            var expireTextBounds    = ElementBounds.Fixed(0, 0, 160, 25).WithParent(Bounds).FixedRightOf(priceTextBounds, 10);
            var sellerTextBounds    = ElementBounds.Fixed(0, offY, 110, 25).WithParent(Bounds).FixedRightOf(expireTextBounds, 10);



            stackNameTextElem = new GuiElementRichtext(capi, VtmlUtil.Richtextify(capi, dummySlot.Itemstack.GetName(), font), stackNameTextBounds);

            double    fl        = font.UnscaledFontsize;
            ItemStack gearStack = capi.ModLoader.GetModSystem <ModSystemAuction>().SingleCurrencyStack;
            var       comps     = new RichTextComponentBase[] {
                new RichTextComponent(capi, "" + auction.Price, font)
                {
                    PaddingRight = 10, VerticalAlign = EnumVerticalAlign.Top
                },
                new ItemstackTextComponent(capi, gearStack, fl * 2.5f, 0, EnumFloat.Inline)
                {
                    VerticalAlign = EnumVerticalAlign.Top, offX = -scaled(fl * 0.5f), offY = -scaled(fl * 0.75f)
                }
            };

            priceTextElem  = new GuiElementRichtext(capi, comps, priceTextBounds);
            expireTextElem = new GuiElementRichtext(capi, VtmlUtil.Richtextify(capi, prevExpireText = auction.GetExpireText(capi), font.Clone().WithFontSize(14)), expireTextBounds);
            expireTextElem.BeforeCalcBounds();
            expireTextBounds.fixedY = 5 + (25 - expireTextElem.TotalHeight / RuntimeEnv.GUIScale) / 2;


            sellerTextElem = new GuiElementRichtext(capi, VtmlUtil.Richtextify(capi, auction.SellerName, font.Clone().WithOrientation(EnumTextOrientation.Right)), sellerTextBounds);

            hoverTexture = new LoadedTexture(capi);
        }
Esempio n. 28
0
        public void RebuildMap(bool rebuildTexture = false)
        {
            foreach (var component in _components)
            {
                component.Dispose();
            }

            _components.Clear();

            if (rebuildTexture)
            {
                _colorTexture?.Dispose();
                _colorTexture = GenerateOverlayTexture();
            }

            foreach (var message in _messages)
            {
                var component = new ProspectorOverlayMapComponent(_clientApi, message.X, message.Z, message.Message, _colorTexture);
                _components.Add(component);
            }
        }
Esempio n. 29
0
        public ProspectorOverlayLayer(ICoreAPI api, IWorldMapManager mapSink) : base(api, mapSink)
        {
            _worldMapManager = mapSink;
            _chunksize       = api.World.BlockAccessor.ChunkSize;
            _messages        = api.LoadOrCreateDataFile <ProspectorMessages>(Filename);
            _triggerwords    = LangUtils.GetAllLanguageStringsOfKey("propick-reading-title").Select(x => x.Split().FirstOrDefault()).Where(x => !string.IsNullOrEmpty(x)).ToArray();
            _cleanupRegex    = new Regex("<.*?>", RegexOptions.Compiled);

            var modSystem = this.api.ModLoader.GetModSystem <ProspectorInfoModSystem>();

            _config = modSystem.Config;

            if (api.Side == EnumAppSide.Client)
            {
                _clientApi = (ICoreClientAPI)api;
                _clientApi.Event.ChatMessage            += OnChatMessage;
                _clientApi.Event.AfterActiveSlotChanged += Event_AfterActiveSlotChanged;
                _clientApi.Event.PlayerJoin             += (p) =>
                {
                    if (p == _clientApi?.World.Player)
                    {
                        var invMan = p?.InventoryManager?.GetHotbarInventory();
                        invMan.SlotModified += Event_SlotModified;
                    }
                };
                _clientApi.Event.PlayerLeave += (p) =>
                {
                    if (p == _clientApi?.World.Player)
                    {
                        var invMan = p?.InventoryManager?.GetHotbarInventory();
                        invMan.SlotModified -= Event_SlotModified;
                    }
                };

                _clientApi.RegisterCommand("pi", "ProspectorInfo main command. Allows you to toggle the visibility of the chunk texture overlay.", "", OnPiCommand);

                _colorTexture?.Dispose();
                _colorTexture = GenerateOverlayTexture();
            }
        }
Esempio n. 30
0
        public override void OnMapOpenedClient()
        {
            bool rebuildAnyway = false;

#if DEBUG
            rebuildAnyway = true;
#endif

            if (texturesByIcon == null || rebuildAnyway)
            {
                texturesByIcon = new Dictionary <string, LoadedTexture>();

                ImageSurface surface = new ImageSurface(Format.Argb32, 25, 25);
                Context      ctx     = new Context(surface);

                string[]       icons = new string[] { "circle", "bee", "cave", "home", "ladder", "pick", "rocks", "ruins", "spiral", "star1", "star2", "trader", "vessel" };
                ICoreClientAPI capi  = api as ICoreClientAPI;

                foreach (var val in icons)
                {
                    ctx.Operator = Operator.Clear;
                    ctx.SetSourceRGBA(0, 0, 0, 0);
                    ctx.Paint();
                    ctx.Operator = Operator.Over;

                    capi.Gui.Icons.DrawIcon(ctx, "wp" + val.UcFirst(), 1, 1, 23, 23, ColorUtil.WhiteArgbDouble);

                    //surface.WriteToPng("icon-" + val+".png");

                    texturesByIcon[val] = new LoadedTexture(api as ICoreClientAPI, (api as ICoreClientAPI).Gui.LoadCairoTexture(surface, false), 20, 20);
                }

                ctx.Dispose();
                surface.Dispose();
            }


            RebuildMapComponents();
        }
Esempio n. 31
0
    public static void DrawSolidRect(float x0, float y0, float x1, float y1, outki.UIColor col = null)
    {
        if (lastTexture != null || begin == 0)
        {
            if (begin != 0)
                GL.End();

            lastTexture = null;
            SolidMaterial.SetPass(0);
            GL.Begin(GL.QUADS);
            begin = 1;
        }

        if (col == null)
            GL.Color(new Color(m_currentColor.r, m_currentColor.g, m_currentColor.b, m_currentColor.a));
        else
            GL.Color(new Color(m_currentColor.r * col.r / 255, m_currentColor.g * col.g / 255.0f, m_currentColor.b * col.b / 255.0f, m_currentColor.a * col.a / 255.0f));

        GL.Vertex3(x0, y0, 0);
        GL.Vertex3(x1, y0, 0);
        GL.Vertex3(x1, y1, 0);
        GL.Vertex3(x0, y1, 0);
    }
Esempio n. 32
0
    public static void DrawGradientRect(float x0, float y0, float x1, float y1, 
	                                    outki.UIColor tl, outki.UIColor tr,
	                                    outki.UIColor bl, outki.UIColor br)
    {
        if (lastTexture != null || begin == 0)
        {
            if (begin != 0)
                GL.End();

            lastTexture = null;
            SolidMaterial.SetPass(0);
            GL.Begin(GL.QUADS);
            begin = 1;
        }

        HelpGLColor(tl);
        GL.Vertex3(x0, y0, 0);
        HelpGLColor(tr);
        GL.Vertex3(x1, y0, 0);
        HelpGLColor(br);
        GL.Vertex3(x1, y1, 0);
        HelpGLColor(bl);
        GL.Vertex3(x0, y1, 0);
    }
Esempio n. 33
0
    public static void UseTexture(Texture tex)
    {
        if (tex.ld != lastTexture || begin == 0)
        {
            if (begin != 0)
                GL.End();

            lastTexture = tex.ld;
            lastTexture.material.SetPass(0);
            GL.Begin(GL.QUADS);
            begin = 1;
        }
    }
Esempio n. 34
0
    public static LoadedTexture LoadTexture(outki.Texture tex)
    {
        string imgPath = null;

        outki.TextureOutput to = tex.Output as outki.TextureOutput;
        if (to == null)
            return null;

        outki.DataContainer container = to.Data;
        if (container == null)
            return null;

        outki.DataContainerOutputFile output = container.Output as outki.DataContainerOutputFile;
        if (output == null)
            return null;

        imgPath = output.FilePath;

        foreach (LoadedTexture lt in loaded)
        {
            if (lt.path == imgPath)
            {
                return lt;
            }
        }

        UnityEngine.Debug.Log("Loading img [" + imgPath + "]");

        LoadedTexture ld = new LoadedTexture();

        TextAsset ta = Resources.Load(imgPath.Replace("Resources/",""), typeof(TextAsset)) as TextAsset;
        if (ta != null)
        {
            ld.unityTexture = new Texture2D (4, 4);
            ld.unityTexture.LoadImage(ta.bytes);
            ld.unityTexture.filterMode = FilterMode.Bilinear;
            ld.unityTexture.anisoLevel = 0;
        }
        else
        {
            // Try loading texture asset
            ld.unityTexture = Resources.Load(imgPath.Replace("Resources/","").Replace(".png", "")) as Texture2D;
            if (ld.unityTexture == null)
            {
                UnityEngine.Debug.LogError("Failed to load texture [" + imgPath + "]");
                return null;
            }
        }

        ld.unityTexture.wrapMode = TextureWrapMode.Clamp;

        ld.material = new Material(TexturedShader);
        ld.material.mainTexture = ld.unityTexture;
        ld.path = imgPath;
        loaded.Add(ld);

        UnityEngine.Debug.Log("Loaded texture " + imgPath + " it is "+ ld.unityTexture);
        return ld;
    }
Esempio n. 35
0
 public static LoadedTexture DynamicTexture(UnityEngine.Texture2D tex)
 {
     LoadedTexture ld = new LoadedTexture();
     ld.unityTexture = tex;
     ld.material = new Material(TexturedShader);
     ld.material.mainTexture = ld.unityTexture;
     return ld;
 }