public final SkillList getSkills() { SkillList skills = new SkillList(); skills.clear(); skills.addAll(defaultSkills); skills.addAll(initSkills()); return skills; }
public SkillViewport(int width, int height, Display display, SkillList skills, Stats stats) { super(width, height, display); this.skills = skills; this.stats = stats; this.skillCount = skills.size(); // this.skillPointsAvailable = 0; this.goldTrim = new Color(223, 196, 99); scaleView(); }
public void handleMouseClick(MouseEvent e) { int mouseX = e.getX(); // For somee reason screen is 25 pixels shorter? int mouseY = e.getY() - 25; int targetSkillNumber; // If within the Y range if (mouseY <= levelUpBoxBottomY && mouseY >= levelUpBoxTopY) { // Check which index of skill they selected if (mouseX >= levelUpBoxLeftX && mouseX <= levelUpBoxRightX) { int distanceFromStart = mouseX - levelUpBoxLeftX; int approximateBoxNumber = (distanceFromStart / skillBoxSize) + 1; System.out.println("Approximately clicked box #: " + approximateBoxNumber); int gapWidth = levelUpBoxLeftX + levelUpBoxLeftXDistanceGap - (levelUpBoxLeftX + levelUpBoxSize); int rightEdgeOfDesiredBox = levelUpBoxLeftX + (approximateBoxNumber * levelUpBoxSize) + ((approximateBoxNumber - 1) * gapWidth); // Means we're in a gap! didnt hit a box. if (levelUpBoxLeftX + distanceFromStart > rightEdgeOfDesiredBox) { System.out.println("hit a gap"); return; } // Get the skill (arrays are indexed by 0 (; ) targetSkillNumber = approximateBoxNumber - 1; Skill desiredSkill = skills.get(targetSkillNumber); // level up levelUpSkill(desiredSkill); } } }
private void drawSkillRectAndBoxes(Graphics g) { // Draw outline g.setColor(goldTrim); // Fill g.drawRect(skillBoxStartX, skillBoxStartY, skillRectWidth, skillRectHeight); g.setColor(Color.darkGray); g.fillRect(skillBoxStartX, skillBoxStartY, skillRectWidth, skillRectHeight); // Values needed to draw int skillBoxX = skillBoxStartX; int skillBoxY = skillBoxStartY; int topAndSideMargin = skillBoxSize / 28; Color coolDownFontColor = Color.RED; Rectangle2D skillRect; Rectangle2D textRect; String skillText; String keyBind; Skill currentSkill; // Draw each box, loop thru each skill for (int i = 0; i < skillCount; i++) { currentSkill = skills.get(i); // Draw skill box g.setColor(goldTrim); g.drawRect(skillBoxX, skillBoxY, skillBoxSize, skillBoxSize); // TODO: Do draw image when have images. Not rly a large priority tbh // Draw item image Image skillImage = currentSkill.getSprite().getImage(); g.drawImage( skillImage, skillBoxX + (skillBoxSize - imgSize) / 2, skillBoxY + (skillBoxSize - imgSize) / 2, imgSize, imgSize, null); // Draw skill image // Draw skill name g.setColor(Color.white); g.setFont(skillLabelFont); skillText = currentSkill.getName(); fm = g.getFontMetrics(skillLabelFont); textRect = fm.getStringBounds(skillText, g); drawSkillName(g, skillText, textRect, skillBoxY, skillBoxX); // Draw Keybind in Upper Left Corner // Only active skils have keybinds if (currentSkill.isActive()) { // Set font g.setFont(keyBindFont); fm = g.getFontMetrics(keyBindFont); g.setColor(goldTrim); // Get keybind ActiveSkill currentActiveSkill = (ActiveSkill) currentSkill; int keyCode = currentActiveSkill.getKeyBind(); keyBind = KeyEvent.getKeyText(keyCode); textRect = fm.getStringBounds(keyBind, g); g.drawString( keyBind, skillBoxX + (int) textRect.getWidth() / 2 + topAndSideMargin, skillBoxY + (int) textRect.getHeight() - 1); } // Set font g.setFont(skillLabelFont); fm = g.getFontMetrics(skillLabelFont); g.setColor(Color.WHITE); // Draw Skill level in Upper Right Corner String skillLvl = "Lvl " + Integer.toString(currentSkill.getLevel()); textRect = fm.getStringBounds(skillLvl, g); g.drawString( skillLvl, skillBoxX + skillBoxSize - (int) textRect.getWidth() - topAndSideMargin, skillBoxY + (int) textRect.getHeight() + topAndSideMargin); // Draw cool down in center, if skill is coolin down if (currentSkill.isCooldown()) { double currentTime = currentSkill.getCooldownTimeRemaining(); drawAndUpdateCoolDown(g, skillBoxX, skillBoxY, currentTime, currentSkill); } // Draw option to level up this skill if have skill points if (stats.getStat(Stats.Type.SKILL_POINTS) > 0) { drawSkillLevelUpBox(g, skillBoxX, skillBoxY); } // Increment x position skillBoxX += skillBoxSize; } }