private static void ExecuteStrategy() { var imageStorage = new ImageStorage(); imageStorage.Store("a", new JpegCompressor(), new BlackAndWhiteFilter()); imageStorage.Store("b", new PngCompressor(), new BlackAndWhiteFilter()); }
static void TestStrategy() { var imageStorage = new ImageStorage(); // Strategy 1 imageStorage.Store("FileName1", new JpegCompressor(), new BlackAndWhiteFilter()); // Strategy 2 imageStorage.Store("FileName1", new PngCompressor(), new HighContrastFilter()); }
IEnumerator LoadImage() { yield return(CommunityEntity.ServerInstance.StartCoroutine(ImageStorage.Store(messageImages))); timer.Every(60f, ChangePicture); loaded = true; Redraw(); }
public void Run() { ImageStorage imageStorage = new ImageStorage(CompressorType.PNG, FilterType.HighContrast); imageStorage.Store(Filename); //imageStorage.Store(Filename, CompressorType.JPEG, FilterType.BlackAndWhite); }
static void Strategy() { JpegCompressor compressor = new JpegCompressor(); BlackAndWhiteFilter filter = new BlackAndWhiteFilter(); ImageStorage imageStorage = new ImageStorage(compressor, filter); imageStorage.Store("Video File"); }
IEnumerator StoreImages() { var images = KitsPng.ToDictionary(p => p.Key, p => p.Value.ToString()); yield return(ImageStorage.Store(images)); KitsPng = images.ToDictionary(p => p.Key, p => (object)p.Value); }
/// <summary> /// Allows passing different algorithms (behaviours) to an object. Allows defining a template (skeleton) for an operation. /// Specific steps will then be implemented in subclasses. /// /// Quite similar to State pattern, difference is there is no state here at all. Dependency is injected right when calling the method. /// One object's any methods can act in a lot of ways depending on what other classes are injected. /// </summary> static void Strategy() { var imageStorage = new ImageStorage(); imageStorage.Store( "File", new JpegCompressor(), new BlackAndWhiteFilter() ); }
public static void Behavioral_Strategy() { var imageStorageJpeg = new ImageStorage(); imageStorageJpeg.Store("aDemo", new JpegCompressor(), new BlackAndWhiteFilter()); var imageStoragePng = new ImageStorage(); imageStoragePng.Store("bDemo", new PngCompressor(), new HighContrastFilter()); Console.WriteLine(""); Console.WriteLine("Strategy Demo 2"); // StrategyDemo2 var chatClient = new ChatClient(new AESEncryption()); chatClient.Send("my demo message 1 AES"); chatClient = new ChatClient(new DESEncryption()); chatClient.Send("my demo message 2 DES"); }
IEnumerator LoadFunctions() { yield return(ImageStorage.Store(imagesDB.ReadObject <Dictionary <string, string> >() ?? new Dictionary <string, string>())); var funcs = uiDB.ReadObject <Dictionary <string, CuiFunction> >(); functions = new Dictionary <string, Dictionary <string, CuiFunction> >(); var comparer = new CuiElementComparer(); foreach (var funcPair in funcs) { var func = funcPair.Key; string plugin, funcName; SplitFunc(func, out plugin, out funcName); if (!functions.ContainsKey(plugin)) { functions[plugin] = new Dictionary <string, CuiFunction>(); } functions[plugin].Add(funcName, funcPair.Value); var function = functions[plugin][funcName]; var argc = function.argc(); for (int i = 0; i < 4; i++) { function.cacheArgs.Add(new List <List <CuiElement> >()); var json = function[i]; if (string.IsNullOrEmpty(json)) { continue; } var elements = CuiHelper.FromJson(json); foreach (var e in elements) { var component = e.Components.FirstOrDefault(c => c.Type == "UnityEngine.UI.RawImage"); var rawImage = component as CuiRawImageComponent; if (!string.IsNullOrEmpty(rawImage?.Png)) { rawImage.Sprite = "assets/content/textures/generic/fulltransparent.tga"; if (rawImage.Png.StartsWith("{")) { if (rawImage.Png == "{colon}") { rawImage.Png = ImageStorage.FetchPng("colon"); } } else { var img = ImageStorage.FetchPng(rawImage.Png); if (string.IsNullOrEmpty(img)) { yield return(CommunityEntity.ServerInstance.StartCoroutine(ImageStorage.Store(rawImage.Png, rawImage.Png))); if (ImageStorage.FetchPng(rawImage.Png) == string.Empty) { Puts("NOT LOADED: " + rawImage.Png); } rawImage.Png = ImageStorage.FetchPng(rawImage.Png); //Puts(e.Name + ": " + rawImage.Png); } else { rawImage.Png = img; } } } else if (rawImage != null && string.IsNullOrEmpty(rawImage.Url) && rawImage.Sprite == "Assets/Icons/rust.png") { rawImage.Sprite = "Assets/Content/UI/UI.Background.Tile.psd"; } } function[i] = json = CuiHelper.ToJson(elements); var jsonArgs = json; if (argc == 0) { function.cacheArgs[i].Add(elements); continue; } for (int j = 0; j < argc; j++) { jsonArgs = jsonArgs.Replace("{" + j + "}", ""); } var elementsArgs = CuiHelper.FromJson(jsonArgs); var changedElements = elements.Except(elementsArgs, comparer).ToList(); var argsElements = changedElements.Select(element => CuiHelper.ToJson(new List <CuiElement>() { element })).ToList(); List <int> argNumbers = new List <int>(); for (int j = 0; j < argc; j++) { for (int k = 0; k < argsElements.Count; k++) { if (argsElements[k].Contains("{" + j + "}")) { argNumbers.Add(k); } } } for (int j = 0; j < argNumbers.Count; j++) { var e = changedElements[argNumbers[j]]; var argsReferences = elements.Where( o => o != e && o.Parent == e.Parent && Intersect(GetRect(e), GetRect(o)) && !changedElements.Contains(o)).ToList(); argsReferences.Insert(0, e); var newReferences = new List <CuiElement>(); for (var index = 0; index < argsReferences.Count; index++) { var element = argsReferences[index]; newReferences.AddRange(GetChildsRecursive(elements, element.Name)); } argsReferences.AddRange(newReferences); argsReferences = argsReferences.Distinct(comparer).ToList(); function.cacheArgs[i].Add(argsReferences); } } } foreach (var pluginFunctions in functions) { foreach (var func in pluginFunctions.Value) { for (int i = 0; i < 4; i++) { var funcAspect = func.Value[i]; if (string.IsNullOrEmpty(funcAspect)) { continue; } var elements = CuiHelper.FromJson(funcAspect); } } } onCuiGeneratorInitialized(); }
void AddShopPlayer(ulong userId) { if (!players.ContainsKey(userId)) { players[userId] = new ShopPlayer() { Points = 15, TotalOnlineSeconds = 0 } } ; } #endregion #region UI void CreateItemsUI() { float gap = 0.014f; float width = 0.15f; float height = 0.17f; float startxBox = gap; float startyBox = 1f - height - 0.05f; float xmin = startxBox; float ymin = startyBox; itemsUI = new CuiElementContainer(); int i = 0; var mainParent = itemsUI.Add(new CuiPanel() { Image = { Color = "0 0 0 0" } }, "rustyshop.items", "rustyshop.items.customui"); foreach (var item in items) { var min = $"{xmin} {ymin}"; var max = $"{xmin + width} {ymin + height}"; var panelname = itemsUI.Add(new CuiPanel() { Image = { Color = "0 0 0 0" }, RectTransform = { AnchorMin = min, AnchorMax = max } }, mainParent); itemsUI.Add(new CuiButton() { Button = { Command = $"rustyshop.buy {i}", Color = "0.3 0.5 0.4 1" }, RectTransform = { AnchorMin = "0 0", AnchorMax = "1 0.25" }, Text = { Text = $"<color=orange><color=#00ccff>{item.Amount}</color> за <color=#ffcc00>{item.Cost}</color> р.</color>", FontSize = 16, Align = TextAnchor.MiddleCenter } }, panelname); itemsUI.Add(new CuiElement() { Name = CuiHelper.GetGuid(), Parent = panelname, Components = { new CuiRawImageComponent() { Png = ImageStorage.FetchPng(item.DisplayName), Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent() { AnchorMin = "0 0.25", AnchorMax = "1 1" } } }); xmin += width + gap; if (xmin + width >= 1) { xmin = startxBox; ymin -= height + gap; } i++; } } void DrawUI(BasePlayer player) { var shopPlayer = players[player.userID]; foreach (var we in itemsUI) { CuiHelper.DestroyUi(player, we.Name); } core.DrawUIWithEx(player, "RustyShop", "menu", itemsUI, shopPlayer.Points, core.TimeToString(shopPlayer.TotalOnlineSeconds)); } void DestroyUI(BasePlayer player) { core.DestroyUI(player, "RustyShop", "menu"); } IEnumerator LoadImages() { foreach (var item in items) { yield return(CommunityEntity.ServerInstance.StartCoroutine(ImageStorage.Store(item.DisplayName, item.URL))); } CreateItemsUI(); }
public IEnumerator StoreImages(Dictionary <string, string> images) { yield return(ImageStorage.Store(images)); }
public IEnumerator StoreImage(string name, string url) { yield return(ImageStorage.Store(name, url)); }
IEnumerator LoadImages() { yield return(ImageStorage.Store("stat", "http://i.imgur.com/iZUSVKg.png")); yield return(ImageStorage.Store("stat2", "http://i.imgur.com/Cyj0NZS.png")); }
IEnumerator StoreImages() { yield return(ImageStorage.Store(gradeImages)); loaded = true; }