コード例 #1
0
        private object LoadTexture(ContentManager contentManager, string assetName, IEnumerable <ModXnb> items, bool isDirty)
        {
            var originalTexture = contentManager.LoadDirect <Texture2D>(assetName);
            var obj             = originalTexture;

            string assetKey = $"{assetName}-\u2764-modified";

            if (_cachedAlteredTextures.ContainsKey(assetKey) && !isDirty)
            {
                obj = _cachedAlteredTextures[assetKey];
            }
            else
            {
                foreach (var item in items)
                {
                    var modItem    = TextureRegistry.GetItem(item.Texture, item.OwningMod);
                    var modTexture = modItem?.Texture;
                    if (item.Destination != null)
                    {
                        var texture = TextureUtility.PatchTexture(obj, modTexture, item.Source ?? new Rectangle(0, 0, modTexture.Width, modTexture.Height), item.Destination);
                        obj = texture;
                    }
                }
                _cachedAlteredTextures[assetKey] = obj;
            }
            var outputMessage = items.Select(n => n.OwningMod.Name + " (" + n.Texture + ")").Aggregate((a, b) => a + ", " + b);

            Log.Verbose($"Using own asset replacement: {assetName} = " + outputMessage);
            return(obj);
        }
コード例 #2
0
        private object LoadTexture(ContentManager contentManager, string assetName, ModXnb item)
        {
            var modItem = TextureRegistry.GetItem(item.Texture, item.OwningMod);
            var obj     = modItem?.Texture;

            if (obj == null)
            {
                return(null);
            }

            if (item.Destination != null)
            {
                //TODO, Error checking on this.
                //TODO, Multiple mods should be able to edit this
                var originalTexture = contentManager.LoadDirect <Texture2D>(assetName);

                string assetKey = $"{assetName}-\u2764-modified";
                if (_cachedAlteredTextures.ContainsKey(assetKey))
                {
                    obj = _cachedAlteredTextures[assetKey];
                }
                else
                {
                    var texture = TextureUtility.PatchTexture(originalTexture, obj, item.Source ?? new Rectangle(0, 0, obj.Width, obj.Height), item.Destination);
                    _cachedAlteredTextures[assetKey] = texture;
                    obj = texture;
                }
            }

            Log.Verbose($"Using own asset replacement: {assetName} = {item.OwningMod.Name}.{item.Texture}");
            return(obj);
        }
コード例 #3
0
 protected override void PreWarm()
 {
     Debug.LogDebug($"Profiler resolution: {Debug.GetProfilerResolution():n0} ticks/sec, High res: {(Debug.IsProfilerHighResolution() ? "Yes" : "No")}");
     TextureRegistry.CheckIn();
     ShaderRegistry.CheckIn();
     __BlockInformation.GetAllBlockInformation();
 }
コード例 #4
0
        protected override void Load()
        {
            Debug.Profile("Loading assets", true, new Task(() =>
            {
                Debug.Profile("Loading textures", true, new Task(() =>
                {
                    // Load textures
                    TextureRegistry.Register(Texture.Load("loading_texture", "textures/gui/loading.png"));
                    TextureRegistry.Register(Texture.Load("block_placeholder", "textures/blocks/placeholder.png"));
                }));

                Debug.Profile("Loading shaders", true, new Task(() =>
                {
                    // Load shaders
                    ShaderRegistry.Register(Shader.Load("interface_shader", "shaders/ui_shader.vert", "shaders/ui_shader.frag"));
                }));

                /*Debug.Profile("Loading models", true, new Task(() =>
                 * {
                 *
                 * }));*/

                /*Debug.Profile("Loading sounds", true, new Task(() =>
                 * {
                 *
                 * }));*/

                /*Debug.Profile("Loading music", true, new Task(() =>
                 * {
                 *
                 * }));*/
            }));
        }
コード例 #5
0
        /// <summary>
        /// Registers a new item
        /// </summary>
        /// <param name="item">Information of item to register</param>
        public static void RegisterItem <T>(ItemInformation item)
        {
            if (Game1.objectSpriteSheet == null)
            {
                throw new Exception("objectInformation is null! This likely occurs if you try to register an item before AfterContentLoaded");
            }

            item.Id = IdManager.AssignNewIdSequential(Game1.objectInformation);
            Items.Add(item);
            TextureUtility.AddSpriteToSpritesheet(ref Game1.objectSpriteSheet, TextureRegistry.GetItem(item.Texture)?.Texture, item.Id, 16, 16);
            Game1.objectInformation[item.Id] = item.ToString();
        }
