Skip to content

Commit

Permalink
Ranking: バグ修正&諸修正
Browse files Browse the repository at this point in the history
・範囲外アクセスエラーを修正
・ランキングをスクロールできるよう実装
  • Loading branch information
Bwambocos committed Jun 9, 2018
1 parent b68c7d2 commit a3191c4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions Gear Attack/App/data/Ranking/Stage3/saveData1.txt
@@ -0,0 +1 @@
0,名無し,
1 change: 1 addition & 0 deletions Gear Attack/App/data/Ranking/Stage3/saveData2.txt
@@ -0,0 +1 @@
0,名無し,
1 change: 1 addition & 0 deletions Gear Attack/App/data/Ranking/Stage3/saveData3.txt
@@ -0,0 +1 @@
0,名無し,
37 changes: 30 additions & 7 deletions Gear Attack/Ranking.cpp
Expand Up @@ -6,7 +6,6 @@
// ランキング 初期化
Ranking::Ranking(const InitData& init) :IScene(init)
{
rankingData.clear();
diffNum = getData().selectedDiffNum;
stageNum = getData().selectedStageNum;
rankingBeginNum = 0;
Expand All @@ -18,6 +17,8 @@ Ranking::Ranking(const InitData& init) :IScene(init)
choice2Rect.x = choice1Rect.x + choice1Rect.w + 10; choice2Rect.y = 20 + titleFont.height(); choice2Rect.w = (Window::Width() - 50) / 4; choice2Rect.h = 54;
choice3Rect.x = choice2Rect.x + choice2Rect.w + 10; choice3Rect.y = 20 + titleFont.height(); choice3Rect.w = (Window::Width() - 50) / 4; choice3Rect.h = 54;
choice4Rect.x = choice3Rect.x + choice3Rect.w + 10; choice4Rect.y = 20 + titleFont.height(); choice4Rect.w = (Window::Width() - 50) / 4; choice4Rect.h = 54;
goUpTrig = HighlightingShape<Triangle>(17.5, choice1Rect.y + choice1Rect.h + 10, 25, choice1Rect.y + choice1Rect.h + 25, 10, choice1Rect.y + choice1Rect.h + 25);
goDownTrig = HighlightingShape<Triangle>(17.5, choice1Rect.y + choice1Rect.h + 10 + rankFont.height() * 5, 10, choice1Rect.y + choice1Rect.h - 5 + rankFont.height() * 5, 25, choice1Rect.y + choice1Rect.h - 5 + rankFont.height() * 5);
}

// ランキング 更新
Expand Down Expand Up @@ -47,6 +48,16 @@ void Ranking::update()
diffNum = 3;
Ranking::reload(false);
}
if (rankingBeginNum >= 1)
{
goUpTrig.update();
if (goUpTrig.leftClicked() || Mouse::Wheel() > 0) --rankingBeginNum;
}
if (rankingBeginNum + 5 < rankingData.size())
{
goDownTrig.update();
if (goDownTrig.leftClicked() || Mouse::Wheel() < 0) ++rankingBeginNum;
}
}

// ランキング 描画
Expand All @@ -61,7 +72,14 @@ void Ranking::draw() const
choiceFont(diffStr[1]).drawAt(choice2Rect.center());
choiceFont(diffStr[2]).drawAt(choice3Rect.center());
choiceFont(diffStr[3]).drawAt(choice4Rect.center());
for (auto i : step(rankingData.size())) rankFont(Format(i + 1) + U"" + rankingData[i].second + U" " + Format(rankingData[i].first) + U"").draw(15, choice1Rect.y + choice1Rect.h + 10 + rankFont.height()*i);
if (rankingBeginNum >= 1) goUpTrig.drawHighlight(goUpTrig.mouseOver() ? Color(0, 255, 255) : Color(255, 255, 255));
if (rankingBeginNum + 5 < rankingData.size()) goDownTrig.drawHighlight(goDownTrig.mouseOver() ? Color(0, 255, 255) : Color(255, 255, 255));
for (auto i : step(Min<int>(5, rankingData.size() - rankingBeginNum)))
{
rankFont(Format(i + 1 + rankingBeginNum) + U"" + rankingData[i + rankingBeginNum].second).draw(35, choice1Rect.y + choice1Rect.h + 10 + rankFont.height()*i);
auto scoreWidth = rankFont(Format(rankingData[i + rankingBeginNum].first) + U"").region().w;
rankFont(Format(rankingData[i + rankingBeginNum].first) + U"").draw(Window::Width() - 35 - scoreWidth, choice1Rect.y + choice1Rect.h + 10 + rankFont.height()*i);
}
}

// ランキング リロード
Expand All @@ -70,6 +88,7 @@ void Ranking::reload(bool newWrite)
String fileDir = U"data//Ranking//Stage" + Format(stageNum) + U"//" + U"saveData" + Format(diffNum) + U".txt", fileLine;
TextReader reader(fileDir);
bool reWriteFlag = false;
rankingData.clear();
while (reader.readLine(fileLine))
{
Array<String>arr;
Expand All @@ -88,12 +107,16 @@ void Ranking::reload(bool newWrite)
arr[0] = Format(Max(Parse<uint64>(arr[0]), getData().gameScore));
reWriteFlag = true;
}
else rankingData.push_back(std::make_pair(Parse<uint64>(arr[0]), arr[1]));
rankingData.push_back(std::make_pair(Parse<uint64>(arr[0]), arr[1]));
}
if (newWrite && !reWriteFlag) rankingData.push_back(std::make_pair(getData().gameScore, getData().playerName));
std::sort(rankingData.rbegin(), rankingData.rend());
reader.close();
TextWriter writer(fileDir);
for (auto data : rankingData) writer.writeln(Format(data.first) + U"," + data.second + ',');
writer.close();
}
if (newWrite)
{
TextWriter writer(fileDir);
for (auto data : rankingData) writer.writeln(Format(data.first) + U"," + data.second + ',');
writer.close();
}
rankingBeginNum = 0;
}
1 change: 1 addition & 0 deletions Gear Attack/Ranking.h
Expand Up @@ -13,6 +13,7 @@ class Ranking :public MyApp::Scene
private:
std::vector<rankData>rankingData;
HighlightingShape<Rect>choice1Rect, choice2Rect, choice3Rect, choice4Rect;
HighlightingShape<Triangle>goUpTrig, goDownTrig;
Font titleFont, choiceFont, rankFont;
String diffStr[4] = { U"かんたん",U"ふつう",U"むずかしい",U"いいえ" };
int diffNum, stageNum, rankingBeginNum;
Expand Down

0 comments on commit a3191c4

Please sign in to comment.