public async Task <IActionResult> CreateBlock(BlockType type, string groupId = null) { var block = new ItemBlock { GroupId = groupId ?? Guid.NewGuid().ToString(), DateCreated = DateTime.Now }; switch (type) { case BlockType.Big: block.Type = "big"; break; case BlockType.Medium: block.Type = "medium"; break; case BlockType.Wide: block.Type = "wide"; break; case BlockType.Tall: block.Type = "tall"; break; default: block.Type = "medium"; break; } Context.ItemBlocks.Add(block); await Context.SaveChangesAsync(); return(Json(block.ToResponse())); }
public void Serialize(StringBuilder sb, ItemBlock block, string indent, ItemSerializeOptions options) { sb.Append(indent); sb.Append("BLOCK"); sb.Append(options.ModelSeparator); sb.Append(block.Id); sb.Append(options.ModelSeparator); sb.Append(block.X); sb.Append(options.ModelSeparator); sb.Append(block.Y); sb.Append(options.ModelSeparator); sb.Append(block.Name); sb.Append(options.ModelSeparator); sb.Append(block.Width); sb.Append(options.ModelSeparator); sb.Append(block.Height); sb.Append(options.ModelSeparator); Serialize(sb, block.Backgroud, options); sb.Append(options.ModelSeparator); sb.Append(block.DataId); sb.Append(options.LineSeparator); Serialize(sb, block.Points, indent + options.IndentWhiteSpace, options); Serialize(sb, block.Lines, indent + options.IndentWhiteSpace, options); Serialize(sb, block.Rectangles, indent + options.IndentWhiteSpace, options); Serialize(sb, block.Ellipses, indent + options.IndentWhiteSpace, options); Serialize(sb, block.Texts, indent + options.IndentWhiteSpace, options); Serialize(sb, block.Images, indent + options.IndentWhiteSpace, options); Serialize(sb, block.Blocks, indent + options.IndentWhiteSpace, options); sb.Append(indent); sb.Append("END"); sb.Append(options.LineSeparator); }
public void PickBlock() { MouseOverObject moo = SharpCraft.Instance.MouseOverObject; if (moo.hit == HitType.Block) { var clickedState = World.GetBlockState(moo.blockPos); if (clickedState.Block != BlockRegistry.GetBlock <BlockAir>()) { for (int i = 0; i < Hotbar.Length; i++) { ItemStack stack = Hotbar[i]; if (stack?.Item is ItemBlock ib && ib.Block == clickedState.Block && stack.Meta == clickedState.Block.GetMetaFromState(clickedState)) { SetSelectedSlot(i); return; } if (stack?.IsEmpty == true) { ItemBlock itemBlock = new ItemBlock(clickedState.Block); ItemStack itemStack = new ItemStack(itemBlock, 1, clickedState.Block.GetMetaFromState(clickedState)); SetItemStackInHotbar(i, itemStack); SetSelectedSlot(i); return; } } SetItemStackInSelectedSlot(new ItemStack(new ItemBlock(clickedState.Block), 1, clickedState.Block.GetMetaFromState(clickedState))); } } }
public void SetSelected(ItemBlock block) { if (Blocks != null) { Blocks.SelectedItem = block; } }
static public bool IsInCurrentList(ItemBlock newItem) { if (gameDaddy.currentItems.Contains(newItem)) { return(true); } return(false); }
static public bool IsInCurrentList(ItemBlock newItem) { if (gridDaddy.itemsInGrid.Contains(newItem)) { return(true); } return(false); }
public override bool PlaceBlock(Level world, Player player, BlockCoordinates targetCoordinates, BlockFace face, Vector3 faceCoords) { Direction = ItemBlock.GetDirectionFromEntity(player); UpsideDownBit = faceCoords.Y > 0.5 && face != BlockFace.Up || face == BlockFace.Down; return(false); }
void spawnItem() { int itemIndex = Random.Range(0, spawnableItems.Length - 1); GameObject clone = Object.Instantiate(spawnableItems [itemIndex], spawnPoint.position, Quaternion.identity, null); ItemBlock cloneItem = clone.transform.GetChild(0).GetComponent <ItemBlock> (); cloneItem.initialize(); conveyorItems.Add(cloneItem); }
public void Move(ItemBlock block, double x, double y) { Move(block.Points, x, y); Move(block.Lines, x, y); Move(block.Rectangles, x, y); Move(block.Ellipses, x, y); Move(block.Texts, x, y); Move(block.Images, x, y); Move(block.Blocks, x, y); }
public void MinMax(ItemBlock block, ref double minX, ref double minY, ref double maxX, ref double maxY) { MinMax(block.Points, ref minX, ref minY, ref maxX, ref maxY); MinMax(block.Lines, ref minX, ref minY, ref maxX, ref maxY); MinMax(block.Rectangles, ref minX, ref minY, ref maxX, ref maxY); MinMax(block.Ellipses, ref minX, ref minY, ref maxX, ref maxY); MinMax(block.Texts, ref minX, ref minY, ref maxX, ref maxY); MinMax(block.Images, ref minX, ref minY, ref maxX, ref maxY); MinMax(block.Blocks, ref minX, ref minY, ref maxX, ref maxY); }
public void SnapPosition(Vector2 newPosition, ItemBlock testItem = null) { Vector2 currentPosition = transform.parent.position; transform.parent.position = newPosition; if (!GridManager.isInGrid(points.itemGridPoints) || !GridManager.isSpaceAvailable(points.itemGridPoints, testItem)) { transform.parent.position = currentPosition; } }
/// <summary> /// Enqueue an item /// </summary> public void Enqueue(T item, int priority) { Contract.Requires(priority >= 0); lock (m_lockObject) { ThrowIfInProcessItems(); // A shortcut for an empty queue if (m_itemBlocks.Count == 0) { var newBlock = new ItemBlock { MinPriority = 0, MaxPriority = int.MaxValue }; newBlock.Insert(priority, item); m_itemBlocks.Add(newBlock); return; } // Find the right block using a binary search; then insert the item in the block. // Note that we guaranteed to always find a block. int l = 0, r = m_itemBlocks.Count - 1; while (true) { int blockIdx = (l + r) / 2; ItemBlock itemBlock = m_itemBlocks[blockIdx]; if (priority > itemBlock.MaxPriority) { r = blockIdx - 1; } else if (priority < itemBlock.MinPriority) { l = blockIdx + 1; } else { if (itemBlock.Count == BlockCapacity) { // Split the block in 2. ItemBlock newBlock = itemBlock.Split(); m_itemBlocks.Insert(blockIdx + 1, newBlock); if (priority < itemBlock.MinPriority) { itemBlock = newBlock; } } // Insert the new item itemBlock.Insert(priority, item); break; // Done } } } }
public void EquipItem(Item item) { Debug.Log("[Inventory] EquipItem: " + item); ItemBlock itemBlock = item.prefab.GetComponent <ItemBlock>(); if (itemBlock != null) { GetComponent <EditTerrain>().SetColor(itemBlock.color); } }
public override bool PlaceBlock(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoords) { FacingDirection = ItemBlock.GetFacingDirectionFromEntity(player); var furnaceBlockEntity = new BlastFurnaceBlockEntity { Coordinates = Coordinates }; world.SetBlockEntity(furnaceBlockEntity); return(false); }
void RespawnItem(iVector3 pos) { ItemBlock itemBlock = Instantiate(Resources.Load <GameObject>("Prefabs/ItemBlock")).GetComponent <ItemBlock>(); itemBlock.pos = pos; itemBlock.transform.SetParent(InGameManager.instance.positionList[BlockTools.iVector3ToIndex(pos)].transform); itemBlock.rTr.anchoredPosition3D = Vector3.zero; itemBlock.rTr.localScale = Vector3.one; itemBlock.itemType = (ItemType)UnityEngine.Random.Range(0, 3); itemBlock.Initialize(); }
public void ResetPosition(ItemBlock block, double originX, double originY, double width, double height) { double minX = width; double minY = height; double maxX = originX; double maxY = originY; MinMax(block, ref minX, ref minY, ref maxX, ref maxY); double x = -(maxX - (maxX - minX)); double y = -(maxY - (maxY - minY)); Move(block, x, y); }
public XBlock Deserialize(ISheet sheet, XBlock parent, ItemBlock blockItem, double thickness) { var block = _blockFactory.CreateBlock(blockItem.Id, blockItem.X, blockItem.Y, blockItem.Width, blockItem.Height, blockItem.DataId, blockItem.Name, blockItem.Backgroud); foreach (var textItem in blockItem.Texts) { Deserialize(sheet, block, textItem); } foreach (var imageItem in blockItem.Images) { Deserialize(sheet, block, imageItem); } foreach (var lineItem in blockItem.Lines) { Deserialize(sheet, block, lineItem, thickness); } foreach (var rectangleItem in blockItem.Rectangles) { Deserialize(sheet, block, rectangleItem, thickness); } foreach (var ellipseItem in blockItem.Ellipses) { Deserialize(sheet, block, ellipseItem, thickness); } foreach (var childBlockItem in blockItem.Blocks) { Deserialize(sheet, block, childBlockItem, thickness); } foreach (var pointItem in blockItem.Points) { Deserialize(sheet, block, pointItem, thickness); } parent.Blocks.Add(block); return(block); }
public string SerializeContents(ItemBlock block, ItemSerializeOptions options) { var sb = new StringBuilder(); Serialize(sb, block.Points, "", options); Serialize(sb, block.Lines, "", options); Serialize(sb, block.Rectangles, "", options); Serialize(sb, block.Ellipses, "", options); Serialize(sb, block.Texts, "", options); Serialize(sb, block.Images, "", options); Serialize(sb, block.Blocks, "", options); return(sb.ToString()); }
public void DisPlay() { foreach (Transform child in transform) { Destroy(child.gameObject); } foreach (ItemEntry item in XMLManager.instance.itemDB.list) { ItemBlock newBlock = Instantiate(blockPrefab) as ItemBlock; newBlock.transform.SetParent(transform, false); newBlock.DisPlay(item); } }
public void AddContents(ISheet sheet, ItemBlock blockItem, XBlock content, XBlock selected, bool select, double thickness) { if (blockItem != null) { var texts = Add(sheet, blockItem.Texts, content, selected, select, thickness); var images = Add(sheet, blockItem.Images, content, selected, select, thickness); var lines = Add(sheet, blockItem.Lines, content, selected, select, thickness); var rectangles = Add(sheet, blockItem.Rectangles, content, selected, select, thickness); var ellipses = Add(sheet, blockItem.Ellipses, content, selected, select, thickness); var blocks = Add(sheet, blockItem.Blocks, content, selected, select, thickness); var points = Add(sheet, blockItem.Points, content, selected, select, thickness); _pointController.UpdateDependencies(blocks, points, lines); } }
void checkSnap() { ItemBlock currentItem = GameManager.GetCurrentItem(); if (currentItem != null && currentItem.isDragging()) { currentItem.SnapPosition(transform.position); currentItem.setSnapped(); } if (currentItem != null && currentItem.isSnapped()) { currentItem.SnapPosition(transform.position); } }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container) { ItemBlock foo = (ItemBlock)item; if (foo.ShowViewType == ItemBlockTypeEnum.Label) { return(LabelDataTemplate); } else if (foo.ShowViewType == ItemBlockTypeEnum.BoxView) { return(BoxViewDataTemplate); } else { return(EntryDataTemplate); } }
// Update is called once per frame public void Display() { ItemList = checkListToDisplay(); foreach (Transform child in transform) { Destroy(child.gameObject); Debug.Log("Hello"); } foreach (ItemEntry item in ItemList) { ItemBlock newBlock = Instantiate <ItemBlock>(blockPrefab); newBlock.transform.SetParent(transform, false); newBlock.name = item.itemName; newBlock.Display(item); } StartCoroutine(Reposition()); }
public void Display() { //cleanup UI each times when you load the store foreach (Transform child in transform) { Destroy(child.gameObject); } foreach (ItemEntry item in XMLManager.ins.ItemDB.list) { ItemBlock newBlock = Instantiate(blockprefab) as ItemBlock; newBlock.transform.SetParent(transform, false); newBlock.Display(item); } }
/// <summary> /// 初期化 /// </summary> public void Initialize() { //乱数を取得 rnd = new Random(); //終了フラグをオフ isEndFlag = false; //キャラクターマネージャを生成 charactorManager = new CharactorManager(); //パドルを追加 charactorManager.Add(new RightPaddle()); charactorManager.Add(centerPaddle = new CenterPaddle()); charactorManager.Add(new LeftPaddle()); //ブロックを追加 for (int i = 0; i <= Screen.Height /*横の長さ*/; i += 35) { for (int j = 100; j <= 138 /*縦の長さ*/; j += 19) { block = new Block(new Rectangle(100 + i, j, 32, 16)); charactorManager.Add(block); } } //アイテムブロックを追加 for (int i = 0; i <= 770; i += 70) { itemBlock = new ItemBlock(new Rectangle(100 + i, 210, 32, 16)); charactorManager.Add(itemBlock); } //ボールを追加 charactorManager.Add(new Ball(new Vector2(512, 578))); //サウンド関係 var gameDevice = GameDevice.Instance(); sound = gameDevice.GetSound(); //カウントダウンタイマー1秒に設定 timer = new CountDownTimer(1); //アイテムカウントの初期化 itemCount = 0; //バレットカウントの初期化 bulletCount = 0; //バレットUIの生成、初期化 bulletUI = new BulletUI(bulletCount); }
public void OnNavigatedTo(INavigationParameters parameters) { Random rnd = new Random(); ItemBlock fooItem; for (int i = 0; i < 3; i++) { fooItem = new ItemBlock() { Width = 120, Height = 100, Color = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), rnd.Next(256)), ShowLabel = false, }; myItemList.Add(fooItem); } fooItem = new ItemBlock() { Width = 360, Height = 50, Color = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), rnd.Next(256)), ShowLabel = true, ShowBoxView = false }; myItemList.Add(fooItem); fooItem = new ItemBlock() { Width = 360, Height = 200, Color = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), rnd.Next(256)), ShowLabel = false, }; myItemList.Add(fooItem); for (int i = 0; i < 31; i++) { fooItem = new ItemBlock() { Width = 120, Height = 100, Color = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), rnd.Next(256)), ShowLabel = false, }; myItemList.Add(fooItem); } }
public void OnNavigatedTo(INavigationParameters parameters) { Random rnd = new Random(); ItemBlock fooItem; for (int i = 0; i < 3; i++) { fooItem = new ItemBlock() { Width = ScreenInfo.GetNewDesingSize(100), Height = ScreenInfo.GetNewDesingSize(100), Color = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), rnd.Next(256)), ShowLabel = false, }; myItemList.Add(fooItem); } fooItem = new ItemBlock() { Width = ScreenInfo.GetNewDesingSize(300), Height = ScreenInfo.GetNewDesingSize(50), Color = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), rnd.Next(256)), ShowLabel = true, ShowBoxView = false }; myItemList.Add(fooItem); fooItem = new ItemBlock() { Width = ScreenInfo.GetNewDesingSize(301), Height = ScreenInfo.GetNewDesingSize(200), Color = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), rnd.Next(256)), ShowLabel = false, }; myItemList.Add(fooItem); for (int i = 0; i < 31; i++) { fooItem = new ItemBlock() { Width = ScreenInfo.GetNewDesingSize(100), Height = ScreenInfo.GetNewDesingSize(100), Color = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), rnd.Next(256)), ShowLabel = false, }; myItemList.Add(fooItem); } }
public void Interacted(bool isGrown) { Vector3 startPos = transform.position; Vector3 newPos = new Vector3(transform.position.x, transform.position.y + movement.moveUpDistance, transform.position.z); switch (type) { case BlockType.Brick: if (isGrown) { MusicController.PlayClipAt(destroy, transform.position); killOnInteractedCollider.SetActive(true); Instantiate(destroyBrickParticles, transform.position, Quaternion.identity); Destroy(gameObject); } else { MusicController.PlayClipAt(bump, transform.position); killOnInteractedCollider.SetActive(true); } StartCoroutine(MoveUp(newPos, startPos)); break; case BlockType.Question: ItemBlock block = GetComponent <ItemBlock>(); block.ItemSelection(isGrown); StartCoroutine(MoveUp(newPos, startPos)); killOnInteractedCollider.SetActive(true); break; case BlockType.Emtpy: break; case BlockType.Hidden: ItemBlock hiddenBlock = GetComponent <ItemBlock>(); hiddenBlock.ItemSelection(isGrown); StartCoroutine(MoveUp(newPos, startPos)); break; default: break; } }
private void Blocks_PreviewMouseMove(object sender, MouseEventArgs e) { Point point = e.GetPosition(null); Vector diff = dragStartPoint - point; if (e.LeftButton == MouseButtonState.Pressed && (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)) { var listBox = sender as ListBox; var listBoxItem = WpfVisualHelper.FindVisualParent <ListBoxItem>((DependencyObject)e.OriginalSource); if (listBoxItem != null) { ItemBlock block = (ItemBlock)listBox.ItemContainerGenerator.ItemFromContainer(listBoxItem); DataObject dragData = new DataObject("Block", block); DragDrop.DoDragDrop(listBoxItem, dragData, DragDropEffects.Move); } } }
/// <summary> /// Create a new block and moves half if the items to the new block /// </summary> /// <returns>The newly created block</returns> public ItemBlock Split() { Contract.Assert(Count == BlockCapacity && m_firstItemIndex == 0); Contract.Assert(Count >= 2); // Split the block in 2. int newBlockCount = Count / 2; int splitIndex = m_firstItemIndex + Count - newBlockCount; int splitPriority = m_items[splitIndex].Priority; ItemBlock newBlock = new ItemBlock(newBlockCount, MinPriority, splitPriority); MinPriority = splitPriority; // Add half of the items to the new block. Array.Copy(m_items, splitIndex, newBlock.m_items, newBlock.m_firstItemIndex, newBlockCount); Count -= newBlockCount; return(newBlock); }
internal void RemoveAllInternal(bool saveRecycleQueue) { // Take _itemMap offline, to protect against reentrancy (bug 1285179) ItemBlock itemMap = _itemMap; _itemMap = null; try { // de-initialize the containers that are being removed if (itemMap != null) { for (ItemBlock block = itemMap.Next; block != itemMap; block = block.Next) { RealizedItemBlock rib = block as RealizedItemBlock; if (rib != null) { for (int offset = 0; offset < rib.ContainerCount; ++offset) { UnlinkContainerFromItem(rib.ContainerAt(offset), rib.ItemAt(offset)); } } } } } finally { PrepareGrouping(); // re-initialize the data structure _itemMap = new ItemBlock(); _itemMap.Prev = _itemMap.Next = _itemMap; UnrealizedItemBlock uib = new UnrealizedItemBlock(); uib.InsertAfter(_itemMap); uib.ItemCount = ItemsInternal.Count; if (!saveRecycleQueue) { ResetRecyclableContainers(); } SetAlternationCount(); // tell generators what happened if (MapChanged != null) { MapChanged(null, -1, 0, uib, 0, 0); } } }
public void InsertBefore(ItemBlock next) { InsertAfter(next.Prev); }
public void InsertAfter(ItemBlock prev) { Next = prev.Next; Prev = prev; Prev.Next = this; Next.Prev = this; }
void GetBlockAndPosition(object item, bool deletedFromItems, out GeneratorPosition position, out ItemBlock block, out int offsetFromBlockStart, out int correctIndex) { correctIndex = 0; int containerIndex = 0; offsetFromBlockStart = 0; int deletionOffset = deletedFromItems ? 1 : 0; position = new GeneratorPosition(-1, 0); if (_itemMap == null) { // handle reentrant call block = null; return; } for (block = _itemMap.Next; block != _itemMap; block = block.Next) { UnrealizedItemBlock uib; RealizedItemBlock rib = block as RealizedItemBlock; if (rib != null) { // compare realized items with item for which we are searching offsetFromBlockStart = rib.OffsetOfItem(item); if (offsetFromBlockStart >= 0) { position = new GeneratorPosition(containerIndex + offsetFromBlockStart, 0); correctIndex += offsetFromBlockStart; break; } } else if ((uib = block as UnrealizedItemBlock) != null) { // if the item isn't realized, we can't find it // directly. Instead, look for indirect evidence that it // belongs to this block by checking the indices of // nearby realized items. #if DEBUG // Sanity check - make sure data structure is OK so far. rib = block.Prev as RealizedItemBlock; if (rib != null && rib.ContainerCount > 0) { Debug.Assert(Object.Equals(rib.ItemAt(rib.ContainerCount - 1), ItemsInternal[correctIndex - 1]), "Generator data structure is corrupt"); } #endif bool itemIsInCurrentBlock = false; rib = block.Next as RealizedItemBlock; if (rib != null && rib.ContainerCount > 0) { // if the index of the next realized item is off by one, // the deleted item likely comes from the current // unrealized block. itemIsInCurrentBlock = Object.Equals(rib.ItemAt(0), ItemsInternal[correctIndex + block.ItemCount - deletionOffset]); } else if (block.Next == _itemMap) { // similarly if we're at the end of the list and the // overall count is off by one, or if the current block // is the only block, the deleted item likely // comes from the current (last) unrealized block itemIsInCurrentBlock = block.Prev == _itemMap || (ItemsInternal.Count == correctIndex + block.ItemCount - deletionOffset); } if (itemIsInCurrentBlock) { // we don't know where it is in this block, so assume // it's the very first item. offsetFromBlockStart = 0; position = new GeneratorPosition(containerIndex-1, 1); break; } } correctIndex += block.ItemCount; containerIndex += block.ContainerCount; } if (block == _itemMap) { // There's no way of knowing which unrealized block it belonged to, so // the data structure can't be updated correctly. Sound the alarm. throw new InvalidOperationException(SR.Get(SRID.CannotFindRemovedItem)); } }
void GetBlockAndPosition(int itemIndex, out GeneratorPosition position, out ItemBlock block, out int offsetFromBlockStart) { position = new GeneratorPosition(-1, 0); block = null; offsetFromBlockStart = itemIndex; if (_itemMap == null || itemIndex < 0) return; int containerIndex = 0; for (block = _itemMap.Next; block != _itemMap; block = block.Next) { if (offsetFromBlockStart >= block.ItemCount) { // item belongs to a later block, increment the containerIndex containerIndex += block.ContainerCount; offsetFromBlockStart -= block.ItemCount; } else { // item belongs to this block. Determine the container index and offset if (block.ContainerCount > 0) { // block has realized items position = new GeneratorPosition(containerIndex + offsetFromBlockStart, 0); } else { // block has unrealized items position = new GeneratorPosition(containerIndex-1, offsetFromBlockStart+1); } break; } } }
void GetBlockAndPosition(object item, int itemIndex, bool deletedFromItems, out GeneratorPosition position, out ItemBlock block, out int offsetFromBlockStart, out int correctIndex) { if (itemIndex >= 0) { GetBlockAndPosition(itemIndex, out position, out block, out offsetFromBlockStart); correctIndex = itemIndex; } else { GetBlockAndPosition(item, deletedFromItems, out position, out block, out offsetFromBlockStart, out correctIndex); } }
// Set the AlternationIndex on a newly-realized container. Also, reset // the AlternationIndex on other containers to maintain the adjacency // criterion. void SetAlternationIndex(ItemBlock block, int offset, GeneratorDirection direction) { // If user doesn't request alternation, don't do anything if (_alternationCount <= 0) return; int index; RealizedItemBlock rib; // Proceed in the direction of generation. This tends to reach the // end sooner (often in one step). if (direction != GeneratorDirection.Backward) { // Forward. Back up one container to determine the starting index -- offset; while (offset < 0 || block is UnrealizedItemBlock) { block = block.Prev; offset = block.ContainerCount - 1; } rib = block as RealizedItemBlock; index = (block == _itemMap) ? -1 : ItemsControl.GetAlternationIndex(rib.ContainerAt(offset)); // loop through the remaining containers, resetting each AlternationIndex for (;;) { // advance to next realized container ++offset; while (offset == block.ContainerCount) { block = block.Next; offset = 0; } // exit if we've reached the end if (block == _itemMap) break; // advance the AlternationIndex index = (index + 1) % _alternationCount; // assign it to the container rib = block as RealizedItemBlock; ItemsControl.SetAlternationIndex(rib.ContainerAt(offset), index); } } else { // Backward. Advance one container to determine the starting index ++ offset; while (offset >= block.ContainerCount || block is UnrealizedItemBlock) { block = block.Next; offset = 0; } rib = block as RealizedItemBlock; // Get the alternation index for the advanced container. Use value 1 if no container // is found, so that 0 gets used for actual container in question. index = (block == _itemMap) ? 1 : ItemsControl.GetAlternationIndex(rib.ContainerAt(offset)); // loop through the remaining containers, resetting each AlternationIndex for (;;) { // retreat to next realized container --offset; while (offset < 0) { block = block.Prev; offset = block.ContainerCount - 1; } // exit if we've reached the end if (block == _itemMap) break; // retreat the AlternationIndex index = (_alternationCount + index - 1) % _alternationCount; // assign it to the container rib = block as RealizedItemBlock; ItemsControl.SetAlternationIndex(rib.ContainerAt(offset), index); } } }
// Move 'count' items starting at position 'offset' in block 'block' // to position 'newOffset' in block 'newBlock'. The difference between // the cumulative item counts of newBlock and block is given by 'deltaCount'. void MoveItems(ItemBlock block, int offset, int count, ItemBlock newBlock, int newOffset, int deltaCount) { RealizedItemBlock ribSrc = block as RealizedItemBlock; RealizedItemBlock ribDst = newBlock as RealizedItemBlock; // when both blocks are Realized, entries must be physically copied if (ribSrc != null && ribDst != null) { ribDst.CopyEntries(ribSrc, offset, count, newOffset); } // when the source block is Realized, clear the vacated entries - // to avoid leaks. (No need if it's now empty - the block will get GC'd). else if (ribSrc != null && ribSrc.ItemCount > count) { ribSrc.ClearEntries(offset, count); } // update block information block.ItemCount -= count; newBlock.ItemCount += count; // tell generators what happened if (MapChanged != null) MapChanged(block, offset, count, newBlock, newOffset, deltaCount); }
void RemoveAndCoalesceBlocksIfNeeded(ItemBlock block) { if (block != null && block != _itemMap && block.ItemCount == 0) { block.Remove(); // coalesce adjacent unrealized blocks if (block.Prev is UnrealizedItemBlock && block.Next is UnrealizedItemBlock) { MoveItems(block.Next, 0, block.Next.ItemCount, block.Prev, block.Prev.ItemCount, -block.Prev.ItemCount-1); block.Next.Remove(); } } }
//------------------------------------------------------ // // Private methods // //------------------------------------------------------ // The map data structure has changed, so the state must change accordingly. // This is called in various different ways. // A. Items were moved within the data structure, typically because // items were realized or un-realized. In this case, the args are: // block - the block from where the items were moved // offset - the offset within the block of the first item moved // count - how many items moved // newBlock - the block to which the items were moved // newOffset - the offset within the new block of the first item moved // deltaCount - the difference between the cumululative item counts // of newBlock and block // B. An item was added or removed from the data structure. In this // case the args are: // block - null (to distinguish case B from case A) // offset - the index of the changed item, w.r.t. the entire item list // count - +1 for insertion, -1 for deletion // newBlock - block where item was inserted (null for deletion) // C. Refresh: all items are returned to a single unrealized block. // In this case, the args are: // block - null // offset - -1 (to distinguish case C from case B) // newBlock = the single unrealized block // others - unused void OnMapChanged(ItemBlock block, int offset, int count, ItemBlock newBlock, int newOffset, int deltaCount) { // Case A. Items were moved within the map data structure if (block != null) { // if the move affects this generator, update the cached state if (block == _cachedState.Block && offset <= _cachedState.Offset && _cachedState.Offset < offset + count) { _cachedState.Block = newBlock; _cachedState.Offset += newOffset - offset; _cachedState.Count += deltaCount; } } // Case B. An item was inserted or deleted else if (offset >= 0) { // if the item occurs before my block, update my item count if (offset < _cachedState.Count || (offset == _cachedState.Count && newBlock != null && newBlock != _cachedState.Block)) { _cachedState.Count += count; _cachedState.ItemIndex += count; } // if the item occurs within my block before my item, update my offset else if (offset < _cachedState.Count + _cachedState.Offset) { _cachedState.Offset += count; _cachedState.ItemIndex += count; } // if the item occurs at my position, ... else if (offset == _cachedState.Count + _cachedState.Offset) { if (count > 0) { // for insert, update my offset _cachedState.Offset += count; _cachedState.ItemIndex += count; } else if (_cachedState.Offset == _cachedState.Block.ItemCount) { // if deleting last item in the block, advance to the next block _cachedState.Block = _cachedState.Block.Next; _cachedState.Offset = 0; } } } // Case C. Refresh else { _cachedState.Block = newBlock; _cachedState.Offset += _cachedState.Count; _cachedState.Count = 0; } }
private int GetCount(ItemBlock stop) { int count = 0; ItemBlock start = _itemMap; ItemBlock block = start.Next; while (block != stop) { RealizedItemBlock rib = block as RealizedItemBlock; if (rib != null) { // Search for groups within realized blocks count += GetRealizedItemBlockCount(rib, rib.ItemCount); } else { count += block.ItemCount; } block = block.Next; } return count; }
public override void Update(GameTime gTime) { MouseState ms = Mouse.GetState(); if (ScreenManager.kbState.IsKeyDown(Keys.I)) { buttonPressed = true; } else if (buttonPressed) { buttonPressed = false; toggleDrawing(); // If paused draw this and not game ScreenManager.getScreen(ScreenId.Game).DoUpdate = !DoDraw; ScreenManager.getScreen(ScreenId.Pause).DoUpdate = !DoDraw; } hoverOver = null; foreach (ItemBlock ib in itemBlocks) { if (ib.Item != null && ib.IsOn(ms)) { if (player.Alive) { if (oldMouse.LeftButton == ButtonState.Pressed && ms.LeftButton == ButtonState.Released) { ib.Action(player); } else if (oldMouse.RightButton == ButtonState.Pressed && ms.RightButton == ButtonState.Released) { player.removeItem(ib.Item); player.GScreen.TileMap.dropItem(ib.Item, player); } } hoverOver = ib; break; } } Point p = new Point(ms.X, ms.Y); if (helmRect.Contains(p)) { if (player.Alive && oldMouse.RightButton == ButtonState.Pressed && ms.RightButton == ButtonState.Released) { player.addItem(player.Equipment.Head.Item); player.Equipment.setHead(null); } else if (player.Equipment.Head != null) hoverOver = new ItemBlock(player.Equipment.Head.Item); } else if (bodyRect.Contains(p)) { if (player.Alive && oldMouse.RightButton == ButtonState.Pressed && ms.RightButton == ButtonState.Released) { player.addItem(player.Equipment.Body.Item); player.Equipment.setBody(null); } else if (player.Equipment.Body != null) hoverOver = new ItemBlock(player.Equipment.Body.Item); } else if (legsRect.Contains(p)) { if (player.Alive && oldMouse.RightButton == ButtonState.Pressed && ms.RightButton == ButtonState.Released) { player.addItem(player.Equipment.Legs.Item); player.Equipment.setLegs(null); } else if (player.Equipment.Legs != null) hoverOver = new ItemBlock(player.Equipment.Legs.Item); } oldMouse = ms; base.Update(gTime); }
private int GetCount(ItemBlock stop) { return GetCount(stop, false); }
public static ItemBlock FromInventoryBase(InventoryItem item) { ItemBlock block = new ItemBlock(); block.AssetID = item.AssetUUID; block.CreationDate = item.CreationDate; block.CreatorID = item.CreatorID; block.Description = item.Description; block.Flags = (int)item.Flags; block.GroupID = item.GroupID; block.ID = item.UUID; block.InvType = item.InventoryType == InventoryType.Unknown && item.AssetType == AssetType.LSLText ? InventoryType.LSL : item.InventoryType; ; block.LastOwnerID = item.LastOwnerID; block.Name = item.Name; block.OwnerID = item.OwnerID; block.PermsBase = (uint)item.Permissions.BaseMask; block.PermsEveryone = (uint)item.Permissions.EveryoneMask; block.PermsGroup = (uint)item.Permissions.GroupMask; block.PermsNextOwner = (uint)item.Permissions.NextOwnerMask; block.PermsOwner = (uint)item.Permissions.OwnerMask; block.PermsGranterID = UUID.Zero; block.Type = item.AssetType; return block; }
//----------------------------------------------------- // // Private methods // //------------------------------------------------------ // The map data structure has changed, so the state must change accordingly. // This is called in various different ways. // A. Items were moved within the data structure, typically because // items were realized or un-realized. In this case, the args are: // block - the block from where the items were moved // offset - the offset within the block of the first item moved // count - how many items moved // newBlock - the block to which the items were moved // newOffset - the offset within the new block of the first item moved // deltaCount - the difference between the cumululative item counts // of newBlock and block // B. An item was added or removed from the data structure. In this // case the args are: // block - null (to distinguish case B from case A) // offset - the index of the changed item, w.r.t. the entire item list // count - +1 for insertion, -1 for deletion // others - unused // C. Refresh: all items are returned to a single unrealized block. // In this case, the args are: // block - null // offset - -1 (to distinguish case C from case B) // newBlock = the single unrealized block // others - unused void OnMapChanged(ItemBlock block, int offset, int count, ItemBlock newBlock, int newOffset, int deltaCount) { // Case A. Items were moved within the map data structure if (block != null) { // if the move affects this generator, update the cached state if (block == _cachedState.Block && offset <= _cachedState.Offset && _cachedState.Offset < offset + count) { _cachedState.Block = newBlock; _cachedState.Offset += newOffset - offset; _cachedState.Count += deltaCount; } } // Case B. An item was inserted or deleted else if (offset >= 0) { // if the item occurs before my block, update my item count if (offset < _cachedState.Count) { _cachedState.Count += count; _cachedState.ItemIndex += count; } // if the item occurs within my block before my item, update my offset else if (offset < _cachedState.Count + _cachedState.Offset) { _cachedState.Offset += count; _cachedState.ItemIndex += count; } // if an insert occurs at my position, update my offset else if (offset == _cachedState.Count + _cachedState.Offset && count > 0) { _cachedState.Offset += count; _cachedState.ItemIndex += count; } } // Case C. Refresh else { _cachedState.Block = newBlock; _cachedState.Offset += _cachedState.Count; _cachedState.Count = 0; } }
private int GetCount(ItemBlock stop, bool returnLocalIndex) { if (_itemMap == null) { // handle reentrant call return 0; } int count = 0; ItemBlock start = _itemMap; ItemBlock block = start.Next; while (block != stop) { count += block.ItemCount; block = block.Next; } if (!returnLocalIndex && IsGrouping) { int n = count; count = 0; for (int i=0; i<n; ++i) { CollectionViewGroup group = Items[i] as CollectionViewGroup; count += (group == null) ? 1 : group.ItemCount; } } return count; }
public void Deserialize(OSDMap map) { Serial = map["serial"].AsInteger(); if (map.ContainsKey("items")) { OSDArray array = (OSDArray)map["items"]; Items = new ItemBlock[array.Count]; for (int i = 0; i < array.Count; i++) { ItemBlock item = new ItemBlock(); item.Deserialize((OSDMap)array[i]); Items[i] = item; } } else { Items = new ItemBlock[0]; } }