mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-19 13:29:54 +00:00
211 lines
6 KiB
Ruby
211 lines
6 KiB
Ruby
class Window_Settings
|
|
MARGIN = 15
|
|
TITLE_TOP_MARGIN = 16
|
|
TITLE_MARGIN = 40
|
|
ITEM_SPACING = 20
|
|
VALUE_MARGIN = 270
|
|
ACTIVE_MARGIN = MARGIN * 2 + 20
|
|
|
|
def initialize
|
|
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
|
|
@viewport.z = 9998
|
|
@bg = Sprite.new(@viewport)
|
|
@bg.bitmap = Bitmap.new(Graphics.width, Graphics.height)
|
|
@bg.bitmap.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(255, 255, 255, 128))
|
|
@bg.blend_type = 2
|
|
@title = Sprite.new(@viewport)
|
|
@title.bitmap = Bitmap.new(320, TITLE_MARGIN)
|
|
@title.bitmap.font.size = 20
|
|
@title.zoom_x = @title.zoom_y = 2
|
|
@title.y = TITLE_TOP_MARGIN
|
|
@title.x = MARGIN
|
|
@title.bitmap.draw_text(0, 0, @title.bitmap.width, @title.bitmap.height, tr("Settings"))
|
|
Language.register_text_sprite(self.class.name + "_title", @title)
|
|
|
|
@content = SettingsContent.new(@viewport, TITLE_TOP_MARGIN + TITLE_MARGIN + 100)
|
|
|
|
DATA.each_with_index do |(screen_title, parameters_info), screen_index|
|
|
@content.add_screen(screen_title)
|
|
parameters_info.each_with_index do |parameter_info, parameter_index|
|
|
if parameters_info == :sep
|
|
@content.add_parameter(screen_title, Separator.new(@content, screen_index, parameter_index, ""))
|
|
else
|
|
case parameter_info[:type]
|
|
when :base
|
|
@content.add_parameter(screen_title, BaseParameter.new(@content, screen_index, parameter_index,
|
|
parameter_info[:name], parameter_info[:parameter], parameter_info[:default]))
|
|
when :bool
|
|
@content.add_parameter(screen_title, BoolParameter.new(@content, screen_index, parameter_index,
|
|
parameter_info[:name], parameter_info[:parameter], parameter_info[:default]))
|
|
when :int
|
|
@content.add_parameter(screen_title, IntParameter.new(@content, screen_index, parameter_index,
|
|
parameter_info[:name], parameter_info[:parameter], parameter_info[:default], parameter_info[:min], parameter_info[:max]))
|
|
when :enum
|
|
@content.add_parameter(screen_title, EnumParameter.new(@content, screen_index, parameter_index,
|
|
parameter_info[:name], parameter_info[:parameter], 0, parameter_info[:values]))
|
|
when :sep
|
|
@content.add_parameter(screen_title, Separator.new(@content, screen_index, parameter_index,
|
|
parameter_info[:name]))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
@content.redraw_all
|
|
|
|
@left_hold_timer = 0
|
|
@right_hold_timer = 0
|
|
|
|
@up_hold_timer = 0
|
|
@down_hold_timer = 0
|
|
|
|
@visible = self.visible = false
|
|
RPG::Mod.exec_hooks("hooks/Window_Settings/init", binding)
|
|
end
|
|
|
|
def dispose
|
|
@bg.dispose
|
|
@title.dispose
|
|
@content.dispose
|
|
end
|
|
|
|
def open
|
|
self.visible = true
|
|
self.opacity = 0
|
|
@fade_in = true
|
|
end
|
|
|
|
def redraw_setting(screen, index)
|
|
if @visible == false
|
|
return
|
|
end
|
|
|
|
@content.get_parameter_by_sceen_id(screen, index)&.redraw
|
|
end
|
|
|
|
def self.load_settings
|
|
Settings.load!
|
|
end
|
|
|
|
def update
|
|
if self.visible
|
|
@content.update
|
|
end
|
|
|
|
if @fade_in
|
|
self.opacity += 20
|
|
if self.opacity == 255
|
|
@fade_in = false
|
|
end
|
|
return
|
|
end
|
|
|
|
if @fade_out
|
|
self.opacity -= 20
|
|
if self.opacity == 0
|
|
@fade_out = false
|
|
self.visible = false
|
|
end
|
|
return
|
|
end
|
|
|
|
return if !self.visible
|
|
|
|
# navigation
|
|
if Input.wheel_y != 0
|
|
@content.parameter_select_offset(-Input.wheel_y.round)
|
|
$game_system.se_play($data_system.cursor_se)
|
|
end
|
|
|
|
if (Input.trigger?(Input::L))
|
|
@content.screen_left
|
|
$game_system.se_play($data_system.cursor_se)
|
|
end
|
|
if (Input.trigger?(Input::R))
|
|
@content.screen_right
|
|
$game_system.se_play($data_system.cursor_se)
|
|
end
|
|
|
|
# hold timers
|
|
if Input.press?(Input::LEFT)
|
|
@left_hold_timer += 1
|
|
else
|
|
@left_hold_timer = 0
|
|
end
|
|
|
|
if Input.press?(Input::RIGHT)
|
|
@right_hold_timer += 1
|
|
else
|
|
@right_hold_timer = 0
|
|
end
|
|
|
|
if Input.press?(Input::UP)
|
|
@up_hold_timer += 1
|
|
else
|
|
@up_hold_timer = 0
|
|
end
|
|
|
|
if Input.press?(Input::DOWN)
|
|
@down_hold_timer += 1
|
|
else
|
|
@down_hold_timer = 0
|
|
end
|
|
|
|
#parameters navigation
|
|
if Input.trigger?(Input::UP) || (Input.press?(Input::UP) && (@up_hold_timer >= 15))
|
|
@up_hold_timer -= 2
|
|
@content.parameter_up
|
|
$game_system.se_play($data_system.cursor_se)
|
|
elsif Input.trigger?(Input::DOWN) || (Input.press?(Input::DOWN) && (@down_hold_timer >= 15))
|
|
@down_hold_timer -= 2
|
|
@content.parameter_down
|
|
$game_system.se_play($data_system.cursor_se)
|
|
end
|
|
|
|
# parameter setting
|
|
current_parameter = @content.get_current_parameter
|
|
old_val = current_parameter&.value
|
|
if Input.trigger?(Input::LEFT) || (Input.press?(Input::LEFT) && (@left_hold_timer >= 15))
|
|
@left_hold_timer -= 2
|
|
@content.parameter_left
|
|
elsif Input.trigger?(Input::RIGHT) || (Input.press?(Input::RIGHT) && (@right_hold_timer >= 15))
|
|
@right_hold_timer -= 2
|
|
@content.parameter_right
|
|
end
|
|
if (Input.trigger?(Input::ACTION))
|
|
current_parameter&.action
|
|
end
|
|
current_val = current_parameter&.value
|
|
if current_val != old_val
|
|
current_type = current_parameter&.class&.const_get(:TYPE)
|
|
if current_type == :int || current_type == :enum
|
|
Audio.se_play("Audio/SE/text_robot.wav", 70, ((current_val.to_f + current_parameter.min_value.to_f) / (current_parameter.max_value.to_f + current_parameter.min_value.to_f) * 50.0).to_i + 75)
|
|
elsif current_type == :bool
|
|
Audio.se_play("Audio/SE/text_robot.wav", 70, current_val ? 125 : 75)
|
|
end
|
|
end
|
|
|
|
# menu closing
|
|
if Input.trigger?(Input::CANCEL)
|
|
$game_system.se_play($data_system.cancel_se)
|
|
@fade_out = true
|
|
|
|
Settings.save!
|
|
end
|
|
end
|
|
|
|
# Attributes
|
|
def visible
|
|
return @visible
|
|
end
|
|
def visible=(val)
|
|
@viewport.visible = val
|
|
@visible = val
|
|
end
|
|
def opacity=(val)
|
|
@bg.opacity = val
|
|
@content.opacity = val
|
|
end
|
|
def opacity
|
|
@bg.opacity
|
|
end
|
|
end
|