ethanwdp Posted June 24, 2015 Share Posted June 24, 2015 I've been stuck on this one part. So far, the rest of the development has gone smoothly, but I've noticed that the keypress event doesn't fire when you're typing into an ISTextEntryBox, meaning that I can't hook an event to cause it to clear, unfocus, and do a thing when enter is pushed. Code: LMSWindow = ISPanel:derive("LMSWindow");function LMSWindow:initialise() ISPanel.initialise(self);endfunction LMSWindow:new(x, y, width, height) local o = {}; o = ISPanel:new(x, y, width, height); setmetatable(o, self); self.__index = self; o.title = ""; o.pin = false; o:noBackground(); return o;endfunction LMSWindow:createChildren() ISPanel.createChildren(self); self.LMSchatBar = ISTextEntryBox:new("", 0, 15, 300, 20) self.LMSchatBar:initialise(); self:addChild(self.LMSchatBar)endfunction LMSspawn() LMSWindow = LMSWindow:new(35, getCore():getScreenHeight() - 100, 300, 40) LMSWindow:addToUIManager(); LMSWindow:setVisible(false);endfunction KeyListener(_keyPressed) if _keyPressed == 20 then if not LMSWindow:getIsVisible() then LMSWindow:setVisible(true); else LMSWindow:setVisible(false); end end if _keyPressed == 28 and LMSWindow.LMSchatBar:getText() then local LMStext = LMSWindow.LMSchatBar:getText() if not string.find(LMStext, "/", 1) then LMSWindow:unfocus() getPlayer():Say(LMStext) LMSWindow.LMSchatBar:clear() end endendfunction getLMSText() if LMSWindow:getIsVisible() then if LMSWindow.LMSchatBar:getText() then -- this ended up not working, as I still couldn't detect a key press end endendEvents.OnKeyPressed.Add(KeyListener);Events.OnGameStart.Add(LMSspawn);Events.OnTick.Add(getLMSText); How do I get the keypress event to fire in this case? Link to comment Share on other sites More sharing options...
ethanwdp Posted June 24, 2015 Author Share Posted June 24, 2015 EDIT:Figured it out.I decided to modify the original ISTextEntryBox, and make the onCommandEntered() function do something.My hunch was right, it DOES invoke onCommandEntered() properly, as it's just mirroring a few Java files.When I made it do something, like print, it actually worked. I'm guessing that's because the default function is empty, probably because making it return true makes horrors happen. So I added this line to my code: function ISTextEntryBox:onCommandEntered() print("test")endAnd it worked! It seemed to override the default ISTextEntryBox:onCommandEntered(), and I didn't have to include an override file. After doing some tweaking, here's the new (working) code: LMSWindow = ISPanel:derive("LMSWindow");function LMSWindow:initialise() ISPanel.initialise(self);endfunction LMSWindow:new(x, y, width, height) local o = {}; o = ISPanel:new(x, y, width, height); setmetatable(o, self); self.__index = self; o.title = ""; o.pin = false; o:noBackground(); return o;endfunction LMSWindow:createChildren() ISPanel.createChildren(self); self.LMSchatBar = ISTextEntryBox:new("", 0, 15, 300, 20) self.LMSchatBar:initialise(); self:addChild(self.LMSchatBar)endfunction LMScreate() LMSWindow = LMSWindow:new(35, getCore():getScreenHeight() - 100, 300, 40) LMSWindow:addToUIManager(); LMSWindow:setVisible(false);endfunction KeyListener(_keyPressed) if _keyPressed == 20 and not LMSWindow.LMSchatBar:getText() ~= nil then if not LMSWindow:getIsVisible() then LMSWindow:setVisible(true); LMSWindow.LMSchatBar:focus() else LMSWindow:setVisible(false); LMSWindow.LMSchatBar:clear() end endendfunction ISTextEntryBox:onCommandEntered() local LMStext = LMSWindow.LMSchatBar:getText() if not string.find(LMStext, "/", 1) then getPlayer():Say(LMStext); LMSWindow.LMSchatBar:clear(); LMSWindow.LMSchatBar:unfocus(); LMSWindow:setVisible(false); endendEvents.OnGameStart.Add(LMScreate);Events.OnKeyPressed.Add(KeyListener); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now