public void Resize() { if (Input.IsActionJustReleased("ui_scroll_up") && Input.IsActionPressed("ui_control")) { Vector2 currentSize = TokenSprite.GetRect().Size *TargetScale; Vector2 sizeTo = new Vector2(currentSize.x + tileSize, currentSize.y + tileSize); Vector2 scale = sizeTo / TokenSprite.GetRect().Size; RpcId(1, nameof(RequestScale), scale); //Update collisionBox float scaleTo = sizeTo.x / tileSize; RpcId(1, nameof(RequestCollisionScale), new Vector2(scaleTo, scaleTo)); } if (Input.IsActionJustReleased("ui_scroll_down") && Input.IsActionPressed("ui_control")) { Vector2 currentSize = TokenSprite.GetRect().Size *TargetScale; Vector2 sizeTo = new Vector2(currentSize.x - tileSize, currentSize.y - tileSize); if (sizeTo.x > tileSize / 2) { Vector2 scale = sizeTo / TokenSprite.GetRect().Size; RpcId(1, nameof(RequestScale), scale); //Update collisionBox float scaleTo = sizeTo.x / tileSize; RpcId(1, nameof(RequestCollisionScale), new Vector2(scaleTo, scaleTo)); } } }
public void InitializeToken(String tokenName, String imagePath, Vector2 position, Vector2 scale) { this.Name = tokenName; TokenName.Text = this.Name; ImagePath = imagePath; Image image = new Image(); Error result = image.Load(ClientVariables.TokenFolder + imagePath); if (result == Error.Ok) { SetImageOnSprite(image); } else { TokenSprite.Texture = (Godot.Texture)ResourceLoader.Load("res://icon.png"); int id = GetTree().NetworkPeer.GetUniqueId(); Rpc(nameof(RequestImageData), id, this.Name, imagePath); } if (!scale.Equals(Vector2.Zero)) { TargetScale = scale; //Update collisionBox float sizeTo = scale.x * TokenSprite.GetRect().Size.x; float scaleTo = sizeTo / tileSize; TargetCollisionScale = new Vector2(scaleTo, scaleTo); } else { Vector2 sizeTo = new Vector2(tileSize, tileSize); TargetScale = sizeTo / TokenSprite.GetRect().Size; float scaleTo = sizeTo.x / tileSize; TargetCollisionScale = new Vector2(scaleTo, scaleTo); } TargetPosition = position.Snapped(new Vector2(tileSize, tileSize)); GlobalPosition = TargetPosition; Scale = TargetScale; CollisionBox.Scale = TargetCollisionScale; /* * if (!GetTree().IsNetworkServer()) * { * RpcId(1, nameof(RequestPostionAndScale)); * } */ }
public void CheckSelection() { if (!TokenSprite.GetRect().HasPoint(ToLocal(GetGlobalMousePosition()))) { if (Input.IsActionJustReleased("ui_mouse_click") || Input.IsActionJustReleased("ui_right_click")) { PopupMenu.Visible = false; } } if (Input.IsActionJustReleased("ui_mouse_click") && Input.IsActionPressed("ui_shift")) { if (ClientVariables.SelectionBox.Intersects(new Rect2(GlobalPosition, TokenSprite.GetRect().Size *Scale))) { ClientVariables.SelectedTokens.Add(this); } } }