Ejemplo n.º 1
0
        //basic scroll right now
        internal void update(double gameTime, SimpleMouseState mouseState)
        {
            if (inventory != null && (invResult = inventory.update(mouseState)) != ItemID.na) {
                //if the inventory returns an item
                inventory = null;
                mBarracks.swapItems(changingChamp, invResult);
                return;
            }
            int mouseY = mouseState.getPos().Y;
            if (GeoLib.isInRect(start,overallRect, new Vector2f(mouseState.getPos().X, mouseState.getPos().Y))){//start.X <= mouseState.getPos().X && mouseState.getPos().X <= start.X + overallRect.Width) {
                if (start.Y <= mouseY && mouseY <= start.Y + scroll) {
                    //clicked in the top box
                    if (mouseState.DoneReleasedIt(mouseButton.LEFT)) {
                        backButton();
                    }
                }else if(start.Y + overallRect.Height - scroll <= mouseY && mouseY <= start.Y + overallRect.Height){
                    //bottom box
                    if (mouseState.DoneReleasedIt(mouseButton.LEFT)){
                        nextButton();
                    }
                } else if (start.Y + scroll <= mouseY && mouseY <= start.Y + overallRect.Height - scroll) {
                    //somewhere in the middle
                    if (draggedChamp != null && mouseState.getPos().X >= start.X + itemIconStart.X) {//if on right side to hover over icons
                        int hoveredOver = -1;//TODO this could be nicer
                        hoveredOver = (int)(topBar + (mouseState.getPos().Y - (int)start.Y - scroll) / (champBarRect.Height));

                        if (mouseState.DoneReleasedIt(mouseButton.LEFT))
                            clickedChampItem(hoveredOver);
                    }
                    //do drag logic
                    if (mouseState.DoneClickedIt(mouseButton.LEFT)) {
                        Vector2f current = new Vector2f(mouseState.getPos().X, mouseState.getPos().Y);
                        draggedChamp = mBarracks.getChamps()[(int)(topBar + (mouseState.getPos().Y - (int)start.Y - scroll) / (champBarRect.Height))];
                        lastClicked = current;
                    } else if (!mouseState.left) {
                        draggedChamp = null;
                    }
                    //do scroll logic
                    if (mouseState.mouseWheelPos - mouseState.prevMouseWheelPos >= 1) {
                        backButton();
                    }
                    if (mouseState.mouseWheelPos - mouseState.prevMouseWheelPos <= -1) {
                        nextButton();
                    }
                }
                for (int i = 0; i < maxShown; i++) {
                    ItemID item = mBarracks.getChamps()[topBar+ i].item;
                    champsItemIcons[topBar+ i].update(mouseState,
                        new Vector2f(start.X + itemIconStart.X, start.Y + itemIconStart.Y + champBarRect.Height * i + scroll),item);
                }
            }
            if (!mouseState.left)//released
                draggedChamp = null;
        }
Ejemplo n.º 2
0
 internal void clickedChampItem(int num)
 {
     if (num == -1) throw new Exception("you clicked on nothing?");
     changingChamp = num;
     if(mBarracks.getTotalSpareItems() > 0)//later we'll display a message TODO
         inventory = new Inventory(mBarracks);
 }