private void Start() { mMousHandler.PickUp += delegate { mStateMachin.SetToken(UIToken.BugMenuOpen); }; mMousHandler.Drop += delegate { mStateMachin.SetToken(UIToken.BugMenuClose); }; mMousHandler.OpenScan += delegate { mStateMachin.SetToken(UIToken.ScanUIOpen); }; mMousHandler.CloseScan += delegate { mStateMachin.SetToken(UIToken.ScanUIClose); }; mDeletAnimator = mBugMenu.Delet.GetComponent <Animator>(); mInfoAnimator = mBugMenu.Info.GetComponent <Animator>(); mScanPanelAnimator = mBugMenu.ScanPanle.GetComponent <Animator>(); EnterDetector d = mBugMenu.Delet.GetComponent <EnterDetector>(); ClickDetector c = mBugMenu.Delet.GetComponent <ClickDetector>(); d.Enter += mMousHandler.EnterDelet; d.Exit += mMousHandler.ExitDelet; c.Click += mMousHandler.ClickDelet; d = mBugMenu.Info.GetComponent <EnterDetector>(); c = mBugMenu.Info.GetComponent <ClickDetector>(); d.Enter += mMousHandler.EnterInfo; d.Exit += mMousHandler.ExitInfo; c.Click += mMousHandler.ClickInfo; RegisterStates(); }
public WrapedViewGroup(Context context) : base(context) { this.Clickable = true; this.tapDetector = new TapDetector(this); this.clickDetector = new ClickDetector(this); }
private void HandlePointerUp(object sender, PointerRoutedEventArgs e) { _pointerDown = false; if (_prevPoint == null) { return; } switch (ToolMode) { case EditMode.Object: case EditMode.Move: _selected = null; _offset = Vector3.Zero; break; case EditMode.Delete: { if (DeleteMode == ObjectType.Object) { var pos = _screen.Camera.Owner.Transform.LocalTranslation; pos.X += (float)_prevPoint.Position.X; pos.Y += (float)_prevPoint.Position.Y + 100; // +100 to offset camera position var toDelete = ClickDetector.GetClicked(pos.X, pos.Y); if (toDelete != null) { _screen.RemoveObject(toDelete); _screen.Objectives.CompleteObjective("deletetree"); } } } break; } _prevPoint = null; }
private void OnDisable() { if (ClickDetector.GetComponent <JumpClickController>().enabled == false) { Buttons.SetActive(true); } }
private void FillPlots(List <Tuple <RectangleF, float> > plots) { float cell = 32; foreach (var plot in plots) { var pos = plot.Item1.Center * cell; var bounds = new RectangleF(plot.Item1.Left * cell, plot.Item1.Top * cell, plot.Item1.Width * cell, plot.Item1.Height * cell); if (ClickDetector.FindIntersects(bounds) != null) { continue; } var rot = plot.Item2; var p = new Dictionary <string, object>(); p.Add("Rotation", rot); _screen.AddObject("house", null, pos.X, pos.Y, 0.5f, p); } }
private void HandlePointerDown(object sender, PointerRoutedEventArgs e) { _prevPoint = e.GetCurrentPoint((UIElement)sender); _pointerDown = true; switch (ToolMode) { case EditMode.Object: var selected = ObjTypeList.SelectedItem; if (selected is string) { var pos = _screen.Camera.Owner.Transform.LocalTranslation; pos.Z = 0; pos.X += (float)_prevPoint.Position.X; pos.Y += (float)_prevPoint.Position.Y + 100; // +100 to offset camera position pos = _gameGrid.Snap(pos); _selected = _screen.AddObject(selected as string, null, pos.X, pos.Y, 0, null); if (((string)selected).ToLower() == "tree") { _screen.Objectives.CompleteObjective("placetree"); } } break; case EditMode.Move: { var pos = _screen.Camera.Owner.Transform.LocalTranslation; pos.X += (float)_prevPoint.Position.X; pos.Y += (float)_prevPoint.Position.Y + 100; // +100 to offset camera position _selected = ClickDetector.GetClicked(pos.X, pos.Y); if (_selected != null) { _offset = _selected.Transform.Translation - pos; _offset.Z = 0; } } break; case EditMode.Road: StampTile((float)_prevPoint.Position.X, (float)_prevPoint.Position.Y, (int)BrushSizeSlider.Value, 1); _screen.Objectives.CompleteObjective("placeroad"); break; case EditMode.Zone: StampTile((float)_prevPoint.Position.X, (float)_prevPoint.Position.Y, (int)ZoneBrushSizeSlider.Value, 2, 0); _screen.Objectives.CompleteObjective("placezone"); break; case EditMode.Delete: if (DeleteMode == ObjectType.Road) { if (StampTile((float)_prevPoint.Position.X, (float)_prevPoint.Position.Y, (int)DelBrushSizeSlider.Value, 0, 1) > 0) { _screen.Objectives.CompleteObjective("deleteroads"); } } else if (DeleteMode == ObjectType.Zone) { StampTile((float)_prevPoint.Position.X, (float)_prevPoint.Position.Y, (int)DelBrushSizeSlider.Value, 0, 2); } break; } }
private void loadEventsPageUpgrade2() { // Create Sections. //Transform genericWordBox = ghostBookWordBoxPrefab; GameObject eventsTab = ghostbookGObj.transform.FindChild("EventsTab").gameObject; GameObject eventsMainPage = eventsTab.transform.FindChild("Pages").FindChild("MainPage").gameObject; extractGUIBoundsAndAddToCache(eventsMainPage.transform.FindChild("ContentArea").gameObject,"EventsGUIScrollArea"); GameObject contentArea = eventsTab.transform.FindChild("Backdrop").FindChild("ContentArea").gameObject; Rect contentArea2DBounds = CommonUnityUtils.get2DBounds(contentArea.renderer.bounds); Transform sectionTemplate = eventsMainPage.transform.FindChild("SectionTemplate"); Rect sectionTemplate2DBounds = CommonUnityUtils.get2DBounds(sectionTemplate.FindChild("SectionBackground").renderer.bounds); Vector3 currFreeSpaceTL = new Vector3(contentArea2DBounds.x,contentArea2DBounds.y); availableEvents = gbMang.getAvailableEvents(); bool pageContainsEntries = false; if(availableEvents != null) { if(availableEvents.Count > 0) { pageContainsEntries = true; } } if(pageContainsEntries) { for(int i=0; i<availableEvents.Count; i++) { // Clone section template and position it. EventSummarySnippit currEvSnip = availableEvents[i]; Transform nwSection = (Transform) Instantiate(sectionTemplate,new Vector3(currFreeSpaceTL.x + (sectionTemplate2DBounds.width/2f),currFreeSpaceTL.y - (sectionTemplate2DBounds.height/2f),sectionTemplate.position.z),Quaternion.identity); nwSection.name = "Section-"+i; Transform smallHeadGuide = nwSection.FindChild("SmallHead"); Transform activitySymbolGuide = nwSection.FindChild("SmallSymbol"); smallHeadGuide.GetComponent<SpriteRenderer>().sprite = characterSmallFaces[currEvSnip.getQuestGiverCharID()].GetComponent<SpriteRenderer>().sprite; activitySymbolGuide.GetComponent<SpriteRenderer>().sprite = activitySymbols[(int) (currEvSnip.getApplicationID())].GetComponent<SpriteRenderer>().sprite; Transform sectionBackground = nwSection.FindChild("SectionBackground"); Rect origSectionBounds = CommonUnityUtils.get2DBounds(sectionBackground.renderer.bounds); Rect adjustedSectionBounds = origSectionBounds;//new Rect(origSectionBounds.x,origSectionBounds.y,origSectionBounds.width,origSectionBounds.y - (endSeparatorBounds.y + endSeparatorBounds.height)); nwSection.parent = eventsTab.transform; currFreeSpaceTL.x = adjustedSectionBounds.x; currFreeSpaceTL.y = adjustedSectionBounds.y - adjustedSectionBounds.height; } Transform firstSection = eventsTab.transform.FindChild("Section-0"); Transform lastSection = eventsTab.transform.FindChild("Section-"+(availableEvents.Count-1)); Rect firstSectionBounds = CommonUnityUtils.get2DBounds(firstSection.FindChild("SectionBackground").renderer.bounds); Rect lastSectionBounds = CommonUnityUtils.get2DBounds(lastSection.FindChild("SectionBackground").renderer.bounds); Transform blowupScrollPane = eventsMainPage.transform.FindChild("BlowupBase"); Rect blowupScrollPane2DBounds = CommonUnityUtils.get2DBounds(blowupScrollPane.renderer.bounds); Rect adjBoundsForScrollPane = new Rect(firstSectionBounds.x,firstSectionBounds.y,firstSectionBounds.width,(firstSectionBounds.y - (lastSectionBounds.y - lastSectionBounds.height))); Vector3 bScale = blowupScrollPane.localScale; bScale.x *= adjBoundsForScrollPane.width / blowupScrollPane2DBounds.width; bScale.y *= adjBoundsForScrollPane.height / blowupScrollPane2DBounds.height; blowupScrollPane.localScale = bScale; Vector3 bPos = blowupScrollPane.position; bPos.x = adjBoundsForScrollPane.x + (adjBoundsForScrollPane.width/2f); bPos.y = adjBoundsForScrollPane.y - (adjBoundsForScrollPane.height/2f); blowupScrollPane.position = bPos; for(int i=0; i<availableEvents.Count; i++) { Transform tmpSection = eventsTab.transform.FindChild("Section-"+i); tmpSection.gameObject.SetActive(true); tmpSection.parent = blowupScrollPane; } scrollableEventsPane = blowupScrollPane; scrollableEventspaneZeroWorldBounds = CommonUnityUtils.get2DBounds(blowupScrollPane.renderer.bounds); scrollableEventsPaneInnerGUIBounds = WorldSpawnHelper.getWorldToGUIBounds(blowupScrollPane.renderer.bounds,upAxisArr); scrollableEventsPaneInnerGUIBounds.x = 0; scrollableEventsPaneInnerGUIBounds.y = 0; //Rect regPaneWBounds = scrollableGridZeroWorldBounds; Rect paneGUIBounds = uiBounds["EventsGUIScrollArea"]; eventsSectionInnerGUIs = new List<EventsPageInnerGUICollection>(); for(int i=0; i<availableEvents.Count; i++) { Transform tmpSection = blowupScrollPane.transform.FindChild("Section-"+i); //Rect tmpSectionGUIBounds = WorldSpawnHelper.getWorldToGUIBounds(tmpSection.FindChild("SectionBackground").renderer.bounds,upAxisArr); Rect tmpFShGUIBounds = WorldSpawnHelper.getWorldToGUIBounds(tmpSection.FindChild("FriendlyShoutoutArea").renderer.bounds,upAxisArr); Rect tmpLA2DGUIBounds = WorldSpawnHelper.getWorldToGUIBounds(tmpSection.FindChild("LanguageAreaField").renderer.bounds,upAxisArr); Rect tmpDiff2DGUIBounds = WorldSpawnHelper.getWorldToGUIBounds(tmpSection.FindChild("DifficultyField").renderer.bounds,upAxisArr); EventsPageInnerGUICollection tmpInnerGUIData = new EventsPageInnerGUICollection(); tmpInnerGUIData.friendlyShoutoutBounds = new Rect(((tmpFShGUIBounds.x - paneGUIBounds.x)/paneGUIBounds.width) * paneGUIBounds.width, ((tmpFShGUIBounds.y - paneGUIBounds.y)/paneGUIBounds.height) * paneGUIBounds.height, tmpFShGUIBounds.width,tmpFShGUIBounds.height); tmpInnerGUIData.langAreaTextFieldBounds = new Rect(((tmpLA2DGUIBounds.x - paneGUIBounds.x)/paneGUIBounds.width) * paneGUIBounds.width, ((tmpLA2DGUIBounds.y - paneGUIBounds.y)/paneGUIBounds.height) * paneGUIBounds.height, tmpLA2DGUIBounds.width,tmpLA2DGUIBounds.height); tmpInnerGUIData.difficultyTextFieldBounds = new Rect(((tmpDiff2DGUIBounds.x - paneGUIBounds.x)/paneGUIBounds.width) * paneGUIBounds.width, ((tmpDiff2DGUIBounds.y - paneGUIBounds.y)/paneGUIBounds.height) * paneGUIBounds.height, tmpDiff2DGUIBounds.width,tmpDiff2DGUIBounds.height); eventsSectionInnerGUIs.Add(tmpInnerGUIData); } // Add apply mask shader to everything on the blowupScrollPane. Vector3 validViewportTL = Camera.main.WorldToViewportPoint(new Vector3(contentArea2DBounds.x,contentArea2DBounds.y,1)); Vector3 validViewportBR = Camera.main.WorldToViewportPoint(new Vector3(contentArea2DBounds.x + contentArea2DBounds.width,contentArea2DBounds.y - contentArea2DBounds.height,1)); maskShaderMaterial.SetVector("_Clip",new Vector4(validViewportTL.x,validViewportTL.y,validViewportBR.x - validViewportTL.x,validViewportTL.y - validViewportBR.y)); maskShaderMaterialForText.SetVector("_Clip",new Vector4(validViewportTL.x,validViewportTL.y,validViewportBR.x - validViewportTL.x,validViewportTL.y - validViewportBR.y)); applyMaskShaderToAllChildren(blowupScrollPane); // Click detector for grid. if(eventsPaneClickDetector == null) { eventsPaneClickDetector = transform.gameObject.AddComponent<ClickDetector>(); eventsPaneClickDetector.registerListener("GhostbookDisplay",this); } } }
private void loadContactGridPage() { // Access ghostbook gobj through global variable. GameObject contactsTab = ghostbookGObj.transform.FindChild("ContactsTab").gameObject; GameObject contentArea = contactsTab.transform.FindChild("Backdrop").FindChild("ContentArea").gameObject; contentArea.renderer.sortingOrder = 152; Rect contentArea2DBounds = CommonUnityUtils.get2DBounds(contentArea.renderer.bounds); float contentAreaZVal = contentArea.transform.position.z; Rect contactsGridScrollGUIArea = new Rect(0,0,1,1); if( ! uiBounds.ContainsKey("ContactsGridScrollArea")) { contactsGridScrollGUIArea = WorldSpawnHelper.getWorldToGUIBounds(contentArea.renderer.bounds,upAxisArr); uiBounds.Add("ContactsGridScrollArea",contactsGridScrollGUIArea); } contactsGridScrollGUIArea = uiBounds["ContactsGridScrollArea"]; int numItemsPerRow = 4; Rect worldSizeForFace = CommonUnityUtils.get2DBounds(unlockedCharacterFaces[0].gameObject.renderer.bounds); float totalWidthForFacesInRow = worldSizeForFace.width * (numItemsPerRow * 1.0f); float unUsedWidth = contentArea2DBounds.width - totalWidthForFacesInRow; float paddingWidth = unUsedWidth/((numItemsPerRow + 1)*1.0f); float paddingHeight = paddingWidth; // Create Sections. Transform genericWordBox = ghostBookWordBoxPrefab; Transform sectionTemplate = contactsTab.transform.FindChild("Pages").FindChild("ContactsGridPage").FindChild("SectionTemplate"); Rect sectionTemplate2DBounds = CommonUnityUtils.get2DBounds(sectionTemplate.FindChild("SectionBackground").renderer.bounds); Vector3 currFreeSpaceTL = new Vector3(contentArea2DBounds.x,contentArea2DBounds.y); List<ContactGridSection> contactGridSectionList = createContactGridSections(); for(int i=0; i<contactGridSectionList.Count; i++) { // Clone section template and position it. ContactGridSection currSection = contactGridSectionList[i]; Transform nwSection = (Transform) Instantiate(sectionTemplate,new Vector3(currFreeSpaceTL.x + (sectionTemplate2DBounds.width/2f),currFreeSpaceTL.y - (sectionTemplate2DBounds.height/2f),sectionTemplate.position.z),Quaternion.identity); nwSection.name = "Section-"+i; Transform titleAreaGuide = nwSection.FindChild("SectionTitleArea"); GameObject nwSectionTitleBox = WordBuilderHelper.buildWordBox(i,currSection.getSectionName(),CommonUnityUtils.get2DBounds(titleAreaGuide.renderer.bounds),titleAreaGuide.position.z,upAxisArr,genericWordBox); nwSectionTitleBox.name = "SectionTitle"; WordBuilderHelper.setBoxesToUniformTextSize(new List<GameObject>() {nwSectionTitleBox},0.09f); nwSectionTitleBox.transform.parent = nwSection; Destroy(nwSectionTitleBox.transform.FindChild("Board").gameObject); nwSectionTitleBox.transform.FindChild("Text").renderer.sortingOrder = 162; Transform portraitAreaGuide = nwSection.FindChild("PortraitArea"); Rect portraitAreaBounds = CommonUnityUtils.get2DBounds(portraitAreaGuide.renderer.bounds); List<GameObject> wordBannerList = new List<GameObject>(); List<int> charIDsForSection = currSection.getSectionCharIDs(); int r=0; int c=0; GameObject lastPortraitInSection = null; for(int k=0; k<charIDsForSection.Count; k++) { int currCharID = charIDsForSection[k]; c = (int) (k % (numItemsPerRow * 1.0f)); r = (int) (k / (numItemsPerRow * 1.0f)); Vector3 nwFaceSpawnPt = new Vector3(portraitAreaBounds.x + ((c+1) * paddingWidth) + (c * (worldSizeForFace.width)) + (worldSizeForFace.width/2f), portraitAreaBounds.y - ((r+1) * paddingHeight) - (r * (worldSizeForFace.height)) - (worldSizeForFace.height/2f), contentAreaZVal); Transform nwlyCreatedPortrait = null; if(gbMang.getContactStatus(currCharID) == CharacterStatus.LOCKED) { // Render locked character portrait. Transform reqLockedPortrait = lockedCharacterFaces[currCharID]; nwlyCreatedPortrait = (Transform) Instantiate(reqLockedPortrait,nwFaceSpawnPt,Quaternion.identity); } else { // Render unlocked character portrait. Transform reqUnlockedPortrait = unlockedCharacterFaces[currCharID]; nwlyCreatedPortrait = (Transform) Instantiate(reqUnlockedPortrait,nwFaceSpawnPt,Quaternion.identity); ContactPageInfoSnippit tmpSnip = gbMang.getContactPageInfoSnippit(currCharID); string charName = tmpSnip.getName(); float percComp = tmpSnip.getPhotoAlbum().getNormalisedPercentageCompletion(); PortraitHelper.replaceEntireDummyPortrait(nwlyCreatedPortrait.gameObject,currCharID,percComp,charName); wordBannerList.Add(nwlyCreatedPortrait.FindChild("NameBar").FindChild("TextBanner").gameObject); BoxCollider bCol = nwlyCreatedPortrait.gameObject.AddComponent<BoxCollider>(); bCol.isTrigger = true; } if(nwlyCreatedPortrait != null) { nwlyCreatedPortrait.name = "Portrait-"+currCharID; nwlyCreatedPortrait.parent = nwSection; lastPortraitInSection = nwlyCreatedPortrait.gameObject; } } WordBuilderHelper.setBoxesToUniformTextSize(wordBannerList,0.04f); Transform endSectionSeparator = nwSection.FindChild("End-SectionSeparator"); if(lastPortraitInSection != null) { Rect lastPortraitBounds = CommonUnityUtils.get2DBounds(lastPortraitInSection.renderer.bounds); Vector3 tmpSepPos = endSectionSeparator.position; tmpSepPos.y = lastPortraitBounds.y - lastPortraitBounds.height - 0.3f; endSectionSeparator.position = tmpSepPos; } Rect endSeparatorBounds = CommonUnityUtils.get2DBounds(endSectionSeparator.renderer.bounds); Transform sectionBackground = nwSection.FindChild("SectionBackground"); Rect origSectionBounds = CommonUnityUtils.get2DBounds(sectionBackground.renderer.bounds); Rect adjustedSectionBounds = new Rect(origSectionBounds.x,origSectionBounds.y,origSectionBounds.width,origSectionBounds.y - (endSeparatorBounds.y + endSeparatorBounds.height)); Vector3 tmpBkScale = sectionBackground.localScale; tmpBkScale.x *= (adjustedSectionBounds.width/origSectionBounds.width); tmpBkScale.y *= (adjustedSectionBounds.height/origSectionBounds.height); sectionBackground.localScale = tmpBkScale; Vector3 tmpBkPos = sectionBackground.position; tmpBkPos.x = adjustedSectionBounds.x + (adjustedSectionBounds.width/2f); tmpBkPos.y = adjustedSectionBounds.y - (adjustedSectionBounds.height/2f); sectionBackground.position = tmpBkPos; nwSection.parent = contactsTab.transform; currFreeSpaceTL.x = adjustedSectionBounds.x; currFreeSpaceTL.y = adjustedSectionBounds.y - adjustedSectionBounds.height; } Transform firstSection = contactsTab.transform.FindChild("Section-0"); Transform lastSection = contactsTab.transform.FindChild("Section-"+(contactGridSectionList.Count-1)); Rect firstSectionBounds = CommonUnityUtils.get2DBounds(firstSection.FindChild("SectionBackground").renderer.bounds); Rect lastSectionBounds = CommonUnityUtils.get2DBounds(lastSection.FindChild("SectionBackground").renderer.bounds); Transform blowupScrollPane = contactsTab.transform.FindChild("Pages").FindChild("ContactsGridPage").FindChild("BlowupBase"); Rect blowupScrollPane2DBounds = CommonUnityUtils.get2DBounds(blowupScrollPane.renderer.bounds); Rect adjBoundsForScrollPane = new Rect(firstSectionBounds.x,firstSectionBounds.y,firstSectionBounds.width,(firstSectionBounds.y - (lastSectionBounds.y - lastSectionBounds.height))); Vector3 bScale = blowupScrollPane.localScale; bScale.x *= adjBoundsForScrollPane.width / blowupScrollPane2DBounds.width; bScale.y *= adjBoundsForScrollPane.height / blowupScrollPane2DBounds.height; blowupScrollPane.localScale = bScale; Vector3 bPos = blowupScrollPane.position; bPos.x = adjBoundsForScrollPane.x + (adjBoundsForScrollPane.width/2f); bPos.y = adjBoundsForScrollPane.y - (adjBoundsForScrollPane.height/2f); blowupScrollPane.position = bPos; for(int i=0; i<contactGridSectionList.Count; i++) { Transform tmpSection = contactsTab.transform.FindChild("Section-"+i); tmpSection.gameObject.SetActive(true); tmpSection.parent = blowupScrollPane; } scrollableContactGrid = blowupScrollPane; scrollableGridZeroWorldBounds = CommonUnityUtils.get2DBounds(blowupScrollPane.renderer.bounds); scrollableGridInnerGUIBounds = WorldSpawnHelper.getWorldToGUIBounds(blowupScrollPane.renderer.bounds,upAxisArr); scrollableGridInnerGUIBounds.x = 0; scrollableGridInnerGUIBounds.y = 0; // Add apply mask shader to everything on the blowupScrollPane. Vector3 validViewportTL = Camera.main.WorldToViewportPoint(new Vector3(contentArea2DBounds.x,contentArea2DBounds.y,1)); Vector3 validViewportBR = Camera.main.WorldToViewportPoint(new Vector3(contentArea2DBounds.x + contentArea2DBounds.width,contentArea2DBounds.y - contentArea2DBounds.height,1)); maskShaderMaterial.SetVector("_Clip",new Vector4(validViewportTL.x,validViewportTL.y,validViewportBR.x - validViewportTL.x,validViewportTL.y - validViewportBR.y)); maskShaderMaterialForText.SetVector("_Clip",new Vector4(validViewportTL.x,validViewportTL.y,validViewportBR.x - validViewportTL.x,validViewportTL.y - validViewportBR.y)); applyMaskShaderToAllChildren(blowupScrollPane); // Click detector for grid. gridClickDetector = transform.GetComponent<ClickDetector>(); if(gridClickDetector == null) { gridClickDetector = transform.gameObject.AddComponent<ClickDetector>(); } gridClickDetector.registerListener("GhostbookDisplay",this); }
// Use this for initialization public virtual void Start() { clickDetector = GetComponentInChildren <ClickDetector>(); clickDetector.mouseClick += Clicked; }