Advertisement
DaxSoft

dsi

Oct 26th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 24.97 KB | None | 0 0
  1. =begin
  2. [GENERAL]
  3.     by Dax Soft
  4.     www.dax-soft.weebly.com
  5.     &beta
  6.     Requeriments: Ligni Core
  7. [DESCRIPTION]
  8.     Dual Screen system, makes your rpg maker game look like a nintendo ds game.
  9. [VERSION]
  10.     0.3 :
  11.         default UI to DSi UI
  12.         Mouse system
  13.         Setup map to DSi
  14.         Menu
  15.         Message System
  16.     0.32 :
  17.         default cursor to selectable window
  18. [COMMAND TO CALL SCRIPT]
  19.     $game_system.default_background = ""
  20.         picture at graphics/system. Submenu background picture
  21.     $game_system.smdbp = ""
  22.         picture at graphics/system. Button submenu picture
  23.     $game_system.smdbs = "SceneManager.call(Scene_Name)"
  24.         Default scene that shall go when hit the button
  25.     $game_system.cursor_window = true/false
  26.         true to enable/false to disable
  27.     $game_system.cursor_visible = true/false
  28.         true to on/false to off
  29. [CTRL+F : LOCATE]
  30.     :module
  31.     :submenu
  32.     :graphic
  33.     :bitmap
  34.     :game_temp
  35.     :game_system
  36.     :game_map
  37.     :game_player
  38.     :default_submenu_picture
  39.     :window_base
  40.     :window_selectable
  41.     :window_command
  42.     :scene_base
  43.     :scene_menubase
  44.     :scene_map
  45.     :sprite_picture
  46.     :window_message
  47.     :window_choice
  48. =end
  49. Ligni.register(:dsi, "dax", 0.32) {
  50.     # [DEFAULT FONT SETTING]
  51.     Font.default_size = 16
  52.     Font.default_bold = false
  53.     Font.default_italic = false
  54.     Font.default_outline = false
  55.     Font.default_shadow = true
  56.     # [MODULE] :module
  57.     module DS; extend self
  58.         # [version]
  59.         VERSION = "0.32 ~ beta"
  60.         # [SETUP OF CONSTANT]
  61.         SETUP = {
  62.             # setup of menu
  63.             MENU: {
  64.                 # Default background picture
  65.                 BACKGROUND: "MenuBackground",
  66.                 # Default cursor icon menu
  67.                 CURSOR: {
  68.                     # picture at graphics/system
  69.                     PICTURE: "cursor",
  70.                     # Additional position to cursor
  71.                     POS: [-4, 0],
  72.                     # Speed of move
  73.                     SPEED: 0.25,
  74.                 },
  75.             },
  76.             # setup of submenu
  77.             SUBMENU: {
  78.                 # DEFAULT PICTURE TO SUBMENU
  79.                 DF: "Grassland",
  80.                 # Default button function on submenu at map
  81.                 DBT: {
  82.                     # picture of button || default | change with $game_system.smdbp = "nome"
  83.                     PICTURE: "savebutton",
  84.                     # scene that when hit the button, shall go || default | change with $game_system.smdbs
  85.                     SCENE: "SceneManager.call(Scene_Menu)",
  86.                     # switch that can on/off. True to off
  87.                     SWITCH: 1,
  88.                     # position
  89.                     POS: [8, (Graphics.height / 2) + 16],
  90.                     # hit keyboard key.
  91.                     KEY: :Q,
  92.                 },
  93.             },
  94.             # setup of message system
  95.             MESSAGE: {
  96.                 # NUMBER OF VISIBLE LINE ON MESSAGE BOX
  97.                 VL: 2,
  98.                 # DEFAULT PICTURE TO BACKGROUND OF MESSAGE BOX. IF YOU DON'T WANNA JUST
  99.                 # KEEP IT EMPTY
  100.                 DBACK: "",
  101.             },
  102.             # setup of title screen
  103.             TITLE: {
  104.                 # the background picture of up part
  105.                 BACKGROUND_UP: "Title/backup",
  106.                 # the background picture of down part
  107.                 BACKGROUND_DOWN: "Title/backdown",
  108.                 # the title logo picture
  109.                 LOGO: "Title/logo",
  110.             },
  111.         }
  112.         # [GET THE VALUE OF SCREEN and the DEFAULT Z] [:STRUCT]
  113.         def screen
  114.             screen = Struct.new(:DSI_ScreenValue, :width, :sheight, :z, :height).new()
  115.             screen.width, screen.sheight, screen.z, screen.height = 284, 432, 9999, 216
  116.             screen
  117.         end
  118.     end
  119.     # [RESIZE SCREEN]
  120.     Graphics.resize_screen(DS.screen.width, DS.screen.sheight)
  121.     # [GRAPHIC] :graphic
  122.     class << Graphics
  123.         # get width screen value
  124.         def width; DS.screen.width; end;
  125.         # get height screen value
  126.         def height; DS.screen.sheight; end;
  127.     end
  128.     # [BITMAP] :bitmap
  129.     class Bitmap
  130.         #--------------------------------------------------------------------------
  131.         # * Desenho do gráfico de rosto
  132.         #     face_name  : nome do gráfico de face
  133.         #     face_index : índice do gráfico de face
  134.         #     x          : coordenada X
  135.         #     y          : coordenada Y
  136.         #     enabled    : habilitar flag, translucido quando false
  137.         #--------------------------------------------------------------------------
  138.         def draw_face(face_name, face_index, x, y, enabled = true, w=96, h=96)
  139.             bitmap = Cache.face(face_name)
  140.             j = (96 - w) / 2 rescue 0
  141.             rect = Rect.new(face_index % 4 * (96 + j), face_index / 4 * 96, w, h)
  142.             self.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  143.             bitmap.dispose
  144.         end
  145.         #--------------------------------------------------------------------------
  146.         # * Desenho do gráfico de face do herói
  147.         #     actor   : herói
  148.         #     x       : coordenada X
  149.         #     y       : coordenada Y
  150.         #     enabled : habilitar flag, translucido quando false
  151.         #--------------------------------------------------------------------------
  152.         def draw_actor_face(actor, x, y, enabled = true, w=96, h=96)
  153.             draw_face(actor.face_name, actor.face_index, x, y, enabled, w, h)
  154.         end
  155.     end
  156.     # [Game_System] :game_system
  157.     class Game_System
  158.         alias :dsi_init :initialize
  159.         #--------------------------------------------------------------------------
  160.         # * Variáveis públicas
  161.         #--------------------------------------------------------------------------
  162.         attr_accessor :default_background       # Imagem padrão do mapa.
  163.         attr_accessor :smdbp
  164.         attr_accessor :smdbs
  165.         attr_accessor :cursor_menu
  166.         attr_accessor :cursor_visible
  167.         #--------------------------------------------------------------------------
  168.         # * Inicialização dos objetos.
  169.         #--------------------------------------------------------------------------
  170.         def initialize
  171.             dsi_init
  172.             @map_img = nil
  173.             @default_background = nil
  174.             @smdbp = DS::SETUP[:SUBMENU][:DBT][:PICTURE]
  175.             @smdbs = DS::SETUP[:SUBMENU][:DBT][:SCENE]
  176.             @cursor_menu = true
  177.             @cursor_visible = true
  178.         end
  179.     end
  180.     # [Game_Temp] :game_temp
  181.     class Game_Temp
  182.         # vars
  183.         attr_accessor :map_img
  184.         # init
  185.         alias :dsi_init :initialize
  186.         def initialize(*args)
  187.             dsi_init(*args)
  188.             @map_img = nil
  189.         end
  190.     end
  191.     # [Game_Map] :game_map
  192.     class Game_Map
  193.         #----------------------------------------------------------------------------
  194.         # • Variável do mapa.
  195.         #----------------------------------------------------------------------------
  196.         def map
  197.             return @map
  198.         end
  199.         #--------------------------------------------------------------------------
  200.         # * Altura do mapa
  201.         #--------------------------------------------------------------------------
  202.         def height
  203.             @map.height - 1
  204.         end
  205.         #--------------------------------------------------------------------------
  206.         # * Aquisição do números de tiles verticais na tela
  207.         #--------------------------------------------------------------------------
  208.         def screen_tile_y
  209.             DS.screen.height / 32
  210.         end
  211.         #--------------------------------------------------------------------------
  212.         # • Definição de coordenada válida
  213.         #     x : coordenada X
  214.         #     y : coordenada Y
  215.         #--------------------------------------------------------------------------
  216.         def valid?(x, y)
  217.             x >= 0 && x < width && y >= 0 && y < (height + 1)
  218.         end
  219.     end
  220.     # [GAME_PLAYER] :game_player
  221.     class Game_Player < Game_Character
  222.         #--------------------------------------------------------------------------
  223.         # * Variáveis públicas
  224.         #--------------------------------------------------------------------------
  225.         attr_accessor :no_movable
  226.         #--------------------------------------------------------------------------
  227.         # * Inicialização do objeto
  228.         #--------------------------------------------------------------------------
  229.         alias :dsi_init :initialize
  230.         def initialize(*args)
  231.             dsi_init(*args)
  232.             @no_movable = false
  233.         end
  234.         #--------------------------------------------------------------------------
  235.         # • Coordenada X do centro da tela
  236.         #--------------------------------------------------------------------------
  237.         def center_x
  238.             (Graphics.width / 32 - 1) / 1.75
  239.         end
  240.         #--------------------------------------------------------------------------
  241.         # • Coordenada Y do centro da tela
  242.         #--------------------------------------------------------------------------
  243.         def center_y
  244.             (DS.screen.height / 32 - 1) / 1.75
  245.         end
  246.         #--------------------------------------------------------------------------
  247.         # * Definição de mobilidade
  248.         #--------------------------------------------------------------------------
  249.         alias :dsi_movable? :movable?
  250.         def movable?
  251.             return    false if @no_movable
  252.             dsi_movable?
  253.         end
  254.     end
  255.     # [DS::Sub::DMF] :default_submenu_picture
  256.     class DMF < Sprite
  257.         # initialize
  258.         def initialize
  259.             super([DS.screen.width, DS.screen.height, 0, DS.screen.height, DS.screen.z])
  260.             @old_background = $game_system.default_background
  261.             unless $game_system.default_background.nil? or $game_system.default_background.empty?
  262.                 self.bitmap = Cache.system($game_system.default_background)
  263.             else
  264.                 self.bitmap.fill_rect(self.rect, "000000".color)
  265.             end
  266.             Ligni::Position[1, self]
  267.         end
  268.         # dispose
  269.         def dispose
  270.             self.bitmap.dispose
  271.             super
  272.         end
  273.         # update
  274.         def update
  275.             unless @old_background == $game_system.default_background
  276.                 unless $game_system.default_background.nil? or $game_system.default_background.empty?
  277.                     self.bitmap.clear
  278.                     blt = Cache.system($game_system.default_background)
  279.                     self.bitmap.blt(0, 0, blt, Rect.new(0, 0, blt.width, blt.height))
  280.                 else
  281.                     self.bitmap.clear
  282.                     self.bitmap.fill_rect(self.rect, "000000".color)
  283.                 end
  284.                 @old_background = $game_system.default_background
  285.             end
  286.             # ...
  287.         end
  288.     end
  289.     # [Window_Base] :window_base
  290.     class Window_Base < Window
  291.         #--------------------------------------------------------------------------
  292.         # * Desenho do gráfico de rosto
  293.         #     face_name  : nome do gráfico de face
  294.         #     face_index : índice do gráfico de face
  295.         #     x          : coordenada X
  296.         #     y          : coordenada Y
  297.         #     enabled    : habilitar flag, translucido quando false
  298.         #--------------------------------------------------------------------------
  299.         def draw_face(face_name, face_index, x, y, enabled = true, w=96, h=96, zoom=1.0)
  300.             bitmap = Cache.face(face_name)
  301.             j = (96 - w) / 2 rescue 0
  302.             rect = Rect.new(face_index % 4 * (96 + j), face_index / 4 * 96, w, h)
  303.             dltrect = Rect.new(x, y, w*zoom, h*zoom)
  304.             #stretch_blt(dest_rect, src_bitmap, src_rect[, opacity])
  305.             #contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  306.             contents.stretch_blt(dltrect, bitmap, rect, enabled ? 255 : translucent_alpha)
  307.             bitmap.dispose
  308.         end
  309.         #--------------------------------------------------------------------------
  310.         # * Desenho do gráfico de face do herói
  311.         #     actor   : herói
  312.         #     x       : coordenada X
  313.         #     y       : coordenada Y
  314.         #     enabled : habilitar flag, translucido quando false
  315.         #--------------------------------------------------------------------------
  316.         def draw_actor_face(actor, x, y, enabled = true, w=96, h=96, zoom=1.0)
  317.             draw_face(actor.face_name, actor.face_index, x, y, enabled, w, h, zoom)
  318.         end
  319.         def exp_gauge_color1;   text_color(21);  end;    
  320.         def exp_gauge_color2;   text_color(17);  end;
  321.         #--------------------------------------------------------------------------
  322.         # • Desenho do EXP
  323.         #     actor  : herói
  324.         #     x      : coordenada X
  325.         #     y      : coordenada Y
  326.         #     width  : largura
  327.         #--------------------------------------------------------------------------
  328.         def draw_actor_exp(actor, x, y, width = 115)
  329.           draw_gauge(x, y, width, actor.exp.to_f / actor.next_level_exp.to_f, exp_gauge_color1, exp_gauge_color2)
  330.           change_color(system_color)
  331.           draw_text(x, y, 30, line_height,"EXP:")
  332.           draw_current_and_max_values(x, y, width, actor.exp, actor.next_level_exp,
  333.           normal_color, normal_color)
  334.         end  
  335.         #--------------------------------------------------------------------------
  336.         # * Desenho dos atributos básicos
  337.         #     actor : herói
  338.         #     x     : coordenada X
  339.         #     y     : coordenada Y
  340.         #--------------------------------------------------------------------------
  341.         def draw_actor_simple_status(actor, x, y)
  342.           draw_actor_name(actor, x, y)
  343.           draw_actor_level(actor, x, y + line_height * 1)
  344.           draw_actor_icons(actor, x, y + line_height * 2)
  345.           draw_actor_class(actor, x + 120, y)
  346.           draw_actor_hp(actor, x + 120, y + line_height * 1, 64)
  347.           draw_actor_mp(actor, x + 120, y + line_height * 2, 64)
  348.         end
  349.     end
  350.     # [Window_Selectable] :window_selectable
  351.     class Window_Selectable < Window_Base
  352.         #--------------------------------------------------------------------------
  353.         # * Definição de controle de confirmação e cancelamento
  354.         #--------------------------------------------------------------------------
  355.         def process_handling
  356.             return unless open? && active
  357.             return process_ok       if ok_enabled?  && (trigger?(:C) or trigger?(0x01))
  358.             return process_cancel   if cancel_enabled? && (trigger?(:B) or trigger?(0x02))
  359.             return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  360.             return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  361.         end
  362.         #--------------------------------------------------------------------------
  363.         # * Atualização da tela
  364.         #--------------------------------------------------------------------------
  365.         alias :dsi_mouse_update :update
  366.         def update
  367.             dsi_mouse_update
  368.             process_mouse_handling if self.active && self.open
  369.         end
  370.         #--------------------------------------------------------------------------
  371.         # * Configuração do processo de movimento do Mouse.
  372.         #--------------------------------------------------------------------------
  373.         def process_mouse_handling
  374.             @delay = @delay ? @delay + 1 : 0
  375.             return if @delay % 3 > 0
  376.             mx, my = Ligni::Mouse.x, Ligni::Mouse.y
  377.             vx = self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x
  378.             vy = self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y
  379.             if mx.between?(vx, vx + self.width) && my.between?(vy, vy + self.height)
  380.                 mx -= vx + padding
  381.                 my -= vy + padding
  382.                 my += oy
  383.                 (0...item_max).each { |i|
  384.                 rect = item_rect(i)
  385.                 next unless mx.between?(rect.x, rect.x + rect.width) && my.between?(rect.y, rect.y + rect.height)
  386.                 last_index = @index
  387.                 select(i)
  388.                     Sound.play_cursor unless @index == last_index
  389.                     break
  390.                 }
  391.             end
  392.         end
  393.     end
  394.     # [Window_Command] :window_command
  395.     class Window_Command < Window_Selectable
  396.         #--------------------------------------------------------------------------
  397.         # * Inicialização do objeto
  398.         #     x      : coordenada X
  399.         #     y      : coordenada Y
  400.         #--------------------------------------------------------------------------
  401.         def initialize(x, y, width=nil, line=nil)
  402.             clear_command_list
  403.             make_command_list
  404.             super(x, y, width || window_width, line.nil? ? window_height : fitting_height(line))
  405.             refresh
  406.             select(0)
  407.             activate
  408.         end
  409.     end
  410.     # [Scene_Base] :scene_base
  411.     class Scene_Base
  412.         alias :dsi_start :start
  413.         alias :dsi_update :update
  414.         alias :dsi_terminate :terminate
  415.         #--------------------------------------------------------------------------
  416.         # * Inicialização do processo
  417.         #--------------------------------------------------------------------------
  418.         def start
  419.             dsi_start
  420.             $game_temp.map_img = DMF.new
  421.         end
  422.         #--------------------------------------------------------------------------
  423.         # * Atualização da tela
  424.         #--------------------------------------------------------------------------
  425.         def update
  426.             dsi_update
  427.             $game_temp.map_img.update rescue nil
  428.         end
  429.         #--------------------------------------------------------------------------
  430.         # * Finalização do processo
  431.         #--------------------------------------------------------------------------
  432.         def terminate
  433.             dsi_terminate
  434.             $game_temp.map_img.dispose rescue nil
  435.         end
  436.     end
  437.     # [Scene_MenuBase] :scene_menubase
  438.     class Scene_MenuBase < Scene_Base
  439.         #--------------------------------------------------------------------------
  440.         # * Criação do plano de fundo
  441.         #--------------------------------------------------------------------------
  442.         def create_background
  443.             @background_sprite = Sprite.new
  444.             @background_sprite.bitmap = SceneManager.background_bitmap
  445.             @background_sprite.color.set(0, 0, 0, 0)
  446.         end
  447.  
  448.         #--------------------------------------------------------------------------
  449.         # * Criação da janela de ajuda.
  450.         #--------------------------------------------------------------------------
  451.         def create_help_window
  452.             @help_window = Window_Help.new
  453.         end
  454.     end
  455.     # [Scene_Map] :scene_map
  456.     class Scene_Map < Scene_Base
  457.         alias :dsi_start3 :start
  458.         #--------------------------------------------------------------------------
  459.         # * Inicialização do processo
  460.         #--------------------------------------------------------------------------
  461.         def start
  462.             $game_system.default_background = DS::SETUP[:SUBMENU][:DF]
  463.             dsi_start3
  464.         end
  465.     end
  466.     # [Sprite_Picture] :sprite_picture
  467.     class Sprite_Picture < Sprite
  468.         #----------------------------------------------------------------------------
  469.         # • Atualização dos objetos.
  470.         #----------------------------------------------------------------------------
  471.         def update
  472.             super
  473.             unless @picture.name == ""
  474.                 update_bitmap
  475.                 update_origin
  476.                 update_position
  477.                 update_zoom
  478.                 update_other
  479.             else
  480.                 self.bitmap.dispose unless self.bitmap.nil?
  481.             end
  482.         end
  483.     end
  484.     # [Window_Message] :window_message
  485.     class Window_Message < Window_Base
  486.         #--------------------------------------------------------------------------
  487.         # * Inicialização do objeto
  488.         #--------------------------------------------------------------------------
  489.         alias :dsi_msg_init :initialize
  490.         def initialize(*args)
  491.             dsi_msg_init
  492.             unless DS::SETUP[:MESSAGE][:DBACK].empty?
  493.                 @background_msgbox = Sprite.new("S: #{DS::SETUP[:MESSAGE][:DBACK]}")
  494.                 @background_msgbox.visible = false
  495.             end
  496.         end
  497.         #--------------------------------------------------------------------------
  498.         # * Aquisição do número de linhas exibidas
  499.         #--------------------------------------------------------------------------
  500.         def visible_line_number
  501.              return DS::SETUP[:MESSAGE][:VL]
  502.         end
  503.         #--------------------------------------------------------------------------
  504.         # * Disposição
  505.         #--------------------------------------------------------------------------
  506.         alias :dsi_msg_dispose :dispose
  507.         def dispose
  508.             dsi_msg_dispose
  509.             @background_msgbox.dispose rescue nil
  510.         end
  511.         #--------------------------------------------------------------------------
  512.         # * Atualização da tela
  513.         #--------------------------------------------------------------------------
  514.         alias :dsi_msg_update :update
  515.         def update
  516.             dsi_msg_update
  517.             unless DS::SETUP[:MESSAGE][:DBACK].empty?
  518.                 @background_msgbox.x, @background_msgbox.y, @background_msgbox.z = self.x, self.y, self.z-1
  519.                 self.opacity = 0
  520.                 @background_msgbox.visible = $game_message.visible
  521.             end
  522.         end
  523.         #--------------------------------------------------------------------------
  524.         # * Atualização da posição da janela
  525.         #--------------------------------------------------------------------------
  526.         def update_placement
  527.             self.z = DS.screen.z
  528.             @position = $game_message.position
  529.             self.y = @position * (DS.screen.height - height) / 2
  530.             @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height
  531.         end
  532.         #--------------------------------------------------------------------------
  533.         # * Execução de espera de entrada
  534.         #--------------------------------------------------------------------------
  535.         def input_pause
  536.             self.pause = true
  537.             wait(10)
  538.             Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C) || trigger?(0x02) || trigger?(0x01)
  539.             Input.update
  540.             self.pause = false
  541.         end
  542.         #--------------------------------------------------------------------------
  543.         # * Definição de quebra de página
  544.         #     text : texto
  545.         #     pos  : posição
  546.         #--------------------------------------------------------------------------
  547.         def new_page(text, pos)
  548.             contents.clear
  549.             draw_face($game_message.face_name, $game_message.face_index, 0, 5, true, 96, 96, 0.4)
  550.             reset_font_settings
  551.             pos[:x] = new_line_x
  552.             pos[:y] = 0
  553.             pos[:new_x] = new_line_x
  554.             pos[:height] = calc_line_height(text)
  555.             clear_flags
  556.         end
  557.         #--------------------------------------------------------------------------
  558.         # * Definição de quebra de linha
  559.         #--------------------------------------------------------------------------
  560.         def new_line_x
  561.             $game_message.face_name.empty? ? 0 : 32 + 16
  562.         end
  563.     end
  564.     # [Window_ChoiceList] :window_choice
  565.     class Window_ChoiceList < Window_Command
  566.         #--------------------------------------------------------------------------
  567.         # * Inicialização do objeto
  568.         #     message_window : janela de mensagem
  569.         #--------------------------------------------------------------------------
  570.         def initialize(message_window)
  571.             @message_window = message_window
  572.             super(0, DS.screen.height + 6)
  573.             self.z = DS.screen.z + 10
  574.             self.openness = 0
  575.             deactivate
  576.         end
  577.  
  578.         #--------------------------------------------------------------------------
  579.         # * Atualização da posição da janela
  580.         #--------------------------------------------------------------------------
  581.         def update_placement
  582.             self.width = [max_choice_width + 12, 164].max + padding * 2
  583.             self.width = [width, Graphics.width].min
  584.             self.height = fitting_height($game_message.choices.size)
  585.             Ligni::Position[1, self]
  586.             self.y = DS.screen.height + ((DS.screen.height - (self.height)) / 2)
  587.         end
  588.     end
  589. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement