| Ancien membre du staff |
 |
 |
Inscrit le: 16 Avr 2007, 00:00 Messages: 174 Logiciel(s) préféré(s): RPGMaker XP Points d'aide: 21/60
Créations :
- Trier les objets par onglet
- Alone
- Icone dans le menu
Voir ses créations
|
Bonjour à tous, voici un script que je viens de faire pour vous, il permet d'afficher une icône devant une sélection dans un menu, lisez l'en-tête du script pour plus de détails. Si vous voyez quelque chose de pas super, un bug ou si vous avez des idées d'amélioration, merci de m'envoyer un MP. Window_With_Icon : - Code: Tout sélectionner
#============================================================================== # Ajout d'une icone à une fenetre de selection #------------------------------------------------------------------------------ # Script de Sunabozu # Fait le samedi 07/11/09 # Mis à jour le mercredi 07/04/10 #------------------------------------------------------------------------------ # Ce script permet d'afficher une icone devant la selection dans un menu # Merci de ne pas distribuer ce script sans ma permission # Si vous avez un problème, contactez moi sur RPG Creative #------------------------------------------------------------------------------ # ● Vous pouvez personnaliser ce script grace au constante au tout debut du script #------------------------------------------------------------------------------ # ● Vous pouvez retirer le rectangle de selection en modifiant la # constante CURSOR_RECT_EMPTY sur true # ● Donner a ICON_NAME le nom de votre icone qui se trouve dans le dossier "Icons" # ● Si vous voulez que l'icone se déplace mettez : # ICON_MOVE_H sur 1 pour un deplacement horizontal # ICON_MOVE_V sur 1 pour un deplacement vertical # ● Si vous voulez augmenter la largeur de deplacement de l'icone, # modifiez la valeur de ICON_AMPLITUDE # ● Si vous voulez augmenter la vitesse de deplacement de l'icone # diminuez la valeur de ICON_WAIT (plus rapide possible = 0) # ● Si vous faites la commande "entrer nom d'un héro" ou "entrer un nombre", # il n'y aura pas d'icone car cela provoque une mauvaise lisibilité #============================================================================== # ** Window_Selectable #------------------------------------------------------------------------------ # This window class contains cursor movement and scroll functions. #==============================================================================
class Window_Base < Window #-------------------------------------------------------------------------- # Definition des constantes #-------------------------------------------------------------------------- CURSOR_RECT_EMPTY = true # false=rectangle visible, true= rectangle invisible ICON_NAME = "fleche" # nom de l'icone mise dans le dossier icone ICON_MOVE_H = 0 # 0=pas de mouvement horizontal, 1= mouvement horizontal ICON_MOVE_V = 1 # 0=pas de mouvement vertical, 1= mouvement vertical ICON_AMPLITUDE = 4 # nombre de pixel de deplacement vers le haut ou le bas ICON_WAIT = 4 # attente avant de deplacer l'icone end
class Window_Selectable < Window_Base #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :index # cursor position attr_reader :help_window # help window #-------------------------------------------------------------------------- # * Object Initialization # x : window x-coordinate # y : window y-coordinate # width : window width # height : window height #-------------------------------------------------------------------------- def initialize(x, y, width, height) super(x, y, width, height) @item_max = 1 @column_max = 1 @index = -1 @icon = Sprite.new @icon.z = self.z + 1000 @icon.visible = false @icon_h = 0 @move_h = ICON_MOVE_H @move_v = ICON_MOVE_V @wait = 0 @refresh_icon = false @cursor_rect_empty = CURSOR_RECT_EMPTY self.refresh_icon end #-------------------------------------------------------------------------- # * Set Cursor Position # index : new cursor position #-------------------------------------------------------------------------- def index=(index) @index = index # Update Help Text (update_help is defined by the subclasses) if self.active and @help_window != nil update_help end if index < 0 @icon.visible = false else self.refresh_icon end # Update cursor rectangle update_cursor_rect end #-------------------------------------------------------------------------- # * Update Cursor Rectangle #-------------------------------------------------------------------------- def update_cursor_rect # If cursor position is less than 0 if @index < 0 self.cursor_rect.empty @icon.visible = false else # rendre le rectangle invisible self.cursor_rect.empty # Get current row row = @index / @column_max # If current row is before top row if row < self.top_row # Scroll so that current row becomes top row self.top_row = row end # If current row is more to back than back row if row > self.top_row + (self.page_row_max - 1) # Scroll so that current row becomes back row self.top_row = row - (self.page_row_max - 1) end # Calculate cursor width cursor_width = self.width / @column_max - 32 # Calculate cursor coordinates x = @index % @column_max * (cursor_width + 32) y = @index / @column_max * 32 - self.oy # Update cursor rectangle self.cursor_rect.set(x, y, cursor_width, 32) if not @cursor_rect_empty @wait += 1 return if @wait < ICON_WAIT self.move_icon(x, y) end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super if @icon.bitmap == nil @icon.bitmap = RPG::Cache.icon(ICON_NAME) @icon_h = @icon.bitmap.height self.refresh_icon if @index >= 0 end # If cursor is movable if self.active and @item_max > 0 and @index >= 0 # If pressing down on the directional buttons if Input.repeat?(Input::DOWN) # If column count is 1 and directional button was pressed down with no # repeat, or if cursor position is more to the front than # (item count - column count) if (@column_max == 1 and Input.trigger?(Input::DOWN)) or @index < @item_max - @column_max # Move cursor down $game_system.se_play($data_system.cursor_se) @index = (@index + @column_max) % @item_max @refresh_icon = true end end # If the up directional button was pressed if Input.repeat?(Input::UP) # If column count is 1 and directional button was pressed up with no # repeat, or if cursor position is more to the back than column count if (@column_max == 1 and Input.trigger?(Input::UP)) or @index >= @column_max # Move cursor up $game_system.se_play($data_system.cursor_se) @index = (@index - @column_max + @item_max) % @item_max @refresh_icon = true end end # If the right directional button was pressed if Input.repeat?(Input::RIGHT) # If column count is 2 or more, and cursor position is closer to front # than (item count -1) if @column_max >= 2 and @index < @item_max - 1 # Move cursor right $game_system.se_play($data_system.cursor_se) @index += 1 @refresh_icon = true end end # If the left directional button was pressed if Input.repeat?(Input::LEFT) # If column count is 2 or more, and cursor position is more back than 0 if @column_max >= 2 and @index > 0 # Move cursor left $game_system.se_play($data_system.cursor_se) @index -= 1 @refresh_icon = true end end # If R button was pressed if Input.repeat?(Input::R) # If bottom row being displayed is more to front than bottom data row if self.top_row + (self.page_row_max - 1) < (self.row_max - 1) # Move cursor 1 page back $game_system.se_play($data_system.cursor_se) @index = [@index + self.page_item_max, @item_max - 1].min self.top_row += self.page_row_max @refresh_icon = true end end # If L button was pressed if Input.repeat?(Input::L) # If top row being displayed is more to back than 0 if self.top_row > 0 # Move cursor 1 page forward $game_system.se_play($data_system.cursor_se) @index = [@index - self.page_item_max, 0].max self.top_row -= self.page_row_max @refresh_icon = true end end end # Update help text (update_help is defined by the subclasses) if self.active and @help_window != nil update_help end if @refresh_icon self.refresh_icon @refresh_icon = false end # Update cursor rectangle update_cursor_rect # définit visiblité de l'icone if self.visible and self.active @icon.visible = true else @icon.visible = false end end #-------------------------------------------------------------------------- # * Move Icon #-------------------------------------------------------------------------- def move_icon(x, y) if @icon.visible # deplacer l'icone horizontalement if @move_h != 0 if @icon.x >= self.x + x + ICON_AMPLITUDE @move_h = -1 elsif @icon.x <= self.x + x - ICON_AMPLITUDE @move_h = +1 end @icon.x += @move_h end # deplacer l'icone verticalement if @move_v != 0 if @icon.y >= self.y + y + 16 +(32-@icon_h)/2 + ICON_AMPLITUDE @move_v = -1 elsif @icon.y <= self.y + y + 16 +(32-@icon_h)/2 - ICON_AMPLITUDE @move_v = +1 end @icon.y += @move_v end @wait = 0 end end #-------------------------------------------------------------------------- # * Refresh Icon : régler position de l'icone #-------------------------------------------------------------------------- def refresh_icon # Calculate cursor width cursor_width = self.width / @column_max - 32 row = @index / @column_max # Definir nouvelle position de l'icone # si la fenetre est une Window_MenuStatus ------ if self.is_a?(Window_MenuStatus) @icon.x = self.x @icon.y = self.y + 16 + (32-@icon_h)/2 + (@index * 116) + 32 # si la fenetre est une Window_PartyCommand ------ elsif self.is_a?(Window_PartyCommand) @icon.x = self.x + 160 + @index * 160 @icon.y = self.y + 16 + (32-@icon_h)/2 # si la fenetre est une Window_Target ------ elsif self.is_a?(Window_Target) @icon.x = self.x if @index <= -2 @icon.y = self.y + 16 + (32-@icon_h)/2 + (@index + 10) * 116 + 32 elsif @index == -1 @icon.y = self.y + 16 + (32-@icon_h)/2 + (@item_max * 116)/2 - 20 else @icon.y = self.y + 16 + (32-@icon_h)/2 + @index * 116 + 32 end # si la fenetre est une Window_Message ------ elsif self.is_a?(Window_Message) @icon.x = self.x + 8 if $game_temp.choice_start > 4 @icon.y = self.y + 16 + (32-@icon_h)/2 + 32 else @icon.y = self.y + 16 + (32-@icon_h)/2 + 32 * ($game_temp.choice_start + @index) end # sinon c'est juste une Window_Selectable ------ else @icon.x = self.x + @index % @column_max * (cursor_width + 32) if ( row < self.top_row ) @icon.y = self.y + 16 + (32-@icon_h)/2 elsif ( row > self.top_row + (self.page_row_max - 1) ) @icon.y = self.y + self.height - 16 - 32 + (32-@icon_h) / 2 else @icon.y = self.y + 16 + (32-@icon_h)/2 + @index / @column_max * 32 - self.oy end end end #-------------------------------------------------------------------------- # * Visible #-------------------------------------------------------------------------- def visible=(bool) super(bool) if bool and self.active @icon.visible = true else @icon.visible = false end end #-------------------------------------------------------------------------- # * Dispose #-------------------------------------------------------------------------- def dispose super if @icon != nil @icon.dispose @icon = nil end end end
Window_With_Icon_Adds : - Code: Tout sélectionner
#============================================================================== # Ajout d'une icone à une fenetre de selection #------------------------------------------------------------------------------ # Script de Sunabozu #------------------------------------------------------------------------------ # Modifications dans certaines classes afin de supporter l'affichage de l'icone #============================================================================== class Window_MenuStatus < Window_Selectable def update_cursor_rect if @index < 0 self.cursor_rect.empty @icon.visible = false else # Calculate cursor width cursor_width = self.width / @column_max - 32 # Calculate cursor coordinates y = @index * 116 + 32 # Update cursor rectangle self.cursor_rect.set(0, @index * 116, self.width - 32, 96) if not @cursor_rect_empty @icon.visible = true @wait += 1 return if @wait < ICON_WAIT self.move_icon(0, y) end end end
################################################################## class Window_PartyCommand < Window_Selectable def update_cursor_rect if @index < 0 self.cursor_rect.empty @icon.visible = false else self.cursor_rect.set(160 + @index * 160, 0, 128, 32) if not @cursor_rect_empty # Calculate cursor width cursor_width = self.width / @column_max - 32 # Calculate cursor coordinates x = 160 + @index * 160 y = 0 # Update cursor rectangle self.cursor_rect.set(160 + index * 160, 0, 128, 32) if not @cursor_rect_empty @icon.visible = true @wait += 1 return if @wait < ICON_WAIT self.move_icon(x, y) end end end
################################################################## class Window_Target < Window_Selectable def update_cursor_rect if @index <= -2 self.cursor_rect.set(0, (@index + 10) * 116, self.width - 32, 96) if not @cursor_rect_empty y = (@index + 10) * 116 + 32 elsif @index == -1 self.cursor_rect.set(0, 0, self.width - 32, @item_max * 116 - 20) if not @cursor_rect_empty y = (@item_max * 116)/2 - 20 else self.cursor_rect.set(0, @index * 116, self.width - 32, 96) if not @cursor_rect_empty y = @index * 116 + 32 end @icon.visible = true @wait += 1 return if @wait < ICON_WAIT self.move_icon(0, y) end end
################################################################## class Window_Message < Window_Selectable def update_cursor_rect if @index >= 0 n = $game_temp.choice_start + @index self.cursor_rect.set(8, n * 32, @cursor_width, 32) if not @cursor_rect_empty @icon.z = 9999 self.z -= 1 @icon.visible = true @wait += 1 return if @wait < ICON_WAIT self.move_icon(8, n*32) else self.cursor_rect.empty @icon.visible = false end end end
################################################################## class Window_SaveFile < Window_Base def update super self.update_cursor_rect end def dispose super if @icon != nil @icon.dispose @icon = nil end end def update_cursor_rect if @icon == nil @icon = Sprite.new @icon.z = self.z + 1000 @icon.bitmap = RPG::Cache.icon(ICON_NAME) @icon_h = @icon.bitmap.height @icon.x = self.x @icon.y = self.y + 16 +(32-@icon_h)/2 @move_h = ICON_MOVE_H @move_v = ICON_MOVE_V @wait = 0 end if @selected @icon.visible = true self.cursor_rect.set(0, 0, @name_width + 8, 32) if not @cursor_rect_empty @wait += 1 return if @wait < ICON_WAIT self.move_icon(0, 0) else @icon.visible = false self.cursor_rect.empty end end def move_icon(x, y) if @icon.visible # deplacer l'icone horizontalement if @move_h != 0 if @icon.x >= self.x + x + ICON_AMPLITUDE @move_h = -1 elsif @icon.x <= self.x + x - ICON_AMPLITUDE @move_h = +1 end @icon.x += @move_h end # deplacer l'icone verticalement if @move_v != 0 if @icon.y >= self.y + y + 16 +(32-@icon_h)/2 + ICON_AMPLITUDE @move_v = -1 elsif @icon.y <= self.y + y + 16 +(32-@icon_h)/2 - ICON_AMPLITUDE @move_v = +1 end @icon.y += @move_v end @wait = 0 end end end
################################################################## class Scene_Battle alias phase3_setup_command_window_suna phase3_setup_command_window def phase3_setup_command_window phase3_setup_command_window_suna # rafraichir la nouvelle position de l'icone @actor_command_window.refresh_icon end end
|
|