Exemplo n.º 1
0
        private void OnChange(string args)
        {
            Blob blob = BlobAllocator.Blob(true);

            blob.ReadJson(args);

            string      message  = blob.GetString("message");
            float       scale    = (float)blob.GetDouble("scale");
            Vector3I    colorVec = blob.FetchBlob("color").GetVector3I();
            Color       color    = new Color(colorVec.X, colorVec.Y, colorVec.Z);
            BmFontAlign align    = (BmFontAlign)blob.GetLong("align");

            Blob.Deallocate(ref blob);

            Blob cmd = BlobAllocator.Blob(true);

            cmd.SetString("action", "changeSign");
            cmd.SetLong("id", this._currentSignId.Id);
            cmd.SetString("message", message);
            cmd.SetLong("color", color.PackedValue);
            cmd.SetDouble("scale", scale);
            cmd.SetLong("align", (long)align);

            ClientContext.OverlayController.AddCommand(cmd);

            this.Hide();
        }
        /// <summary>
        /// Change a sign
        /// </summary>
        /// <param name="message"></param>
        /// <param name="color"></param>
        /// <param name="scale"></param>
        public void ChangeSign(string message, Color color, float scale, BmFontAlign align)
        {
            this._message = message;
            this._color   = color;
            this._scale   = scale;
            this._align   = align;

            this._needsStore = true;
        }
