Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Scene_InputSimple
- # Version : 1.00
- # Author : LiTTleDRAgo
- #==============================================================================
- class Scene_InputSimple
- #--------------------------------------------------------------------------
- # * initialize
- #--------------------------------------------------------------------------
- def initialize(text, icon,digit_max, x=0 , y=0,can_cancel = true)
- @text = text.to_s
- @digit_max = digit_max
- @pos_x = x
- @pos_y = y
- @can_cancel = can_cancel
- cache = Cache
- if icon[/Item(\d+)/i]
- @icon = $data_items[$1.to_i]
- elsif icon[/Armor(\d+)/i]
- @icon = $data_armors[$1.to_i]
- elsif icon[/Weapon(\d+)/i]
- @icon = $data_weapons[$1.to_i]
- elsif icon[/Skill(\d+)/i]
- @icon = $data_skills[$1.to_i]
- end
- end
- #--------------------------------------------------------------------------
- # * main
- #--------------------------------------------------------------------------
- def main
- create_bakground_map
- create_things
- create_transition
- update while $scene == self
- dispose
- end
- #--------------------------------------------------------------------------
- # * create_bakground_map
- #--------------------------------------------------------------------------
- def create_bakground_map
- @menuback_sprite = Sprite.new
- @menuback_sprite.bitmap = $game_temp.background_bitmap
- @menuback_sprite.color.set(16, 16, 16, 128)
- end
- #--------------------------------------------------------------------------
- # * create_things
- #--------------------------------------------------------------------------
- def create_things
- bitmap = Bitmap.new(400,400)
- width = bitmap.text_size(@text).width
- @window_input = Window_InputNumberXP.new(@digit_max)
- text = @window_input.width
- @window_master = Window_Base.new(@pos_x,@pos_y,width+text+60,64)
- @window_input.x = @window_master.x + width + 12
- @window_input.y = @window_master.y + 4
- @all_window = [@window_master,@window_input,@menuback_sprite]
- @window_master.contents = Bitmap.new(@window_master.width-32,@window_master.height-32)
- @window_master.contents.draw_text(3,4,width,32,@text)
- if @icon
- @window_master.contents.draw_text(width+text,4,width,32,'x')
- @window_master.draw_icon(@icon.icon_index, width+text+8,4, true)
- end
- end
- #--------------------------------------------------------------------------
- # * create_transition
- #--------------------------------------------------------------------------
- def create_transition
- Graphics.transition
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- update_grafis
- update_sesungguhnya
- @window_input.update
- end
- #--------------------------------------------------------------------------
- # * update_grafis
- #--------------------------------------------------------------------------
- def update_grafis
- [Graphics,Input].each {|s|s.update}
- end
- #--------------------------------------------------------------------------
- # * update_sesungguhnya
- #--------------------------------------------------------------------------
- def update_sesungguhnya
- if Input.trigger?(Input::C)
- Sound.play_decision
- $output_number = @window_input.number
- $scene = Scene_Map.new
- end
- if Input.trigger?(Input::B)
- return Sound.play_buzzer if !@can_cancel
- Sound.play_cancel
- $output_number = 0
- $scene = Scene_Map.new
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Dispose
- #--------------------------------------------------------------------------
- def dispose
- @all_window.flatten.each {|s| s.dispose}
- end
- end
- #==============================================================================
- # ** Window_InputNumber
- #------------------------------------------------------------------------------
- # This window is for inputting numbers, and is used within the
- # message window.
- #==============================================================================
- class Window_InputNumberXP < Window_Base
- #--------------------------------------------------------------------------
- # * Object Initialization
- # digits_max : digit count
- #--------------------------------------------------------------------------
- def initialize(digits_max)
- @digits_max = digits_max
- @number = 0
- # Calculate cursor width from number width (0-9 equal width and postulate)
- dummy_bitmap = Bitmap.new(32, 32)
- @cursor_width = dummy_bitmap.text_size("0").width + 8
- dummy_bitmap.dispose
- super(0, 0, @cursor_width * @digits_max + 32, 64)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.z += 9999
- self.opacity = 0
- @index = 0
- refresh
- update_cursor_rect
- end
- #--------------------------------------------------------------------------
- # * Get Number
- #--------------------------------------------------------------------------
- def number
- return @number
- end
- #--------------------------------------------------------------------------
- # * Set Number
- # number : new number
- #--------------------------------------------------------------------------
- def number=(number)
- @number = [[number, 0].max, 10 ** @digits_max - 1].min
- refresh
- end
- #--------------------------------------------------------------------------
- # * Cursor Rectangle Update
- #--------------------------------------------------------------------------
- def update_cursor_rect
- self.cursor_rect.set(@index * @cursor_width, 0, @cursor_width, 32)
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
- Sound.play_cursor
- place = 10 ** (@digits_max - 1 - @index)
- n = @number / place % 10
- @number -= n * place
- n = (n + 1) % 10 if Input.repeat?(Input::UP)
- n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
- @number += n * place
- refresh
- end
- if Input.repeat?(Input::RIGHT)
- if @digits_max >= 2
- Sound.play_cursor
- @index = (@index + 1) % @digits_max
- end
- end
- if Input.repeat?(Input::LEFT)
- if @digits_max >= 2
- Sound.play_cursor
- @index = (@index + @digits_max - 1) % @digits_max
- end
- end
- update_cursor_rect
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- self.contents.font.color = normal_color
- s = sprintf("%0*d", @digits_max, @number)
- for i in 0...@digits_max
- self.contents.draw_text(i * @cursor_width + 4, 0, 32, 32, s[i,1])
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement