public IViewComponentResult Invoke(string widgetZone, object additionalData) { //Validate the request is being invoked from admin order's page if (!(additionalData is OrderModel order)) { return(View("~/Plugins/Widgets.ProductPictureModifier/Views/PublicCartColorSelector.cshtml", new List <ProductPictureModifierModel>())); } var cartPictureModifierModel = new List <ProductPictureModifierModel>(); foreach (var orderItem in order.Items) { string[] attributes = orderItem.AttributeInfo.Split("<br />"); string colorAttributesString = attributes .FirstOrDefault(x => x.Contains(ProductPictureModifierDefault.ProductAttributeName)); string customUploadAttribute = attributes.FirstOrDefault(x => x.Contains($"{ProductPictureModifierDefault.ProductAttributeNameForLogoUpload}: <a href=")); if (string.IsNullOrWhiteSpace(colorAttributesString) || colorAttributesString.Split(":").Length != 2) { continue; } (int, string)mergedPicture = (0, ""); if (!string.IsNullOrEmpty(customUploadAttribute)) { //Get the download Download download = _productPictureModifierService.GetDownloadFromAttributeXml(customUploadAttribute); //Get position setting LogoPosition logoPosition = _logoPositionService.GetByProductId(orderItem.ProductId); //Get the picture with custom logo mergedPicture = _customLogoService.MergeProductPictureWithLogo( download.DownloadBinary, download.Id, orderItem.ProductId, ProductPictureModifierUploadType.Custom, logoPosition.Size, logoPosition.Opacity, logoPosition.XCoordinate, logoPosition.YCoordinate, 75 ); } cartPictureModifierModel.Add(new ProductPictureModifierModel { ColorCode = colorAttributesString.Split(":").Last().Trim(), EntityId = orderItem.Id, CustomImagePath = mergedPicture.Item2 }); } return(View("~/Plugins/Widgets.ProductPictureModifier/Views/AdminOrderItemsColor.cshtml", cartPictureModifierModel)); }
/// <inheritdoc cref="ILogoPositionService.Update"/> public void Update(LogoPosition position) { if (position == null) { throw new ArgumentNullException(nameof(position)); } _logoPositionRepository.Update(position); }
/// <summary> /// Retrieves the preferences members in the EditorPrefs. /// </summary> static void LoadPreferencesMembers() { s_PrefsLoaded = true; s_EnabledStateName = EditorPrefs.GetBool("BM.EnabledStateName", true); s_EditorOnGUI = EditorPrefs.GetBool("BM.EditorOnGUI", true); s_SnapMove = EditorPrefs.GetFloat("BM.SnapMove", 10f); s_ShowScrollView = EditorPrefs.GetBool("BM.ShowScrollView", false); s_LogoPosition = (LogoPosition)EditorPrefs.GetInt("BM.LogoPosition", 0); }
/// <inheritdoc cref="ILogoPositionService.Insert"/> public void Insert(LogoPosition position) { if (position == null) { throw new ArgumentNullException(nameof(position)); } _logoPositionRepository.Insert(position); }
static void BehaviourMachinePreferencesGUI() { if (s_Styles == null) { s_Styles = new BehaviourMachinePrefs.Styles(); } if (!s_PrefsLoaded) { LoadPreferencesMembers(); } // Draw preferences gui s_EnabledStateName = EditorGUILayout.Toggle(new GUIContent("Show States Name Gizmo", "The name of the enabled states should be shown as a gizmo?"), s_EnabledStateName); s_EditorOnGUI = EditorGUILayout.Toggle(new GUIContent("OnGUI nodes in the Editor", "WYSIWYG option. If True you can see your Unity GUI controls while editing an ActionState or BehaviourTree"), s_EditorOnGUI); s_SnapMove = Mathf.Max(0f, EditorGUILayout.FloatField(new GUIContent("State Snap Move", "The value to snap the states in the {b}'s window grid"), s_SnapMove)); s_ShowScrollView = EditorGUILayout.Toggle(new GUIContent("Show Scroll View?", "If True the {b} window will show the scroll view"), s_ShowScrollView); s_LogoPosition = (LogoPosition)EditorGUILayout.EnumPopup(new GUIContent("{b} Logo Position", "Used for the {b} logo in the Hierarchy view"), s_LogoPosition); // Save preferences? if (GUI.changed) { SavePreferencesMembers(); } // Reset preferences? EditorGUILayout.Space(); if (GUILayout.Button("Use Defaults", GUILayout.Width(120f))) { ResetToDefaults(); } // Updater EditorGUILayout.Space(); EditorGUILayout.LabelField(string.Empty, s_Styles.line); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Auto Update"); EditorGUILayout.BeginVertical(); if (GUILayout.Button(new GUIContent("FsmEvent", "Use this update when the FsmEvents in this project are using an older serialization (version 1.2 or previous) data and need to be updated"))) { s_SelectedOption = 1; EditorApplication.delayCall += OnDelayCall; } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); }
public IActionResult Edit(ProductPictureModifierModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets)) { return(AccessDeniedView()); } //todo find out why model state validation failed even though product id is only validated and model has product id if (model.ProductId < 1) { ModelState.AddModelError(nameof(model.ProductId), _localizationService.GetResource("Admin.Widgets.ProductPictureModifier.Fields.Product.Required")); return(View("~/Plugins/Widgets.ProductPictureModifier/Views/Admin/Edit.cshtml", model)); } ProductAttributeMapping productAttributeMapping = _productAttributeService. GetProductAttributeMappingById(model.EntityId); productAttributeMapping.DefaultValue = model.ColorCode; _productAttributeService.UpdateProductAttributeMapping(productAttributeMapping); //Update logo setting LogoPosition existingLogoSetting = _logoPositionService.GetByProductId(productAttributeMapping.ProductId); existingLogoSetting.ColorCode = model.ColorCode; _logoPositionService.Update(existingLogoSetting); //Clear the cache for product picture preparation _cacheManager.RemoveByPattern(string.Format(ModelCacheEventConsumer.PRODUCT_DEFAULTPICTURE_PATTERN_KEY_BY_ID, model.ProductId)); SuccessNotification(_localizationService.GetResource("Widgets.ProductPictureModifier.Mapping.Updated")); if (!continueEditing) { return(RedirectToAction("Configure")); } return(RedirectToAction("Edit", new { id = productAttributeMapping.Id })); }
/// <summary> /// Applies the scaling values based on the logo position /// </summary> /// <param name="o"></param> /// <param name="lp"></param> public void ApplyLogoPositionMagicValues(Overlay o, LogoPosition lp) { //Apply arbitrary pixel scaling factors switch (lp) { case LogoPosition.CenterChest: //6.5" max logo width o.PolyWidthInLogoPixels = 218; break; case LogoPosition.FullChest: //12" max logo width o.PolyWidthInLogoPixels = 402; break; case LogoPosition.LeftChest: //5.88" max logo width o.PolyWidthInLogoPixels = 197; break; case LogoPosition.LeftThigh: //4.5" max logo width o.PolyWidthInLogoPixels = 151; break; case LogoPosition.VerticalLeg: case LogoPosition.LeftSleeve: //3" max logo width - width of logo is left to right with logo hanging vertically //o.PolyWidthInLogoPixels = 101; - In fact, the previous algorithm NEVER applied this value, so specifying it will cause an undesired result. o.PolyHeightInLogoPixels = 469; //14" logo break; case LogoPosition.General: //3.5" o.PolyWidthInLogoPixels = 118; break; } }
public IActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets)) { return(AccessDeniedView()); } ProductAttributeMapping productAttributeMapping = _productAttributeService. GetProductAttributeMappingById(id); //_mediaSettings.ProductDetailsPictureSiz ProductPicture defaultProductPicture = _productPictureModifierService.GetFirstProductPicture(productAttributeMapping.ProductId); //Existing logoSetting LogoPosition existingLogoSetting = _logoPositionService.GetByProductId(productAttributeMapping.ProductId); var model = new ProductPictureModifierModel { CustomImagePath = defaultProductPicture == null ? "" : _pictureService.GetPictureUrl(defaultProductPicture.Picture), EntityId = productAttributeMapping.Id, ProductId = productAttributeMapping.ProductId, ProductName = productAttributeMapping.Product.Name, ColorCode = productAttributeMapping.DefaultValue, LogoModel = new LogoModel() { Opacity = IsLogoSettingNew(existingLogoSetting) ? ProductPictureModifierDefault.LogoOpacity : existingLogoSetting.Opacity, Size = IsLogoSettingNew(existingLogoSetting) ? ProductPictureModifierDefault.LogoSizeInPercent : existingLogoSetting.Size, XCoordinate = existingLogoSetting.XCoordinate, YCoordinate = existingLogoSetting.YCoordinate, MarkAsDefault = IsLogoSettingNew(existingLogoSetting) } }; model.LogoSearchModel.SetGridPageSize(); return(View("~/Plugins/Widgets.ProductPictureModifier/Views/Admin/Edit.cshtml", model)); }
public virtual IActionResult CustomLogoAdd(LogoModel logo) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageWidgets)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(Json(new { Result = false, Errors = GetErrorsFromModelState() })); } //Get 1st product picture we use 1st picture of product to combine with logo ProductPicture productPicture = _productPictureModifierService .GetFirstProductPicture(logo.ProductId); if (productPicture == null) { throw new Exception("Product does not have any image"); } byte[] logoBinary = _pictureService.LoadPictureBinary(_pictureService.GetPictureById(logo.PictureId)); //Get new product image which has been merged with the logo uploaded (int, string)mergedPicture = _logoService.MergeProductPictureWithLogo( logoBinary, logo.PictureId, logo.ProductId, ProductPictureModifierUploadType.Predefined, logo.Size, logo.Opacity, logo.XCoordinate, logo.YCoordinate, overrideThumb: true); if (logo.AttributeValueId > 0) { var existingAttributeValue = _productAttributeService. GetProductAttributeValueById(logo.AttributeValueId); var existingProductPicture = _productService.GetProductPicturesByProductId(logo.ProductId) .First(x => x.PictureId == existingAttributeValue.PictureId); //update product attribute value existingAttributeValue.PictureId = mergedPicture.Item1; existingAttributeValue.ImageSquaresPictureId = logo.PictureId; _productAttributeService.UpdateProductAttributeValue(existingAttributeValue); //update product picture existingProductPicture.PictureId = mergedPicture.Item1; _productService.UpdateProductPicture(existingProductPicture); return(Json(new { Result = true, AttributeId = logo.AttributeValueId })); } //Insert the image as product picture _productService.InsertProductPicture(new ProductPicture { ProductId = logo.ProductId, PictureId = mergedPicture.Item1, DisplayOrder = ProductPictureModifierDefault.MergedPictureDisplayOrder }); ProductAttribute logoAttribute = _productPictureModifierService .GetProductAttributeByName(ProductPictureModifierDefault.ProductAttributeNameForLogo) .FirstOrDefault() ?? throw new ArgumentException("Product Attribute Not Found"); //get product's attribute for predefined logo attributes ProductAttributeMapping logoProductMapping = _productAttributeService .GetProductAttributeMappingsByProductId(logo.ProductId) .FirstOrDefault(x => x.ProductAttributeId == logoAttribute.Id); //create the mapping if it does not exist if (logoProductMapping == null) { logoProductMapping = new ProductAttributeMapping { ProductAttributeId = logoAttribute.Id, ProductId = logo.ProductId, AttributeControlTypeId = (int)AttributeControlType.ImageSquares }; _productAttributeService.InsertProductAttributeMapping(logoProductMapping); ////no logo attribute ////todo find a way to use the picture for this //_productAttributeService.InsertProductAttributeValue(new ProductAttributeValue //{ // ProductAttributeMappingId = logoProductMapping.Id, // AttributeValueType = AttributeValueType.Simple, // Name = _localizationService.GetResource("Widgets.ProductPictureModifier.Attributes.NoLogo"), // ImageSquaresPictureId = 1, // PictureId = productPicture.PictureId, //}); //provision for manual upload by user Setting customUploadIconSetting = _settingService .GetSetting(ProductPictureModifierDefault.UploadIconPictureIdSetting); var customUploadForLogoAttribute = new ProductAttributeValue { ProductAttributeMappingId = logoProductMapping.Id, AttributeValueType = AttributeValueType.Simple, Name = _localizationService.GetResource("Widgets.ProductPictureModifier.Attributes.Upload"), ImageSquaresPictureId = int.Parse(customUploadIconSetting.Value), }; _productAttributeService.InsertProductAttributeValue(customUploadForLogoAttribute); ProductAttribute productAttributeForCustomUpload = _productPictureModifierService .GetProductAttributeByName(ProductPictureModifierDefault.ProductAttributeNameForLogoUpload) .FirstOrDefault() ?? throw new ArgumentException("Product Attribute Not Found for Custom Upload"); //custom upload attribute mapping with product based on condition var customUploadProductAttributeMapping = new ProductAttributeMapping { ProductAttributeId = productAttributeForCustomUpload.Id, ProductId = logo.ProductId, AttributeControlTypeId = (int)AttributeControlType.FileUpload, ValidationFileAllowedExtensions = "png", ConditionAttributeXml = _productAttributeParser.AddProductAttribute(null, logoProductMapping, customUploadForLogoAttribute.Id.ToString()) }; _productAttributeService.InsertProductAttributeMapping(customUploadProductAttributeMapping); } //save the actual logo attribute var productAttributeValue = new ProductAttributeValue { ProductAttributeMappingId = logoProductMapping.Id, AttributeValueType = AttributeValueType.Simple, Name = "Custom Logo", ImageSquaresPictureId = logo.PictureId, PictureId = mergedPicture.Item1, }; _productAttributeService.InsertProductAttributeValue(productAttributeValue); //Logo Position for custom upload LogoPosition logoPosition = _logoPositionService.GetByProductId(logo.ProductId); if (logo.MarkAsDefault || IsLogoSettingNew(logoPosition)) { logoPosition.Size = logo.Size; logoPosition.XCoordinate = logo.XCoordinate; logoPosition.YCoordinate = logo.YCoordinate; logoPosition.Opacity = logo.Opacity; _logoPositionService.Update(logoPosition); } return(Json(new { Result = true, AttributeId = productAttributeValue.Id })); }
protected bool IsLogoSettingNew(LogoPosition existingLogoSetting) { return(existingLogoSetting.Opacity == 0 && existingLogoSetting.Size == 0 && existingLogoSetting.XCoordinate == 0 && existingLogoSetting.YCoordinate == 0); }
//private Overlay GetOverlayFromDb(int designMapId, int masterId, int colorId) { private Overlay GetOverlayFromDb(int designId, int masterId, int colorId, int orgId, int logoUsageId) { using (var conn = GetConnection()) { conn.Open(); var c = new SqlCommand(SqlQuery, conn); c.Parameters.AddWithValue("designid", designId); c.Parameters.AddWithValue("masterid", masterId); c.Parameters.AddWithValue("colorid", colorId); c.Parameters.AddWithValue("orgid", orgId); c.Parameters.AddWithValue("logousageid", logoUsageId); using (var r = c.ExecuteReader(System.Data.CommandBehavior.SingleRow)) { if (!r.HasRows) { return(null); //No results? } r.Read(); /*NickName Description IsDarkColor Description X1 Y1 X2 Y2 X3 Y3 X4 Y4 * CampusCloz Alumni 1 1 Full Chest 309 289 705 289 309 384 705 384 */ /* * So working through this example which has real values from the NEW sample db I provided: * · designid=3233 locates for us LogoDesignMap.ID=3233 which represents a 'Alumni 1' logo design for Org=Campus Cloz in the Full Chest position. * · mastid=9464, colorid=1577, and Logo Position=Full Chest are used to locate LogoImage2.ID=63392. Now we know the source product image (1020_99_z.jpg), coordinates for the logo, and the logo position (this answers your question). * · colorid=1577 tells us the color is a dark color (Color.IsDarkColor=1). We need to know if color is light or dark because we put white logos on dark colors only, and dark logos on light colors only. * Now we know enough to build the logo filename. This was described in earlier email, but I'll repeat: * Our logo image file names will use a strict naming convention i.e. [Organization.NickName]_[Logo Design Name]_[Light or Dark]_[Logo Position].png, * i.e. CampusCloz_athletics9_light_leftsleeve.png. So, the logo image name should be: CampusCloz_athletics1_dark_FullChest.png. Note we collapse spaces in these file names, i.e. 'Campus Cloz' becomes 'CampusCloz', 'Athletics 1' -> 'Athletics1, 'Full Chest' -> FullChest * * */ //Build overlay path Overlay o = new Overlay(); StringBuilder p = new StringBuilder(); //p.AppendFormat("{4}/{0}_{1}_{2}_{3}.png", r.GetString(0), r.GetString(1), r.GetBoolean(2) ? "dark" : "light", r.GetString(3), this.OverlayBasePath.TrimEnd('/')); p.AppendFormat("{4}/{0}/LogoImages/{0}_{1}_{2}_{3}.png", r.GetString(0), r.GetString(1), r.GetBoolean(2) ? "dark" : "light", r.GetString(3), this.OverlayBasePath.TrimEnd('/')); p.Replace(" ", ""); o.OverlayPath = p.ToString(); //Parse logo position and use it to fill in magic values string logoPosition = r.GetString(3).Replace(" ", ""); LogoPosition type = (LogoPosition)Enum.Parse(typeof(LogoPosition), logoPosition, true); this.ApplyLogoPositionMagicValues(o, type); o.Align = (ContentAlignment)r.GetInt32(12); //LogoAlignment //Store coordinates o.Poly = new PointF[4]; for (int i = 0; i < 4; i++) { int x = r.GetInt32(4 + (i * 2)); int y = r.GetInt32(5 + (i * 2)); o.Poly[i] = new PointF(x, y); } return(o); } } }
static void BehaviourMachinePreferencesGUI () { if (s_Styles == null) s_Styles = new BehaviourMachinePrefs.Styles(); if (!s_PrefsLoaded) LoadPreferencesMembers(); // Draw preferences gui s_EnabledStateName = EditorGUILayout.Toggle (new GUIContent("Show States Name Gizmo", "The name of the enabled states should be shown as a gizmo?"), s_EnabledStateName); s_EditorOnGUI = EditorGUILayout.Toggle (new GUIContent("OnGUI nodes in the Editor", "WYSIWYG option. If True you can see your Unity GUI controls while editing an ActionState or BehaviourTree"), s_EditorOnGUI); s_SnapMove = Mathf.Max(0f, EditorGUILayout.FloatField (new GUIContent("State Snap Move", "The value to snap the states in the {b}'s window grid"), s_SnapMove)); s_ShowScrollView = EditorGUILayout.Toggle (new GUIContent("Show Scroll View?", "If True the {b} window will show the scroll view"), s_ShowScrollView); s_LogoPosition = (LogoPosition)EditorGUILayout.EnumPopup(new GUIContent("{b} Logo Position", "Used for the {b} logo in the Hierarchy view"), s_LogoPosition); // Save preferences? if (GUI.changed) SavePreferencesMembers(); // Reset preferences? EditorGUILayout.Space(); if (GUILayout.Button("Use Defaults", GUILayout.Width(120f))) { ResetToDefaults(); } // Updater EditorGUILayout.Space(); EditorGUILayout.LabelField(string.Empty, s_Styles.line); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Auto Update"); EditorGUILayout.BeginVertical(); if (GUILayout.Button(new GUIContent("FsmEvent", "Use this update when the FsmEvents in this project are using an older serialization (version 1.2 or previous) data and need to be updated"))) { s_SelectedOption = 1; EditorApplication.delayCall += OnDelayCall; } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); }
/// <summary> /// Retrieves the preferences members in the EditorPrefs. /// </summary> static void LoadPreferencesMembers () { s_PrefsLoaded = true; s_EnabledStateName = EditorPrefs.GetBool ("BM.EnabledStateName", true); s_EditorOnGUI = EditorPrefs.GetBool ("BM.EditorOnGUI", true); s_SnapMove = EditorPrefs.GetFloat ("BM.SnapMove", 10f); s_ShowScrollView = EditorPrefs.GetBool ("BM.ShowScrollView", false); s_LogoPosition = (LogoPosition)EditorPrefs.GetInt ("BM.LogoPosition", 0); }