public override void Activate() { if (content == null) content = new ContentManager(Manager.Game.Services, "Content"); ImageFont font = new ImageFont(); font.LoadContent(content, "Textures/gamefont", 1f); font.SpaceWidth = 10; dialogs = new MessageDialog[introText.Length]; face = content.Load<Texture2D>("Textures/Face1"); float y = 2 * ScreenHelper.Viewport.Height / 3; for (int i = 0; i < introText.Length; ++i) { float x = ScreenHelper.Center.X - font.MeasureString(introText[i]).X / 2; float height = font.MeasureString(introText[i]).Y + 10; dialogs[i] = new MessageDialog(font, new Vector2(x, y), introText[i], TimeSpan.FromSeconds(0.07), TimeSpan.FromSeconds(0.2)); y += height; } }
private void showNumber(int number, int type) { GameObject obj = GameObject.Instantiate(fontPrefab); obj.transform.SetParent(numberBack.transform); ImageFont script = obj.GetComponent <ImageFont> (); switch (type) { case 1: script.create("Battle/Number/zc_shanghaishu", number); break; case 2: script.create("Battle/Number/zc_baojishu", number); break; case 3: script.create("Battle/Number/zc_jiaxueshu", number); break; case 4: script.create(); break; } }
public ActionResult UploadFile(FormCollection collection, string type) { if (type == "UploadFile") { try { HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; if (files.Count == 0) { return(Json(new { status = "Fail", message = "请先上传文件!" }, JsonRequestBehavior.AllowGet)); } var fullFileName = $"/UploadFiles/FontFiles/{Guid.NewGuid() + "_" + files[0].FileName}"; if (!System.IO.File.Exists(fullFileName)) { files[0].SaveAs(Server.MapPath(fullFileName)); } return(Content(fullFileName)); } catch (Exception ex) { log.Error(ex); return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet)); } } try { ImageFont imageFont = new ImageFont(); imageFont.name = collection["Name"]; imageFont.ifSystem = false; var ifSystem = int.Parse(collection["ifSystem"]); if (0 == ifSystem) //非系统字体 { imageFont.ifSystem = false; imageFont.url = collection["imageFont"]; if (string.IsNullOrEmpty(imageFont.url)) { throw new Exception("请先上传字体文件!"); } } else//系统字体 { imageFont.ifSystem = true; imageFont.url = ""; } imageFontService.Add(imageFont); var logs = new Logs { Action = EnumAction.新建字体, Detail = imageFont.name, UserId = UserHelper.GetCurrentUser.Id, Time = DateTime.Now }; logService.Insert(logs); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error(ex); return(View()); } }
public int Add(ImageFont imageFont) { const string commandSQL = "INSERT INTO imagefont (NAME, URL, IfSystem) VALUES (@Name, @URL, @IfSystem)"; var parameters = new Dictionary <string, object> { { "Name", imageFont.name }, { "URL", imageFont.url }, { "IfSystem", imageFont.ifSystem } }; return(contexto.ExecuteCommand(commandSQL, parameters)); }
protected virtual void DisposeAlgo(bool disposing) { if (!disposed) { if (disposing) { // нету полей } Grap.Dispose(); ImageFont.Dispose(); SolBrush.Dispose(); disposed = true; } }
public List <ImageFont> GetAll() { List <ImageFont> list = new List <ImageFont>(); ImageFont imageFont = null; string sql = "SELECT * FROM imagefont ORDER BY CONVERT(NAME USING gbk);"; var rows = contexto.ExecuteCommandSQL(sql, null); foreach (var row in rows) { imageFont = new ImageFont(); imageFont.id = int.Parse(row["id"].ToString()); imageFont.name = row["Name"].ToString(); imageFont.url = row["URL"].ToString(); imageFont.ifSystem = Convert.ToBoolean(int.Parse(row["IfSystem"].ToString())); list.Add(imageFont); } return(list); }
private static void CreateFonts(MiyagiSystem system) { const string FontPath = @"../Media/Fonts/"; var fonts = new[] { // load ttf definitions from xml file TrueTypeFont.CreateFromXml(Path.Combine(FontPath, "TrueTypeFonts.xml"), system) .Cast <Font>().ToDictionary(f => f.Name), // load image font definitions from xml file ImageFont.CreateFromXml(Path.Combine(FontPath, "ImageFonts.xml"), system) .Cast <Font>().ToDictionary(f => f.Name) }; Fonts = fonts.SelectMany(dict => dict) .ToDictionary(pair => pair.Key, pair => pair.Value); // set BlueHighway as default font Font.Default = Fonts["Expressway"]; }
public ImageFont GetByName(string name) { ImageFont imageFont = null; string sql = "SELECT * FROM imagefont where name = @name limit 1;"; var parameters = new Dictionary <string, object> { { "name", name } }; var rows = contexto.ExecuteCommandSQL(sql, parameters); foreach (var row in rows) { imageFont = new ImageFont(); imageFont.id = int.Parse(row["id"].ToString()); imageFont.name = row["Name"].ToString(); imageFont.url = row["URL"].ToString(); imageFont.ifSystem = Convert.ToBoolean(int.Parse(row["IfSystem"].ToString())); } return(imageFont); }
private static void CreateFonts(MiyagiSystem system) { const string FontPath = @"../../../Media/Gfx/Fonts/"; var fonts = new[] { // load ttf definitions from xml file TrueTypeFont.CreateFromXml(Path.Combine(FontPath, "TrueTypeFonts.xml"), system) .Cast <Font>().ToDictionary(f => f.Name), // load image font definitions from xml file ImageFont.CreateFromXml(Path.Combine(FontPath, "ImageFonts.xml"), system) .Cast <Font>().ToDictionary(f => f.Name) }; Fonts = fonts.SelectMany(dict => dict) .ToDictionary(pair => pair.Key, pair => pair.Value); var font = TrueTypeFont.Create(system, "DejaVuSans", Path.Combine(FontPath, "DejaVuSans.ttf"), 12, 96, System.Drawing.FontStyle.Regular); Fonts.Add(font.Name, font); // set BlueHighway as default font Font.Default = Fonts["BlueHighway"]; }
public override void OnInspectorGUI() { ImageFont txt = target as ImageFont; if (txt) { showSyms = EditorGUILayout.Foldout(showSyms, "符号集"); if (showSyms) { for (int i = 0; i < txt.SymbolData.Length; i++) { SymbolData data = txt.SymbolData[i]; GUILayout.BeginHorizontal(); data.Value = GUILayout.TextField(data.Value, GUILayout.Width(150)); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); data.Sprite = EditorGUILayout.ObjectField(data.Sprite, typeof(Sprite), false, GUILayout.Height(32), GUILayout.Width(32)) as Sprite; //if(data.Sprite) // GUILayout.Label(data.Sprite.name,GUILayout.MaxWidth(150)); GUILayout.EndVertical(); GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(22f))) { SymbolData[] arr = txt.SymbolData; ArrayUtility.RemoveAt(ref arr, i); txt.SymbolData = arr; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); newName = GUILayout.TextField(newName, GUILayout.Width(150)); bool hasName = !string.IsNullOrEmpty(newName); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); newSprite = EditorGUILayout.ObjectField(newSprite, typeof(Sprite), false, GUILayout.Height(32), GUILayout.Width(32)) as Sprite; //bool hasSprite = newSprite; //if (hasSprite) // GUILayout.Label(newSprite.name, GUILayout.MaxWidth(150)); GUILayout.EndVertical(); bool isValid = hasName; GUI.backgroundColor = Color.green; if (GUILayout.Button("添加", GUILayout.Width(35f)) && isValid) { SymbolData d = new SymbolData(); d.Value = newName; d.Sprite = newSprite; if (txt.SymbolData.Length > 0) { SymbolData[] arr = new SymbolData[txt.SymbolData.Length + 1]; txt.SymbolData.CopyTo(arr, 0); arr[txt.SymbolData.Length] = d; txt.SymbolData = arr; } else { txt.SymbolData = new SymbolData[1] { d }; } newName = ""; newSprite = null; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (txt.SymbolData.Length == 0) { EditorGUILayout.HelpBox("想要添加表情符号吗? 在第一个文本框中输入表情字符,例如‘:)’,然后第二个图片栏中选上对应的图片,再点击添加即可", MessageType.Info); } else { GUILayout.Space(4f); } } } serializedObject.Update(); serializedObject.ApplyModifiedProperties(); }
public void LoadContent(ImageFont font, Texture2D texture) { _SpriteBatch = new SpriteBatch(ScreenHelper.GraphicsDevice); _Font = font; _Hud = texture; }
public ActionResult Create(FormCollection collection, string type) { Order order = new Order(); order.SampleId = int.Parse(collection["SampleId"]); order.TaobaoId = order.SampleId + "_" + DateTime.Now.Ticks; order.ImageUrl = collection["ImageUrl"]; string mainText = collection["MainText"] ?? ""; string smallText = collection["SmallText"] ?? ""; order.MainText = mainText.Trim(); order.SmallText = smallText.Trim(); string fontStr = collection["Font"]; ImageFont font = null; order.Sample = sampleService.GetSample(order.SampleId, true); if (fontStr != "" && fontStr != "0") //改了sample的字体 { int fontId = int.Parse(fontStr); font = imageFontService.GetById(fontId); order.Font = font.name; order.Sample.ImageFont = font; } else//沿用sample的字体 { order.Font = order.Sample.Font; font = imageFontService.GetByName(order.Sample.Font); order.Sample.ImageFont = font; } if (type == "提交订单") { try { if (string.IsNullOrEmpty(order.ImageUrl)) { throw new Exception("请先生成订单图片!"); } order.SubmitTime = DateTime.Now; order.Status = (int)EnumStatus.待审批; order.SubmitTime = DateTime.Now; order.ProductTime = DateTime.MinValue; order.AuditTime = DateTime.MinValue; order.DeleteTime = DateTime.MinValue; orderService.Save(order); string logDetail = order.Sample.ImageType.ToString() + "-" + order.MainText; var logs = new Logs { Action = EnumAction.新建订单, Detail = logDetail, UserId = UserHelper.GetCurrentUser.Id, Time = DateTime.Now }; logService.Insert(logs); return(RedirectToAction("DownloadFile", new { imageURL = order.ImageUrl })); } catch (Exception ex) { ViewBag.Message = ex.Message; log.Error(ex); return(View("Create", order.Sample)); } } else if (type == "CreateImage") { try { var ifExist = orderService.CheckTaobaoIdExist(order.TaobaoId); if (ifExist) { return(Json(new { status = "Fail", message = "该淘宝订单号已经生成订单!" }, JsonRequestBehavior.AllowGet)); } if (order.MainText.Length != order.Sample.MainTextNumber) { return(Json(new { status = "Fail", message = "输入的文字数量不对!" }, JsonRequestBehavior.AllowGet)); } for (int i = 0; i < order.Sample.MainTextNumber; i++) { order.Sample.MainText[i].Text = order.MainText[i].ToString(); } if (order.Sample.IfHasSmallText) { var smallTextArray = collection.AllKeys.Where(t => t.StartsWith("SmallText")); foreach (var item in smallTextArray) { string indexSt = item.Substring(9, 1); int i = Convert.ToInt32(indexSt); string text = collection["SmallText" + i].ToString(); if (text.Length > Constants.smallTextLimits) { return(Json(new { status = "Fail", message = "副文字不能超过11个字!" }, JsonRequestBehavior.AllowGet)); } order.Sample.SmallText[i - 1].Text = text; } } string imageUrl = ImageHelp.CreateImage(order.Sample, false, order.TaobaoId); var logs = new Logs { Action = EnumAction.创建订单图片, Detail = order.MainText, UserId = UserHelper.GetCurrentUser.Id, Time = DateTime.Now }; logService.Insert(logs); var result = Json(imageUrl); return(result); } catch (Exception ex) { log.Error(ex); return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet)); } } return(View(order)); }
public ActionResult Update(FormCollection collection, string type) { try { #region init sample data int sampleId = int.Parse(collection["ID"]); Sample sample = sampleService.GetSample(sampleId, true); sample.IfHasBgImg = Convert.ToBoolean(int.Parse(collection["DDLIfHasBgImg"])); if (!sample.IfHasBgImg) { sample.BgImage = ""; } else { sample.BgImage = collection["BgImage"]; } if (type == "UploadFile") //处理上传背景图片 { HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; if (files.Count == 0) { return(Json(new { status = "Fail", message = "请先上传文件!" }, JsonRequestBehavior.AllowGet)); } try { var fullFileName = $"/UploadFiles/BgImages/{Guid.NewGuid() + "_" + files[0].FileName}"; if (!System.IO.File.Exists(fullFileName)) { files[0].SaveAs(Server.MapPath(fullFileName)); } sample.BgImage = fullFileName; sample.IfHasBgImg = true; return(Json(fullFileName)); } catch (Exception ex) { log.Error(ex.Message); return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet)); } } sample.Name = collection["Name"]; sample.ImageUrl = collection["ImageUrl"]; List <ImageText> mainTexts = new List <ImageText>(); ImageText imageText = null; ImageFont imageFont = null; int fontId = int.Parse(collection["Font"]); imageFont = imageFontService.GetById(fontId); sample.Font = imageFont.name;//第一个字的字体作为sample的字体,用于搜索过滤。 sample.ImageFont = imageFont; string sizeStr = collection["Size"]; sample = Utils.SetSize(sizeStr, sample); for (int i = 1; i < 5; i++) { if (!string.IsNullOrEmpty(collection["Text" + i])) { imageText = new ImageText(); imageText.Text = collection["Text" + i]; imageText.Font = imageFont.name; imageText.imageFont = imageFont; imageText.FontSize = int.Parse(collection["FontSize" + i]); imageText.PositionX = int.Parse(collection["PositionX" + i]); imageText.PositionY = int.Parse(collection["PositionY" + i]); imageText.Type = (int)EnumTextType.MainText; imageText.Order = true; mainTexts.Add(imageText); } } sample.MainText = mainTexts; sample.MainTextNumber = mainTexts.Count; // todo //if (!string.IsNullOrEmpty(collection["Text5"])) //small text //{ // imageText = new ImageText(); // imageText.Text = collection["Text5"]; // imageText.Font = imageFont.name; // imageText.imageFont = imageFont; // imageText.FontSize = int.Parse(collection["FontSize5"]); // imageText.PositionX = int.Parse(collection["PositionX5"]); // imageText.PositionY = int.Parse(collection["PositionY5"]); // imageText.Type = (int)EnumTextType.SmallText; // imageText.Order = Convert.ToBoolean(int.Parse(collection["FontOrder"])); // sample.IfHasSmallText = true; // sample.SmallText = imageText; //} #endregion if (type == "保存") { if (string.IsNullOrEmpty(sample.ImageUrl)) { throw new Exception("请先生成样式图片!"); } sampleService.Update(sample); return(RedirectToAction("Index")); } else if (type == "CreateImage") { try { InitData(); if (!CheckUpdateNameUnique(sample.Name, sample.Id)) { return(Json(new { status = "Fail", message = "该名称已经存在,请使用唯一的名称!" }, JsonRequestBehavior.AllowGet)); } string imageUrl = ImageHelp.CreateImage(sample, true, null); return(Json(imageUrl)); } catch (Exception ex) { log.Error(ex.Message); return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet)); } } return(View()); } catch (Exception ex) { InitData(); ViewBag.Message = ex.Message; log.Error(ex); return(View("Update")); } }
public ActionResult Create(FormCollection collection, string type) { try { #region init sample data Sample sample = new Sample(); sample.IfHasBgImg = Convert.ToBoolean(int.Parse(collection["IfHasBgImage"])); if (!sample.IfHasBgImg) { sample.BgImage = ""; } else { sample.BgImage = collection["BgImage"]; } if (type == "UploadFile") //处理上传背景图片 { HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; if (files.Count == 0) { return(Json(new { status = "Fail", message = "请先上传文件!" }, JsonRequestBehavior.AllowGet)); } try { var fullFileName = $"/UploadFiles/BgImages/{Guid.NewGuid() + "_" + files[0].FileName}"; if (!System.IO.File.Exists(fullFileName)) { files[0].SaveAs(Server.MapPath(fullFileName)); } sample.BgImage = fullFileName; sample.IfHasBgImg = true; return(Json(fullFileName)); } catch (Exception ex) { log.Error(ex.Message); return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet)); } } sample.Name = collection["Name"]; sample.ImageType = (EnumImageType)int.Parse(collection["ImageType"]); sample.Style = (EnumImageStyle)int.Parse(collection["Style"]); sample.ImageUrl = collection["ImageUrl"]; string sizeStr = collection["Size"]; sample = Utils.SetSize(sizeStr, sample); List <ImageText> mainTexts = new List <ImageText>(); List <ImageText> smallTexts = new List <ImageText>(); ImageText imageText = null; ImageFont imageFont = null; int fontId = int.Parse(collection["Font"]); imageFont = imageFontService.GetById(fontId); sample.Font = imageFont.name;//第一个字的字体作为sample的字体,用于搜索过滤。 sample.ImageFont = imageFont; var mainTextArray = collection.AllKeys.Where(t => t.StartsWith("Text")); //把所有Text开头的拿出来,遍历。 foreach (string str in mainTextArray) { int i = Convert.ToInt32(str.Substring(4, 1)); //Text1 取后面的数字 string text = collection["Text" + i]; if (!string.IsNullOrEmpty(text)) { imageText = new ImageText(); imageText.Text = text; imageText.Font = imageFont.name; imageText.imageFont = imageFont; imageText.FontSize = int.Parse(collection["FontSize" + i]); imageText.PositionX = int.Parse(collection["PositionX" + i]); imageText.PositionY = int.Parse(collection["PositionY" + i]); imageText.Type = (int)EnumTextType.MainText; imageText.Order = true; mainTexts.Add(imageText); } } sample.MainText = mainTexts; sample.MainTextNumber = mainTexts.Count; var smallTextArray = collection.AllKeys.Where(t => t.StartsWith("SmallText")); //把所有SmallText开头的拿出来,遍历。 foreach (string str in smallTextArray) { int i = Convert.ToInt32(str.Substring(9, 1)); //SmallText1 取后面的数字 string text = collection["SmallText" + i]; if (!string.IsNullOrEmpty(text)) //small text { imageText = new ImageText(); imageText.Text = text; imageText.Font = imageFont.name; imageText.imageFont = imageFont; imageText.FontSize = int.Parse(collection["SmallFontSize" + i]); imageText.PositionX = int.Parse(collection["SmallPositionX" + i]); imageText.PositionY = int.Parse(collection["SmallPositionY" + i]); imageText.Type = (int)EnumTextType.SmallText; imageText.Order = Convert.ToBoolean(int.Parse(collection["SmallFontOrder" + i])); smallTexts.Add(imageText); } } sample.SmallText = smallTexts; if (smallTexts.Count > 0) { sample.IfHasSmallText = true; sample.SmallTextNumber = smallTexts.Count; } #endregion if (type == "保存") { if (string.IsNullOrEmpty(sample.ImageUrl)) { throw new Exception("请先生成样式图片!"); } sampleService.Insert(sample); var logs = new Logs { Action = EnumAction.新建预设样式, Detail = sample.Name, UserId = UserHelper.GetCurrentUser.Id, Time = DateTime.Now }; logService.Insert(logs); return(RedirectToAction("Index")); } else if (type == "CreateImage") { try { InitData(); if (!CheckNameUnique(sample.Name)) { return(Json(new { status = "Fail", message = "该名称已经存在,请使用唯一的名称!" }, JsonRequestBehavior.AllowGet)); } string imageUrl = ImageHelp.CreateImage(sample, true, null); return(Json(imageUrl)); } catch (Exception ex) { log.Error(ex.Message); return(Json(new { status = "Fail", message = ex.Message }, JsonRequestBehavior.AllowGet)); } } return(View()); } catch (Exception ex) { InitData(); ViewBag.Message = ex.Message; log.Error(ex); return(View("Create")); } }