Skip to content

Commit

Permalink
moved filters to a filter manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dadcop2 committed Feb 19, 2017
1 parent 44aa0d2 commit 758fda7
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local function FilterInput(event)
if SSQuery[activebound][ActiveSS] == "" then
SSQuery[activebound][ActiveSS] = "0"
end
GAMESTATE:SetSSFilter(tonumber(SSQuery[activebound][ActiveSS]), ActiveSS, activebound)
FILTERMAN:SetSSFilter(tonumber(SSQuery[activebound][ActiveSS]), ActiveSS, activebound)
whee:SongSearch("") -- stupid workaround?
MESSAGEMAN:Broadcast("UpdateFilter")
end
Expand Down Expand Up @@ -113,22 +113,22 @@ local f = Def.ActorFrame{
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+frameWidth/2,175;zoom,textzoom;halign,0),
SetCommand=function(self)
self:settextf("Max Rate:%5.1fx",GAMESTATE:GetMaxFilterRate())
self:settextf("Max Rate:%5.1fx",FILTERMAN:GetMaxFilterRate())
end,
MaxFilterRateChangedMessageCommand=cmd(queuecommand,"Set"),
},
Def.Quad{
InitCommand=cmd(xy,frameX+frameWidth/2,175;zoomto,130,18;halign,0;diffusealpha,0),
MouseLeftClickMessageCommand=function(self)
if isOver(self) and active then
GAMESTATE:SetMaxFilterRate(GAMESTATE:GetMaxFilterRate()+0.1)
FILTERMAN:SetMaxFilterRate(FILTERMAN:GetMaxFilterRate()+0.1)
MESSAGEMAN:Broadcast("MaxFilterRateChanged")
whee:SongSearch("")
end
end,
MouseRightClickMessageCommand=function(self)
if isOver(self) and active then
GAMESTATE:SetMaxFilterRate(GAMESTATE:GetMaxFilterRate()-0.1)
FILTERMAN:SetMaxFilterRate(FILTERMAN:GetMaxFilterRate()-0.1)
MESSAGEMAN:Broadcast("MaxFilterRateChanged")
whee:SongSearch("")
end
Expand All @@ -137,22 +137,22 @@ local f = Def.ActorFrame{
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+frameWidth/2,175 + spacingY;zoom,textzoom;halign,0),
SetCommand=function(self)
self:settextf("Min Rate:%5.1fx",GAMESTATE:GetMinFilterRate())
self:settextf("Min Rate:%5.1fx",FILTERMAN:GetMinFilterRate())
end,
MaxFilterRateChangedMessageCommand=cmd(queuecommand,"Set"),
},
Def.Quad{
InitCommand=cmd(xy,frameX+frameWidth/2,175 + spacingY;zoomto,130,18;halign,0;diffusealpha,0),
MouseLeftClickMessageCommand=function(self)
if isOver(self) and active then
GAMESTATE:SetMinFilterRate(GAMESTATE:GetMinFilterRate()+0.1)
FILTERMAN:SetMinFilterRate(FILTERMAN:GetMinFilterRate()+0.1)
MESSAGEMAN:Broadcast("MaxFilterRateChanged")
whee:SongSearch("")
end
end,
MouseRightClickMessageCommand=function(self)
if isOver(self) and active then
GAMESTATE:SetMinFilterRate(GAMESTATE:GetMinFilterRate()-0.1)
FILTERMAN:SetMinFilterRate(FILTERMAN:GetMinFilterRate()-0.1)
MESSAGEMAN:Broadcast("MaxFilterRateChanged")
whee:SongSearch("")
end
Expand All @@ -161,7 +161,7 @@ local f = Def.ActorFrame{
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+frameWidth/2,175 + spacingY * 2;zoom,textzoom;halign,0),
SetCommand=function(self)
if GAMESTATE:GetFilterMode() then
if FILTERMAN:GetFilterMode() then
self:settext("Mode: ".."AND")
else
self:settext("Mode: ".."OR")
Expand All @@ -173,7 +173,7 @@ local f = Def.ActorFrame{
InitCommand=cmd(xy,frameX+frameWidth/2,175 + spacingY * 2;zoomto,120,18;halign,0;diffusealpha,0),
MouseLeftClickMessageCommand=function(self)
if isOver(self) and active then
GAMESTATE:ToggleFilterMode()
FILTERMAN:ToggleFilterMode()
MESSAGEMAN:Broadcast("FilterModeChanged")
whee:SongSearch("")
end
Expand All @@ -182,12 +182,12 @@ local f = Def.ActorFrame{
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+frameWidth/2,175 + spacingY * 3;zoom,textzoom;halign,0),
SetCommand=function(self)
if GAMESTATE:GetHighestSkillsetsOnly() then
if FILTERMAN:GetHighestSkillsetsOnly() then
self:settext("Highest Only: ".."ON")
else
self:settext("Highest Only: ".."OFF")
end
if GAMESTATE:GetFilterMode() then
if FILTERMAN:GetFilterMode() then
self:diffuse(color("#666666"))
else
self:diffuse(color("#FFFFFF"))
Expand All @@ -199,7 +199,7 @@ local f = Def.ActorFrame{
InitCommand=cmd(xy,frameX+frameWidth/2,175 + spacingY * 3;zoomto,160,18;halign,0;diffusealpha,0),
MouseLeftClickMessageCommand=function(self)
if isOver(self) and active then
GAMESTATE:ToggleHighestSkillsetsOnly()
FILTERMAN:ToggleHighestSkillsetsOnly()
MESSAGEMAN:Broadcast("FilterModeChanged")
whee:SongSearch("")
end
Expand Down Expand Up @@ -244,7 +244,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 = GAMESTATE:GetSSFilter(i,0) -- lower bounds
local fval = FILTERMAN:GetSSFilter(i,0) -- lower bounds
self:settext(fval)
if fval <= 0 and ActiveSS ~= i then
self:diffuse(color("#666666"))
Expand Down Expand Up @@ -280,7 +280,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 = GAMESTATE:GetSSFilter(i,1) -- upper bounds
local fval = FILTERMAN:GetSSFilter(i,1) -- upper bounds
self:settext(fval)
if fval <= 0 and ActiveSS ~= i then
self:diffuse(color("#666666"))
Expand All @@ -300,7 +300,7 @@ f[#f+1] = Def.Quad{
InitCommand=cmd(xy,frameX+frameWidth-150,frameY+250;zoomto,60,20;halign,0.5;diffuse,getMainColor('frames');diffusealpha,0),
MouseLeftClickMessageCommand=function(self)
if isOver(self) and active then
GAMESTATE:ResetSSFilters()
FILTERMAN:ResetSSFilters()
for i=1,#ms.SkillSets do
SSQuery[0][i] = "0"
SSQuery[1][i] = "0"
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 GAMESTATE:AnyActiveFilter() then
if index == 6 and FILTERMAN:AnyActiveFilter() then
self:diffuse(color("#cc2929"))
else
self:diffuse(getMainColor('positive'))
Expand Down
147 changes: 147 additions & 0 deletions src/FilterManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#include "global.h"
#include "FilterManager.h"
#include "PlayerState.h"

FilterManager* FILTERMAN = NULL;

FilterManager::FilterManager() {
// filter stuff - mina
ZERO(SSFilterLowerBounds);
ZERO(SSFilterUpperBounds);

FOREACH_PlayerNumber(p)
{
m_pPlayerState[p] = new PlayerState;
m_pPlayerState[p]->SetPlayerNumber(p);
}

// Register with Lua.
{
Lua *L = LUA->Get();
lua_pushstring(L, "FILTERMAN");
this->PushSelf(L);
lua_settable(L, LUA_GLOBALSINDEX);
LUA->Release(L);
}
}

FilterManager::~FilterManager() {
FOREACH_PlayerNumber(p)
SAFE_DELETE(m_pPlayerState[p]);

// Unregister with Lua.
LUA->UnsetGlobal("FILTERMAN");
}

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

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

// reset button for filters
void FilterManager::ResetSSFilters() {
FOREACH_ENUM(Skillset, ss) {
SSFilterLowerBounds[ss] = 0;
SSFilterUpperBounds[ss] = 0;
}
}

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

// lua start
#include "LuaBinding.h"

class LunaFilterManager : public Luna<FilterManager>
{
public:
DEFINE_METHOD(AnyActiveFilter, AnyActiveFilter())
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 ResetSSFilters(T* p, lua_State *L) {
p->ResetSSFilters();
return 1;
}
static int SetMaxFilterRate(T* p, lua_State* L) {
float mfr = FArg(1);
auto loot = p->m_pPlayerState[0];
CLAMP(mfr, loot->wtFFF, 2.f);
p->MaxFilterRate = mfr;
return 1;
}
static int GetMaxFilterRate(T* p, lua_State* L) {
lua_pushnumber(L, p->MaxFilterRate);
return 1;
}
static int SetMinFilterRate(T* p, lua_State* L) {
float mfr = FArg(1);
CLAMP(mfr, 0.7f, p->MaxFilterRate);
auto loot = p->m_pPlayerState[0];
loot->wtFFF = mfr;
return 1;
}
static int GetMinFilterRate(T* p, lua_State* L) {
auto loot = p->m_pPlayerState[0];
lua_pushnumber(L, loot->wtFFF);
return 1;
}
static int ToggleFilterMode(T* p, lua_State* L) {
p->ExclusiveFilter = !p->ExclusiveFilter;
return 1;

}
static int GetFilterMode(T* p, lua_State* L) {
lua_pushboolean(L, p->ExclusiveFilter);
return 1;
}
static int ToggleHighestSkillsetsOnly(T* p, lua_State* L) {
p->HighestSkillsetsOnly = !p->HighestSkillsetsOnly;
return 1;

}
static int GetHighestSkillsetsOnly(T* p, lua_State* L) {
lua_pushboolean(L, p->HighestSkillsetsOnly);
return 1;
}
LunaFilterManager() {
ADD_METHOD(SetSSFilter);
ADD_METHOD(GetSSFilter);
ADD_METHOD(ResetSSFilters);
ADD_METHOD(AnyActiveFilter);
ADD_METHOD(SetMaxFilterRate);
ADD_METHOD(GetMaxFilterRate);
ADD_METHOD(SetMinFilterRate);
ADD_METHOD(GetMinFilterRate);
ADD_METHOD(ToggleFilterMode);
ADD_METHOD(GetFilterMode);
ADD_METHOD(ToggleHighestSkillsetsOnly);
ADD_METHOD(GetHighestSkillsetsOnly);
}
};

LUA_REGISTER_CLASS(FilterManager)
// lua end
31 changes: 31 additions & 0 deletions src/FilterManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef FilterManager_H
#define FilterManager_H
#include "PlayerNumber.h"
#include "GameConstantsAndTypes.h"

class PlayerState;
class FilterManager {
public:
FilterManager();
~FilterManager();

PlayerState* m_pPlayerState[NUM_PLAYERS];

float SSFilterLowerBounds[NUM_Skillset];
float SSFilterUpperBounds[NUM_Skillset];
float MaxFilterRate = 1.f;
bool ExclusiveFilter = false; // if true the filter system will only match songs that meet all criteria rather than all that meet any - mina
float GetSSFilter(Skillset ss, int bound);
void SetSSFilter(float v, Skillset ss, int bound);
void ResetSSFilters(); // reset button for filters
bool HighestSkillsetsOnly = false;
bool SkillsetFiltersActive = false; // appears to be unused
bool AnyActiveFilter();

//Lua
void PushSelf(lua_State *L);
};

extern FilterManager* FILTERMAN;

#endif
Loading

0 comments on commit 758fda7

Please sign in to comment.