コード例 #6
0
ファイル: layer.cs プロジェクト: jgiacomini/xamarin.flutter
 public PaintContext(SKCanvas canvas,
                     ExternalViewEmbedder view_embedder,
                     TextureRegistry texture_registry,
                     RasterCache raster_cache,
                     bool checkerboard_offscreen_layers)
 {
     this.canvas           = canvas;
     this.view_embedder    = view_embedder;
     this.texture_registry = texture_registry;
     this.raster_cache     = raster_cache;
     this.checkerboard_offscreen_layers = checkerboard_offscreen_layers;
 }
コード例 #7
0
 public bool Exists(ModManifest mod)
 {
     if (IsXnb)
     {
         return(System.IO.File.Exists(AbsoluteFilePath + ".xnb"));
     }
     if (IsTexture)
     {
         return(TextureRegistry.GetItem(Texture, mod) != null);
     }
     return(false);
 }
コード例 #8
0
ファイル: layer.cs プロジェクト: ishrakland/xamarin.flutter
 public PrerollContext(RasterCache raster_cache,
                       GRContext gr_context,
                       SKColorSpace dst_color_space,
                       SKRect child_paint_bounds,
                       TextureRegistry texture_registry,
                       bool checkerboard_offscreen_layers)
 {
     this.raster_cache                  = raster_cache;
     this.gr_context                    = gr_context;
     this.dst_color_space               = dst_color_space;
     this.child_paint_bounds            = child_paint_bounds;
     this.texture_registry              = texture_registry;
     this.checkerboard_offscreen_layers = checkerboard_offscreen_layers;
 }
コード例 #9
0
        public SKPicture Flatten(SKRect bounds)
        {
            TRACE_EVENT0("flutter", "LayerTree::Flatten");

            SKPictureRecorder recorder = new SKPictureRecorder();
            var canvas = recorder.BeginRecording(bounds);

            if (canvas == null)
            {
                return(null);
            }

            Stopwatch       unused_stopwatch            = new Stopwatch();
            TextureRegistry unused_texture_registry     = new TextureRegistry();
            SKMatrix        root_surface_transformation = new SKMatrix();

            // No root surface transformation. So assume identity.
            canvas.ResetMatrix();

            PrerollContext preroll_context = new PrerollContext(
                null, null, null,
                SKRect.Empty,
                unused_stopwatch,
                unused_stopwatch,
                unused_texture_registry,
                false);

            Layer.PaintContext paint_context = new Layer.PaintContext(
                canvas, null,
                unused_stopwatch,
                unused_stopwatch,
                unused_texture_registry,
                null, false);

            // Even if we don't have a root layer, we still need to create an empty
            // picture.
            if (root_layer_ != null)
            {
                root_layer_.Preroll(preroll_context, root_surface_transformation);
                // The needs painting flag may be set after the preroll. So check it after.
                if (root_layer_.needs_painting())
                {
                    root_layer_.Paint(paint_context);
                }
            }

            return(recorder.EndRecording());
        }
コード例 #10
0
        public void LoadContent(ModManifest mod)
        {
            Logging.Log.Verbose("Loading Content");
            if (Textures != null)
            {
                foreach (var texture in Textures)
                {
                    texture.AbsoluteFilePath = $"{mod.ModDirectory}\\{Constants.ModContentDirectory}\\{texture.File}";

                    if (!texture.Exists())
                    {
                        throw new Exception($"Missing Texture: {texture.AbsoluteFilePath}");
                    }

                    Logging.Log.Verbose($"Registering new texture: {texture.Id}");
                    TextureRegistry.RegisterItem(texture.Id, texture, mod);
                }
            }

            if (Xnb == null)
            {
                return;
            }

            foreach (var file in Xnb)
            {
                if (file.IsXnb)
                {
                    file.AbsoluteFilePath = $"{mod.ModDirectory}\\{Constants.ModContentDirectory}\\{file.File}";
                }
                file.OwningMod = mod;
                if (!file.Exists(mod))
                {
                    if (file.IsXnb)
                    {
                        throw new Exception($"Replacement File: {file.AbsoluteFilePath}");
                    }
                    if (file.IsTexture)
                    {
                        throw new Exception($"Replacement Texture: {file.Texture}");
                    }
                }
                Logging.Log.Verbose("Registering new texture XNB override");
                XnbRegistry.RegisterItem(file.Original, file);
            }
        }
