Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Commit

Permalink
add result ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ouoam committed Nov 27, 2018
1 parent 40e85d3 commit ce8d837
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Oshu/DB/ScoringDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class ScoringDB : public virtual DB {
score->Statistics[Scoring::HitResult::Good] = std::stoi(GetWithDef(*ranking, "StatGood", "0"));
score->Statistics[Scoring::HitResult::Great] = std::stoi(GetWithDef(*ranking, "StatGreat", "0"));

score->time = GetWithDef(*ranking, "Time", "Now");

BeatmapScoreData->push_back(score);
}

Expand Down
2 changes: 2 additions & 0 deletions Oshu/Scoring/Score.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Score {

int BeatmapID;

std::string time;

std::string User = "";
std::map<HitResult::Enum, int> Statistics;
};
Expand Down
16 changes: 16 additions & 0 deletions Oshu/Scoring/enum.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <string>

namespace Scoring {

class HitResult {
Expand Down Expand Up @@ -36,6 +38,20 @@ class ScoreRank {
X,
XH
};

static std::string tostring(Enum e) {
switch (e) {
case F: return "F";
case D: return "D";
case C: return "C";
case B: return "B";
case A: return "A";
case S: return "S";
case SH: return "SH";
case X: return "X";
case XH: return "XH";
}
}
};

class ScoringMode {
Expand Down
1 change: 1 addition & 0 deletions Oshu/Skin/Skin.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace Skin {
textureLoad = loadFile(base_dir + file);
if (!textureLoad)
std::cout << "can not load" << std::endl;

setSmooth(true);
}
};
Expand Down
115 changes: 112 additions & 3 deletions Oshu/UI/Results.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,149 @@
#pragma once

#include <SFML/Graphics.hpp>

#include "UI.h"
#include "../DB/gameDB.h"
#include "../Object/Cursor.h"
#include "../Skin/Skin.h"
#include "../Beatmap/Beatmap.h"

#include "../Scoring/ScoreProcessor.h"
#include "../Utility/stl.h"

class Results : public UI {
DB::gameDB gameDB;
std::unordered_map<std::string, std::string> beatmapData;
Scoring::Score record;

Beatmap::Beatmap bmPlay;

Object::Cursor cur;

Scoring::Score record;
sf::Font font;
sf::Text Line1;
sf::Text Line2;
sf::Text Line3;

sf::Sprite rankingPanel;
sf::Sprite bg;
sf::Sprite rankingTitle;
sf::Sprite ranking;

sf::Texture bgTexture;

sf::RectangleShape topFilter;

void onDraw() {
m_window.draw(bg);
m_window.draw(topFilter);

m_window.draw(rankingPanel);

m_window.draw(Line1);
m_window.draw(Line2);
m_window.draw(Line3);

m_window.draw(ranking);
m_window.draw(rankingTitle);

m_window.draw(cur);
}

void onUpdate() {
cur.update();
}

void onEvent(sf::Event event) {
switch (event.type) {
case sf::Event::Resized:
setScale();
break;
}
}

void setScale() {
sf::Vector2u winSize = m_window.getSize();

sf::Vector2u size = rankingPanel.getTexture()->getSize();

double sx = (double)winSize.x * 0.6 / size.x;
double sy = (double)winSize.y * 0.65 / size.y;

double scale = std::min(sx, sy);

rankingPanel.setScale(scale, scale);
rankingPanel.setPosition(0, winSize.y * 0.125);


sf::Vector2u bgSize = bgTexture.getSize();
sx = (double)winSize.x / (double)bgSize.x;
sy = (double)winSize.y / (double)bgSize.y;
scale = std::max(sx, sy);

bg.setOrigin(bgSize.x / 2.0, bgSize.y / 2.0);
bg.setPosition(winSize.x / 2.0, winSize.y / 2.0);
bg.setScale(scale, scale);

sf::Rect<int> BackgroundRect(0, 0, bgSize.x, bgSize.y);
bg.setTextureRect(BackgroundRect);

topFilter.setSize(sf::Vector2f(winSize.x, winSize.y * 0.125));

Line1.setPosition(5, 5);
Line2.setPosition(5, winSize.y * 0.05);
Line3.setPosition(5, winSize.y * 0.075);

Line1.setCharacterSize(winSize.y * 0.5 * 0.08);
Line2.setCharacterSize(winSize.y * 0.5 * 0.05);
Line3.setCharacterSize(winSize.y * 0.5 * 0.05);

rankingTitle.setPosition(sf::Vector2f(winSize.x - (800 * 0.4 * winSize.y / 600), 0));
size = rankingTitle.getTexture()->getSize();

sy = (winSize.y / 600 * 0.175) / size.y;

rankingTitle.setScale(sy, sy);
}

public:
Results(sf::RenderWindow& window, UI *from, DB::gameDB DB, Scoring::Score rec) :
UI(window, from), cur(window), gameDB(DB), record(rec)
Results(sf::RenderWindow& window, UI *from, DB::gameDB DB, std::unordered_map<std::string, std::string> bmData, Scoring::Score rec) :
UI(window, from), cur(window), gameDB(DB), beatmapData(bmData), record(rec)
{
std::string base_dir = "D:/osu!/Songs/";
base_dir += beatmapData["OsuDir"] + "/";

bmPlay.load(base_dir + beatmapData["OsuFile"]);

font.loadFromFile("resource\\Chakra-Petch-master\\fonts\\ChakraPetch-Medium.ttf");

Line1.setFont(font);
Line2.setFont(font);
Line3.setFont(font);

Line1.setFillColor(sf::Color::White);
Line2.setFillColor(sf::Color::White);
Line3.setFillColor(sf::Color::White);

Line1.setString(bmPlay.Metadata.Artist + " - " + bmPlay.Metadata.Title + " [" + bmPlay.Metadata.Version + "]");
Line2.setString("Beatmap by " + bmPlay.Metadata.Creator);
Line3.setString("Played by " + rec.User + " on " + rec.time + " UTC .");

rankingPanel.setTexture(*Skin::get("ranking-panel"));

if (!bgTexture.loadFromFile(base_dir + bmPlay.Events.Background))
bg.setColor(sf::Color(0, 0, 0, 0));
else
bg.setColor(sf::Color(255,255,255,128));
bgTexture.setSmooth(true);
bg.setTexture(bgTexture);

topFilter.setFillColor(sf::Color(0, 0, 0, 200));

ranking.setTexture(*Skin::get("ranking-" + Scoring::ScoreRank::tostring(rec.Rank)));
rankingTitle.setTexture(*Skin::get("ranking-title"));


setScale();
}
};
35 changes: 33 additions & 2 deletions Oshu/UI/Select.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "UI.h"
#include "Playfield.h"
#include "Results.h"
#include "../DB/gameDB.h"

#include "../Object/Cursor.h"
Expand Down Expand Up @@ -65,6 +66,8 @@ class SelectUI : public UI {

sf::Vector2f globalScale;

sf::Text name;

protected:
void OnPressed(sf::Event event) {
cur.onMouseDown(event.key.code);
Expand Down Expand Up @@ -303,12 +306,28 @@ class SelectUI : public UI {
int to = (*beatmapScore).size() - 1;
for (int i = 0; i <= to; i++) {
sf::Vector2f position;
position.x = 50;
position.x = 10;
position.y = 100 + i * 60;

position.x *= globalScale.x;
position.y *= globalScale.y;

float scale = std::max(globalScale.x, globalScale.y);

sf::Sprite rank;
rank.setTexture(*Skin::get("ranking-" + Scoring::ScoreRank::tostring((*((*beatmapScore)[i])).Rank) + "-small"));
rank.setPosition(sf::Vector2f(10, position.y + 60 * globalScale.y * 0.05));

sf::Vector2u size = rank.getTexture()->getSize();

float sy = (60.0 * globalScale.y * 0.9) / size.y;

rank.setScale(sy, sy);

position.x += (sy * (float)size.x) + 10;



textUser.setString((*((*beatmapScore)[i])).User);
textUser.setPosition(position);

Expand All @@ -325,6 +344,7 @@ class SelectUI : public UI {
textAccuracy.setString(std::string(buff) + " %");
textAccuracy.setPosition(position + sf::Vector2f(150 * globalScale.x, 6 * globalScale.y));

renderScore.draw(rank);
renderScore.draw(textUser);
renderScore.draw(textScore);
renderScore.draw(textAccuracy);
Expand Down Expand Up @@ -515,7 +535,15 @@ class SelectUI : public UI {
randomSongs();
break;
case sf::Keyboard::Enter:
gotoUI(new Playfield(m_window, this, *((*beatmapSetData)[selectBeatmapIndex]), playSong, gameDB));
{
Scoring::Score *score;
if (beatmapScore->size() > 0)
score = (*beatmapScore)[0];
else
score = new Scoring::Score;
gotoUI(new Results(m_window, this, gameDB, *((*beatmapSetData)[selectBeatmapIndex]), *score));
//gotoUI(new Playfield(m_window, this, *((*beatmapSetData)[selectBeatmapIndex]), playSong, gameDB));
}
break;

case sf::Keyboard::F5:
Expand Down Expand Up @@ -649,5 +677,8 @@ class SelectUI : public UI {
generator.seed(seed);

font.loadFromFile("resource\\Chakra-Petch-master\\fonts\\ChakraPetch-SemiBoldItalic.ttf");

name.setFont(font);
name.setString(L"61010827 ÀÙÁÔä¼· ¨Ñ¹·ÃÈÃÕǧÈì");
}
};
6 changes: 0 additions & 6 deletions Oshu/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include "UI/Select.h"
#include "UI/testtest.h"

#include "UI/Results.h"
#include "Scoring/Score.h"

UI *ui;

void renderThread(sf::RenderWindow* window)
Expand Down Expand Up @@ -58,9 +55,6 @@ int main()
ui = new SelectUI(window, nullptr, aa);
//ui = new testtest(window, nullptr);

Scoring::Score score;
//ui = new Results(window, nullptr, aa, score);

window.setActive(false);
sf::Thread thread(&renderThread, &window);
sf::Thread thread2(&updateThread, &window);
Expand Down

0 comments on commit ce8d837

Please sign in to comment.