Skip to content

Commit

Permalink
Newgoaldisplay (#200)
Browse files Browse the repository at this point in the history
* draft goaldisplay

* almost ready to port

* make goal management 1000% less buggy and more sane

still need to implement sorts and i guess some way to scroll the list

* i cant believe its not dunner
  • Loading branch information
MinaciousGrace authored Jul 25, 2018
1 parent ca6ee26 commit 108a036
Show file tree
Hide file tree
Showing 9 changed files with 628 additions and 522 deletions.

Large diffs are not rendered by default.

460 changes: 460 additions & 0 deletions Themes/Til Death/BGAnimations/goaldisplay.lua

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Themes/Til Death/BGAnimations/packlistDisplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ local o = Def.ActorFrame{
UpdateCommand=function(self)
if ind < 0 then
ind = 0
elseif ind == #packtable then
ind = ind - numpacks
elseif ind > #packtable - (#packtable % numpacks) then
ind = #packtable - (#packtable % numpacks)
end
Expand Down
8 changes: 6 additions & 2 deletions src/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,11 @@ void DownloadManager::AddGoal(string chartkey, float wife, float rate, DateTime

void DownloadManager::UpdateGoal(string chartkey, float wife, float rate, bool achieved, DateTime timeAssigned, DateTime timeAchieved)
{
string req = "user/" + DLMAN->sessionUser + "/goals";
string doot = "0000:00:00 00:00:00";
if (achieved)
doot = timeAchieved.GetString();

string req = "user/" + DLMAN->sessionUser + "/goals/update";
auto done = [](HTTPRequest& req, CURLMsg *) {

};
Expand All @@ -643,7 +647,7 @@ void DownloadManager::UpdateGoal(string chartkey, float wife, float rate, bool a
make_pair("wife", to_string(wife)),
make_pair("achieved", to_string(achieved)),
make_pair("timeAssigned", timeAssigned.GetString()),
make_pair("timeAchieved", timeAchieved.GetString()) };
make_pair("timeAchieved", doot) };
SendRequest(req, postParams, done, true, true);
}

Expand Down
165 changes: 148 additions & 17 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "ScreenManager.h"
#include "XMLProfile.h"
#include "DownloadManager.h"
#include "RageString.h"

/** @brief The filename for where one can edit their personal profile information. */
const RString EDITABLE_INI = "Editable.ini";
Expand Down Expand Up @@ -1230,7 +1231,7 @@ void Profile::AddGoal(const string& ck) {
ScoreGoal goal;
goal.timeassigned = DateTime::GetNowDateTime();
goal.rate = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate;

goal.chartkey = ck;
// duplication avoidance should be simpler than this? -mina
if (goalmap.count(ck))
for (auto& n : goalmap[ck].goals)
Expand All @@ -1240,6 +1241,19 @@ void Profile::AddGoal(const string& ck) {

goal.CheckVacuity();
goalmap[ck].Add(goal);
DLMAN->AddGoal(ck, goal.percent, goal.rate, goal.timeassigned);
FillGoalTable();
MESSAGEMAN->Broadcast("GoalTableRefresh");
}

void Profile::FillGoalTable() {
goaltable.clear();
for (auto& sgv : goalmap)
for (auto& sg : sgv.second.goals)
goaltable.emplace_back(&sg);

auto comp = [](ScoreGoal* a, ScoreGoal* b) { return a->timeassigned > b->timeassigned; };
sort(goaltable.begin(), goaltable.end(), comp);
}

XNode* ScoreGoal::CreateNode() const {
Expand Down Expand Up @@ -1328,6 +1342,7 @@ void Profile::SetAnyAchievedGoals(const string& ck, float& rate, const HighScore
tmp.achieved = true;
tmp.timeachieved = pscore.GetDateTime();
tmp.scorekey = pscore.GetScoreKey();
DLMAN->UpdateGoal(tmp.chartkey, tmp.percent, tmp.rate, tmp.achieved, tmp.timeassigned, tmp.timeachieved);
}
}
}
Expand Down Expand Up @@ -1577,24 +1592,127 @@ class LunaProfile : public Luna<Profile>
}

DEFINE_METHOD(GetGUID, m_sGuid);
static int GetAllGoals(T* p, lua_State *L) {
lua_newtable(L);
int idx = 0;
FOREACHUM(string, GoalsForChart, p->goalmap, i) {
const string &ck = i->first;
auto &sgv = i->second.Get();
FOREACH(ScoreGoal, sgv, sg) {
ScoreGoal &tsg = *sg;
if(ck != "") // not sure how this can happen or if it is happening here... but it shouldn't be able to -mina
tsg.chartkey = ck;
tsg.PushSelf(L);
lua_rawseti(L, -2, idx + 1);
idx++;

static int GetGoalTable(T* p, lua_State *L) {
LuaHelpers::CreateTableFromArray(p->goaltable, L);
return 1;
}
static int SetFromAll(T* p, lua_State *L) {
p->FillGoalTable();
p->filtermode = 1;
return 1;
}

static int SortByDate(T* p, lua_State* L) {
if (p->sortmode == 1)
if (p->asc) {
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return a->timeassigned > b->timeassigned; }; // custom operators?
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->asc = false;
return 1;
}
}
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return a->timeassigned < b->timeassigned; };
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->sortmode = 1;
p->asc = true;
return 1;
}

static int SortByRate(T* p, lua_State* L) {
if (p->sortmode == 2)
if (p->asc) {
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return a->rate > b->rate; }; // custom operators?
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->asc = false;
return 1;
}
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return a->rate < b->rate; };
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->sortmode = 2;
p->asc = true;
return 1;
}

