mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Many more Rubocop-inspired code improvements
This commit is contained in:
@@ -144,8 +144,6 @@ class SpriteWindow < Window
|
||||
@viewport = value
|
||||
for i in @spritekeys
|
||||
@sprites[i].dispose if @sprites[i]
|
||||
end
|
||||
for i in @spritekeys
|
||||
if @sprites[i].is_a?(Sprite)
|
||||
@sprites[i] = Sprite.new(@viewport)
|
||||
else
|
||||
@@ -306,11 +304,10 @@ class SpriteWindow < Window
|
||||
@cursoropacity += 8
|
||||
@cursorblink = 0 if @cursoropacity >= 255
|
||||
end
|
||||
privRefreshCursor
|
||||
else
|
||||
@cursoropacity = 128
|
||||
privRefreshCursor
|
||||
end
|
||||
privRefreshCursor
|
||||
if @pause
|
||||
oldpauseframe = @pauseframe
|
||||
oldpauseopacity = @pauseopacity
|
||||
@@ -591,7 +588,7 @@ class SpriteWindow < Window
|
||||
trimX + 32, trimY + 64,
|
||||
trimX + 48, trimY + 64,
|
||||
trimX + 32, trimY + 80,
|
||||
trimX + 48, trimY + 80,
|
||||
trimX + 48, trimY + 80
|
||||
]
|
||||
pauseWidth = 16
|
||||
pauseHeight = 16
|
||||
@@ -838,13 +835,13 @@ class SpriteWindow_Base < SpriteWindow
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.z = 100
|
||||
@curframe = MessageConfig.pbGetSystemFrame()
|
||||
@curfont = MessageConfig.pbGetSystemFontName()
|
||||
@curframe = MessageConfig.pbGetSystemFrame
|
||||
@curfont = MessageConfig.pbGetSystemFontName
|
||||
@sysframe = AnimatedBitmap.new(@curframe)
|
||||
RPG::Cache.retain(@curframe) if @curframe && !@curframe.empty?
|
||||
@customskin = nil
|
||||
__setWindowskin(@sysframe.bitmap)
|
||||
__resolveSystemFrame()
|
||||
__resolveSystemFrame
|
||||
pbSetSystemFont(self.contents) if self.contents
|
||||
end
|
||||
|
||||
@@ -861,7 +858,7 @@ class SpriteWindow_Base < SpriteWindow
|
||||
def __resolveSystemFrame
|
||||
if self.skinformat == 1
|
||||
if !@resolvedFrame
|
||||
@resolvedFrame = MessageConfig.pbGetSystemFrame()
|
||||
@resolvedFrame = MessageConfig.pbGetSystemFrame
|
||||
@resolvedFrame.sub!(/\.[^\.\/\\]+$/, "")
|
||||
end
|
||||
self.loadSkinFile("#{@resolvedFrame}.txt") if @resolvedFrame != ""
|
||||
@@ -886,7 +883,7 @@ class SpriteWindow_Base < SpriteWindow
|
||||
@customskin.dispose if @customskin
|
||||
@customskin = nil
|
||||
__setWindowskin(@sysframe.bitmap)
|
||||
__resolveSystemFrame()
|
||||
__resolveSystemFrame
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -904,23 +901,23 @@ class SpriteWindow_Base < SpriteWindow
|
||||
end
|
||||
end
|
||||
end
|
||||
if @curframe != MessageConfig.pbGetSystemFrame()
|
||||
@curframe = MessageConfig.pbGetSystemFrame()
|
||||
if @curframe != MessageConfig.pbGetSystemFrame
|
||||
@curframe = MessageConfig.pbGetSystemFrame
|
||||
if @sysframe && !@customskin
|
||||
@sysframe.dispose if @sysframe
|
||||
@sysframe = AnimatedBitmap.new(@curframe)
|
||||
RPG::Cache.retain(@curframe) if @curframe && !@curframe.empty?
|
||||
@resolvedFrame = nil
|
||||
__setWindowskin(@sysframe.bitmap)
|
||||
__resolveSystemFrame()
|
||||
__resolveSystemFrame
|
||||
end
|
||||
begin
|
||||
refresh
|
||||
rescue NoMethodError
|
||||
end
|
||||
end
|
||||
if @curfont != MessageConfig.pbGetSystemFontName()
|
||||
@curfont = MessageConfig.pbGetSystemFontName()
|
||||
if @curfont != MessageConfig.pbGetSystemFontName
|
||||
@curfont = MessageConfig.pbGetSystemFontName
|
||||
if self.contents && !self.contents.disposed?
|
||||
pbSetSystemFont(self.contents)
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ class IconWindow < SpriteWindow_Base
|
||||
end
|
||||
|
||||
def dispose
|
||||
clearBitmaps()
|
||||
clearBitmaps
|
||||
super
|
||||
end
|
||||
|
||||
@@ -38,7 +38,7 @@ class IconWindow < SpriteWindow_Base
|
||||
|
||||
# Sets the icon's filename.
|
||||
def setBitmap(file, hue = 0)
|
||||
clearBitmaps()
|
||||
clearBitmaps
|
||||
@name = file
|
||||
return if file == nil
|
||||
if file != ""
|
||||
@@ -67,7 +67,7 @@ class PictureWindow < SpriteWindow_Base
|
||||
end
|
||||
|
||||
def dispose
|
||||
clearBitmaps()
|
||||
clearBitmaps
|
||||
super
|
||||
end
|
||||
|
||||
@@ -92,7 +92,7 @@ class PictureWindow < SpriteWindow_Base
|
||||
# Sets the icon's bitmap or filename. (hue parameter
|
||||
# is ignored unless pathOrBitmap is a filename)
|
||||
def setBitmap(pathOrBitmap, hue = 0)
|
||||
clearBitmaps()
|
||||
clearBitmaps
|
||||
if pathOrBitmap != nil && pathOrBitmap != ""
|
||||
if pathOrBitmap.is_a?(Bitmap)
|
||||
@_iconbitmap = pathOrBitmap
|
||||
|
||||
@@ -245,13 +245,14 @@ class IconSprite < SpriteWrapper
|
||||
attr_reader :name
|
||||
|
||||
def initialize(*args)
|
||||
if args.length == 0
|
||||
case args.length
|
||||
when 0
|
||||
super(nil)
|
||||
self.bitmap = nil
|
||||
elsif args.length == 1
|
||||
when 1
|
||||
super(args[0])
|
||||
self.bitmap = nil
|
||||
elsif args.length == 2
|
||||
when 2
|
||||
super(nil)
|
||||
self.x = args[0]
|
||||
self.y = args[1]
|
||||
@@ -265,7 +266,7 @@ class IconSprite < SpriteWrapper
|
||||
end
|
||||
|
||||
def dispose
|
||||
clearBitmaps()
|
||||
clearBitmaps
|
||||
super
|
||||
end
|
||||
|
||||
@@ -277,7 +278,7 @@ class IconSprite < SpriteWrapper
|
||||
# Sets the icon's filename.
|
||||
def setBitmap(file, hue = 0)
|
||||
oldrc = self.src_rect
|
||||
clearBitmaps()
|
||||
clearBitmaps
|
||||
@name = file
|
||||
return if file == nil
|
||||
if file != ""
|
||||
|
||||
@@ -45,26 +45,27 @@ end
|
||||
def rgbToColor(param)
|
||||
return Font.default_color if !param
|
||||
baseint = param.to_i(16)
|
||||
if param.length == 8 # 32-bit hex
|
||||
case param.length
|
||||
when 8 # 32-bit hex
|
||||
return Color.new(
|
||||
(baseint >> 24) & 0xFF,
|
||||
(baseint >> 16) & 0xFF,
|
||||
(baseint >> 8) & 0xFF,
|
||||
(baseint) & 0xFF
|
||||
)
|
||||
elsif param.length == 6 # 24-bit hex
|
||||
when 6 # 24-bit hex
|
||||
return Color.new(
|
||||
(baseint >> 16) & 0xFF,
|
||||
(baseint >> 8) & 0xFF,
|
||||
(baseint) & 0xFF
|
||||
)
|
||||
elsif param.length == 4 # 16-bit hex
|
||||
when 4 # 16-bit hex
|
||||
return Color.new(
|
||||
((baseint) & 0x1F) << 3,
|
||||
((baseint >> 5) & 0x1F) << 3,
|
||||
((baseint >> 10) & 0x1F) << 3
|
||||
)
|
||||
elsif param.length == 1 # Color number
|
||||
when 1 # Color number
|
||||
i = param.to_i
|
||||
return Font.default_color if i >= 8
|
||||
return [
|
||||
@@ -291,7 +292,7 @@ def getFormattedTextFast(bitmap, xDst, yDst, widthDst, heightDst, text, lineheig
|
||||
end
|
||||
|
||||
def isWaitChar(x)
|
||||
return (x == "\001" || x == "\002")
|
||||
return (["\001", "\002"].include?(x))
|
||||
end
|
||||
|
||||
def getLastParam(array, default)
|
||||
@@ -418,14 +419,13 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
x = y = 0
|
||||
characters = []
|
||||
charactersInternal = []
|
||||
realtext = nil
|
||||
realtextStart = ""
|
||||
if !explicitBreaksOnly && textchunks.join("").length == 0
|
||||
# All commands occurred at the beginning of the text string
|
||||
realtext = (newlineBreaks) ? text : text.gsub(/\n/, " ")
|
||||
realtextStart = oldtext[0, oldtext.length - realtext.length]
|
||||
realtextHalf = text.length / 2
|
||||
end
|
||||
# realtext = nil
|
||||
# realtextStart = ""
|
||||
# if !explicitBreaksOnly && textchunks.join("").length == 0
|
||||
# # All commands occurred at the beginning of the text string
|
||||
# realtext = (newlineBreaks) ? text : text.gsub(/\n/, " ")
|
||||
# realtextStart = oldtext[0, oldtext.length - realtext.length]
|
||||
# end
|
||||
textchunks.push(text)
|
||||
for chunk in textchunks
|
||||
chunk.gsub!(/</, "<")
|
||||
@@ -483,14 +483,15 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
control = controls[i][0]
|
||||
param = controls[i][1]
|
||||
endtag = controls[i][3]
|
||||
if control == "c"
|
||||
case control
|
||||
when "c"
|
||||
if endtag
|
||||
colorstack.pop
|
||||
else
|
||||
color = rgbToColor(param)
|
||||
colorstack.push([color, nil])
|
||||
end
|
||||
elsif control == "c2"
|
||||
when "c2"
|
||||
if endtag
|
||||
colorstack.pop
|
||||
else
|
||||
@@ -498,7 +499,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
shadow = Rgb16ToColor(param[4, 4])
|
||||
colorstack.push([base, shadow])
|
||||
end
|
||||
elsif control == "c3"
|
||||
when "c3"
|
||||
if endtag
|
||||
colorstack.pop
|
||||
else
|
||||
@@ -509,25 +510,25 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
shadow = (param[1] && param[1] != "") ? rgbToColor(param[1]) : oldColors[1]
|
||||
colorstack.push([base, shadow])
|
||||
end
|
||||
elsif control == "o"
|
||||
when "o"
|
||||
if endtag
|
||||
opacitystack.pop
|
||||
else
|
||||
opacitystack.push(param.sub(/\s+$/, "").to_i)
|
||||
end
|
||||
elsif control == "b"
|
||||
when "b"
|
||||
boldcount += (endtag ? -1 : 1)
|
||||
elsif control == "i"
|
||||
when "i"
|
||||
italiccount += (endtag ? -1 : 1)
|
||||
elsif control == "u"
|
||||
when "u"
|
||||
underlinecount += (endtag ? -1 : 1)
|
||||
elsif control == "s"
|
||||
when "s"
|
||||
strikecount += (endtag ? -1 : 1)
|
||||
elsif control == "outln"
|
||||
when "outln"
|
||||
outlinecount += (endtag ? -1 : 1)
|
||||
elsif control == "outln2"
|
||||
when "outln2"
|
||||
outline2count += (endtag ? -1 : 1)
|
||||
elsif control == "fs" # Font size
|
||||
when "fs" # Font size
|
||||
if endtag
|
||||
fontsizestack.pop
|
||||
else
|
||||
@@ -535,7 +536,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
end
|
||||
fontsize = getLastParam(fontsizestack, defaultfontsize)
|
||||
bitmap.font.size = fontsize
|
||||
elsif control == "fn" # Font name
|
||||
when "fn" # Font name
|
||||
if endtag
|
||||
fontnamestack.pop
|
||||
else
|
||||
@@ -544,38 +545,35 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
end
|
||||
fontname = getLastParam(fontnamestack, defaultfontname)
|
||||
bitmap.font.name = fontname
|
||||
elsif control == "ar" # Right align
|
||||
if !endtag
|
||||
when "ar" # Right align
|
||||
if endtag
|
||||
alignstack.pop
|
||||
else
|
||||
alignstack.push(1)
|
||||
nextline = 1 if x > 0 && nextline == 0
|
||||
else
|
||||
alignstack.pop
|
||||
nextline = 1 if x > 0 && nextline == 0
|
||||
end
|
||||
elsif control == "al" # Left align
|
||||
if !endtag
|
||||
nextline = 1 if x > 0 && nextline == 0
|
||||
when "al" # Left align
|
||||
if endtag
|
||||
alignstack.pop
|
||||
else
|
||||
alignstack.push(0)
|
||||
nextline = 1 if x > 0 && nextline == 0
|
||||
else
|
||||
alignstack.pop
|
||||
nextline = 1 if x > 0 && nextline == 0
|
||||
end
|
||||
elsif control == "ac" # Center align
|
||||
if !endtag
|
||||
nextline = 1 if x > 0 && nextline == 0
|
||||
when "ac" # Center align
|
||||
if endtag
|
||||
alignstack.pop
|
||||
else
|
||||
alignstack.push(2)
|
||||
nextline = 1 if x > 0 && nextline == 0
|
||||
else
|
||||
alignstack.pop
|
||||
nextline = 1 if x > 0 && nextline == 0
|
||||
end
|
||||
elsif control == "icon" # Icon
|
||||
nextline = 1 if x > 0 && nextline == 0
|
||||
when "icon" # Icon
|
||||
if !endtag
|
||||
param = param.sub(/\s+$/, "")
|
||||
graphic = "Graphics/Icons/#{param}"
|
||||
controls[i] = nil
|
||||
break
|
||||
end
|
||||
elsif control == "img" # Icon
|
||||
when "img" # Icon
|
||||
if !endtag
|
||||
param = param.sub(/\s+$/, "")
|
||||
param = param.split("|")
|
||||
@@ -589,11 +587,11 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
controls[i] = nil
|
||||
break
|
||||
end
|
||||
elsif control == "br" # Line break
|
||||
when "br" # Line break
|
||||
if !endtag
|
||||
nextline += 1
|
||||
end
|
||||
elsif control == "r" # Right align this line
|
||||
when "r" # Right align this line
|
||||
if !endtag
|
||||
x = 0
|
||||
rightalign = 1
|
||||
@@ -679,7 +677,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
|
||||
havenl = true if !graphic && isWaitChar(textchars[position])
|
||||
extraspace = (!graphic && italiccount > 0) ? 2 + (width / 2) : 2
|
||||
characters.push([
|
||||
graphic ? graphic : textchars[position],
|
||||
graphic || textchars[position],
|
||||
x + xStart, texty, width + extraspace, lineheight,
|
||||
graphic ? true : false,
|
||||
(boldcount > 0), (italiccount > 0), colors[0], colors[1],
|
||||
@@ -929,12 +927,11 @@ def getLineBrokenChunks(bitmap, value, width, dims, plain = false)
|
||||
y += 32
|
||||
next
|
||||
end
|
||||
textcols = []
|
||||
if ccheck[/</] && !plain
|
||||
textcols = []
|
||||
ccheck.scan(re) { textcols.push(rgbToColor($1)) }
|
||||
words = ccheck.split(reNoMatch) # must have no matches because split can include match
|
||||
else
|
||||
textcols = []
|
||||
words = [ccheck]
|
||||
end
|
||||
for i in 0...words.length
|
||||
@@ -1161,9 +1158,10 @@ def pbDrawTextPositions(bitmap, textpos)
|
||||
textsize = bitmap.text_size(i[0])
|
||||
x = i[1]
|
||||
y = i[2] + 6
|
||||
if i[3] == true || i[3] == 1 # right align
|
||||
case i[3]
|
||||
when true, 1 # right align
|
||||
x -= textsize.width
|
||||
elsif i[3] == 2 # centered
|
||||
when 2 # centered
|
||||
x -= (textsize.width / 2)
|
||||
end
|
||||
if i[6] == true || i[6] == 1 # outline text
|
||||
|
||||
@@ -191,15 +191,15 @@ def pbChooseNumber(msgwindow, params)
|
||||
if Input.trigger?(Input::USE)
|
||||
ret = cmdwindow.number
|
||||
if ret > maximum
|
||||
pbPlayBuzzerSE()
|
||||
pbPlayBuzzerSE
|
||||
elsif ret < minimum
|
||||
pbPlayBuzzerSE()
|
||||
pbPlayBuzzerSE
|
||||
else
|
||||
pbPlayDecisionSE()
|
||||
pbPlayDecisionSE
|
||||
break
|
||||
end
|
||||
elsif Input.trigger?(Input::BACK)
|
||||
pbPlayCancelSE()
|
||||
pbPlayCancelSE
|
||||
ret = cancelNumber
|
||||
break
|
||||
end
|
||||
@@ -324,7 +324,7 @@ def pbGetGoldString
|
||||
end
|
||||
|
||||
def pbDisplayGoldWindow(msgwindow)
|
||||
moneyString = pbGetGoldString()
|
||||
moneyString = pbGetGoldString
|
||||
goldwindow = Window_AdvancedTextPokemon.new(_INTL("Money:\n<ar>{1}</ar>", moneyString))
|
||||
goldwindow.setSkin("Graphics/Windowskins/goldskin")
|
||||
goldwindow.resizeToFit(goldwindow.text, Graphics.width)
|
||||
@@ -386,7 +386,7 @@ def pbCreateStatusWindow(viewport = nil)
|
||||
msgwindow.visible = false
|
||||
msgwindow.letterbyletter = false
|
||||
pbBottomLeftLines(msgwindow, 2)
|
||||
skinfile = MessageConfig.pbGetSpeechFrame()
|
||||
skinfile = MessageConfig.pbGetSpeechFrame
|
||||
msgwindow.setSkin(skinfile)
|
||||
return msgwindow
|
||||
end
|
||||
@@ -403,7 +403,7 @@ def pbCreateMessageWindow(viewport = nil, skin = nil)
|
||||
msgwindow.back_opacity = MessageConfig::WINDOW_OPACITY
|
||||
pbBottomLeftLines(msgwindow, 2)
|
||||
$game_temp.message_window_showing = true if $game_temp
|
||||
skin = MessageConfig.pbGetSpeechFrame() if !skin
|
||||
skin = MessageConfig.pbGetSpeechFrame if !skin
|
||||
msgwindow.setSkin(skin)
|
||||
return msgwindow
|
||||
end
|
||||
@@ -562,7 +562,7 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni
|
||||
if startSE != nil
|
||||
pbSEPlay(pbStringToAudioFile(startSE))
|
||||
elsif signWaitCount == 0 && letterbyletter
|
||||
pbPlayDecisionSE()
|
||||
pbPlayDecisionSE
|
||||
end
|
||||
########## Position message window ##############
|
||||
pbRepositionMessageWindow(msgwindow, linecount)
|
||||
|
||||
@@ -348,7 +348,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
def getLineY(line)
|
||||
textchars = getTextChars
|
||||
return 0 if textchars.length == 0
|
||||
totallines = getTotalLines()
|
||||
totallines = getTotalLines
|
||||
line = 0 if line < 0
|
||||
line = totallines - 1 if line >= totallines
|
||||
maximumY = 0
|
||||
@@ -364,7 +364,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
def getColumnsInLine(line)
|
||||
textchars = getTextChars
|
||||
return 0 if textchars.length == 0
|
||||
totallines = getTotalLines()
|
||||
totallines = getTotalLines
|
||||
line = 0 if line < 0
|
||||
line = totallines - 1 if line >= totallines
|
||||
endpos = 0
|
||||
@@ -379,7 +379,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
def getPosFromLineAndColumn(line, column)
|
||||
textchars = getTextChars
|
||||
return 0 if textchars.length == 0
|
||||
totallines = getTotalLines()
|
||||
totallines = getTotalLines
|
||||
line = 0 if line < 0
|
||||
line = totallines - 1 if line >= totallines
|
||||
endpos = 0
|
||||
@@ -405,7 +405,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
end
|
||||
|
||||
def getLastVisibleLine
|
||||
getTextChars()
|
||||
getTextChars
|
||||
textheight = [1, self.contents.text_size("X").height].max
|
||||
lastVisible = @firstline + ((self.height - self.borderY) / textheight) - 1
|
||||
return lastVisible
|
||||
@@ -419,7 +419,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
self.refresh
|
||||
end
|
||||
@firstline = @cursorLine if @cursorLine < @firstline
|
||||
lastVisible = getLastVisibleLine()
|
||||
lastVisible = getLastVisibleLine
|
||||
@firstline += (@cursorLine - lastVisible) if @cursorLine > lastVisible
|
||||
end
|
||||
|
||||
@@ -428,7 +428,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
# can affect line offset)
|
||||
# echoln ["beforemoving",@cursorLine,@cursorColumn]
|
||||
totalColumns = getColumnsInLine(@cursorLine) # check current line
|
||||
totalLines = getTotalLines()
|
||||
totalLines = getTotalLines
|
||||
oldCursorLine = @cursorLine
|
||||
oldCursorColumn = @cursorColumn
|
||||
@cursorColumn += columnOffset
|
||||
@@ -487,7 +487,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
return
|
||||
elsif Input.press?(Input::CTRL) && Input.triggerex?(:END)
|
||||
# Move cursor to end
|
||||
@cursorLine = getTotalLines() - 1
|
||||
@cursorLine = getTotalLines - 1
|
||||
@cursorColumn = getColumnsInLine(@cursorLine)
|
||||
updateCursorPos(true)
|
||||
return
|
||||
@@ -511,7 +511,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
|
||||
getTextChars
|
||||
height = self.height - self.borderY
|
||||
cursorcolor = Color.new(0, 0, 0)
|
||||
textchars = getTextChars()
|
||||
textchars = getTextChars
|
||||
startY = getLineY(@firstline)
|
||||
for i in 0...textchars.length
|
||||
thisline = textchars[i][5]
|
||||
|
||||
Reference in New Issue
Block a user