Skip to content

Commit

Permalink
sketch of skillset filter implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Jan 13, 2017
1 parent 845b8e8 commit d614537
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
local searchstring = "" -- GetPersistentSearch()
local searchstring = ""
local englishes = {"a", "b", "c", "d", "e","f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",";"}
local numbershers = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
local frameX = 10
local frameY = 180+capWideScale(get43size(120),120)
local active = false
local textsearchactive = false
local whee
local lastsearchstring = "" -- GetPersistentSearch()
local lastsearchstring = ""
local activeskillsetfilter = 0
local skillsetfilterqueries = {}

for i=1,#ms.SkillSets do
skillsetfilterqueries[i] = ""
end


local function searchInput(event)
if event.type ~= "InputEventType_Release" and active == true then
if event.type ~= "InputEventType_Release" and textsearchactive == true then
if event.button == "Back" then
searchstring = ""
whee:SongSearch(searchstring)
Expand Down Expand Up @@ -39,6 +47,27 @@ local function searchInput(event)
whee:SongSearch(searchstring)
lastsearchstring = searchstring
end
elseif event.type ~= "InputEventType_Release" and activeskillsetfilter > 0 then
if event.button == "Start" then
textsearchactive = true
activeskillsetfilter = 0
MESSAGEMAN:Broadcast("NumericInputEnded")
return true
elseif event.DeviceInput.button == "DeviceButton_backspace" then
skillsetfilterqueries[activeskillsetfilter] = skillsetfilterqueries[activeskillsetfilter]:sub(1, -2) -- remove the last element of the string
elseif event.DeviceInput.button == "DeviceButton_delete" then
skillsetfilterqueries[activeskillsetfilter] = ""
else
for i=1,#numbershers do -- add standard characters to string
if event.DeviceInput.button == "DeviceButton_"..numbershers[i] then
skillsetfilterqueries[activeskillsetfilter] = skillsetfilterqueries[activeskillsetfilter]..numbershers[i]
end
end
end
MESSAGEMAN:Broadcast("UpdateFilter")
if skillsetfilterqueries[activeskillsetfilter] ~= "" then
whee:SetSkillsetFilter(tonumber(skillsetfilterqueries[activeskillsetfilter]), activeskillsetfilter)
end
end
end

Expand All @@ -54,13 +83,13 @@ local t = Def.ActorFrame{
ms.ok("Song search activated")
MESSAGEMAN:Broadcast("BeginningSearch")
self:visible(true)
active = true
textsearchactive = true
SCREENMAN:set_input_redirected(PLAYER_1, true)
MESSAGEMAN:Broadcast("RefreshSearchResults")
else
self:visible(false)
self:queuecommand("Off")
active = false
textsearchactive = false
SCREENMAN:set_input_redirected(PLAYER_1, false)
end
end,
Expand All @@ -69,7 +98,7 @@ local t = Def.ActorFrame{
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+250-capWideScale(get43size(120),30),frameY-90;zoom,0.7;halign,0.5;maxwidth,470),
SetCommand=function(self)
if active then
if textsearchactive then
self:settext("Search Active:")
self:diffuse(getGradeColor("Grade_Tier03"))
else
Expand Down Expand Up @@ -116,4 +145,37 @@ local t = Def.ActorFrame{
},
}





local i = 1

local f = Def.ActorFrame{
InitCommand=cmd(xy,frameX+20,frameY-75;zoom,0.4;halign,0),
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+20,frameY-70;zoom,0.5;halign,0),
SetCommand=cmd(settext, "Overall")
},
Def.Quad{
InitCommand=cmd(zoomto,100,100),
MouseLeftClickMessageCommand=function(self)
if isOver(self) then
textsearchactive = false
activeskillsetfilter = i
MESSAGEMAN:Broadcast("NumericInputActive")
end
end,
},
LoadFont("Common Large")..{
InitCommand=cmd(xy,frameX+170,frameY-70;zoom,0.5;halign,0),
SetCommand=cmd(settext, skillsetfilterqueries[i]),
UpdateFilterMessageCommand=cmd(queuecommand,"Set"),
},
}