Exemplo n.º 3
0
 public EffectInstance(Timestep step, Entity entity, EntityPainter painter, EntityUniverseFacade facade, Blob data)
 {
     this._entityId = data.GetLong("id");
     this._message  = data.GetString("message");
     this._color    = new Color()
     {
         PackedValue = (uint)data.GetLong("color")
     };
     this._scale = (float)data.GetDouble("scale");
     this._align = (BmFontAlign)data.GetLong("align");
 }
        /// <summary>
        /// Restore from persistent save data
        /// </summary>
        /// <param name="data"></param>
        /// <param name="facade"></param>
        public override void RestoreFromPersistedData(Blob data, EntityUniverseFacade facade)
        {
            base.RestoreFromPersistedData(data, facade);
            Entity.Construct(data.GetBlob("constructData"), facade);

            this._centerPos = data.GetBlob("centerPos").GetVector3D();
            this._isRemoved = data.GetBool("isRemoved");

            this._message = data.GetString("message");
            this._color   = new Color()
            {
                PackedValue = (uint)data.GetLong("color")
            };
            this._scale = (float)data.GetDouble("scale");
            this._align = (BmFontAlign)data.GetLong("align");

            this._needsStore = true;
            this.Store();
        }
        public void Invoke(PlayerEntityLogic logic, Entity entity, Blob config, Timestep timestep, EntityUniverseFacade facade)
        {
            string message = config.GetString("message");
            Color  color   = new Color()
            {
                PackedValue = (uint)config.GetLong("color")
            };
            float       scale = (float)config.GetDouble("scale");
            BmFontAlign align = (BmFontAlign)config.GetLong("align");

            EntityId id  = config.GetLong("id");
            Entity   ent = default(Entity);

            if (facade.TryGetEntity(id, out ent) && ent.TileStateEntityLogic != null)
            {
                BetterSignTileStateEntityLogic entLogic = ent.TileStateEntityLogic as BetterSignTileStateEntityLogic;
                entLogic.ChangeSign(message, color, scale, align);
            }
        }
        /// <summary>
        /// Restore entity from temp save data
        /// </summary>
        public override void Restore()
        {
            base.Restore();

            this.Location       = base._blob.FetchBlob("location").GetVector3I();
            this._variant       = (uint)base._blob.GetLong("variant");
            this._configuration = GameContext.TileDatabase.GetTileConfiguration(base._blob.GetString("tile"));

            this._centerPos = base._blob.GetBlob("centerPos").GetVector3D();
            this._isRemoved = base._blob.GetBool("isRemoved");

            this._message = base._blob.GetString("message");
            this._color   = new Color()
            {
                PackedValue = (uint)base._blob.GetLong("color")
            };
            this._scale = (float)base._blob.GetDouble("scale");
            this._align = (BmFontAlign)base._blob.GetLong("align");

            this._signComponent = _configuration.Components.GetOrDefault <SignComponent>();
        }
        public override void ClientUpdate(Timestep timestep, Entity entity, AvatarController avatarController, EntityUniverseFacade facade)
        {
            BetterSignTileStateEntityLogic logic = entity.TileStateEntityLogic as BetterSignTileStateEntityLogic;

            if (logic != null)
            {
                string      message = logic.GetMessage();
                Color       color   = logic.GetColor();
                float       scale   = logic.GetScale();
                BmFontAlign align   = logic.GetAlign();

                if (message != this._message || color != this._color || scale != this._scale || align != this._align)
                {
                    this.WorldTextRenderer.Purge();

                    // If the message is not blank add it to the WorldTextRenderer
                    if (message != "")
                    {
                        this._textInitialized = false;
                    }
                }
            }
        }
        /// <summary>
        /// Clear out any old pending draw calls pre-render
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="renderOrigin"></param>
        /// <param name="entity"></param>
        /// <param name="avatarController"></param>
        /// <param name="renderTimestep"></param>
        public override void BeforeRender(DeviceContext graphics, Vector3D renderOrigin, Entity entity, AvatarController avatarController, Timestep renderTimestep)
        {
            this.WorldTextRenderer.Init(graphics);

            if (!this._textInitialized)
            {
                //GameContext.DebugGraphics.Enabled = true;

                BetterSignTileStateEntityLogic logic = entity.TileStateEntityLogic as BetterSignTileStateEntityLogic;
                if (logic != null)
                {
                    this._position = logic.GetCenterPosition();
                    if (this._position != Vector3D.Zero)
                    {
                        this._rotation = (logic.GetVariation() >> 10) & 3;
                        this._message  = logic.GetMessage();
                        this._color    = logic.GetColor();
                        this._scale    = logic.GetScale();
                        this._align    = logic.GetAlign();

                        this.WorldTextRenderer.DrawString(
                            this._message,
                            logic.GetTextRegionSize(),
                            this._align,
                            Vector3D.Zero,
                            this._position,
                            this._scale,
                            this._rotation,
                            this._color
                            );

                        this._textInitialized = true;
                    }
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Draw text contained within a region
 /// </summary>
 /// <param name="text"></param>
 /// <param name="location"></param>
 /// <param name="rotation"></param>
 /// <param name="color"></param>
 public void DrawString(string text, Vector2F textBox, BmFontAlign alignment, Vector3D offset, Vector3D location, float scale, uint rotation, Color color)
 {
     this._drawCalls.Add(new BmFontDrawCall(this.BuildDrawable(text, textBox, alignment, color, scale), location, offset, rotation));
 }
Exemplo n.º 10
0
        /// <summary>
        /// Build a TextureVertexDrawable from the text where it is contained within a region
        /// </summary>
        /// <param name="text"></param>
        /// <param name="textBox"></param>
        /// <param name="alignment"></param>
        /// <param name="color"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private TextureVertexDrawable BuildDrawable(string text, Vector2F textBox, BmFontAlign alignment, Color color, float scale)
        {
            float UnitScale     = WorldTextRenderer.Units * scale;
            int   verticesCount = text.Length * 4;

            TextureVertex[]       vertices   = new TextureVertex[verticesCount];
            List <BmFontCharInfo> charInfo   = new List <BmFontCharInfo>();
            List <float>          lineWidths = new List <float>();

            // Textbox edge locations, make its origin the center
            float textBoxLeft   = -textBox.X * 0.5f;
            float textBoxRight  = textBox.X * 0.5f;
            float textBoxTop    = textBox.Y * 0.5f;
            float textBoxBottom = -textBox.Y * 0.5f;

            // Keep track of offset positions
            int   vIdx       = 0;     // Vertex index
            float x          = textBoxLeft;
            float y          = textBoxTop;
            float lineHeight = WorldTextRenderer.FontFile.Info.Size * UnitScale;
            float lineWidth  = 0f;
            int   lineNumber = 1;
            int   wordNumber = 1;

            // First we build everything, afterward we reposition vertices according to the BmFontCharinfo and alignment
            // Should be slightly more efficient as to realign all previous characters on the line as soon as we add a new one
            foreach (char c in text)
            {
                // Supplied new line
                if (c == '\r' || c == '\n')
                {
                    x  = textBoxLeft;
                    y -= lineHeight;
                    lineWidths.Add(lineWidth);
                    lineWidth  = 0f;
                    wordNumber = 1;
                    lineNumber++;

                    continue;
                }

                BmFontChar fontChar = WorldTextRenderer.CharacterMap.GetOrDefault(c);
                if (fontChar == null)
                {
                    continue;
                }

                float xOffset  = fontChar.XOffset * UnitScale;
                float yOffset  = fontChar.YOffset * UnitScale;
                float xAdvance = fontChar.XAdvance * UnitScale;
                float width    = fontChar.Width * UnitScale;
                float height   = fontChar.Height * UnitScale;

                // Newline supplied or needed
                if (lineWidth + xAdvance >= textBox.X)
                {
                    x  = textBoxLeft;
                    y -= lineHeight;

                    // Outside of bottom boundary; just stop
                    if (y - yOffset - lineHeight < textBoxBottom)
                    {
                        break;
                    }

                    // If we exceed the textbox and are not on the first word
                    // we move the last word down a line
                    if (wordNumber != 1)
                    {
                        float previousLineWidth = lineWidth;
                        lineWidth = 0f;

                        for (int i = 0; i < charInfo.Count; i++)
                        {
                            // If the previous line ended with a space remove it's width
                            if (charInfo[i].LineNumber == lineNumber && charInfo[i].WordNumber == (wordNumber - 1) && charInfo[i].Char == ' ')
                            {
                                previousLineWidth -= charInfo[i].XAdvance;
                            }

                            if (charInfo[i].LineNumber == lineNumber && charInfo[i].WordNumber == wordNumber)
                            {
                                charInfo[i].LineNumber++;
                                charInfo[i].WordNumber = 1;

                                vertices[charInfo[i].FirstVertexIndex].Position.X     = x + charInfo[i].XOffset;
                                vertices[charInfo[i].FirstVertexIndex].Position.Y     = y - charInfo[i].Height;
                                vertices[charInfo[i].FirstVertexIndex + 1].Position.X = x + charInfo[i].XOffset;
                                vertices[charInfo[i].FirstVertexIndex + 1].Position.Y = y;
                                vertices[charInfo[i].FirstVertexIndex + 2].Position.X = x + charInfo[i].XOffset + charInfo[i].Width;
                                vertices[charInfo[i].FirstVertexIndex + 2].Position.Y = y;
                                vertices[charInfo[i].FirstVertexIndex + 3].Position.X = x + charInfo[i].XOffset + charInfo[i].Width;
                                vertices[charInfo[i].FirstVertexIndex + 3].Position.Y = y - charInfo[i].Height;

                                x         += charInfo[i].XAdvance;
                                lineWidth += charInfo[i].XAdvance;
                            }
                        }

                        lineWidths.Add(previousLineWidth - lineWidth);
                    }
                    else
                    {
                        lineWidths.Add(lineWidth);
                        lineWidth = 0f;
                    }

                    wordNumber = 1;
                    lineNumber++;
                }

                // Ignore spaces on a new line
                if (lineWidth == 0f && c == ' ')
                {
                    continue;
                }

                Vector4F UVPos = this.CharPositionToUV(fontChar.GetVector4I());

                vertices[vIdx].Color     = color;
                vertices[vIdx + 1].Color = color;
                vertices[vIdx + 2].Color = color;
                vertices[vIdx + 3].Color = color;

                vertices[vIdx].Position     = new Vector3F(x + xOffset, y - height, 0f);
                vertices[vIdx + 1].Position = new Vector3F(x + xOffset, y, 0f);
                vertices[vIdx + 2].Position = new Vector3F(x + xOffset + width, y, 0f);
                vertices[vIdx + 3].Position = new Vector3F(x + xOffset + width, y - height, 0f);

                vertices[vIdx].Texture     = new Vector2F(UVPos.X, UVPos.W);
                vertices[vIdx + 1].Texture = new Vector2F(UVPos.X, UVPos.Y);
                vertices[vIdx + 2].Texture = new Vector2F(UVPos.Z, UVPos.Y);
                vertices[vIdx + 3].Texture = new Vector2F(UVPos.Z, UVPos.W);

                if (c == ' ')
                {
                    wordNumber++;
                }

                charInfo.Add(new BmFontCharInfo(c, vIdx, xOffset, yOffset, width, height, xAdvance, lineNumber, wordNumber));

                if (c == ' ')
                {
                    wordNumber++;
                }

                x         += xAdvance;
                lineWidth += xAdvance;
                vIdx      += 4;
            }

            // Bail out early if we have top left alignment
            if (!alignment.HasFlag(BmFontAlign.Center) && !alignment.HasFlag(BmFontAlign.Right) &&
                !alignment.HasFlag(BmFontAlign.Middle) && !alignment.HasFlag(BmFontAlign.Bottom))
            {
                return(new TextureVertexDrawable(vertices, verticesCount));
            }

            // Add last line, this never creates a new line so we need to manually add it
            lineWidths.Add(lineWidth);

            // Lets justify the text!
            float offsetX    = 0;
            float offsetY    = 0;
            float textHeight = lineWidths.Count * lineHeight;

            if (alignment.HasFlag(BmFontAlign.Middle))
            {
                offsetY -= (textBox.Y - textHeight) / 2;
            }
            if (alignment.HasFlag(BmFontAlign.Bottom))
            {
                offsetY -= textBox.Y - textHeight;
            }

            for (int line = 0; line < lineWidths.Count; line++)
            {
                lineWidth = lineWidths[line];

                if (alignment.HasFlag(BmFontAlign.Center))
                {
                    offsetX = (textBox.X - lineWidth) / 2;
                }
                if (alignment.HasFlag(BmFontAlign.Right))
                {
                    offsetX = textBox.X - lineWidth;
                }

                for (int j = 0; j < charInfo.Count; j++)
                {
                    if (charInfo[j].LineNumber == (line + 1))
                    {
                        vertices[charInfo[j].FirstVertexIndex].Position.X     += offsetX;
                        vertices[charInfo[j].FirstVertexIndex].Position.Y     += offsetY;
                        vertices[charInfo[j].FirstVertexIndex + 1].Position.X += offsetX;
                        vertices[charInfo[j].FirstVertexIndex + 1].Position.Y += offsetY;
                        vertices[charInfo[j].FirstVertexIndex + 2].Position.X += offsetX;
                        vertices[charInfo[j].FirstVertexIndex + 2].Position.Y += offsetY;
                        vertices[charInfo[j].FirstVertexIndex + 3].Position.X += offsetX;
                        vertices[charInfo[j].FirstVertexIndex + 3].Position.Y += offsetY;
                    }
                }
            }

            return(new TextureVertexDrawable(vertices, verticesCount));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Setup the UI to show a specific sign's information
        /// </summary>
        /// <param name="message"></param>
        /// <param name="color"></param>
        /// <param name="scale"></param>
        public void Setup(EntityId entityId, string message, Color color, float scale, BmFontAlign align)
        {
            this._currentSignId = entityId;

            Blob blob = BlobAllocator.Blob(true);

            blob.SetLong("id", entityId.Id);
            blob.SetString("message", message);
            blob.FetchBlob("color").SetVector3F(new Vector3F(color.R, color.G, color.B));
            blob.SetDouble("scale", scale);
            blob.SetLong("align", (long)align);

            this._data = blob.ToString();
            Blob.Deallocate(ref blob);
        }