Skip to content

Commit

Permalink
move filter to gamestate so it persists and add diffrentiate between …
Browse files Browse the repository at this point in the history
…upper and lower bounds
  • Loading branch information
MinaciousGrace committed Jan 14, 2017
1 parent f022192 commit 41cb039
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local t = Def.ActorFrame{
LoadFont("Common Large") .. {
InitCommand=cmd(xy,PlayerFrameX+52,PlayerFrameY+28;halign,0;zoom,0.75;maxwidth,50),
BeginCommand=function(self)
local meter = GAMESTATE:GetCurrentSteps(PLAYER_1):GetMSD(getCurRateValue(),0)
local meter = GAMESTATE:GetCurrentSteps(PLAYER_1):GetMSD(getCurRateValue(),1)
self:settextf("%05.2f",meter)
self:diffuse(ByMSD(meter))
end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local frameWidth = capWideScale(360,400)
local frameHeight = 350
local offsetX = 10
local offsetY = 20
local activebound = 0
for i=1,#ms.SkillSets do
SSQuery[i] = "0"
end
Expand Down Expand Up @@ -39,7 +40,8 @@ local function FilterInput(event)
if SSQuery[ActiveSS] == "" or #SSQuery[ActiveSS] > 2 then
SSQuery[ActiveSS] = "0"
end
whee:SetSkillsetFilter(tonumber(SSQuery[ActiveSS]), ActiveSS)
GAMESTATE:SetSSFilter(tonumber(SSQuery[ActiveSS]), ActiveSS, activebound)
whee:SongSearch("") -- stupid workaround?
MESSAGEMAN:Broadcast("UpdateFilter")
end
end
Expand All @@ -60,13 +62,15 @@ local f = Def.ActorFrame{
self:visible(true)
active = true
else
MESSAGEMAN:Broadcast("NumericInputEnded")
self:visible(false)
self:queuecommand("Off")
end
end,
TabChangedMessageCommand=cmd(queuecommand,"Set"),
MouseRightClickMessageCommand=function(self)
ActiveSS = 0
MESSAGEMAN:Broadcast("NumericInputEnded")
MESSAGEMAN:Broadcast("UpdateFilter")
SCREENMAN:set_input_redirected(PLAYER_1, false)
end,
Expand All @@ -88,22 +92,48 @@ local f = Def.ActorFrame{
self:settext("Greyed out values are inactive.")
end,
},
Def.Quad{
InitCommand=cmd(xy,frameX+frameWidth/2+90,175;zoomto,40,30;halign,0;diffusealpha,0),
MouseLeftClickMessageCommand=function(self)
if isOver(self) then
GAMESTATE:SetMaxFilterRate(GAMESTATE:GetMaxFilterRate()+0.1)
MESSAGEMAN:Broadcast("MaxFilterRateChanged")
whee:SongSearch("")
end
end,
MouseRightClickMessageCommand=function(self)
if isOver(self) then
GAMESTATE:SetMaxFilterRate(GAMESTATE:GetMaxFilterRate()-0.1)
MESSAGEMAN:Broadcast("MaxFilterRateChanged")
whee:SongSearch("")
end
end,
},
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+frameWidth/2,175;zoom,textzoom;halign,0),
SetCommand=function(self)
self:settext("Max Rate: 1.5x")
self:settextf("Max Rate:%5.1fx",GAMESTATE:GetMaxFilterRate())
end,
MaxFilterRateChangedMessageCommand=cmd(queuecommand,"Set"),
},
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+frameWidth/2,175 + spacingY;zoom,textzoom;halign,0),
SetCommand=function(self)
self:settext("Mode: ".."Inclusive")
SetCommand=function(self)
--local mode = GAMESTATE:GetFilterMode()
if mode then
self:settext("Mode: ".."AND")
else
self:settext("Mode: ".."OR")
end
end,
},
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+frameWidth/2,175 + spacingY*2;zoom,textzoom;halign,0),
SetCommand=function(self)
self:settext("Highest SS Only : ".."Off")
Def.Quad{
InitCommand=cmd(xy,frameX+frameWidth/2+90,175;zoomto,40,30;halign,0;diffusealpha,0),
MouseLeftClickMessageCommand=function(self)
if isOver(self) then
GAMESTATE:ToggleFilterMode()
whee:SongSearch("")
end
end,
},
}
Expand All @@ -119,16 +149,17 @@ local function CreateFilterInputBox(i)
MouseLeftClickMessageCommand=function(self)
if isOver(self) then
ActiveSS = i
activebound = 0
MESSAGEMAN:Broadcast("NumericInputActive")
self:diffusealpha(0.1)
SCREENMAN:set_input_redirected(PLAYER_1, true)
end
end,
SetCommand=function(self)
if ActiveSS ~= i then
self:diffuse(color("#000000"))
else
if ActiveSS == i and activebound == 0 then
self:diffuse(color("#666666"))
else
self:diffuse(color("#000000"))
end
end,
UpdateFilterMessageCommand=cmd(queuecommand,"Set"),
Expand All @@ -137,7 +168,7 @@ local function CreateFilterInputBox(i)
LoadFont("Common Large")..{
InitCommand=cmd(addx,150;addy,175 + (i-1)*spacingY;halign,1;maxwidth,40;zoom,textzoom),
SetCommand=function(self)
local fval = whee:GetSkillsetFilter(i)
local fval = GAMESTATE:GetSSFilter(i,0) -- lower bounds
self:settext(fval)
if fval <= 0 and ActiveSS ~= i then
self:diffuse(color("#666666"))
Expand All @@ -152,16 +183,17 @@ local function CreateFilterInputBox(i)
MouseLeftClickMessageCommand=function(self)
if isOver(self) and false then
ActiveSS = i
activebound = 1
MESSAGEMAN:Broadcast("NumericInputActive")
self:diffusealpha(0.1)
SCREENMAN:set_input_redirected(PLAYER_1, true)
end
end,
SetCommand=function(self)
if ActiveSS ~= i or true then
self:diffuse(color("#000000"))
else
if ActiveSS == i and activebound == 1 then
self:diffuse(color("#666666"))
else
self:diffuse(color("#000000"))
end
end,
UpdateFilterMessageCommand=cmd(queuecommand,"Set"),
Expand All @@ -170,7 +202,7 @@ local function CreateFilterInputBox(i)
LoadFont("Common Large")..{
InitCommand=cmd(addx,175;addy,175 + (i-1)*spacingY;halign,1;maxwidth,40;zoom,textzoom),
SetCommand=function(self)
local fval = 0 --whee:GetSkillsetFilter(i)
local fval = GAMESTATE:GetSSFilter(i,1) -- upper bounds
self:settext(fval)
if fval <= 0 then
self:diffuse(color("#666666"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function tabs(index)
SetCommand=function(self)
self:settext(tabNames[index])
if isTabEnabled(index) then
if index == 6 and whee:AnyActiveSkillsetFilter() then
if index == 6 and GAMESTATE:AnyActiveFilter() then
self:diffuse(color("#cc2929"))
else
self:diffuse(getMainColor('positive'))
Expand Down
67 changes: 63 additions & 4 deletions src/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ GameState::GameState() :


// filter stuff - mina
ZERO( SkillsetFilters );
MaxFilterRate = 1.5;

ZERO( SSFilterLowerBounds );
ZERO( SSFilterUpperBounds );
MaxFilterRate = 1.f;
FilterMode = 0;

// Register with Lua.
{
Expand All @@ -207,6 +208,31 @@ GameState::~GameState()
SAFE_DELETE( processedTiming );
}

// tmp filter stuff - mina
bool GameState::AnyActiveFilter() {
FOREACH_ENUM(Skillset, ss) {
if (SSFilterLowerBounds[ss] > 0)
return true;
if (SSFilterUpperBounds[ss] > 0)
return true;
}
return false;
}

void GameState::SetSSFilter(float v, Skillset ss, int bound) {
if (bound == 0)
SSFilterLowerBounds[ss] = v;
else
SSFilterUpperBounds[ss] = v;
}

float GameState::GetSSFilter(Skillset ss, int bound) {
if (bound == 0)
return SSFilterLowerBounds[ss];
else
return SSFilterUpperBounds[ss];
}

PlayerNumber GameState::GetMasterPlayerNumber() const
{
return this->masterPlayerNumber;
Expand Down Expand Up @@ -2815,6 +2841,7 @@ class LunaGameState: public Luna<GameState>
DEFINE_METHOD( GetCoinMode, GetCoinMode() )
DEFINE_METHOD( GetPremium, GetPremium() )
DEFINE_METHOD( GetSongOptionsString, m_SongOptions.GetCurrent().GetString() )
DEFINE_METHOD( AnyActiveFilter, AnyActiveFilter())
static int GetSessionTime(T* p, lua_State *L) { lua_pushnumber(L, p->m_timeGameStarted.GetTimeSinceStart()); return 1; }
static int GetSongOptions( T* p, lua_State *L )
{
Expand Down Expand Up @@ -3242,8 +3269,34 @@ class LunaGameState: public Luna<GameState>
p->m_autogen_fargs[si]= v;
COMMON_RETURN_SELF;
}
static int SetSSFilter(T* p, lua_State *L) {
p->SetSSFilter(FArg(1), static_cast<Skillset>(IArg(2) - 1), IArg(3));
return 1;
}
static int GetSSFilter(T* p, lua_State *L) {
float f = p->GetSSFilter(static_cast<Skillset>(IArg(1) - 1), IArg(2));
lua_pushnumber(L, f);
return 1;
}
static int SetMaxFilterRate(T* p, lua_State* L) {
p->MaxFilterRate = FArg(1);
float mfr = FArg(1);
CLAMP(mfr, 0.7f, 2.f);
p->MaxFilterRate = mfr;
return 1;
}
static int GetMaxFilterRate(T* p, lua_State* L) {
lua_pushnumber(L, p->MaxFilterRate);
return 1;
}
static int ToggleFilterMode(T* p, lua_State* L) {
if (p->FilterMode == 1)
p->FilterMode = 0;
else
p->FilterMode = 1;
return 1;
}
static int GetFilterMode(T* p, lua_State* L) {
lua_pushnumber(L, p->FilterMode);
return 1;
}

Expand Down Expand Up @@ -3374,7 +3427,13 @@ class LunaGameState: public Luna<GameState>
ADD_METHOD( SetStepsForEditMode );
ADD_METHOD( GetAutoGenFarg );
ADD_METHOD( SetAutoGenFarg );
ADD_METHOD( SetSSFilter );
ADD_METHOD( GetSSFilter );
ADD_METHOD( AnyActiveFilter );
ADD_METHOD( SetMaxFilterRate );
ADD_METHOD( GetMaxFilterRate );
ADD_METHOD( ToggleFilterMode );
ADD_METHOD( GetFilterMode );
}
};

Expand Down
15 changes: 12 additions & 3 deletions src/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,19 @@ class GameState
int GetLoadingCourseSongIndex() const;


// mina was here to drop in some temporary(?) filter things that need to persist - mina
float SkillsetFilters[NUM_Skillset];
// todo: make a filterman or something - mina
float SSFilterLowerBounds[NUM_Skillset];
float SSFilterUpperBounds[NUM_Skillset];
float MaxFilterRate;
void SetMaxFilterRate(float v) { MaxFilterRate; }
int FilterMode; // 0 = OR 1 = AND
float GetSSFilter(Skillset ss, int bound);
void SetSSFilter(float v, Skillset ss, int bound);

bool SkillsetFiltersActive = false;
bool AnyActiveFilter();




// State Info used during gameplay

Expand Down
34 changes: 4 additions & 30 deletions src/MusicWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ void MusicWheel::Load( const RString &sType )
FOREACH_ENUM( SortOrder, so ) {
m_WheelItemDatasStatus[so]=INVALID;
}
ZERO( SkillsetFilters );
FOREACH_ENUM(Skillset, ss)
SkillsetFilters[ss] = GAMESTATE->SkillsetFilters[ss];
}

void MusicWheel::BeginScreen()
Expand Down Expand Up @@ -261,8 +258,6 @@ MusicWheel::~MusicWheel()
delete *i;
}
}
FOREACH_ENUM(Skillset, ss)
GAMESTATE->SkillsetFilters[ss] = SkillsetFilters[ss];
}