static int SortByName(T* p, lua_State* L) {
if (p->sortmode == 3)
if (p->asc) {
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return Rage::make_lower(SONGMAN->GetSongByChartkey(a->chartkey)->GetDisplayMainTitle()) >
Rage::make_lower(SONGMAN->GetSongByChartkey(b->chartkey)->GetDisplayMainTitle()); }; // custom operators?
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->asc = false;
return 3;
}
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return Rage::make_lower(SONGMAN->GetSongByChartkey(a->chartkey)->GetDisplayMainTitle()) <
Rage::make_lower(SONGMAN->GetSongByChartkey(b->chartkey)->GetDisplayMainTitle()); };
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->sortmode = 3;
p->asc = true;
return 1;
}

static int SortByPriority(T* p, lua_State* L) {
if (p->sortmode == 4)
if (p->asc) {
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return a->priority > b->priority; }; // custom operators?
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->asc = false;
return 3;
}
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return a->priority < b->priority; };
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->sortmode = 4;
p->asc = true;
return 1;
}

static int SortByDiff(T* p, lua_State* L) {
if (p->sortmode == 5)
if (p->asc) {
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return SONGMAN->GetStepsByChartkey(a->chartkey)->GetMSD(a->rate, 0) >
SONGMAN->GetStepsByChartkey(b->chartkey)->GetMSD(b->rate, 0); };
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->asc = false;
return 3;
}
auto comp = [](ScoreGoal* a, ScoreGoal* b) { return SONGMAN->GetStepsByChartkey(a->chartkey)->GetMSD(a->rate, 0) <
SONGMAN->GetStepsByChartkey(b->chartkey)->GetMSD(b->rate, 0); };
sort(p->goaltable.begin(), p->goaltable.end(), comp);
p->sortmode = 5;
p->asc = true;
return 1;
}

