static void ValueTypeAssignment() { Console.WriteLine("=> Assigning type values\n"); PointRef p1 = new PointRef(10, 10); PointRef p2 = p1; p1.Display(); p2.Display(); p1.X = 100; Console.WriteLine("=> Changed P1.X"); p1.Display(); p2.Display(); }
IntRef SelectedWearPlace(PointRef scaledMouse) { for (int i = 0; i < wearPlaceStartLength; i++) { PointRef p = wearPlaceStart[i]; p.X += InventoryStartX(); p.Y += InventoryStartY(); PointRef cells = wearPlaceCells[i]; if (scaledMouse.X >= p.X && scaledMouse.Y >= p.Y && scaledMouse.X < p.X + cells.X * CellDrawSize && scaledMouse.Y < p.Y + cells.Y * CellDrawSize) { return(IntRef.Create(i)); } } return(null); }
public static void AddUserPoint(string uid, double pointAdded, Action onSuccess) { FirebaseHelper.GetUserPoint(uid, (point) => { double result = point + pointAdded; PointRef .SetValueAsync(result) .ContinueWithOnMainThread(task => { if (task.IsFaulted) { // error handling here } else if (task.IsCompleted) { Debug.Log("point updated to " + result); onSuccess.Invoke(); } }); }); // elapsedTime = 0; // double currentPoint = 0; // // yield return FirebaseHelper.GetUserPoint(FO.userId, (point) => { // // currentPoint = point; // // }); // currentPoint = FO.userPoint; // double pointResult = currentPoint + pointAdded; // var task = PointRef.SetValueAsync(pointResult); // yield return new WaitUntil(() => IsTask(task.IsCompleted)); // if (task.IsFaulted || task.IsCanceled) // { // Debug.Log("Error when updating point." + task.Exception); // yield break; // } // Debug.Log("Point successfully added"); // onSuccess.Invoke(); // yield return null; // } }
internal PointRef ItemAtCell(PointRef p) { for (int i = 0; i < d_Inventory.ItemsCount; i++) { Packet_PositionItem k = d_Inventory.Items[i]; Packet_Item item = k.Value_; for (int x = 0; x < d_Items.ItemSizeX(item); x++) { for (int y = 0; y < d_Items.ItemSizeY(item); y++) { int px = k.X + x; int py = k.Y + y; if (p.X == px && p.Y == py) { return(PointRef.Create(k.X, k.Y)); } } } } return(null); }
static void Do(object obj2) { bool isPointRef = obj2 is PointRef; if (isPointRef) { PointRef pr = (PointRef)obj2; //obj. Console.WriteLine(pr.X); } Console.WriteLine(isPointRef); //OR PointRef pr1 = obj2 as PointRef; if (pr1 != null) { Console.WriteLine(pr1.X); } }
internal PointRef[] ItemsAtArea(int pX, int pY, int sizeX, int sizeY, IntRef retCount) { PointRef[] itemsAtArea = new PointRef[256]; int itemsAtAreaCount = 0; for (int xx = 0; xx < sizeX; xx++) { for (int yy = 0; yy < sizeY; yy++) { PointRef cell = PointRef.Create(pX + xx, pY + yy); if (!IsValidCell(cell)) { return(null); } if (ItemAtCell(cell) != null) { bool contains = false; for (int i = 0; i < itemsAtAreaCount; i++) { if (itemsAtArea[i] == null) { continue; } if (itemsAtArea[i].X == ItemAtCell(cell).X && itemsAtArea[i].Y == ItemAtCell(cell).Y) { contains = true; } } if (!contains) { itemsAtArea[itemsAtAreaCount++] = ItemAtCell(cell); } } } } retCount.value = itemsAtAreaCount; return(itemsAtArea); }
public static void GetUserPoint(string uid, Action <double> point) { PointRef .GetValueAsync() .ContinueWithOnMainThread(task => { if (task.IsFaulted) { // error handling here } else if (task.IsCompleted) { DataSnapshot s = task.Result; if (s.Exists) { double p = Convert.ToDouble(s.Value.ToString()); point.Invoke(p); } else { Debug.Log("point is null"); } } }); // if (task.IsFaulted || task.IsCanceled) // { // Debug.Log("Network error " + task.Exception); // yield break; // } // var result = task.Result; // if (result == null || result.Value == null) // { // Debug.Log("Error : "+task.Exception); // yield break; // } // else // { // Debug.Log("Point gathered"); // double p = Convert.ToDouble(result.Value.ToString()); // FO.userPoint = p; // point.Invoke(p); // yield return null; // } // yield return null; // Debug.Log("Coroutine Get User Point Called."); // elapsedTime = 0; // var task = PointRef.GetValueAsync(); // yield return new WaitUntil(() => IsTask(task.IsCompleted)); // if (task.IsFaulted || task.IsCanceled) // { // Debug.Log("Network error " + task.Exception); // yield break; // } // var result = task.Result; // if (result == null || result.Value == null) // { // Debug.Log("Error : "+task.Exception); // yield break; // } // else // { // Debug.Log("Point gathered"); // double p = Convert.ToDouble(result.Value.ToString()); // FO.userPoint = p; // point.Invoke(p); // yield return null; // } // yield return null; }
public override void OnNewFrameDraw2d(Game game_, float deltaTime) { game = game_; if (dataItems == null) { dataItems = new GameDataItemsClient(); dataItems.game = game_; controller = ClientInventoryController.Create(game_); inventoryUtil = game.d_InventoryUtil; } if (game.guistate == GuiState.MapLoading) { return; } DrawMaterialSelector(); if (game.guistate != GuiState.Inventory) { return; } if (ScrollingUpTimeMilliseconds != 0 && (game.platform.TimeMillisecondsFromStart() - ScrollingUpTimeMilliseconds) > 250) { ScrollingUpTimeMilliseconds = game.platform.TimeMillisecondsFromStart(); ScrollUp(); } if (ScrollingDownTimeMilliseconds != 0 && (game.platform.TimeMillisecondsFromStart() - ScrollingDownTimeMilliseconds) > 250) { ScrollingDownTimeMilliseconds = game.platform.TimeMillisecondsFromStart(); ScrollDown(); } PointRef scaledMouse = PointRef.Create(game.mouseCurrentX, game.mouseCurrentY); game.Draw2dBitmapFile("inventory.png", InventoryStartX(), InventoryStartY(), 1024, 1024); //the3d.Draw2dTexture(terrain, 50, 50, 50, 50, 0); //the3d.Draw2dBitmapFile("inventory_weapon_shovel.png", 100, 100, 60 * 2, 60 * 4); //the3d.Draw2dBitmapFile("inventory_gauntlet_gloves.png", 200, 200, 60 * 2, 60 * 2); //main inventory for (int i = 0; i < game.d_Inventory.ItemsCount; i++) { Packet_PositionItem k = game.d_Inventory.Items[i]; if (k == null) { continue; } int screeny = k.Y - ScrollLine; if (screeny >= 0 && screeny < CellCountInPageY) { DrawItem(CellsStartX() + k.X * CellDrawSize, CellsStartY() + screeny * CellDrawSize, k.Value_, 0, 0); } } //draw area selection if (game.d_Inventory.DragDropItem != null) { PointRef selectedInPage = SelectedCell(scaledMouse); if (selectedInPage != null) { int x = (selectedInPage.X) * CellDrawSize + CellsStartX(); int y = (selectedInPage.Y) * CellDrawSize + CellsStartY(); int sizex = dataItems.ItemSizeX(game.d_Inventory.DragDropItem); int sizey = dataItems.ItemSizeY(game.d_Inventory.DragDropItem); if (selectedInPage.X + sizex <= CellCountInPageX && selectedInPage.Y + sizey <= CellCountInPageY) { int c; IntRef itemsAtAreaCount = new IntRef(); PointRef[] itemsAtArea = inventoryUtil.ItemsAtArea(selectedInPage.X, selectedInPage.Y + ScrollLine, sizex, sizey, itemsAtAreaCount); if (itemsAtArea == null || itemsAtAreaCount.value > 1) { c = Game.ColorFromArgb(100, 255, 0, 0); // red } else //0 or 1 { c = Game.ColorFromArgb(100, 0, 255, 0); // green } game.Draw2dTexture(game.WhiteTexture(), x, y, CellDrawSize * sizex, CellDrawSize * sizey, null, 0, c, false); } } IntRef selectedWear = SelectedWearPlace(scaledMouse); if (selectedWear != null) { PointRef p = PointRef.Create(wearPlaceStart[selectedWear.value].X + InventoryStartX(), wearPlaceStart[selectedWear.value].Y + InventoryStartY()); PointRef size = wearPlaceCells[selectedWear.value]; int c; Packet_Item itemsAtArea = inventoryUtil.ItemAtWearPlace(selectedWear.value, game.ActiveMaterial); if (!dataItems.CanWear(selectedWear.value, game.d_Inventory.DragDropItem)) { c = Game.ColorFromArgb(100, 255, 0, 0); // red } else //0 or 1 { c = Game.ColorFromArgb(100, 0, 255, 0); // green } game.Draw2dTexture(game.WhiteTexture(), p.X, p.Y, CellDrawSize * size.X, CellDrawSize * size.Y, null, 0, c, false); } } //material selector DrawMaterialSelector(); //wear //DrawItem(Offset(wearPlaceStart[(int)WearPlace.LeftHand], InventoryStart), inventory.LeftHand[ActiveMaterial.ActiveMaterial], null); DrawItem(wearPlaceStart[WearPlace_.RightHand].X + InventoryStartX(), wearPlaceStart[WearPlace_.RightHand].Y + InventoryStartY(), game.d_Inventory.RightHand[game.ActiveMaterial], 0, 0); DrawItem(wearPlaceStart[WearPlace_.MainArmor].X + InventoryStartX(), wearPlaceStart[WearPlace_.MainArmor].Y + InventoryStartY(), game.d_Inventory.MainArmor, 0, 0); DrawItem(wearPlaceStart[WearPlace_.Boots].X + InventoryStartX(), wearPlaceStart[WearPlace_.Boots].Y + InventoryStartY(), game.d_Inventory.Boots, 0, 0); DrawItem(wearPlaceStart[WearPlace_.Helmet].X + InventoryStartX(), wearPlaceStart[WearPlace_.Helmet].Y + InventoryStartY(), game.d_Inventory.Helmet, 0, 0); DrawItem(wearPlaceStart[WearPlace_.Gauntlet].X + InventoryStartX(), wearPlaceStart[WearPlace_.Gauntlet].Y + InventoryStartY(), game.d_Inventory.Gauntlet, 0, 0); //info if (SelectedCell(scaledMouse) != null) { PointRef selected = SelectedCell(scaledMouse); selected.Y += ScrollLine; PointRef itemAtCell = inventoryUtil.ItemAtCell(selected); if (itemAtCell != null) { Packet_Item item = GetItem(game.d_Inventory, itemAtCell.X, itemAtCell.Y); if (item != null) { int x = (selected.X) * CellDrawSize + CellsStartX(); int y = (selected.Y) * CellDrawSize + CellsStartY(); DrawItemInfo(scaledMouse.X, scaledMouse.Y, item); } } } if (SelectedWearPlace(scaledMouse) != null) { int selected = SelectedWearPlace(scaledMouse).value; Packet_Item itemAtWearPlace = inventoryUtil.ItemAtWearPlace(selected, game.ActiveMaterial); if (itemAtWearPlace != null) { DrawItemInfo(scaledMouse.X, scaledMouse.Y, itemAtWearPlace); } } if (SelectedMaterialSelectorSlot(scaledMouse) != null) { int selected = SelectedMaterialSelectorSlot(scaledMouse).value; Packet_Item item = game.d_Inventory.RightHand[selected]; if (item != null) { DrawItemInfo(scaledMouse.X, scaledMouse.Y, item); } } if (game.d_Inventory.DragDropItem != null) { DrawItem(scaledMouse.X, scaledMouse.Y, game.d_Inventory.DragDropItem, 0, 0); } }
public override void OnMouseDown(Game game_, MouseEventArgs args) { if (game.guistate != GuiState.Inventory) { return; } PointRef scaledMouse = PointRef.Create(args.GetX(), args.GetY()); //material selector if (SelectedMaterialSelectorSlot(scaledMouse) != null) { //int oldActiveMaterial = ActiveMaterial.ActiveMaterial; game.ActiveMaterial = SelectedMaterialSelectorSlot(scaledMouse).value; //if (oldActiveMaterial == ActiveMaterial.ActiveMaterial) { Packet_InventoryPosition p = new Packet_InventoryPosition(); p.Type = Packet_InventoryPositionTypeEnum.MaterialSelector; p.MaterialId = game.ActiveMaterial; controller.InventoryClick(p); } args.SetHandled(true); return; } if (game.guistate != GuiState.Inventory) { return; } //main inventory PointRef cellInPage = SelectedCell(scaledMouse); //grab from inventory if (cellInPage != null) { if (args.GetButton() == MouseButtonEnum.Left) { Packet_InventoryPosition p = new Packet_InventoryPosition(); p.Type = Packet_InventoryPositionTypeEnum.MainArea; p.AreaX = cellInPage.X; p.AreaY = cellInPage.Y + ScrollLine; controller.InventoryClick(p); args.SetHandled(true); return; } else { { Packet_InventoryPosition p = new Packet_InventoryPosition(); p.Type = Packet_InventoryPositionTypeEnum.MainArea; p.AreaX = cellInPage.X; p.AreaY = cellInPage.Y + ScrollLine; controller.InventoryClick(p); } { Packet_InventoryPosition p = new Packet_InventoryPosition(); p.Type = Packet_InventoryPositionTypeEnum.WearPlace; p.WearPlace = WearPlace_.RightHand; p.ActiveMaterial = game.ActiveMaterial; controller.InventoryClick(p); } { Packet_InventoryPosition p = new Packet_InventoryPosition(); p.Type = Packet_InventoryPositionTypeEnum.MainArea; p.AreaX = cellInPage.X; p.AreaY = cellInPage.Y + ScrollLine; controller.InventoryClick(p); } } if (game.guistate == GuiState.Inventory) { args.SetHandled(true); return; } } // //drop items on ground //if (scaledMouse.X < CellsStartX() && scaledMouse.Y < MaterialSelectorStartY()) //{ // int posx = game.SelectedBlockPositionX; // int posy = game.SelectedBlockPositionY; // int posz = game.SelectedBlockPositionZ; // Packet_InventoryPosition p = new Packet_InventoryPosition(); // { // p.Type = Packet_InventoryPositionTypeEnum.Ground; // p.GroundPositionX = posx; // p.GroundPositionY = posy; // p.GroundPositionZ = posz; // } // controller.InventoryClick(p); //} if (SelectedWearPlace(scaledMouse) != null) { Packet_InventoryPosition p = new Packet_InventoryPosition(); p.Type = Packet_InventoryPositionTypeEnum.WearPlace; p.WearPlace = (SelectedWearPlace(scaledMouse).value); p.ActiveMaterial = game.ActiveMaterial; controller.InventoryClick(p); args.SetHandled(true); return; } if (scaledMouse.X >= ScrollUpButtonX() && scaledMouse.X < ScrollUpButtonX() + ScrollButtonSize() && scaledMouse.Y >= ScrollUpButtonY() && scaledMouse.Y < ScrollUpButtonY() + ScrollButtonSize()) { ScrollUp(); ScrollingUpTimeMilliseconds = game.platform.TimeMillisecondsFromStart(); args.SetHandled(true); return; } if (scaledMouse.X >= ScrollDownButtonX() && scaledMouse.X < ScrollDownButtonX() + ScrollButtonSize() && scaledMouse.Y >= ScrollDownButtonY() && scaledMouse.Y < ScrollDownButtonY() + ScrollButtonSize()) { ScrollDown(); ScrollingDownTimeMilliseconds = game.platform.TimeMillisecondsFromStart(); args.SetHandled(true); return; } game.GuiStateBackToGame(); return; }
IntRef SelectedWearPlace(PointRef scaledMouse) { for (int i = 0; i < wearPlaceStartLength; i++) { PointRef p = wearPlaceStart[i]; p.X += InventoryStartX(); p.Y += InventoryStartY(); PointRef cells = wearPlaceCells[i]; if (scaledMouse.X >= p.X && scaledMouse.Y >= p.Y && scaledMouse.X < p.X + cells.X * CellDrawSize && scaledMouse.Y < p.Y + cells.Y * CellDrawSize) { return IntRef.Create(i); } } return null; }
IntRef SelectedMaterialSelectorSlot(PointRef scaledMouse) { if (scaledMouse.X >= MaterialSelectorStartX() && scaledMouse.Y >= MaterialSelectorStartY() && scaledMouse.X < MaterialSelectorStartX() + 10 * ActiveMaterialCellSize() && scaledMouse.Y < MaterialSelectorStartY() + 10 * ActiveMaterialCellSize()) { return IntRef.Create((scaledMouse.X - MaterialSelectorStartX()) / ActiveMaterialCellSize()); } return null; }
PointRef SelectedCell(PointRef scaledMouse) { if (scaledMouse.X < CellsStartX() || scaledMouse.Y < CellsStartY() || scaledMouse.X > CellsStartX() + CellCountInPageX * CellDrawSize || scaledMouse.Y > CellsStartY() + CellCountInPageY * CellDrawSize) { return null; } PointRef cell = PointRef.Create((scaledMouse.X - CellsStartX()) / CellDrawSize, (scaledMouse.Y - CellsStartY()) / CellDrawSize); return cell; }
internal PointRef ItemAtCell(PointRef p) { for (int i = 0; i < d_Inventory.ItemsCount; i++) { Packet_PositionItem k = d_Inventory.Items[i]; Packet_Item item = k.Value_; for (int x = 0; x < d_Items.ItemSizeX(item); x++) { for (int y = 0; y < d_Items.ItemSizeY(item); y++) { int px = k.X + x; int py = k.Y + y; if (p.X == px && p.Y == py) { return PointRef.Create(k.X, k.Y); } } } } return null; }
public bool IsValidCell(PointRef p) { return(!(p.X < 0 || p.Y < 0 || p.X >= CellCountX || p.Y >= CellCountY)); }
public static PointRef Create(int x_, int y_) { PointRef p = new PointRef(); p.X = x_; p.Y = y_; return p; }
static void Main() { Point p1 = new Point(5, 7); PointRef p2 = new PointRef(6, 8); conv6(); }
//returns null if area is invalid. public PointRef[] ItemsAtArea(int pX, int pY, int sizeX, int sizeY, IntRef retCount) { PointRef[] itemsAtArea = new PointRef[256]; int itemsAtAreaCount = 0; for (int xx = 0; xx < sizeX; xx++) { for (int yy = 0; yy < sizeY; yy++) { PointRef cell = PointRef.Create(pX + xx, pY + yy); if (!IsValidCell(cell)) { return null; } if (ItemAtCell(cell) != null) { bool contains = false; for (int i = 0; i < itemsAtAreaCount; i++) { if (itemsAtArea[i] == null) { continue; } if (itemsAtArea[i].X == ItemAtCell(cell).X && itemsAtArea[i].Y == ItemAtCell(cell).Y) { contains = true; } } if (!contains) { itemsAtArea[itemsAtAreaCount++] = ItemAtCell(cell); } } } } retCount.value = itemsAtAreaCount; return itemsAtArea; }
public IEnumerable<PointRef> ItemCells(PointRef p) { Item item = d_Inventory.Items[new ProtoPoint(p.X, p.Y)]; for (int x = 0; x < d_Items.ItemSizeX(item); x++) { for (int y = 0; y < d_Items.ItemSizeY(item); y++) { yield return PointRef.Create(p.X + x, p.Y + y); } } }
public PointRef ItemAtCell(PointRef p) { foreach (var k in d_Inventory.Items) { foreach (var pp in ItemCells(PointRef.Create(k.Key.X, k.Key.Y))) { if (p.X == pp.X && p.Y == pp.Y) { return PointRef.Create(k.Key.X, k.Key.Y); } } } return null; }
public bool IsValidCell(PointRef p) { return !(p.X < 0 || p.Y < 0 || p.X >= CellCountX || p.Y >= CellCountY); }
static void exemplo1() { Point p1 = new Point(5, 7); Point p2 = new Point(5, 7); Point p3 = new Point(9, 11); /* * Estamos a testar o Equals herdado de ValueType (cmp Igualdade entre campos). * !!!!!! Esta implementação de Euals recorre a Reflexão !!!! * Porque o Point não tem uma implementação de Equals. */ Console.WriteLine("{0}.Equals({1}) = {2}", p1, p2, p1.Equals(p2)); Console.WriteLine("{0}.Equals({1}) = {2}", p1, p3, p1.Equals(p3)); PointRef r1 = new PointRef(5, 7); PointRef r2 = new PointRef(5, 7); PointRef r3 = new PointRef(9, 11); /* * Estamos a testar o Equals redefinido em PointRef. */ Console.WriteLine("{0}.Equals({1}) = {2}", r1, r2, r1.Equals(r2)); Console.WriteLine("{0}.Equals({1}) = {2}", r1, r3, r1.Equals(r3)); Console.WriteLine("{0} == {1} = {2}", r1, r2, r1 == r2); Console.WriteLine("{0} == {1} = {2}", r1, r3, r1 == r3); Console.WriteLine("{0} == {1} = {2}", r1, r2, Object.ReferenceEquals(r1, r2)); Console.WriteLine("{0} == {1} = {2}", r1, r3, Object.ReferenceEquals(r1, r3)); }