private void item_Click(object sender, EventArgs e) { if (ClickItem != null) { ClickItem.Invoke(this, null); } }
/// <summary> /// Replace all CustomClickItem in ItemsSource with `customClickItems` /// If there are more CustomClickItem in ItemsSource, those are deleted. /// Additional customClickItem left in customClickItems will be appended to the back of list. /// </summary> /// <param name="customClickItems"></param> /// <returns></returns> private ObservableCollection <ClickItem> ReplaceCustomItemsInItemsSource(Queue <CustomItem> customClickItems) { for (int i = 0; i < Items.Count(); i++) { ClickItem clickItem = Items.ElementAt(i); if (clickItem is CustomItem) { if (customClickItems.Count() > 0) { CustomItem customClickItem = customClickItems.Dequeue(); Items.RemoveAt(i); Items.Insert(i, customClickItem); } else { Items.RemoveAt(i); i--; } } } while (customClickItems.Count() > 0) { CustomItem customClickItem = customClickItems.Dequeue(); Items.Add(customClickItem); } return(Items); }
private void AddItemBelowContextMenu_Click(object sender, RoutedEventArgs e) { ClickItem item = ((MenuItem)sender).CommandParameter as ClickItem; ExplanationItem selfExplanationClickItem = new ExplanationItem(captionText: string.Empty); selfExplanationClickItem.tagNo = SelfExplanationTagService.GenerateUniqueTag(); int index; if (item is ExplanationItem) { index = Items.ToList().FindIndex(x => x is ExplanationItem && ((ExplanationItem)x).TagNo == ((ExplanationItem)item).TagNo); } else { index = Items.IndexOf(item); } if (index < listView.Items.Count - 1) { Items.Insert(index + 1, selfExplanationClickItem); } else { Items.Add(selfExplanationClickItem); } isSynced = false; UpdateClickNumAndTriggerInItems(useWorker: false, e: null); ScrollItemToView(selfExplanationClickItem); }
public MainMenuScreen(Game i_Game) : base(i_Game) { this.IsUsingKeyboard = true; this.m_Background = new Background(this, @"Sprites\BG_Space01_1024x768", 1); this.m_MenuHeader = new MenuHeader(this, @"Screens\MainMenu\MainMenuLogo"); this.m_MenuHeader.OffsetX = 20; int index = 0; ToggleItem playersItem = new ToggleItem(@"Screens\MainMenu\PlayersWhite", @"Screens\MainMenu\PlayersOptions_70x50", this, index++); playersItem.ToggleValueChanched += new EventHandler <EventArgs>(this.numOfPlayers_Changed); this.AddMenuItem(playersItem); ClickItem SettingsScreenItem = new ClickItem("ScreenSettingsScreen", @"Screens\MainMenu\ScreenSettings", this, index++); ClickItem SoundSettingsItem = new ClickItem("SoundSettingsScreen", @"Screens\MainMenu\SoundSettings", this, index++); ClickItem playItem = new ClickItem("PlayScreen", @"Screens\MainMenu\PlayGameWhite", this, index++); ClickItem QuitItem = new ClickItem("Quit", @"Screens\Wellcome\QuitGame", this, index++); SettingsScreenItem.ItemClicked += new EventHandler <ScreenEventArgs>(this.menuItem_Click); SoundSettingsItem.ItemClicked += new EventHandler <ScreenEventArgs>(this.menuItem_Click); playItem.ItemClicked += new EventHandler <ScreenEventArgs>(this.menuItem_Click); QuitItem.ItemClicked += new EventHandler <ScreenEventArgs>(this.buttonQuit_click); this.AddMenuItem(SettingsScreenItem); this.AddMenuItem(SoundSettingsItem); this.AddMenuItem(playItem); this.AddMenuItem(QuitItem); }
public static void attack(DadCell cell, ClickItem item) { Spider[] spiders = FindObjectsOfType <Spider>(); int index = -1; float dist = 15; for (int i = 0; i < spiders.Length; i++) { Vector3 relative = GameObject.FindGameObjectWithTag("Dreamer").transform.InverseTransformPoint(spiders[i].transform.position); if (relative.x < 3 && relative.x > -3 && relative.z > 0 && dist > Vector3.Distance(spiders[i].transform.position, GameObject.FindGameObjectWithTag("Dreamer").transform.position)) { index = i; dist = Vector3.Distance(spiders[i].transform.position, GameObject.FindGameObjectWithTag("Dreamer").transform.position); } } if (dist < 5) { spiders[index].walking = false; spiders[index].CancelInvoke(); spiders[index].anim.SetTrigger("Die"); Destroy(spiders[index].gameObject, 1f); item.uses--; item.GetComponentInChildren <EditText>().updateText(item.uses); if (item.uses == 0) { cell.RemoveItem(); } } }
public static void burn(DadCell cell, ClickItem item) { SpiderSpawner[] spiders = FindObjectsOfType <SpiderSpawner>(); int index = -1; float dist = 100; for (int i = 0; i < spiders.Length; i++) { Vector3 relative = GameObject.FindGameObjectWithTag("Dreamer").transform.InverseTransformPoint(spiders[i].transform.position); if (relative.x < 3 && relative.x > -3 && relative.z > 0 && dist > Vector3.Distance(spiders[i].transform.position, GameObject.FindGameObjectWithTag("Dreamer").transform.position)) { index = i; dist = Vector3.Distance(spiders[i].transform.position, GameObject.FindGameObjectWithTag("Dreamer").transform.position); } } if (dist < 10) { Destroy(spiders[index].gameObject, 1f); item.uses--; if (item.uses == 0) { cell.RemoveItem(); } } }
/// <summary> /// Creates the quick item. /// </summary> /// <returns>The quick item.</returns> /// <param name="item">Item.</param> public QuickItem CreateQuickItem(GameObject item) { QuickItem res = null; DadCell dadCell = GetComponent <DadCell>(); if (item != null && dadCell != null) { ClickItem clickItem = item.GetComponent <ClickItem>(); if (clickItem != null) { // Remove old quick item RemoveQuickItem(); // Load quick item template GameObject newQuickItem = Instantiate(Resources.Load <GameObject>("QuickItemPrefab")); newQuickItem.name = item.name; res = newQuickItem.GetComponent <QuickItem>(); res.itemSource = clickItem; Image myImage = newQuickItem.GetComponent <Image>(); Image sourceImage = item.GetComponent <Image>(); if (myImage != null && sourceImage != null) { myImage.sprite = sourceImage.sprite; myImage.color = sourceImage.color; } // Place quick item to quick cell dadCell.AddItem(newQuickItem.gameObject); } } return(res); }
readonly List <ClickItem> mListItems = new List <ClickItem>(); //A List of ClickItems public ClickItem AddObject(ClickObject vObject) { ClickItem tLI = new ClickItem(transform, vObject); //Parent it to panel mListItems.Add(tLI); //Add item to list return(tLI); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(trigger)) { DadCell cell2 = this.GetComponentInParent <DadCell>(); ClickItem item = cell2.GetComponentInChildren <ClickItem>(); if (item != null) { if (item.type == ClickItem.Type.consumable) { DadItem.eat(cell, item); } if (item.type == ClickItem.Type.weapon) { if (item.value == 1) { DadItem.attack(cell, item); } if (item.value == 2) { DadItem.burn(cell, item); } } } } }
/// <summary> /// Raises the item click event. /// </summary> /// <param name="item">Item.</param> public void OnItemUse(GameObject item) { if (item != null) { // We can use potions only if vendor is inactive if (vendorStackGroup == null || vendorStackGroup.isActiveAndEnabled == false) { // Heal on potion use DummyHealthPotion healthPotion = item.GetComponent <DummyHealthPotion>(); ClickItem clickItem = item.GetComponent <ClickItem>(); if (healthPotion != null) { if (GetHealth() < GetMaxHealth()) { // Add health if it is not full AddHealth(healthPotion.healAmount); PlaySound(clickItem.audioClip); StackItem stackItem = item.GetComponent <StackItem>(); if (stackItem != null) { // Reduce potion's stack stackItem.ReduceStack(1); } } } } } }
private void ItemClick(object obj) { string path = null; int index = 0; if (ClickItem != null) { foreach (var card in Cards) { if (card.FrontPath == ClickItem.ToString()) { path = card.BackPath; } else if (card.BackPath == ClickItem.ToString()) { path = card.FrontPath; } } foreach (var image in CardImages) { if (image == ClickItem) { break; } index++; } CardImages[index] = path; } }
/// <summary> /// 进行鼠标点击次数累计 /// </summary> /// <param name="x">鼠标光标X坐标</param> /// <param name="y">鼠标光标Y坐标</param> /// <param name="tickCount">鼠标点击时的系统时刻数</param> /// <returns>连续点击的次数</returns> public int Count(int x, int y, int tickCount) { ClickItem item = new ClickItem(); item.X = x; item.Y = y; item.TickCount = System.Environment.TickCount; if (myItems.Count == 0) { myItems.Add(item); } else { ClickItem LastItem = (ClickItem)myItems[myItems.Count - 1]; System.Drawing.Size size = SystemInformation.DoubleClickSize; if (Math.Abs(item.X - LastItem.X) <= size.Width && Math.Abs(item.Y - LastItem.Y) <= size.Height && item.TickCount - LastItem.TickCount <= SystemInformation.DoubleClickTime) { myItems.Add(item); return(myItems.Count); } else { myItems.Clear(); myItems.Add(item); } } return(myItems.Count); }
public SoundSettingsScreen(Game i_Game) : base(i_Game, 150f, 15f) { int index = 0; this.m_Background = new Background(this, @"Sprites\BG_Space01_1024x768", 1); this.m_MenuHeader = new MenuHeader(this, @"Screens\Settings\SoundSettingsLogo"); this.m_SoundSettingManager = i_Game.Services.GetService(typeof(ISoundSettingsManager)) as ISoundSettingsManager; ToggleItem toggleGameSound = new ToggleItem(@"Screens\Settings\ToggleSound", @"Screens\Settings\OnOff_53x52", this, index++); VolumeItem bgMusicVolume = new VolumeItem(@"Screens\Settings\BgMusic", this, index++); VolumeItem soundEffectsVolume = new VolumeItem(@"Screens\Settings\SoundEffects", this, index++); ClickItem doneItem = new ClickItem("Done", @"Screens\Settings\Done", this, index++); toggleGameSound.ToggleValueChanched += new EventHandler <EventArgs>(this.m_SoundSettingManager.ToggleGameSound_Click); bgMusicVolume.IncreaseVolumeButtonClicked += new EventHandler <EventArgs>(this.m_SoundSettingManager.IncreaseBackgroundMusic_Click); bgMusicVolume.DecreaseVolumeButtonClicked += new EventHandler <EventArgs>(this.m_SoundSettingManager.DecreaseBackgroundMusic_Click); soundEffectsVolume.IncreaseVolumeButtonClicked += new EventHandler <EventArgs>(this.m_SoundSettingManager.IncreaseSoundEffects_Click); soundEffectsVolume.DecreaseVolumeButtonClicked += new EventHandler <EventArgs>(this.m_SoundSettingManager.DecreaseSoundEffects_Click); doneItem.ItemClicked += this.menuItem_Click; this.AddMenuItem(toggleGameSound); this.AddMenuItem(bgMusicVolume); this.AddMenuItem(soundEffectsVolume); this.AddMenuItem(doneItem); }
/// <summary> /// Raises the item click event. /// </summary> /// <param name="item">Item.</param> public void OnItemUse(GameObject item) { if (item != null) { // Heal on potion use DummyHealthPotion healthPotion = item.GetComponent <DummyHealthPotion>(); ClickItem clickItem = item.GetComponent <ClickItem>(); if (healthPotion != null) { if (GetHealth() < GetMaxHealth()) { // Add health if it is not full AddHealth(healthPotion.healAmount); if (audioSource != null && clickItem != null && clickItem.audioClip != null) { audioSource.PlayOneShot(clickItem.audioClip); } StackItem stackItem = item.GetComponent <StackItem>(); if (stackItem != null) { // Reduce potion's stack stackItem.ReduceStack(1); } } } } }
private int AddItemAbove(ClickItem item, ExplanationItem selfExplanationClickItem) { int index = GetItemIndex(item); Items.Insert(index, selfExplanationClickItem); return(index); }
private static int canvasSortOrder = 100; // Sort order for canvas public static void eat(DadCell cell, ClickItem item) { HungerBar hunger = GameObject.FindObjectOfType <HungerBar>(); hunger.AddHunger(item.value); cell.RemoveItem(); }
void Start() { ClickItem ci = GetComponent <ClickItem>(); ci.Id = heroId; ci.ClickWithId += ChangeSelect; OnEnable(); }
private void ConversationItem_MouseClick(object sender, MouseEventArgs e) { if (_conversation == null) { return; } ClickItem?.Invoke(_conversation); }
private void ScrollItemToView(ClickItem item) { Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(delegate { listView.ScrollIntoView(item); })); }
public void RemoveObject(ClickItem vListItem) { if (vListItem != null) //If found { mListItems.Remove(vListItem); //Remove it Destroy(vListItem.mText.gameObject); //Delete Text GO vListItem.mText = null; vListItem.mClickObject = null; //Mark for Garbage collection } }
private int GetItemIndex(ClickItem item) { if (item is ExplanationItem) { return(Items.ToList().FindIndex(x => x is ExplanationItem && ((ExplanationItem)x).TagNo == ((ExplanationItem)item).TagNo)); } else { return(Items.IndexOf(item)); } }
private void UpdateClickNumOnClickItem(ClickItem clickItem, int startClickNo, int index) { bool isOnClickSelfExplanationAfterCustomItem = index > 0 && clickItem is ExplanationItem && (Items.ElementAt(index - 1) is CustomItem) && (clickItem as ExplanationItem).TriggerIndex != (int)TriggerType.OnClick; bool isFirstOnClickSelfExplanationItem = index == 0 && (clickItem is ExplanationItem) && (clickItem as ExplanationItem).TriggerIndex == (int)TriggerType.OnClick; bool isFirstWithPreviousSelfExplanationItem = index == 0 && (clickItem is ExplanationItem) && (clickItem as ExplanationItem).TriggerIndex != (int)TriggerType.OnClick; bool isDummySelfExplanationItem = clickItem is ExplanationItem && (clickItem as ExplanationItem).IsDummyItem; /* This commented piece of code is trying to handle the case when first self explanation item (SEI) * is dummy item, but the second one is active SEI item. * bool isAfterDummySelfExplanationItem = * index > 0 && (Items.ElementAt(index - 1) is ExplanationItem) * && (Items.ElementAt(index - 1) as ExplanationItem).IsDummyItem; */ if (index == 0) { clickItem.ClickNo = startClickNo; if (isFirstOnClickSelfExplanationItem && !isDummySelfExplanationItem) { clickItem.ClickNo = 1; clickItem.ShouldLabelDisplay = true; } if (isFirstWithPreviousSelfExplanationItem) { clickItem.ClickNo = 0; clickItem.ShouldLabelDisplay = true; } if (isDummySelfExplanationItem) { clickItem.ClickNo = 0; clickItem.ShouldLabelDisplay = false; } } else if (isOnClickSelfExplanationAfterCustomItem || isDummySelfExplanationItem) { clickItem.ClickNo = Items.ElementAt(index - 1).ClickNo; clickItem.ShouldLabelDisplay = false; } else { clickItem.ClickNo = Items.ElementAt(index - 1).ClickNo + 1; clickItem.ShouldLabelDisplay = true; } clickItem.NotifyPropertyChanged("ShouldLabelDisplay"); }
/// <summary> /// Update ClickNo property in ClickItem when old CustomClickItem is replaced with new ones. /// Note that we cannot reply on `BlockToIndexConverter` to update ClickNo, /// because ListViewItem which invokes `BlockToIndexConverter`, is loaded lazily. /// </summary> /// <param name="clickItems"></param> /// <returns></returns> private ObservableCollection <ClickItem> UpdatePropertiesInItemsSource(bool uncheckAzureAudio, bool uncheckWatsonAudio) { int clickNo = FirstClickNumber; for (int i = 0; i < Items.Count(); i++) { ClickItem clickItem = Items.ElementAt(i); UpdateClickNumOnClickItem(clickItem, clickNo, i); if (clickItem is ExplanationItem) { UpdateSelfExplanationItem(clickItem as ExplanationItem, uncheckAzureAudio, uncheckWatsonAudio); } } return(Items); }
private void AddExplanationItem(ClickItem reference, InsertItemAction action) { ExplanationItem selfExplanationClickItem = new ExplanationItem(captionText: string.Empty); selfExplanationClickItem.tagNo = SelfExplanationTagService.GenerateUniqueTag(); int index = action(reference, selfExplanationClickItem); ExplanationItem template = Items.LastOrDefault(o => o is ExplanationItem && GetItemIndex(o) < index) as ExplanationItem; selfExplanationClickItem.CopyFormat(template); isSynced = false; UpdateClickNumAndTriggerInItems(useWorker: false, e: null); ScrollItemToView(selfExplanationClickItem); }
void select(int i) { if (Type == PickerType.Select) { selected = i; } else if (Type == PickerType.Check) { Checked[i] = !Checked[i]; } else { ClickItem?.Invoke(this, i); } }
private int InsertItemBelow(ClickItem item, ExplanationItem selfExplanationClickItem) { int index; index = GetItemIndex(item); if (index < listView.Items.Count - 1) { Items.Insert(index + 1, selfExplanationClickItem); return(index + 1); } else { Items.Add(selfExplanationClickItem); return(Items.Count - 1); } }
/// <summary> /// Repair coroutine. /// </summary> /// <returns>The coroutine.</returns> /// <param name="skillIcon">Skill icon.</param> private IEnumerator RepairCoroutine(Image skillIcon) { // Start highlight skill skillIcon.GetComponent <Highlight>().StartHighlight(); // Change cursor Cursor.SetCursor(repairCursor, Vector2.zero, CursorMode.Auto); // Wait for mouse pressing while (Input.GetMouseButton(0) == true) { yield return(new WaitForEndOfFrame()); } while (Input.GetMouseButton(0) == false) { yield return(new WaitForEndOfFrame()); } // Check if any item under cursor PointerEventData pointerData = new PointerEventData(EventSystem.current); pointerData.position = Input.mousePosition; List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointerData, results); if (results.Count > 0) { foreach (RaycastResult res in results) { StackItem stackItem = res.gameObject.GetComponent <StackItem>(); if (stackItem != null) { // Start skill cooldown skillIcon.GetComponent <CooldownItem>().StartCooldown(); ClickItem clickItem = skillIcon.GetComponent <ClickItem>(); if (audioSource != null && clickItem.audioClip != null) { // Play SFX audioSource.PlayOneShot(clickItem.audioClip); } break; } } } // Return default cursor Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); // Stop highlight skill skillIcon.GetComponent <Highlight>().StopHighlight(); repairCoroutine = null; }
/// <summary> /// Rage coroutine. /// </summary> /// <returns>The coroutine.</returns> /// <param name="skillCooldown">Skill cooldown.</param> private IEnumerator RageCoroutine(CooldownItem skillCooldown) { // Add temporary attack bonus dummyParameters.attackBonus += 10; dummyParameters.UpdateParameters(); // Start skill cooldown skillCooldown.StartCooldown(); ClickItem clickItem = skillCooldown.GetComponent <ClickItem>(); PlaySound(clickItem.audioClip); // Wait for cooldown end while (skillCooldown.timeLeft > 0f) { yield return(new WaitForEndOfFrame()); } // Remove attack bonus dummyParameters.attackBonus -= 10; dummyParameters.UpdateParameters(); }
public WelcomeScreen(Game i_Game) : base(i_Game) { this.IsUsingKeyboard = false; this.m_Background = new Background(this, @"Sprites\BG_Space01_1024x768", 1); this.m_MenuHeader = new MenuHeader(this, @"Screens\Wellcome\SpaceInvadersLogo", 0.8f); int index = 0; ClickItem playItem = new ClickItem("PlayScreen", @"Screens\Wellcome\PlayGame", this, index++); ClickItem mainMenuItem = new ClickItem("MainMenuScreen", @"Screens\Wellcome\MainMenu", this, index++); ClickItem QuitItem = new ClickItem("Quit", @"Screens\Wellcome\QuitGame", this, index++); playItem.ItemClicked += new EventHandler <ScreenEventArgs>(this.menuItem_Click); mainMenuItem.ItemClicked += new EventHandler <ScreenEventArgs>(this.menuItem_Click); QuitItem.ItemClicked += new EventHandler <ScreenEventArgs>(this.buttonQuit_click); this.AddMenuItem(playItem); this.AddMenuItem(mainMenuItem); this.AddMenuItem(QuitItem); }
private void UpdateClickNumAndTriggerInItems(bool useWorker, DoWorkEventArgs e) { int clickNum = FirstClickNumber; for (int i = 0; i < Items.Count(); i++) { if (useWorker && worker.CancellationPending) { e.Cancel = true; return; } ClickItem clickItem = Items.ElementAt(i); UpdateClickNumOnClickItem(clickItem, clickNum, i); if (clickItem is ExplanationItem) { UpdateTriggerOnExplanationItem(clickItem as ExplanationItem, i); } } }