Ejemplo n.º 1
0
        public static bool PresetSaveHook(CharacterMgr mgr, out CharacterMgr.Preset preset, Maid maid,
                                          CharacterMgr.PresetType presetType)
        {
            if (!Input.GetKey(KeyCode.LeftControl) && !Input.GetKey(KeyCode.LeftControl))
            {
                preset = null;
                return(false);
            }

            preset = new CharacterMgr.Preset
            {
                ePreType = presetType,
                texThum  = ThumShot.ShotThumPreset(maid)
            };

            var bigThumTex = ThumUtil.MakeMaidThumbnail(maid);

            if (!Directory.Exists(PresetPath))
            {
                Directory.CreateDirectory(PresetPath);
            }

            using (var bw = new BinaryWriter(File.Create(Path.Combine(PresetPath,
                                                                      $"pre_{maid.status.lastName}{maid.status.firstName}_{DateTime.Now:yyyyMMddHHmmss}.png"))))
            {
                // Load our layers and combine them
                // Janky AF, but it works, so /shrug
                Texture2D composedImagePreset;
                var       backgroundLayer = LoadPNG(Path.Combine(LayerPath, "background.png"));
                composedImagePreset = CombineTextures(backgroundLayer, bigThumTex);
                var foregroundLayer = LoadPNG(Path.Combine(LayerPath, "foreground.png"));
                composedImagePreset = CombineTextures(composedImagePreset, foregroundLayer);

                bw.Write(composedImagePreset.EncodeToPNG());
                bw.Write(mgr.PresetSaveNotWriteFile(maid, presetType));

                var exData = ExtPresetSupport.SaveExPresetData(maid);

                if (exData != null)
                {
                    bw.Write(EXT_DATA_BEGIN_MAGIC);
                    bw.Write(exData);
                    bw.Write(EXT_DATA_END_MAGIC);
                }
            }

            GameMain.Instance.SysDlg.Show(
                "Saved image as a preset card\n(If you want to save a normal preset, don't hold [CTRL] while saving)",
                SystemDialog.TYPE.OK);

            return(true);
        }