コード例 #11
0
        public GadgetView(TextureRegistry texRegistry, Gadget gadget, WindowSpace space)
        {
            TextureRegistry = texRegistry;
            Gadget          = gadget;
            Space           = space;

            ToolTip = gadget.Command;

            HorizontalAlignment = HorizontalAlignment.Left;
            VerticalAlignment   = VerticalAlignment.Top;
            UseLayoutRounding   = true;
            SnapsToDevicePixels = true;

            Arrange();

            IsVisibleChanged += GadgetView_IsVisibleChanged;
            MouseEnter       += GadgetView_MouseEnter;
            MouseLeave       += GadgetView_MouseLeave;

            Gadget.OnPropertyChanged(VisualChange, "Hidden", "Rectangle1024");
        }
コード例 #12
0
        public void ResetTextures(VisualElement ve)
        {
            AtlasBase       atlas             = this.atlas;
            TextureRegistry registry          = m_TextureRegistry;
            BasicNodePool <TextureEntry> pool = m_TexturePool;

            BasicNode <TextureEntry> current = ve.renderChainData.textures;

            ve.renderChainData.textures = null;
            while (current != null)
            {
                var next = current.next;
                if (current.data.replaced)
                {
                    atlas.ReturnAtlas(ve, current.data.source as Texture2D, current.data.actual);
                }
                else
                {
                    registry.Release(current.data.actual);
                }
                pool.Return(current);
                current = next;
            }
        }
コード例 #13
0
        public PrerollContext(RasterCache raster_cache,
                              GRContext gr_context,
                              SKColorSpace dst_color_space,
                              SKRect child_paint_bounds,
                              Stopwatch frameTime,
                              Stopwatch engineTime,
                              TextureRegistry texture_registry,
                              bool checkerboard_offscreen_layers)
        {
            this.raster_cache = raster_cache;

            if (raster_cache == null)
            {
                this.raster_cache = new RasterCache();
            }

            this.gr_context                    = gr_context;
            this.dst_color_space               = dst_color_space;
            this.child_paint_bounds            = child_paint_bounds;
            this.frame_time                    = frameTime;
            this.engine_time                   = engineTime;
            this.texture_registry              = texture_registry;
            this.checkerboard_offscreen_layers = checkerboard_offscreen_layers;
        }
コード例 #14
0
        public void LoadContent()
        {
            if (this.Content == null)
            {
                return;
            }

            Log.Verbose("Loading Content");
            if (this.Content.Textures != null)
            {
                foreach (var texture in this.Content.Textures)
                {
                    texture.Texture = ApplicationResourcesUtility.LoadTexture(texture.File);

                    if (texture.Texture == null)
                    {
                        throw new Exception($"Missing API Texture: {texture.File}");
                    }

                    Log.Verbose($"Registering new API texture: {texture.Id}");
                    TextureRegistry.RegisterItem(texture.Id, texture);
                }
            }

            if (this.Content.Maps != null)
            {
                foreach (var map in this.Content.Maps)
                {
                    map.Map = ApplicationResourcesUtility.LoadMap(map.File);

                    if (map.Map == null)
                    {
                        throw new Exception($"Missing API map: {map.AbsoluteFilePath}");
                    }

                    Log.Verbose($"Registering new API map: {map.Id}");
                    MapRegistry.RegisterItem(map.Id, map);
                }
            }

            if (this.Content.Xnb == null)
            {
                return;
            }

            foreach (var file in this.Content.Xnb)
            {
                if (file.IsXnb)
                {
                    throw new NotImplementedException();
                }

                file.OwningMod = null;

                if (!file.Exists(null))
                {
                    if (file.IsXnb)
                    {
                        throw new Exception($"Replacement File: {file.AbsoluteFilePath}");
                    }

                    if (file.IsTexture)
                    {
                        throw new Exception($"Replacement Texture: {file.Texture}");
                    }
                }

                Log.Verbose("Registering new API texture XNB override");
                XnbRegistry.RegisterItem(file.Original, file);
            }
        }
コード例 #15
0
 public GameRegistry()
 {
     _textures = new TextureRegistry();
 }