void MusicWheel::ReloadSongList(bool searching, RString findme)
Expand Down Expand Up @@ -597,9 +592,10 @@ void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
for (size_t i = 0; i < inv.size(); i++) {
bool addsong = false;
FOREACH_ENUM(Skillset, ss) {
if (SkillsetFilters[ss] > 0.f) {
float lb = GAMESTATE->SSFilterLowerBounds[ss];
if (lb > 0.f) {
float val = inv[i]->GetHighestOfSkillsetAllSteps(static_cast<int>(ss), GAMESTATE->MaxFilterRate);
if (val > SkillsetFilters[ss])
if (val > lb)
addsong = addsong || true;
}
}
Expand All @@ -609,14 +605,6 @@ void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
inv.swap(tmp);
}

// should make an explicit toggle soon - mina
bool MusicWheel::AnyActiveSkillsetFilter() {
FOREACH_ENUM(Skillset, ss)
if (SkillsetFilters[ss] > 0)
return true;
return false;
}

void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelItemDatas, SortOrder so, bool searching, RString findme )
{
switch( so )
Expand Down Expand Up @@ -670,7 +658,7 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
if (searching)
FilterBySearch(arraySongs, findme);

if (AnyActiveSkillsetFilter())
if (GAMESTATE->AnyActiveFilter())
FilterBySkillsets(arraySongs);

bool bUseSections = true;
Expand Down Expand Up @@ -1793,7 +1781,6 @@ class LunaMusicWheel : public Luna<MusicWheel>
return 1;
}
DEFINE_METHOD(GetSelectedSection, GetSelectedSection());
DEFINE_METHOD(AnyActiveSkillsetFilter, AnyActiveSkillsetFilter());
static int IsRouletting(T* p, lua_State *L) { lua_pushboolean(L, p->IsRouletting()); return 1; }
static int SelectSong(T* p, lua_State *L)
{
Expand All @@ -1819,16 +1806,6 @@ class LunaMusicWheel : public Luna<MusicWheel>
p->ReloadSongList(true, SArg(1));
return 1;
}
static int SetSkillsetFilter(T* p, lua_State *L) {
p->SetSkillsetFilter(FArg(1), static_cast<Skillset>(IArg(2)-1));
p->ReloadSongList(true, "");
return 1;
}
static int GetSkillsetFilter(T* p, lua_State *L) {
float f = p->GetSkillsetFilter(static_cast<Skillset>(IArg(1) - 1));
lua_pushnumber(L, f);
return 1;
}

LunaMusicWheel()
{
Expand All @@ -1838,9 +1815,6 @@ class LunaMusicWheel : public Luna<MusicWheel>
ADD_METHOD( SelectSong );
ADD_METHOD( SelectCourse );
ADD_METHOD( SongSearch );
ADD_METHOD( SetSkillsetFilter );
ADD_METHOD( GetSkillsetFilter );
ADD_METHOD( AnyActiveSkillsetFilter );
}
};

Expand Down
Loading

0 comments on commit 41cb039

Please sign in to comment.