--*********************************************************** --** THE INDIE STONE ** --** Author: turbotutone ** --*********************************************************** require "ISUI/ISPanel" ISLcdBar = ISPanel:derive("ISLcdBar"); ISLcdBar.charW = 8; ISLcdBar.charH = 12; ISLcdBar.indexes = " !\"#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\\]^_"; ISLcdBar.unsupported = { "CH", "CN", "JP", "KO", "RU", "TH", "UA"}; ISLcdBar.special = {"[","%","("} --these characters need a '%' appended in string.find function ISLcdBar:initialise() ISPanel.initialise(self) local lang = Translator.getLanguage():name(); -- unsupported languages mode is not implemented -- instead the device panel (which uses this LCD bar) always passes the English language strings -- and sets self.textMode to false. for k,v in ipairs(ISLcdBar.unsupported) do if lang==v then self.textMode = true; end end end function ISLcdBar:createChildren() end function ISLcdBar:update() ISPanel.update(self); local isPaused = UIManager.getSpeedControls() and UIManager.getSpeedControls():getCurrentGameSpeed() == 0 if isPaused then return end if self.isOn and self.doScroll then local ticks = UIManager.getSecondsSinceLastUpdate(); self.posCounter = self.posCounter+ticks; if self.posCounter>0.35 then self.posCounter = 0; self.pos = self.pos + 1; if (not self.text) or self.pos>self.text:len()-1 then self.pos = 0; end end end end function ISLcdBar:prerender() ISPanel.prerender(self); end function ISLcdBar:toggleOn( _b ) if self.isOn~=_b then self.isOn = _b; self.pos = 0; end end function ISLcdBar:renderChar( _pos, _index, _r, _g, _b, _a ) if self.javaObject ~= nil then local yoffset = 0; if _index>=32 then _index = _index-32; yoffset = ISLcdBar.charH; end local ind = _index*ISLcdBar.charW; local pos = _pos*ISLcdBar.charW; self.javaObject:DrawSubTextureRGBA(self.lcdfont, ind, yoffset, ISLcdBar.charW, ISLcdBar.charH, pos+2, 2, ISLcdBar.charW, ISLcdBar.charH, _r, _g, _b, _a); end end function ISLcdBar:isSpecial( _char ) for i=1,#ISLcdBar.special do if ISLcdBar.special[i]==_char then return true; end end return false; end function ISLcdBar:printChar( _pos, _char ) local index = 0; if self:isSpecial(_char) then index = string.find(ISLcdBar.indexes, "%".._char:lower()); else index = string.find(ISLcdBar.indexes, _char:lower()); end if _char=="." then index = 15; end self:renderChar(_pos, index and index-1 or 0, self.ledTextColor.r, self.ledTextColor.g, self.ledTextColor.b, self.ledTextColor.a); end function ISLcdBar:render() ISPanel.render(self); if self.isOn then self:renderBackground(self.ledColor.r, self.ledColor.g, self.ledColor.b, self.ledColor.a) else self:renderBackground(self.ledColor.r, self.ledColor.g, self.ledColor.b, 0.5) end if self.isOn then if self.text then for i=0, self.lcdwidth-1 do local p = self.pos+i; if p>self.text:len()-1 then p = p-self.text:len(); end self:printChar(i, self.text:sub(p+1,p+1)) end end end end function ISLcdBar:renderBackground(_r, _g, _b, _a) for i=0, self.lcdwidth-1 do local pos = i*ISLcdBar.charW; --(texture, x, y, w, h, a, r, g, b) self:drawTextureScaled(self.lcdback, pos+2, 2, ISLcdBar.charW, ISLcdBar.charH, _a, _r, _g, _b); end end function ISLcdBar:setDoScroll(_b) self.doScroll = _b; if not self.doScroll then self.pos = 0; end end function ISLcdBar:setTextMode(_b) self.textMode = _b; end function ISLcdBar:setText(_text) if self.textCache~=_text then self.textCache = _text; self.text = _text; self.pos = 0; if self.textMode then return; end if self.text then -- this reverts accents to ascii letter as the LCD font doesnt support the former self.text = RecordedMedia.toAscii(self.text); end if self.text and self.text:len()