static int ToggleFilter(T* p, lua_State* L) {
p->FillGoalTable();

if (p->filtermode == 3) {
p->filtermode = 1;
return 1;
}

vector<ScoreGoal*> doot;
if (p->filtermode == 1) {
for (auto& sg : p->goaltable)
if(sg->achieved)
doot.emplace_back(sg);
p->goaltable = doot;
p->filtermode = 2;
return 1;
}
if (p->filtermode == 2) {
for (auto& sg : p->goaltable)
if (!sg->achieved)
doot.emplace_back(sg);
p->goaltable = doot;
p->filtermode = 3;
return 1;
}
return 1;
}
static int GetFilterMode(T* p, lua_State *L) {
lua_pushnumber(L, p->filtermode);
return 1;
}
static int GetIgnoreStepCountCalories(T* p, lua_State *L) {
lua_pushboolean(L, 0);
return 1;
Expand Down Expand Up @@ -1689,12 +1807,20 @@ class LunaProfile : public Luna<Profile>
ADD_METHOD( GetPlayerRating );
ADD_METHOD( GetPlayerSkillsetRating );
ADD_METHOD( GetNumFaves );
ADD_METHOD( GetAllGoals );
ADD_METHOD(GetGoalTable);
ADD_METHOD(GetIgnoreStepCountCalories);
ADD_METHOD(CalculateCaloriesFromHeartRate);
ADD_METHOD(IsCurrentChartPermamirror);
ADD_METHOD(GetEasiestGoalForChartAndRate);
ADD_METHOD(RenameProfile);
ADD_METHOD(SetFromAll);
ADD_METHOD(SortByDate);
ADD_METHOD(SortByRate);
ADD_METHOD(SortByPriority);
ADD_METHOD(SortByName);
ADD_METHOD(SortByDiff);
ADD_METHOD(ToggleFilter);
ADD_METHOD(GetFilterMode);
}
};

Expand Down Expand Up @@ -1727,14 +1853,19 @@ class LunaScoreGoal : public Luna<ScoreGoal>
p->CheckVacuity();
p->UploadIfNotVacuous();
}

return 1;
}

static int SetPercent(T* p, lua_State *L) {
if (!p->achieved) {
float newpercent = FArg(1);
CLAMP(newpercent, .8f, 1.f);

if (p->percent < 0.995f && newpercent > 0.995f)
newpercent = 0.9975f;
if (p->percent < 0.9990f && newpercent > 0.9997f)
newpercent = 0.9997f;

p->percent = newpercent;
p->CheckVacuity();
p->UploadIfNotVacuous();
Expand Down
5 changes: 5 additions & 0 deletions src/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ class Profile
void AddGoal(const string& ck);
void RemoveGoal(const string& ck, DateTime assigned);
unordered_map<string, GoalsForChart> goalmap;
void FillGoalTable();
vector<ScoreGoal*> goaltable;
int sortmode = 1; // 1=date 2=rate 3=name 4=priority 5=diff, init to name because that's the default- mina
int filtermode = 1; // 1=all, 2=completed, 3=uncompleted
int asc = false;

bool HasGoal(const string& ck) { return goalmap.count(ck) == 1; }
ScoreGoal& GetLowestGoalForRate(const string& ck, float rate);
Expand Down
1 change: 0 additions & 1 deletion src/ScreenNetSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ bool ScreenNetSelectMusic::Input(const InputEventPlus &input)
Song* asonglol = m_MusicWheel.GetSelectedSong();
asonglol->SetHasGoal(true);
MESSAGEMAN->Broadcast("FavoritesUpdated");
MESSAGEMAN->Broadcast("UpdateGoals");
m_MusicWheel.ChangeMusic(0);
return true;
}
Expand Down
1 change: 0 additions & 1 deletion src/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ bool ScreenSelectMusic::Input(const InputEventPlus &input)
return true;
asonglol->SetHasGoal(true);
MESSAGEMAN->Broadcast("FavoritesUpdated");
MESSAGEMAN->Broadcast("UpdateGoals");
m_MusicWheel.ChangeMusic(0);
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/XMLProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ XNode* GoalsForChart::CreateNode() const {
XNode* cg = new XNode("GoalsForChart");

if (!goals.empty()) {
ASSERT(goals[0].chartkey != "" && goals[0].chartkey != " ");
cg->AppendAttr("Key", goals[0].chartkey);
FOREACH_CONST(ScoreGoal, goals, sg)
cg->AppendChild(sg->CreateNode());
Expand Down Expand Up @@ -486,6 +487,10 @@ void XMLProfile::LoadScoreGoalsFromNode(const XNode *pNode) {
chgoals->GetAttrValue("Key", ck);
ck = SONGMAN->ReconcileBustedKeys(ck);
loadingProfile->goalmap[ck].LoadFromNode(chgoals);

// this should load using the chart system but ensure keys are set properly here for now -mina
for (auto& sg : loadingProfile->goalmap[ck].goals)
sg.chartkey = ck;
}
}

Expand Down

0 comments on commit 108a036

Please sign in to comment.