protected override void OnActivateTool() { base.OnActivateTool(); Vector3 cursorPos = PlayerController.GetCursorPos(KInputManager.GetMousePos()); GameObject buildingPreview = def.BuildingPreview; Vector3 position = cursorPos; Grid.SceneLayer sceneLayer = Grid.SceneLayer.Ore; int gameLayer = LayerMask.NameToLayer("Place"); visualizer = GameUtil.KInstantiate(buildingPreview, position, sceneLayer, null, gameLayer); KBatchedAnimController component = visualizer.GetComponent <KBatchedAnimController>(); if ((Object)component != (Object)null) { component.visibilityType = KAnimControllerBase.VisibilityType.Always; component.isMovable = true; component.SetDirty(); } visualizer.SetActive(true); Play(visualizer, "None_Place"); BuildToolHoverTextCard component2 = GetComponent <BuildToolHoverTextCard>(); component2.currentDef = def; ResourceRemainingDisplayScreen.instance.ActivateDisplay(visualizer); IHaveUtilityNetworkMgr component3 = def.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>(); conduitMgr = component3.GetNetworkManager(); }
private void GetMouseHoverInfo(out bool is_hovering_screen, out bool is_hovering_button) { UnityEngine.EventSystems.EventSystem current = UnityEngine.EventSystems.EventSystem.current; if ((UnityEngine.Object)current == (UnityEngine.Object)null) { is_hovering_button = false; is_hovering_screen = false; } else { List <RaycastResult> list = new List <RaycastResult>(); PointerEventData pointerEventData = new PointerEventData(current); pointerEventData.position = KInputManager.GetMousePos(); current.RaycastAll(pointerEventData, list); bool flag = false; bool flag2 = false; foreach (RaycastResult item in list) { if ((UnityEngine.Object)item.gameObject.GetComponent <OptionSelector>() != (UnityEngine.Object)null || ((UnityEngine.Object)item.gameObject.transform.parent != (UnityEngine.Object)null && (UnityEngine.Object)item.gameObject.transform.parent.GetComponent <OptionSelector>() != (UnityEngine.Object)null)) { flag = true; flag2 = true; break; } if (HasParent(item.gameObject, base.gameObject)) { flag2 = true; } } is_hovering_screen = flag2; is_hovering_button = flag; } }
private void Update() { if (!Game.Instance.timelapser.CapturingTimelapseScreenshot) { if (FreeCameraEnabled && cinemaCamEnabled) { CinemaCamUpdate(); } else { NormalCamUpdate(); } } Color color = infoText.color; if (color.a > 0f) { Color color2 = infoText.color; Color color3 = infoText.color; color2.a = Mathf.Max(0f, color3.a - Time.unscaledDeltaTime * 0.5f); infoText.color = color2; } ConstrainToWorld(); Vector3 vector = PointUnderCursor(KInputManager.GetMousePos(), Camera.main); Vector3 position = base.transform.GetPosition(); float x = position.x; Vector3 position2 = base.transform.GetPosition(); float y = position2.y; Vector3 position3 = base.transform.GetPosition(); Shader.SetGlobalVector("_WorldCameraPos", new Vector4(x, y, position3.z, Camera.main.orthographicSize)); Shader.SetGlobalVector("_WorldCursorPos", new Vector4(vector.x, vector.y, 0f, 0f)); VisibleArea.Update(); soundCuller = SoundCuller.CreateCuller(); }
public void CreateVisualizer() { if (visualizer != null) { Destroy(visualizer); } visualizer = new GameObject("UseBlueprintVisualizer"); visualizer.SetActive(false); GameObject offsetObject = new GameObject(); SpriteRenderer spriteRenderer = offsetObject.AddComponent <SpriteRenderer>(); spriteRenderer.color = BlueprintsAssets.BLUEPRINTS_COLOR_BLUEPRINT_DRAG; spriteRenderer.sprite = BlueprintsAssets.BLUEPRINTS_USE_VISUALIZER_SPRITE; offsetObject.transform.SetParent(visualizer.transform); offsetObject.transform.localPosition = new Vector3(0, Grid.HalfCellSizeInMeters); var sprite = spriteRenderer.sprite; offsetObject.transform.localScale = new Vector3( Grid.CellSizeInMeters / (sprite.texture.width / sprite.pixelsPerUnit), Grid.CellSizeInMeters / (sprite.texture.height / sprite.pixelsPerUnit) ); offsetObject.SetLayerRecursively(LayerMask.NameToLayer("Overlay")); visualizer.transform.SetParent(transform); OnMouseMove(PlayerController.GetCursorPos(KInputManager.GetMousePos())); }
/// <summary> /// Updates the hover card text. /// </summary> /// <param name="selected">The objects under the cursor.</param> public override void UpdateHoverElements(List <KSelectable> selected) { var ts = FilteredClearTool.Instance.TypeSelect; var hoverInstance = HoverTextScreen.Instance; // Determine if in default Sweep All mode bool all = ts.IsAllSelected; int cell = Grid.PosToCell(Camera.main.ScreenToWorldPoint(KInputManager. GetMousePos())); // Draw the tool title string titleStr = all ? STRINGS.UI.TOOLS.MARKFORSTORAGE.TOOLNAME : SweepByTypeStrings.TOOL_NAME_FILTERED; var drawer = hoverInstance.BeginDrawing(); drawer.BeginShadowBar(false); drawer.DrawText(titleStr.ToUpper(), ToolTitleTextStyle); // Draw the instructions ActionName = all ? STRINGS.UI.TOOLS.MARKFORSTORAGE.TOOLACTION.text : SweepByTypeStrings.TOOLTIP_FILTERED.text; DrawInstructions(hoverInstance, drawer); drawer.EndShadowBar(); if (selected != null && Grid.IsValidCell(cell) && Grid.IsVisible(cell)) { DrawPickupText(selected, drawer, hoverInstance.GetSprite("dash")); } drawer.EndDrawing(); }
public void OnPointerClick(PointerEventData eventData) { if (KInputManager.isFocused) { KInputManager.SetUserActive(); if (interactable) { KKeyCode btn = KKeyCode.None; switch (eventData.button) { case PointerEventData.InputButton.Left: btn = KKeyCode.Mouse0; break; case PointerEventData.InputButton.Right: btn = KKeyCode.Mouse1; break; case PointerEventData.InputButton.Middle: btn = KKeyCode.Mouse2; break; } if ((eventData.clickCount == 1 || this.onDoubleClick == null) && (this.onClick != null || this.onBtnClick != null)) { SignalClick(btn); } else if (eventData.clickCount == 2 && this.onDoubleClick != null) { SignalDoubleClick(btn); } } } }
public void UpdateData(Texture2D texture, byte[] textureBytes, HashedString viewMode, byte alpha) { if (!dataUpdateFuncs.TryGetValue(viewMode, out Action <SimDebugView, Texture> value)) { value = SetDefaultPoint; } value(this, texture); Grid.GetVisibleExtents(out int min_x, out int min_y, out int max_x, out int max_y); selectedPathProber = null; KSelectable selected = SelectTool.Instance.selected; if ((UnityEngine.Object)selected != (UnityEngine.Object)null) { selectedPathProber = selected.GetComponent <PathProber>(); } updateSimViewWorkItems.Reset(new UpdateSimViewSharedData(this, texBytes, viewMode, this)); int num = 16; for (int i = min_y; i <= max_y; i += num) { int y = Math.Min(i + num - 1, max_y); updateSimViewWorkItems.Add(new UpdateSimViewWorkItem(min_x, i, max_x, y)); } currentFrame = Time.frameCount; selectedCell = Grid.PosToCell(Camera.main.ScreenToWorldPoint(KInputManager.GetMousePos())); GlobalJobManager.Run(updateSimViewWorkItems); texture.LoadRawTextureData(textureBytes); texture.Apply(); }
public void OnPointerExit(PointerEventData eventData) { pointerOver = false; if (KInputManager.isFocused) { KInputManager.SetUserActive(); if (states.Length != 0) { if (states[state].use_color_on_hover && states[state].color_on_hover != states[state].color) { toggle_image.color = states[state].color; } if (states[state].use_rect_margins) { toggle_image.rectTransform().sizeDelta = states[state].rect_margins; } StatePresentationSetting[] additional_display_settings = states[state].additional_display_settings; for (int i = 0; i < additional_display_settings.Length; i++) { StatePresentationSetting statePresentationSetting = additional_display_settings[i]; if (!((UnityEngine.Object)statePresentationSetting.image_target == (UnityEngine.Object)null) && statePresentationSetting.use_color_on_hover) { statePresentationSetting.image_target.color = statePresentationSetting.color; } } if (onExit != null) { onExit(); } } } }
/// <summary> /// Fired when a key is pressed. /// </summary> /// <param name="e">The event that occurred.</param> public void OnKeyDown(KButtonEvent e) { var es = UnityEngine.EventSystems.EventSystem.current; if (e.TryConsume(snapshotAction) && es != null) { var results = ListPool <RaycastResult, DebugHandler> .Allocate(); es.RaycastAll(new PointerEventData(es) { position = KInputManager. GetMousePos() }, results); GameObject obj; foreach (var hit in results) { if (hit.isValid && (obj = hit.gameObject) != null) { // Found it! PUIUtils.DebugObjectTree(obj); PUIUtils.DebugObjectHierarchy(obj); } } results.Recycle(); } }
public void OnPointerEnter(PointerEventData eventData) { if (KInputManager.isFocused) { KInputManager.SetUserActive(); PlaySound(UISoundHelper.MouseOver); } }
public void OnPointerDown(PointerEventData eventData) { if (KInputManager.isFocused) { KInputManager.SetUserActive(); PlaySound(UISoundHelper.Click); } }
public static void Postfix(ref string __result, GameObject go, bool upperName) { var pos = KInputManager.GetMousePos(); int num = Grid.PosToCell(Camera.main.ScreenToWorldPoint(pos)); string boxSizeInfo = $" [{num} ({pos.x},{pos.y})]"; __result += " " + boxSizeInfo; }
public static Vector3 GetMousePos() { Vector3 mousePos = KInputManager.GetMousePos(); Vector3 position = Camera.main.transform.GetPosition(); mousePos.z = 0f - position.z - Grid.CellSizeInMeters; return(Camera.main.ScreenToWorldPoint(mousePos)); }
public void OnPointerUp(PointerEventData eventData) { if (KInputManager.isFocused) { KInputManager.SetUserActive(); UpdateColor(interactable, false, false); this.onPointerUp.Signal(); } }
public void Lock(bool shouldLock) { if (interactable && lockType == LockingType.Drag) { lockRange = shouldLock; range = maxSlider.value - minSlider.value; mousePos = KInputManager.GetMousePos(); } }
public void OnPointerDown(PointerEventData eventData) { if (KInputManager.isFocused) { KInputManager.SetUserActive(); PlaySound(UISoundHelper.SliderStart); OnChange?.Invoke(); } }
public void OnPointerDown(PointerEventData eventData) { if (KInputManager.isFocused) { KInputManager.SetUserActive(); UpdateColor(interactable, true, true); PlayPointerDownSound(); this.onPointerDown.Signal(); } }
// This is a little lazy, but it works just fine public void OnDrag(PointerEventData eventData) { if (KInputManager.isFocused) { KInputManager.SetUserActive(); PlayMoveSound(); UpdateSlider(); } }
public static void Postfix() { var pos = KInputManager.GetMousePos(); int num = Grid.PosToCell(Camera.main.ScreenToWorldPoint(pos)); Element element = Grid.Element[num]; if (PrevName != null) { element.nameUpperCase = PrevName; } }
public static void Prefix(List <KSelectable> hoverObjects) { var pos = KInputManager.GetMousePos(); int num = Grid.PosToCell(Camera.main.ScreenToWorldPoint(pos)); string boxSizeInfo = $" [{num} ({pos.x},{pos.y})]"; //__result += " " + boxSizeInfo; Element element = Grid.Element[num]; PrevName = element.nameUpperCase; element.nameUpperCase += boxSizeInfo; }
private static IEnumerator GetSelectedCell() { while (true) { if (SimDebugView.Instance.GetMode() == InfoOverlay.ID && Camera.main is Camera c) { selectedCell = Grid.PosToCell(c.ScreenToWorldPoint(KInputManager.GetMousePos())); } yield return(new WaitForEndOfFrame()); } }
private void Update() { Vector3 vector = Camera.main.ScreenToWorldPoint(KInputManager.GetMousePos()); if ((Object)OverlayScreen.Instance == (Object)null || vector.x < 0f || vector.x > Grid.WidthInMeters || vector.y < 0f || vector.y > Grid.HeightInMeters) { drawer.SetEnabled(false); } else { bool enabled = PlayerController.Instance.ActiveTool.ShowHoverUI(); drawer.SetEnabled(enabled); } }
public void OnDrag() { if (interactable && lockRange && lockType == LockingType.Drag) { Vector3 vector = KInputManager.GetMousePos(); float num = vector.x - mousePos.x; if (direction == Slider.Direction.TopToBottom || direction == Slider.Direction.BottomToTop) { Vector3 vector2 = KInputManager.GetMousePos(); num = vector2.y - mousePos.y; } currentMinValue = Mathf.Max(currentMinValue + num, minLimit); mousePos = KInputManager.GetMousePos(); } }
/// <summary> /// Calculates the color to tint the plants found by the overlay. /// </summary> /// <returns>The color to tint the plant - red if too many, green if OK.</returns> private Color GetHighlightColor(KMonoBehaviour _) { var color = Color.black; // Same method as used by the decor overlay int mouseCell = Grid.PosToCell(CameraController.Instance.baseCamera. ScreenToWorldPoint(KInputManager.GetMousePos())); var colors = GlobalAssets.Instance.colorSet; if (Grid.IsValidCell(mouseCell)) { color = (cells[mouseCell] == PipPlantFailedReasons.PlantCount) ? colors.cropHalted : colors.cropGrown; } return(color); }
public override void UpdateHoverElements(List <KSelectable> selected) { int num = Grid.PosToCell(Camera.main.ScreenToWorldPoint(KInputManager.GetMousePos())); if (Grid.IsValidCell(num)) { HoverTextScreen instance = HoverTextScreen.Instance; HoverTextDrawer hoverTextDrawer = instance.BeginDrawing(); hoverTextDrawer.BeginShadowBar(false); if (Grid.IsVisible(num)) { DrawTitle(instance, hoverTextDrawer); DrawInstructions(HoverTextScreen.Instance, hoverTextDrawer); Element element = Grid.Element[num]; bool flag = false; if (Grid.Solid[num] && Diggable.IsDiggable(num)) { flag = true; } if (flag) { hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawText(element.nameUpperCase, Styles_Title.Standard); hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawIcon(instance.GetSprite("dash"), 18); hoverTextDrawer.DrawText(element.GetMaterialCategoryTag().ProperName(), Styles_BodyText.Standard); hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawIcon(instance.GetSprite("dash"), 18); string[] array = WorldInspector.MassStringsReadOnly(num); hoverTextDrawer.DrawText(array[0], Styles_Values.Property.Standard); hoverTextDrawer.DrawText(array[1], Styles_Values.Property_Decimal.Standard); hoverTextDrawer.DrawText(array[2], Styles_Values.Property.Standard); hoverTextDrawer.DrawText(array[3], Styles_Values.Property.Standard); hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawIcon(instance.GetSprite("dash"), 18); hoverTextDrawer.DrawText(GameUtil.GetHardnessString(Grid.Element[num], true), Styles_BodyText.Standard); } } else { hoverTextDrawer.DrawIcon(instance.GetSprite("iconWarning"), 18); hoverTextDrawer.DrawText(UI.TOOLS.GENERIC.UNKNOWN, Styles_BodyText.Standard); } hoverTextDrawer.EndShadowBar(); hoverTextDrawer.EndDrawing(); } }
protected override void OnActivateTool() { lastDragCell = -1; if ((Object)visualizer != (Object)null) { ClearTilePreview(); Object.Destroy(visualizer); } active = true; base.OnActivateTool(); buildingOrientation = Orientation.Neutral; placementPivot = def.placementPivot; Vector3 cursorPos = PlayerController.GetCursorPos(KInputManager.GetMousePos()); GameObject buildingPreview = def.BuildingPreview; Vector3 position = cursorPos; Grid.SceneLayer sceneLayer = Grid.SceneLayer.Ore; int gameLayer = LayerMask.NameToLayer("Place"); visualizer = GameUtil.KInstantiate(buildingPreview, position, sceneLayer, null, gameLayer); KBatchedAnimController component = visualizer.GetComponent <KBatchedAnimController>(); if ((Object)component != (Object)null) { component.visibilityType = KAnimControllerBase.VisibilityType.Always; component.isMovable = true; component.Offset = def.GetVisualizerOffset(); component.Offset += def.placementPivot; component.name = component.GetComponent <KPrefabID>().GetDebugName() + "_visualizer"; } visualizer.SetActive(true); UpdateVis(cursorPos); BuildToolHoverTextCard component2 = GetComponent <BuildToolHoverTextCard>(); component2.currentDef = def; ResourceRemainingDisplayScreen.instance.ActivateDisplay(visualizer); if ((Object)component == (Object)null) { visualizer.SetLayerRecursively(LayerMask.NameToLayer("Place")); } else { component.SetLayer(LayerMask.NameToLayer("Place")); } GridCompositor.Instance.ToggleMajor(true); }
/// <summary> /// Adds the coordinates and cell number to the select tool. /// </summary> private static HoverTextDrawer DrawCoordinates(HoverTextDrawer drawer, HoverTextConfiguration instance) { int cell = Grid.PosToCell(Camera.main.ScreenToWorldPoint( KInputManager.GetMousePos())); if (Grid.IsValidCell(cell)) { Grid.CellToXY(cell, out int x, out int y); drawer.BeginShadowBar(); drawer.DrawText(string.Format(DebugNotIncludedStrings.UI.TOOLTIPS.DNI_CELL, cell, x, y), instance.Styles_BodyText.Standard); drawer.EndShadowBar(); } return(drawer); }
private void Update() { if (Input.GetKey(KeyCode.RightArrow)) { base.transform.SetPosition(base.transform.GetPosition() + Vector3.right * pan_speed * Time.deltaTime); } if (Input.GetKey(KeyCode.LeftArrow)) { base.transform.SetPosition(base.transform.GetPosition() + Vector3.left * pan_speed * Time.deltaTime); } if (Input.GetKey(KeyCode.UpArrow)) { base.transform.SetPosition(base.transform.GetPosition() + Vector3.up * pan_speed * Time.deltaTime); } if (Input.GetKey(KeyCode.DownArrow)) { base.transform.SetPosition(base.transform.GetPosition() + Vector3.down * pan_speed * Time.deltaTime); } ClampToBounds(); if (Input.GetKey(KeyCode.LeftShift)) { if (Input.GetMouseButtonDown(0)) { do_pan = true; last_pan = KInputManager.GetMousePos(); } else if (Input.GetMouseButton(0) && do_pan) { Vector3 vector = cam.ScreenToViewportPoint(last_pan - KInputManager.GetMousePos()); Vector3 translation = new Vector3(vector.x * pan_speed, vector.y * pan_speed, 0f); base.transform.Translate(translation, Space.World); ClampToBounds(); last_pan = KInputManager.GetMousePos(); } } if (Input.GetMouseButtonUp(0)) { do_pan = false; } float axis = Input.GetAxis("Mouse ScrollWheel"); if (axis != 0f) { cam.fieldOfView = Mathf.Clamp(cam.fieldOfView - axis * zoom_speed, zoom_min, zoom_max); } }
public virtual bool ShowHoverUI() { bool result = false; UnityEngine.EventSystems.EventSystem current = UnityEngine.EventSystems.EventSystem.current; if ((UnityEngine.Object)current != (UnityEngine.Object)null) { Vector3 mousePos = KInputManager.GetMousePos(); float x = mousePos.x; Vector3 mousePos2 = KInputManager.GetMousePos(); Vector3 v = new Vector3(x, mousePos2.y, 0f); PointerEventData pointerEventData = new PointerEventData(current); pointerEventData.position = v; current.RaycastAll(pointerEventData, castResults); result = (castResults.Count == 0); } return(result); }
public HoverTextDrawer BeginDrawing() { Vector2 localPoint = Vector2.zero; Vector2 screenPoint = KInputManager.GetMousePos(); RectTransform rectTransform = base.transform.parent as RectTransform; RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, screenPoint, base.transform.parent.GetComponent <Canvas>().worldCamera, out localPoint); float x = localPoint.x; Vector2 sizeDelta = rectTransform.sizeDelta; localPoint.x = x + sizeDelta.x / 2f; float y = localPoint.y; Vector2 sizeDelta2 = rectTransform.sizeDelta; localPoint.y = y - sizeDelta2.y / 2f; drawer.BeginDrawing(localPoint); return(drawer); }