private void Rotate() { if (!InventoryItem.ItemContentInfo.Rotatable) { return; } GridPosR.Orientation newOri = GridPosR.RotateOrientationClockwise90(InventoryItem.GridPos_Matrix.orientation); InventoryItem.GridPos_Matrix = new GridPosR(InventoryItem.GridPos_Matrix.x, InventoryItem.GridPos_Matrix.z, newOri); SetVirtualGridPos(InventoryItem.GridPos_World); dragStartLocalPos += new Vector2(InventoryItem.BoundingRect.x_min * UIInventory.GridSize, -InventoryItem.BoundingRect.z_min * UIInventory.GridSize) - RectTransform.anchoredPosition; RefreshView(); }
public static MechaInfo GetMechaInfo(this MechaConfig mechaConfig, MechaCamp mechaCamp) { MechaInfo mechaInfo = new MechaInfo(mechaConfig.MechaConfigName, mechaCamp, mechaConfig.Clone()); foreach (MechaConfig.Config config in mechaConfig.MechaComponentList) { MechaComponentConfig mcc = ConfigManager.Instance.GetMechaComponentConfig(config.MechaComponentKey); MechaComponentInfo mci = new MechaComponentInfo(mcc, config.MechaComponentQuality, config.MechaComponentAlias); GridPosR finalGPR = config.GridPosR + ConfigManager.EDIT_AREA_HALF_SIZE * GridPosR.One; mechaInfo.AddMechaComponentInfo(mci, finalGPR); } return(mechaInfo); }
public void RotateOccupiedPositions() { List <GridPos> gps = new List <GridPos>(); foreach (SkillGrid sg in OccupiedPositions) { gps.Add(sg.GridPos); } gps = GridPosR.TransformOccupiedPositions(new GridPosR(0, 0, GridPosR.Orientation.Right), gps); for (int index = 0; index < OccupiedPositions.Count; index++) { OccupiedPositions[index] = new SkillGrid(gps[index], OccupiedPositions[index].SkillGridType); } }
private void SetVirtualGridPos(GridPosR gridPos_World) { UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.Clear(); foreach (GridPos gp_matrix in InventoryItem.OccupiedGridPositions_Matrix) { if (!UIInventory.ContainsGP(gp_matrix)) { continue; } UIInventoryVirtualOccupationQuad quad = UIInventory.CreateUIInventoryItemVirtualOccupationQuad(UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.transform); quad.Init(InventoryItem.Inventory.GridSize, gp_matrix, InventoryItem.Inventory); UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.uiInventoryVirtualOccupationQuads.Add(quad); } }
private void SetVirtualGridPos(GridPosR gridPos_World) { City.CityInventoryVirtualOccupationQuadRoot.Clear(); foreach (GridPos gp_matrix in InventoryItem.OccupiedGridPositions_Matrix) { if (!CityInventory.ContainsGP(gp_matrix)) { continue; } CityInventoryVirtualOccupationQuad quad = CityInventory.CreateCityInventoryVirtualOccupationQuad(City.CityInventoryVirtualOccupationQuadRoot.transform); quad.Init(InventoryItem.Inventory.GridSize, gp_matrix, InventoryItem.Inventory); City.CityInventoryVirtualOccupationQuadRoot.cityInventoryVirtualOccupationQuads.Add(quad); } }
public void AddMechaComponentInfo(MechaComponentInfo mci, GridPosR gp_matrix) { if (IsBuilding) { _totalLife = 0; } mci.MechaInfo = this; mci.OnRemoveMechaComponentInfoSuc += RemoveMechaComponentInfo; MechaComponentInfoDict.Add(mci.GUID, mci); if (!string.IsNullOrEmpty(mci.Alias)) { if (MechaComponentInfoDict_Alias.ContainsKey(mci.Alias)) { MechaComponentInfo tempMCI = MechaComponentInfoDict_Alias[mci.Alias]; Debug.LogError($"机甲组件花名重复. " + $"机甲: {LogIdentityName}, 组件: {mci.LogIdentityName}, 花名: {mci.Alias}" + $"重复对象组件: {tempMCI.LogIdentityName}"); } else { MechaComponentInfoDict_Alias.Add(mci.Alias, mci); } } InventoryItem item = new InventoryItem(mci, MechaEditorInventory, gp_matrix); item.AmIRootItemInIsolationCalculationHandler = () => ((MechaComponentInfo)item.ItemContentInfo).MechaComponentType == MechaComponentType.Core; mci.SetInventoryItem(item); void instantiateMechaComponent() { item.Inventory = MechaEditorInventory; OnAddMechaComponentInfoSuc.Invoke(mci, gp_matrix); MechaEditorInventory.TryAddItem(item); MechaEditorInventory.RefreshConflictAndIsolation(); } if (MechaEditorInventory != null) { instantiateMechaComponent(); } else { OnInstantiated += instantiateMechaComponent; } }
private void Initialize(MechaComponentInfo mechaComponentInfo, Mecha parentMecha) { SetLayer(LayerManager.Instance.GetLayerByMechaCamp(mechaComponentInfo.MechaInfo.MechaCamp)); mechaComponentInfo.OnRemoveMechaComponentInfoSuc += (mci) => { OnRemoveMechaComponentSuc?.Invoke(this); PoolRecycle(); }; mechaComponentInfo.OnHighLightColorChange += HighLightColorChange; HighLightColorChange(QualityManager.GetQuality(mechaComponentInfo.Quality).Color, mechaComponentInfo.CurrentPowerUpgradeData.HighLightColorIntensity); { mechaComponentInfo.InventoryItem.OnSetGridPosHandler = (gridPos_World) => { GridPosR.ApplyGridPosToLocalTrans(gridPos_World, transform, ConfigManager.GridSize); MechaInfo.MechaEditorInventory.RefreshConflictAndIsolation(); }; mechaComponentInfo.InventoryItem.OnIsolatedHandler = (shown) => { if (shown) { MechaComponentModelRoot.SetBuildingBasicEmissionColor(CommonUtils.HTMLColorToColor("#E42835")); } else { MechaComponentModelRoot.ResetBuildingBasicEmissionColor(); } MechaComponentGridRoot.SetIsolatedIndicatorShown(shown); }; mechaComponentInfo.InventoryItem.OnConflictedHandler = MechaComponentGridRoot.SetGridConflicted; mechaComponentInfo.InventoryItem.OnResetConflictHandler = MechaComponentGridRoot.ResetAllGridConflict; } MechaComponentInfo = mechaComponentInfo; GridPos.ApplyGridPosToLocalTransXZ(MechaComponentInfo.InventoryItem.GridPos_World, transform, ConfigManager.GridSize); Mecha = parentMecha; MechaComponentGridRoot.SetInBattle(true); Initialize_Fighting(); }
public void Draggable_OnMousePressed(DragArea dragArea, Vector3 diffFromStart, Vector3 deltaFromLastFrame) { if (dragArea.Equals(Backpack.DragArea)) { if (Backpack.RotateItemKeyDownHandler != null && Backpack.RotateItemKeyDownHandler.Invoke()) { Rotate(); } if (diffFromStart.magnitude <= Draggable_DragMinDistance) { // stay } else { Vector2 diffLocal = RectTransform.parent.InverseTransformVector(diffFromStart); Vector2 currentLocalPos = dragStartLocalPos + diffLocal; GridPosR diff_world = GridPos.GetGridPosByPointXY(diffLocal, Backpack.GridSize); diff_world.orientation = InventoryItem.GridPos_Matrix.orientation; GridPosR diff_matrix = Backpack.CoordinateTransformationHandler_FromPosToMatrixIndex(diff_world); GridPosR gp_matrix = dragStartGridPos_Matrix + diff_matrix; gp_matrix.orientation = InventoryItem.GridPos_Matrix.orientation; InventoryItem.SetGridPosition(gp_matrix); RectTransform.anchoredPosition = currentLocalPos; } } else { if (Backpack.DragItemOutBackpackCallback != null) { Backpack.BackpackPanel.BackpackItemVirtualOccupationRoot.Clear(); if (Backpack.DragItemOutBackpackCallback.Invoke(this)) { InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix; Backpack.RemoveItem(InventoryItem, true); PoolRecycle(); } } } }
public void SetConnection(GridPosR.OrientationFlag adjacentConnection, GridPosR.OrientationFlag diagonalConnection) { foreach (GridPosR.Orientation orientation in Enum.GetValues(typeof(GridPosR.Orientation))) { MainImageBorders[(int)orientation].enabled = !adjacentConnection.HasFlag(orientation.ToFlag()); GridPosR.Orientation next = GridPosR.RotateOrientationClockwise90(orientation); if (!adjacentConnection.HasFlag(orientation.ToFlag()) && !adjacentConnection.HasFlag(next.ToFlag())) { SideImageBorders[((int)orientation) * 2].enabled = false; SideImageBorders[((int)orientation) * 2 + 1].enabled = false; } else if (adjacentConnection.HasFlag(orientation.ToFlag()) && adjacentConnection.HasFlag(next.ToFlag())) { if (diagonalConnection.HasFlag(orientation.ToFlag())) { SideImageBorders[((int)orientation) * 2].enabled = false; SideImageBorders[((int)orientation) * 2 + 1].enabled = false; } else { SideImageBorders[((int)orientation) * 2].enabled = true; SideImageBorders[((int)orientation) * 2 + 1].enabled = true; } } else { if (adjacentConnection.HasFlag(orientation.ToFlag())) { SideImageBorders[((int)orientation) * 2].enabled = true; SideImageBorders[((int)orientation) * 2 + 1].enabled = false; } else { SideImageBorders[((int)orientation) * 2].enabled = false; SideImageBorders[((int)orientation) * 2 + 1].enabled = true; } } } }
public void SetGridPosition(GridPosR gp_matrix) { if (!gp_matrix.Equals(GridPos_Matrix)) { GridPosR oriGPR = GridPos_Matrix; GridPos_Matrix = gp_matrix; foreach (GridPos gp in OccupiedGridPositions_Matrix) { if (gp.x >= Inventory.Columns) { GridPos_Matrix = oriGPR; SetGridPosition(new GridPosR(gp_matrix.x - 1, gp_matrix.z, gp_matrix.orientation)); return; } if (gp.x < 0) { GridPos_Matrix = oriGPR; SetGridPosition(new GridPosR(gp_matrix.x + 1, gp_matrix.z, gp_matrix.orientation)); return; } if (gp.z >= Inventory.Rows) { GridPos_Matrix = oriGPR; SetGridPosition(new GridPosR(gp_matrix.x, gp_matrix.z - 1, gp_matrix.orientation)); return; } if (gp.z < 0) { GridPos_Matrix = oriGPR; SetGridPosition(new GridPosR(gp_matrix.x, gp_matrix.z + 1, gp_matrix.orientation)); return; } } OnSetGridPosHandler?.Invoke(GridPos_World); } }
public void Initialize() { Orientation = GridPosR.GetGridPosByLocalTrans(transform, ConfigManager.GridSize).orientation; }
public void CameraRightRotate() { RotateDirection = GridPosR.RotateOrientationAntiClockwise90(RotateDirection); TargetConfigData.HorAngle -= 90f; }
public void CameraLeftRotate() { RotateDirection = GridPosR.RotateOrientationClockwise90(RotateDirection); TargetConfigData.HorAngle += 90f; }
public InventoryItem(IInventoryItemContentInfo itemContentInfo, Inventory inventory, GridPosR gp_matrix) { GUID = GetGUID(); Inventory = inventory; GridPos_Matrix = gp_matrix; ItemContentInfo = itemContentInfo; }
public void Rotate() { SetGridPosition(new GridPosR(GridPos_Matrix.x, GridPos_Matrix.z, GridPosR.RotateOrientationClockwise90(GridPos_Matrix.orientation))); }
public void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { CurrentSelectedBuildingKey = BuildingKey.None; } City.CityEditAreaIndicator.GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix); if (CurrentSelectedBuildingKey != BuildingKey.None && !EventSystem.current.IsPointerOverGameObject()) { // add preview if (City.CityInventory.InventoryInfo.PreviewInventoryItem == null) { BuildingInfo bi = BuildingInfoDict[CurrentSelectedBuildingKey].Clone(); InventoryItem ii = new InventoryItem(bi, City.CityInventory, gp_matrix); City.CityInventory.AddPreviewItem(ii); } // move with cursor if (City.CityInventory.InventoryInfo.PreviewInventoryItem != null) { GridPosR newGPR = gp_matrix; newGPR.orientation = City.CityInventory.InventoryInfo.PreviewInventoryItem.GridPos_Matrix.orientation; City.CityInventory.InventoryInfo.PreviewInventoryItem?.SetGridPosition(newGPR); City.RefreshBuildingCoverMaskMatrix(true); City.RefreshBuildingRangeGridView(CurrentSelectedBuildingKey); } } // put down building if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { InventoryItem previewItem = City.CityInventory.InventoryInfo.PreviewInventoryItem; if (previewItem != null) { bool sucPutDown = false; if (City.CityInventory.CheckSpaceAvailable(previewItem.OccupiedGridPositions_Matrix)) { bool needAllOccupationValid = BuildingInfoDict[CurrentSelectedBuildingKey].NeedAllOccupationValid; if (needAllOccupationValid) { sucPutDown = true; foreach (GridPos gp in previewItem.OccupiedGridPositions_Matrix) { if (!City.CityInventory.InventoryValidMatrix[gp.x, gp.z]) { sucPutDown = false; } } } else { if (City.CityInventory.InventoryValidMatrix[previewItem.GridPos_Matrix.x, previewItem.GridPos_Matrix.z]) { sucPutDown = true; } } if (sucPutDown) { City.CityInventory.PutDownItem(previewItem); BuildingInfo buildingInfo = BuildingInfoDict[City.GetBuilding(previewItem.GUID).BuildingInfo.buildingKey]; Budget -= buildingInfo.BudgetCost; Oxygen -= buildingInfo.OxygenCost; City.RefreshResourcesInfo(); RecheckResourcesMeetCurrentSelectBuilding(); City.RefreshBuildingCoverMaskMatrix(false); City.RefreshValidGridView(CurrentSelectedBuildingKey); City.RefreshBuildingCoverMaskMatrix(true); City.RefreshBuildingRangeGridView(CurrentSelectedBuildingKey); City.CityInventoryVirtualOccupationQuadRoot.Clear(); } } if (!sucPutDown) { City.CityInventory.RemoveItem(previewItem, true); } } } if (City.CityInventory.RotateItemKeyDownHandler != null && City.CityInventory.RotateItemKeyDownHandler.Invoke()) { InventoryItem previewItem = City.CityInventory.InventoryInfo.PreviewInventoryItem; if (previewItem != null) { Building building = City.GetBuilding(previewItem.GUID); if (building != null) { building.Rotate(); City.RefreshBuildingCoverMaskMatrix(true); City.RefreshBuildingRangeGridView(CurrentSelectedBuildingKey); } } } }
public void Draggable_OnMousePressed(DragAreaIndicator dragAreaIndicator, Vector3 diffFromStart, Vector3 deltaFromLastFrame) { void ResumePausedDrag() { InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix; UIInventory.RemoveItem(InventoryItem, true); Destroy(gameObject); DragManager.Instance.ResumePausedDrag(); } if (dragAreaIndicator == UIInventory.DragAreaIndicator) { if (UIInventory.RotateItemKeyDownHandler != null && UIInventory.RotateItemKeyDownHandler.Invoke()) { Rotate(); } if (diffFromStart.magnitude > Draggable_DragMinDistance) { Vector2 diffLocal = RectTransform.parent.InverseTransformVector(diffFromStart); Vector2 currentLocalPos = dragStartLocalPos + diffLocal; GridPosR diff_world = GridPos.GetGridPosByPointXY(diffLocal, UIInventory.GridSize); diff_world.orientation = InventoryItem.GridPos_Matrix.orientation; GridPosR diff_matrix = UIInventory.CoordinateTransformationHandler_FromPosToMatrixIndex(diff_world); GridPosR gp_matrix = dragStartGridPos_Matrix + diff_matrix; gp_matrix.orientation = InventoryItem.GridPos_Matrix.orientation; InventoryItem.GridPos_Matrix = gp_matrix; SetVirtualGridPos(InventoryItem.GridPos_World); RectTransform.anchoredPosition = currentLocalPos; } } else { Vector2 diffLocal = RectTransform.parent.InverseTransformVector(diffFromStart); Vector2 currentLocalPos = dragStartLocalPos + diffLocal; RectTransform.anchoredPosition = currentLocalPos; UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.Clear(); if (dragAreaIndicator != null) // drag to other DragAreas { if (DragManager.Instance.PausedDrag != null) { ResumePausedDrag(); } else { // only when mouse move to available grid then generate previewItem if (dragAreaIndicator is UIInventoryDragAreaIndicator uiDAI) { uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix); GridPosR gpr = gp_matrix; gpr.orientation = InventoryItem.GridPos_Matrix.orientation; InventoryItem previewItem = new InventoryItem(InventoryItem.Clone().ItemContentInfo, uiDAI.UIInventory, gpr); uiDAI.UIInventory.AddPreviewItem(previewItem); UIInventoryItem uiInventoryItem = uiDAI.UIInventory.UIInventoryPanel.GetUIInventoryItem(previewItem.GUID); DragManager.Instance.PauseDrag(); DragManager.Instance.CurrentDrag = uiInventoryItem.Draggable; uiInventoryItem.Draggable.SetOnDrag(true, uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.BoxCollider, UIInventory.DragProcessor); } } } else // drag to non-DragArea { if (DragManager.Instance.PausedDrag != null) { ResumePausedDrag(); } } } }