t[#t+1] = f



return t
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
local active = true
local numericinputactive = false

local function input(event)
if event.type ~= "InputEventType_Release" and active then
for i=1,6 do
if event.DeviceInput.button == "DeviceButton_"..i then
setTabIndex(i-1)
MESSAGEMAN:Broadcast("TabChanged")
if numericinputactive == false then
for i=1,6 do
if event.DeviceInput.button == "DeviceButton_"..i then
setTabIndex(i-1)
MESSAGEMAN:Broadcast("TabChanged")
end
end
end
if event.DeviceInput.button == "DeviceButton_left mouse button" then
Expand All @@ -23,6 +26,11 @@ local t = Def.ActorFrame{
PlayerJoinedMessageCommand=function(self) resetTabIndex() end,
BeginningSearchMessageCommand=function(self) active = true end,
EndingSearchMessageCommand=function(self) active = true end,
NumericInputActiveMessageCommand=function(self)
ms.ok("woot")
numericinputactive = true
end,
NumericInputEndedMessageCommand=function(self) numericinputactive = false end,
}

-- Just for debug
Expand Down
36 changes: 34 additions & 2 deletions src/MusicWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void MusicWheel::Load( const RString &sType )
FOREACH_ENUM( SortOrder, so ) {
m_WheelItemDatasStatus[so]=INVALID;
}
ZERO( SkillsetFilters );
}

void MusicWheel::BeginScreen()
Expand Down Expand Up @@ -597,6 +598,29 @@ void MusicWheel::FilterBySearch(vector<Song*>& inv, RString findme) {
FilterBySearch(inv, lastvalidsearch);
}

void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
vector<Song*> tmp;
for (size_t i = 0; i < inv.size(); i++) {
bool addsong = false;
FOREACH_ENUM(Skillset, ss) {
if (SkillsetFilters[ss] > 0.f) {
LOG->Trace("%i", (int)ss);
float val = inv[i]->GetHighestSkillsetAllSteps(static_cast<int>(ss));
LOG->Trace("val %f", val);
LOG->Trace("comp %f", SkillsetFilters[ss]);
if (val > SkillsetFilters[ss]) {
LOG->Trace("hi");
addsong = addsong || true;
}
}
}
LOG->Trace("addsong %i", addsong);
if (addsong == true)
tmp.emplace_back(inv[i]);
}
inv.swap(tmp);
}

void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelItemDatas, SortOrder so, bool searching, RString findme )
{
switch( so )
Expand Down Expand Up @@ -647,9 +671,11 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
vector<Song*> arraySongs;
GetSongList( arraySongs, so );

if (searching)
if (searching) {
FilterBySearch(arraySongs, findme);

FilterBySkillsets(arraySongs);
}

bool bUseSections = true;

// sort the songs
Expand Down Expand Up @@ -1795,6 +1821,11 @@ 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;
}

LunaMusicWheel()
{
Expand All @@ -1804,6 +1835,7 @@ class LunaMusicWheel : public Luna<MusicWheel>
ADD_METHOD( SelectSong );
ADD_METHOD( SelectCourse );
ADD_METHOD( SongSearch );
ADD_METHOD( SetSkillsetFilter );
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/MusicWheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class MusicWheel : public WheelBase

virtual void ReloadSongList(bool searching, RString findme);

// mina was here - mina
void SetSkillsetFilter(float v, Skillset ss) { SkillsetFilters[ss] = v; }
// Lua
void PushSelf( lua_State *L );

Expand All @@ -63,6 +65,8 @@ class MusicWheel : public WheelBase
bool SelectModeMenuItem();

void FilterBySearch(vector<Song*>& inv, RString findme);
float SkillsetFilters[NUM_Skillset];
void FilterBySkillsets(vector<Song*>& inv);
RString lastvalidsearch;

virtual void UpdateSwitch();
Expand Down

0 comments on commit d614537

Please sign in to comment.