示例#1
0
文件: Engine.cs 项目: bsimser/CoM
    /** Sets the cursor to cursor of given name. */
    public static void SetCursor(string name, Vector2 hotspot = default(Vector2))
    {
        //stupid webgl is bugged and I can't used custom cursors without cursor corruption.  Forcing software is terraible so I don't do that either.
        if (isWebGL)
        {
            return;
        }

        string fullPath = "Mouse Cursors/" + name;

        Sprite standardCursor = ResourceManager.GetSprite(fullPath);
        Sprite largeCursor    = ResourceManager.GetSprite(fullPath + "@x2") ?? standardCursor;

        if (standardCursor == null)
        {
            Trace.LogWarning("Invalid cursor name {0}, not found.", fullPath);
            return;
        }

        bool useLargeCursor = Screen.width >= 1920;

        Texture2D cursorTexture = (useLargeCursor ? largeCursor.texture : standardCursor.texture);

        Util.Assert(TextureMagic.IsReadable(cursorTexture), "Cursor texture must be readwrite enabled.");

        Cursor.SetCursor(cursorTexture, hotspot * (useLargeCursor ? 2 : 1), CursorMode.Auto);
    }
示例#2
0
    /** Process the source texture by remapping the colors, write to destination as output */
    private void Process()
    {
        Refresh = false;

        CreateDestinationTexture();

        if ((Source == null) || (Destination == null))
        {
            return;
        }

        Trace.Log("Processing texture " + Source);

        if (!TextureMagic.IsReadable(Source))
        {
            throw new UnityException("Can not read from source texture.");
        }

        data = Source.GetPixels32();

        for (int ylp = 0; ylp < Source.height; ylp++)
        {
            for (int xlp = 0; xlp < Source.width; xlp++)
            {
                Color32 col = Color.red;

                switch (GetTexelType(xlp, ylp))
                {
                case TexelType.Background:
                    col = BackgroundColor;
                    break;

                case TexelType.Edge:
                    col = EdgeColor;
                    break;

                case TexelType.Normal:
                    col = GetTexel(xlp, ylp);
                    break;

                case TexelType.Shadow:
                    col = ShadowColor;
                    break;
                }
                Destination.SetPixel(xlp, ylp, col);
            }
        }

        Destination.Apply();
        TextureMagic.SaveTextureToFile(Destination, DestinationPath);

        Trace.Log("Saved " + DestinationPath);

        data = null;
    }
示例#3
0
        /** Draws a fragment of a map tile (i.e. door etc) */
        private void DrawFragment(Vector2 location, int index)
        {
            int offsetX;
            int offsetY;

            offsetX = offsetY = 0;

            if (FieldRecord.isEastWallBit(index))
            {
                offsetX = +7;
            }

            if (FieldRecord.isNorthWallBit(index))
            {
                offsetY = +7;
            }

            TextureMagic.BlitWithAlpha(MapIcons[index], MapCanvas, (int)location.x + offsetX, (int)location.y + offsetY);
        }
示例#4
0
文件: CoM.cs 项目: bsimser/CoM
    /** Finds and organises all the sprites required to display the gui. */
    public static void LoadGraphics()
    {
        DateTime startTime = DateTime.Now;

        Trace.Log("Loading graphic resources:");

        Instance.MiscSprites      = LoadGraphicResources(MiscAtlasPath);
        Instance.MonsterSprites   = LoadGraphicResources(MonsterAtlasPath);
        Instance.MapIconSprites   = LoadGraphicResources(MapIconsAtlasPath);
        Instance.ItemIconSprites  = LoadGraphicResources(ItemIconsAtlasPath);
        Instance.SpellIconSprites = LoadGraphicResources(SpellIconsAtlasPath);
        Instance.IconSprites      = LoadGraphicResources(IconsAtlasPath, "NotFound");
        Instance.Portraits        = SpriteLibrary.FromXML(PortraitsXMLPath);

        Util.Assert(TextureMagic.IsReadable(Instance.MapIconSprites[0].texture), "Map sprites atlas needs to be set to readable under import settings (advanced).");

        Trace.Log("Graphic resource loading completed in " + (DateTime.Now - startTime).TotalMilliseconds.ToString("0.0") + "ms.");

        _graphicsLoaded = true;
    }
示例#5
0
        /** renders the map tiles to a texture */
        private void RenderMap()
        {
            DateTime startTime = DateTime.Now;

            TextureMagic.Clear(MapCanvas, new Color(0, 0, 0, 1));
            //TextureMagic.FrameRect(MapCanvas, 0, 0, MapCanvas.width, MapCanvas.height, Settings.MAP_UNEXPLOREDTILE_COLOR);

            for (int ylp = 1; ylp < Map.Height - 1; ylp++)
            {
                for (int xlp = 1; xlp < Map.Width - 1; xlp++)
                {
                    // full is needed so that walls west from unexplored tiles are drawn on exlplored tiles
                    RenderTile(xlp, ylp, TileRenderMode.Full);
                }
            }

            DateTime endTime = DateTime.Now;

            MapCanvas.Apply();
            Dirty = false;

            Trace.Log("Map rendered in " + (endTime - startTime).TotalMilliseconds + "ms");
        }
示例#6
0
        /**
         * Renders a single tile to the map canvas.  The canvas will not be updated so you will need to call
         * mapCanvas.Apply() in order to see the results
         *
         * @param accent.  Draws tile is a different way, used to indicate newly discovered tiles.
         */
        public void RenderTile(int tileX, int tileY, TileRenderMode mode = TileRenderMode.Normal, bool accent = false)
        {
            if (!Map.InBounds(tileX, tileY))
            {
                throw new Exception("Tile (" + tileX + "," + tileY + ") out of bounds");
            }

            FieldRecord field    = Map.GetField(tileX, tileY);
            Vector2     location = TileToTexel(tileX, tileY);

            const int startIndex = 0;
            const int endIndex   = 38;

            if (mode == TileRenderMode.Normal || mode == TileRenderMode.Full)
            {
                if (!field.Explored)
                {
                    TextureMagic.FillRect(MapCanvas, (int)location.x, (int)location.y, TILE_SIZE, TILE_SIZE, Colors.MAP_UNEXPLOREDTILE_COLOR);
                }
                else
                {
                    if (accent)
                    {
                        TextureMagic.FillRect(MapCanvas, (int)location.x, (int)location.y, TILE_SIZE, TILE_SIZE, new Color(0f, 0f, 0f, 0.5f));
                        TextureMagic.FillRect(MapCanvas, (int)location.x + 1, (int)location.y + 1, TILE_SIZE - 1, TILE_SIZE - 1, new Color(1f, 0f, 0.5f, 0.25f));
                    }
                    else
                    {
                        TextureMagic.FillRect(MapCanvas, (int)location.x, (int)location.y, TILE_SIZE, TILE_SIZE, Color.clear);
                    }
                }
            }

            for (int index = startIndex; index < endIndex; index++)
            {
                if (mode == TileRenderMode.EastWall && !FieldRecord.isEastWallBit(index))
                {
                    continue;
                }

                if (mode == TileRenderMode.NorthWall && !FieldRecord.isNorthWallBit(index))
                {
                    continue;
                }

                if (field.GetBit(index))
                {
                    DrawFragment(location, index);
                }
            }

            if (mode == TileRenderMode.Full)
            {
                if (tileX >= 1)
                {
                    RenderTile(tileX - 1, tileY, TileRenderMode.EastWall);
                }
                if (tileY >= 1)
                {
                    RenderTile(tileX, tileY - 1, TileRenderMode.NorthWall);
                }
            }
        }