private static Color AlterColor(Color origColor, bool random) { if (random) { return(new Color(RandomUtil.GetInt(255), RandomUtil.GetInt(255), RandomUtil.GetInt(255))); } else { // mSavedColors is a Vector color stored as RGB ratios of 0 to 1 Vector3 hsv = CompositorUtil.ColorShifter.ColorToHsv(CompositorUtil.ColorToVector3(origColor)); /* * hsv.x += RandomUtil.GetFloat(-0.01f, 0.01f); * if (hsv.x > 1) * { * hsv.x = 1; * } * else if (hsv.x < 0) * { * hsv.x = 0; * } */ hsv.y += RandomUtil.GetFloat(-0.25f, 0.25f); if (hsv.y > 1) { hsv.y = 1; } else if (hsv.y < 0.01) { hsv.y = 0.01f; } hsv.z += RandomUtil.GetFloat(-0.25f, 0.25f); if (hsv.z > 1) { hsv.z = 1; } else if (hsv.z < 0.01) { hsv.z = 0.01f; } return(CompositorUtil.Vector3ToColor(CompositorUtil.ColorShifter.HsvToColor(hsv))); } }
private static void OnColorsSaved(Color[] colors) { try { CASMakeup ths = CASMakeup.gSingleton; if (ths == null) { return; } bool flag = false; bool flag2 = false; if (CASMakeup.sCategory != BodyTypes.CostumeMakeup) { foreach (ItemGridCellItem item in ths.mGridMakeupPresets.Items) { flag2 = true; ResourceKey mTag = (ResourceKey)item.mTag; ColorInfo info = ColorInfo.FromResourceKey(mTag); for (int i = 0x0; i < info.Colors.Length; i++) { Vector3 vector = CompositorUtil.ColorToVector3(colors[i]); Vector3 v = CompositorUtil.ColorToVector3(info.Colors[i]); if (!vector.IsSimilarTo(v)) { flag2 = false; break; } } if (flag2) { break; } } if (!flag2) { ColorInfo info2 = new ColorInfo(); info2.Usage = ColorInfo.PreferredUse.Makeup; switch (CASMakeup.sCategory) { case BodyTypes.FirstFace: info2.UsageSubCategory = ColorInfo.eUsageSubCategory.MakeupLipstick; break; case BodyTypes.EyeShadow: info2.UsageSubCategory = ColorInfo.eUsageSubCategory.MakeupEyeshadow; break; case BodyTypes.EyeLiner: info2.UsageSubCategory = ColorInfo.eUsageSubCategory.MakeupEyeliner; break; case BodyTypes.Blush: info2.UsageSubCategory = ColorInfo.eUsageSubCategory.MakeupBlush; break; } info2.Colors = colors; flag = info2.SaveMakeupPreset(info2.UsageSubCategory) != ResourceKey.kInvalidResourceKey; ths.PopulatePresetsGrid(CASMakeup.sCategory, ths.mCurrentPreset.mPart, ths.mButtonFilter.Selected); } } else { CASPart wornPart = ths.mCurrentPreset.mPart; ObjectDesigner.SetCASPart(wornPart.Key); Vector3[] makeupVectorColors = ths.GetMakeupVectorColors(wornPart); uint num = CASUtils.PartDataNumPresets(wornPart.Key); for (uint j = 0x0; j < num; j++) { KeyValuePair <string, Dictionary <string, Complate> > presetEntryFromPresetString = (KeyValuePair <string, Dictionary <string, Complate> >)SimBuilder.GetPresetEntryFromPresetString(CASUtils.PartDataGetPreset(wornPart.Key, j)); Vector3[] vectorArray2 = ths.GetMakeupVectorColors(presetEntryFromPresetString); flag2 = true; for (uint k = 0x0; k < vectorArray2.Length; k++) { if (!makeupVectorColors[k].IsSimilarTo(vectorArray2[k])) { flag2 = false; break; } } if (flag2) { break; } } if (!flag2) { uint index = ObjectDesigner.AddDesignPreset(Responder.Instance.CASModel.GetDesignPreset(wornPart)); flag = index != uint.MaxValue; CASClothingRow row = ths.FindRow(wornPart); if (row != null) { row.CreateGridItems(true); row.PopulateGrid(true); } ths.mButtonCostumeFilter.Tag = true; ths.mContentTypeFilter.UpdateFilterButtonState(); ThumbnailKey key = new ThumbnailKey(wornPart.Key, (int)CASUtils.PartDataGetPresetId(wornPart.Key, index), (uint)wornPart.BodyType, (uint)wornPart.AgeGenderSpecies, ThumbnailSize.Large); ThumbnailManager.InvalidateThumbnail(key); } } if (flag) { CASController.Singleton.ErrorMsg(CASErrorCode.SaveSuccess); } else if (flag2) { Simulator.AddObject(new OneShotFunctionTask(delegate { string messageText = Responder.Instance.LocalizationModel.LocalizeString("Ui/Caption/CAS/Hair:SaveDuplicate", new object[0x0]); SimpleMessageDialog.Show(null, messageText, ModalDialog.PauseMode.PauseTask, new Vector2(-1f, -1f), "ui_error", "ui_hardwindow_close"); })); } else { CASController.Singleton.ErrorMsg(CASErrorCode.SaveFailed); } } catch (Exception e) { Common.Exception("OnColorsSaved", e); } }
private static void OnDialogClosed(bool accept, bool colorChanged, Color[] colors) { try { CASMakeup ths = CASMakeup.gSingleton; if (ths == null) { return; } if (CASMakeup.sCategory == BodyTypes.CostumeMakeup) { if (accept) { SetMakeupColors(ths, CASMakeup.sCategory, colors, true); List <ItemGridCellItem> items = ths.mGridCostumeParts.Items; int num = 0x0; foreach (ItemGridCellItem item in items) { CASClothingRow mWin = item.mWin as CASClothingRow; if (mWin != null) { mWin.ShowSelectedItem(false); if (mWin.SelectedItem != -1) { mWin.CreateGridItems(true); mWin.PopulateGrid(true); ths.mGridCostumeParts.SelectedItem = num; ths.mCurrentFocusedRow = mWin; ths.mCurrentFocusedRow.SetArrowGlow(true); ths.mCurrentPreset = mWin.Selection as CASPartPreset; ths.UpdateCostumePresetState(); } num++; } } } else if (colorChanged) { Responder.Instance.CASModel.RequestUndo(); Responder.Instance.CASModel.RequestClearRedoOperations(); } } else if (!accept) { if (colorChanged) { Responder.Instance.CASModel.RequestUndo(); Responder.Instance.CASModel.RequestClearRedoOperations(); } } else { SetMakeupColors(ths, CASMakeup.sCategory, colors, true); ths.mGridMakeupPresets.SelectedItem = -1; int index = 0x0; List <ItemGridCellItem> list2 = ths.mGridMakeupPresets.Items; Vector3[] vecColors = new Vector3[colors.Length]; foreach (Color color in colors) { vecColors[index] = CompositorUtil.ColorToVector3(color); index++; } index = 0x0; foreach (ItemGridCellItem item2 in list2) { ResourceKey mTag = (ResourceKey)item2.mTag; ColorInfo colorInfo = ColorInfo.FromResourceKey(mTag); if (CASMakeup.CompareColors(vecColors, colorInfo)) { ths.mGridMakeupPresets.SelectedItem = index; break; } index++; } ths.UpdatePresetState(); } } catch (Exception e) { Common.Exception("OnDialogClosed", e); } }