コード例 #16
0
 /// <summary>
 ///     Gets a texture registered by this mod via it's manifest file
 /// </summary>
 /// <param name="id">
 ///     The id of the texture.
 /// </param>
 /// <returns>
 ///     The registered <see cref="Texture2D" />.
 /// </returns>
 public Texture2D GetTexture(string id)
 {
     return(TextureRegistry.GetItem(id, this).Texture);
 }
コード例 #17
0
        internal void LoadContent()
        {
            if (this.Content == null)
            {
                return;
            }

            Log.Verbose("Loading Content");
            if (this.Content.Textures != null)
            {
                foreach (var texture in this.Content.Textures)
                {
                    texture.AbsoluteFilePath = $"{this.ModDirectory}\\{Constants.ModContentDirectory}\\{texture.File}";

                    if (!texture.Exists())
                    {
                        throw new Exception($"Missing Texture: {texture.AbsoluteFilePath}");
                    }

                    Log.Verbose($"Registering new texture: {texture.Id}");
                    TextureRegistry.RegisterItem(texture.Id, texture, this);
                }
            }

            if (this.Content.Maps != null)
            {
                foreach (var map in this.Content.Maps)
                {
                    map.AbsoluteFilePath = $"{this.ModDirectory}\\{Constants.ModContentDirectory}\\{map.File}";

                    if (!map.Exists())
                    {
                        throw new Exception($"Missing map: {map.AbsoluteFilePath}");
                    }

                    Log.Verbose($"Registering new map: {map.Id}");
                    MapRegistry.RegisterItem(map.Id, map, this);
                }
            }

            if (this.Content.Xnb == null)
            {
                return;
            }

            foreach (var file in this.Content.Xnb)
            {
                if (file.IsXnb)
                {
                    file.AbsoluteFilePath = $"{this.ModDirectory}\\{Constants.ModContentDirectory}\\{file.File}";
                }

                file.OwningMod = this;
                if (!file.Exists(this))
                {
                    if (file.IsXnb)
                    {
                        throw new Exception($"Replacement File: {file.AbsoluteFilePath}");
                    }

                    if (file.IsTexture)
                    {
                        throw new Exception($"Replacement Texture: {file.Texture}");
                    }
                }

                Log.Verbose("Registering new texture XNB override");
                XnbRegistry.RegisterItem(file.Original, file, this);
            }
        }
コード例 #18
0
        public override void setUpIcons()
        {
            this.buttons.Clear();

            var index = 0;

            this.buttons.Add(
                new ClickableTextureComponent(
                    "New",
                    new Rectangle(
                        this.width / 2 + this.GetItemOffsetX(index++, 3 + CustomOptions.Count),
                        this.height - 174 - 24,
                        222,
                        174),
                    string.Empty,
                    "New",
                    this.titleButtonsTexture,
                    new Rectangle(0, 187, 74, 58),
                    3f));
            this.buttons.Add(
                new ClickableTextureComponent(
                    "Load",
                    new Rectangle(
                        this.width / 2 + this.GetItemOffsetX(index++, 3 + CustomOptions.Count),
                        this.height - 174 - 24,
                        222,
                        174),
                    string.Empty,
                    "Load",
                    this.titleButtonsTexture,
                    new Rectangle(74, 187, 74, 58),
                    3f));
            foreach (var customOption in CustomOptions)
            {
                this.buttons.Add(
                    new ClickableTextureComponent(
                        customOption.Key,
                        new Rectangle(
                            this.width / 2 + this.GetItemOffsetX(index++, 3 + CustomOptions.Count),
                            this.height - 174 - 24,
                            222,
                            174),
                        string.Empty,
                        customOption.Key,
                        customOption.Texture,
                        customOption.TextureSourceRect,
                        3f));
            }

            this.buttons.Add(
                new ClickableTextureComponent(
                    "Exit",
                    new Rectangle(
                        this.width / 2 + this.GetItemOffsetX(index, 3 + CustomOptions.Count),
                        this.height - 174 - 24,
                        222,
                        174),
                    string.Empty,
                    "Exit",
                    this.titleButtonsTexture,
                    new Rectangle(222, 187, 74, 58),
                    3f));

            var num = this.height < 800 ? 2 : 3;

            this.eRect = new Rectangle(
                this.width / 2 - 200 * num + 251 * num,
                -300 * num - (int)(this.viewportY / 3.0) * num + 26 * num,
                42 * num,
                68 * num);
            this.folderButton = new ClickableTextureComponent(
                "Folder",
                new Rectangle(57, this.height - 75 - 24, 72, 75),
                string.Empty,
                "Mods Folder",
                TextureRegistry.GetItem("FarmhandUI.modTitleMenu").Texture,
                new Rectangle(52, 458, 24, 25),
                3f);
            this.backButton = new ClickableTextureComponent(
                "Back",
                new Rectangle(this.width - 198 - 48, this.height - 81 - 24, 198, 81),
                string.Empty,
                "Back",
                this.titleButtonsTexture,
                new Rectangle(296, 252, 66, 27),
                3f);
            this.aboutButton = new ClickableTextureComponent(
                "About",
                new Rectangle(this.width - 66 - 48, this.height - 75 - 24, 66, 75),
                string.Empty,
                "About",
                this.titleButtonsTexture,
                new Rectangle(8, 458, 22, 25),
                3f);
            this.skipButton =
                new ClickableComponent(
                    new Rectangle(this.width / 2 - 261, this.height / 2 - 102, 249, 201),
                    "Skip",
                    string.Empty);
        }
