Skip to content

Commit

Permalink
IsBeingPressed lua wrapper and input.char for lua (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram authored and MinaciousGrace committed Nov 20, 2017
1 parent e103a9a commit 82c4cc3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,14 @@ local function DlInput(event)
changed = true
else
if inputting == 2 or inputting == 3 or inputting == 4 or inputting == 5 then
for i=1,#numbershers do
if event.DeviceInput.button == "DeviceButton_"..numbershers[i] then
curInput = curInput..numbershers[i]
changed = true
break
end
if tonumber(event.char) ~= nil then
curInput = curInput..event.char
changed = true
end
else
for i=1,#englishes do -- add standard characters to string
if event.DeviceInput.button == "DeviceButton_"..englishes[i] then
curInput = curInput..englishes[i]
changed = true
break
end
if event.char and event.char ~= "" then
curInput = curInput..event.char
changed = true
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
local searchstring = ""
local englishes = {"?","-",".",",","1","2","3","4","5","6","7","8","9","0","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 frameX = 10
local frameY = 180+capWideScale(get43size(120),120)
local active = false
local whee
local lastsearchstring = ""
local CtrlPressed = false

local function searchInput(event)
if event.type ~= "InputEventType_Release" and active == true then
Expand All @@ -30,10 +28,10 @@ local function searchInput(event)
elseif event.DeviceInput.button == "DeviceButton_v" and CtrlPressed then
searchstring = searchstring..HOOKS:GetClipboard()
else
for i=1,#englishes do -- add standard characters to string
if event.DeviceInput.button == "DeviceButton_"..englishes[i] then
searchstring = searchstring..englishes[i]
end
--if not nil and (not a number or (ctrl pressed and not online))
local CtrlPressed = INPUTFILTER:IsBeingPressed("left ctrl") or INPUTFILTER:IsBeingPressed("right ctrl")
if event.char and (tonumber(event.char) == nil or CtrlPressed == (not IsNetSMOnline())) then
searchstring = searchstring..event.char
end
end
if lastsearchstring ~= searchstring then
Expand All @@ -42,13 +40,6 @@ local function searchInput(event)
lastsearchstring = searchstring
end
end
if event.DeviceInput.button == "DeviceButton_right ctrl" or event.DeviceInput.button == "DeviceButton_left ctrl" then
if event.type == "InputEventType_Release" then
CtrlPressed = false
else
CtrlPressed = true
end
end
end

local t = Def.ActorFrame{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ local packinputactive = false
local whee

local tabNames = {"General","MSD","Score","Search","Profile","Filters", "Goals", "Playlists", "Packs"} -- this probably should be in tabmanager.
--[[
]]
local function input(event)
if event.type ~= "InputEventType_Release" and active then
if numericinputactive == false and packinputactive == false then
for i=1,#tabNames do
if event.DeviceInput.button == "DeviceButton_"..i then
if not (INPUTFILTER:IsBeingPressed("left ctrl") or INPUTFILTER:IsBeingPressed("right ctrl") or IsNetSMOnline()) and event.char and tonumber(event.char) and tonumber(event.char)==i then
setTabIndex(i-1)
MESSAGEMAN:Broadcast("TabChanged")
end
Expand Down
2 changes: 1 addition & 1 deletion Themes/_fallback/Scripts/01 alias.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ Health = {
Alive = 'HealthState_Alive',
Danger = 'HealthState_Danger',
Dead = 'HealthState_Dead'
}
}
17 changes: 13 additions & 4 deletions src/InputFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,21 @@ class LunaInputFilter: public Luna<InputFilter>
lua_pushnumber( L, fZ );
return 1;
}

static int IsBeingPressed(T* p, lua_State *L) {
if (lua_isnil(L, 1)) {
return luaL_error(L, "IsBeingPressed(button, inputDevice=keyboard) expects at least one parameter");
}
DeviceButton button = StringToDeviceButton(SArg(1));
InputDevice device = (lua_isnil(L, 2) ? StringToInputDevice(SArg(2)) : DEVICE_KEYBOARD);
lua_pushboolean(L, INPUTFILTER->IsBeingPressed(DeviceInput(device, button)));
return 1;
}
LunaInputFilter()
{
ADD_METHOD( GetMouseX );
ADD_METHOD( GetMouseY );
ADD_METHOD( GetMouseWheel );
ADD_METHOD(GetMouseX);
ADD_METHOD(GetMouseY);
ADD_METHOD(GetMouseWheel);
ADD_METHOD(IsBeingPressed);
}
};

Expand Down
5 changes: 5 additions & 0 deletions src/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ActorUtil.h"
#include "InputEventPlus.h"
#include "InputMapper.h"
#include "RageInput.h"

#define NEXT_SCREEN THEME->GetMetric (m_sName,"NextScreen")
#define PREV_SCREEN THEME->GetMetric (m_sName,"PrevScreen")
Expand Down Expand Up @@ -347,6 +348,10 @@ bool Screen::PassInputToLua(const InputEventPlus& input)
lua_setfield(L, -2, "button");
Enum::Push(L, input.type);
lua_setfield(L, -2, "type");
char s[5];
wctomb(s, INPUTMAN->DeviceInputToChar(input.DeviceI, true));
LuaHelpers::Push(L, string(s));
lua_setfield(L, -2, "char");
LuaHelpers::Push(L, GameButtonToString(INPUTMAPPER->GetInputScheme(), input.MenuI));
lua_setfield(L, -2, "GameButton");
Enum::Push(L, input.pn);
Expand Down

0 comments on commit 82c4cc3

Please sign in to comment.