/** Overriding the rendering method to render our own resources */ @Override public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException { /* Get mouse position */ int posX = Mouse.getX(); int posY = stateContainer.Game.MAXIMUMHEIGHT - Mouse.getY(); // Fixing posY to reflect graphics coords /* Draw the background */ menuBackground.draw(0, 0); /* If mouse over the menu button show hover version */ if (posX > 20 && posX < 136 && posY > 20 && posY < 66) menuHover.draw(20, 20); else menuButton.draw(20, 20); // Draw background panel // pale orange, semi-transparent g.setColor(new Color(250, 235, 215, 50)); g.fillRoundRect(50, 230, 1100, 320, 5); { // Draw credits screen g.setColor(Color.white); /* Starting y coordinate */ int y = 240; for (String[] section : credits) { for (String line : section) { g.drawString(line, 60, y); /* * Each new line at 15 px from the previous */ y += 15; } /* Each new paragraph at 30 px from the previous */ y += 30; } } }
@Override public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException { int width = container.getWidth(); int height = container.getHeight(); // draw background Beatmap beatmap = MusicController.getBeatmap(); if (Options.isDynamicBackgroundEnabled() && beatmap != null && beatmap.drawBG(width, height, bgAlpha, true)) ; else { Image bg = GameImage.MENU_BG.getImage(); bg.setAlpha(bgAlpha); bg.draw(); } // top/bottom horizontal bars float oldAlpha = Utils.COLOR_BLACK_ALPHA.a; Utils.COLOR_BLACK_ALPHA.a = 0.2f; g.setColor(Utils.COLOR_BLACK_ALPHA); g.fillRect(0, 0, width, height / 9f); g.fillRect(0, height * 8 / 9f, width, height / 9f); Utils.COLOR_BLACK_ALPHA.a = oldAlpha; // draw downloads button downloadsButton.draw(); // draw buttons if (logoTimer > 0) { playButton.draw(); exitButton.draw(); optionsButton.draw(); } logo.draw(); // draw music buttons if (MusicController.isPlaying()) musicPause.draw(); else musicPlay.draw(); musicNext.draw(); musicPrevious.draw(); // draw music position bar int mouseX = input.getMouseX(), mouseY = input.getMouseY(); g.setColor((musicPositionBarContains(mouseX, mouseY)) ? BG_HOVER : BG_NORMAL); g.fillRoundRect(musicBarX, musicBarY, musicBarWidth, musicBarHeight, 4); g.setColor(Color.white); if (!MusicController.isTrackLoading() && beatmap != null) { float musicBarPosition = Math.min((float) MusicController.getPosition() / MusicController.getDuration(), 1f); g.fillRoundRect(musicBarX, musicBarY, musicBarWidth * musicBarPosition, musicBarHeight, 4); } // draw repository button if (repoButton != null) repoButton.draw(); // draw update button if (Updater.get().showButton()) { Color updateColor = null; switch (Updater.get().getStatus()) { case UPDATE_AVAILABLE: updateColor = Color.red; break; case UPDATE_DOWNLOADED: updateColor = Color.green; break; case UPDATE_DOWNLOADING: updateColor = Color.yellow; break; default: updateColor = Color.white; break; } updateButton.draw(updateColor); } // draw text float marginX = width * 0.015f, topMarginY = height * 0.01f, bottomMarginY = height * 0.015f; g.setFont(Utils.FONT_MEDIUM); float lineHeight = Utils.FONT_MEDIUM.getLineHeight() * 0.925f; g.drawString( String.format( "Loaded %d songs and %d beatmaps.", BeatmapSetList.get().getMapSetCount(), BeatmapSetList.get().getMapCount()), marginX, topMarginY); if (MusicController.isTrackLoading()) g.drawString("Track loading...", marginX, topMarginY + lineHeight); else if (MusicController.trackExists()) { if (Options.useUnicodeMetadata()) // load glyphs Utils.loadGlyphs(Utils.FONT_MEDIUM, beatmap.titleUnicode, beatmap.artistUnicode); g.drawString( (MusicController.isPlaying()) ? "Now Playing:" : "Paused:", marginX, topMarginY + lineHeight); g.drawString( String.format("%s: %s", beatmap.getArtist(), beatmap.getTitle()), marginX + 25, topMarginY + (lineHeight * 2)); } g.drawString( String.format( "opsu! has been running for %s.", Utils.getTimeString((int) (System.currentTimeMillis() - programStartTime) / 1000)), marginX, height - bottomMarginY - (lineHeight * 2)); g.drawString( String.format("It is currently %s.", new SimpleDateFormat("h:mm a").format(new Date())), marginX, height - bottomMarginY - lineHeight); UI.draw(g); }