コード例 #19
0
ファイル: Overlord.cs プロジェクト: Weesals/ModHQ
        public void Load(Action <LogCapture> onLoad)
        {
            TextureRegistry = new TextureRegistry();
            TextureRegistry.Initialize(Texture2File, TextureFile);
            PrototypeList protoList    = null;
            Action        completeLoad = () => {
                Prototypes = protoList;
                var logger = SerializationContext.GetService <LogCapture>();
                if (logger != null)
                {
                    onLoad(logger);

                    /*string errors = logger.ErrorsAsString, warnings = logger.WarningsAsString, infos = logger.InfosAsString;
                     * if (!string.IsNullOrWhiteSpace(errors) || !string.IsNullOrWhiteSpace(warnings) || !string.IsNullOrWhiteSpace(infos)) {
                     *  MessageBox.Show("Load complete." +
                     *      (!string.IsNullOrWhiteSpace(errors) ? "\n\nErrors:\n" + errors : "") +
                     *      (!string.IsNullOrWhiteSpace(warnings) ? "\n\nWarnings:\n" + warnings : "") +
                     *      (!string.IsNullOrWhiteSpace(infos) ? "\n\nInfo:\n" + infos : "")
                     *  );
                     * }*/
                    logger.Clear();
                }
                if (OnLoad != null)
                {
                    OnLoad();
                }
                loaded = true;
                NotifyPropertyChanged("IsLoaded", "IsNotLoaded");
            };

            ThreadPool.QueueUserWorkItem(delegate {
                /*using (var outFile = File.Create(@"E:\Games\AOM - Other shit\extracted\protox_uncomp.xmb")) {
                 *  XMBFile.DecompressAndSkipHeader(DataFile.GetFileStream("protox.xmb")).CopyTo(outFile);
                 * }*/
                Data.XMBFile protoFile = null;
                if (protoFile == null)
                {
                    try { LoadXMB(Data2File ?? DataFile, "protox.xmb"); } catch { }
                }
                if (protoFile == null)
                {
                    try { protoFile = LoadXMB(Data2File ?? DataFile, "proto.xmb"); } catch { }
                }
                if (protoFile == null)
                {
                    try { protoFile = LoadXMB(Data2File ?? DataFile, "proto.xml"); } catch { }
                }

                /*string fileName = @"E:\Games\AOM - Other shit\extracted\protox_my_uncomp.xmb";
                 * using (var protoFileOut = File.Create(fileName)) { protoFile.Save(protoFileOut, false); }
                 * XMBFile protoFile2 = null;
                 * using (var protoFileOut = File.OpenRead(fileName)) { protoFile2 = XMBFile.Load(protoFileOut); }
                 * using (var protoFileOut = File.Create(fileName + ".xml")) { protoFile2.GetAsXDocument().Save(protoFileOut); }*/
                if (protoFile != null)
                {
                    using (new XElementExt.Case(true)) {
                        var xml   = protoFile.GetAsXDocument();
                        protoList = new ProtoXML().Deserialize(
                            SerializationContext,
                            xml.Root
                            );
                    }
                }
                App.Current.Dispatcher.BeginInvoke(completeLoad);
            });
        }