[XP] Enhanced Details

Started by Xuroth, March 10, 2011, 07:00:46 pm

Previous topic - Next topic

Xuroth

March 10, 2011, 07:00:46 pm Last Edit: March 23, 2011, 05:11:27 am by Xuroth
Enhanced Details
Authors: Xuroth
Version: 0.9
Type: Details Display
Key Term: Menu Add-on



Introduction

This is my first script! This script allows you to show details for your Items, Weapons, Armors, Skills, and Characters. This is just a very basic system.


Features


  • Show Item details!

  • Show Armor details!

  • Show Weapon details!

  • Show Skill details!

  • Show Character Biographies!

  • Display 10 lines of text!

  • Display Custom Pictures in Scene!




Screenshots
I suppose you can have one: ShowHide




Demos
http://www.mediafire.com/?5dyfj896yfsj132 MediaFire (195.14KB)(Version 0.7)
http://www.mediafire.com/?mk3knsq3b2ueccd MediaFire (230.16KB)(Version 0.9) <- NEW


Script


Spoiler: ShowHide

#===============================================================================
#                                Expanded Details
#                                   by: Xuroth
#                                      v0.9
#-------------------------------------------------------------------------------
#  Intro: This script allows you to display details for any selected item.
#         You can use this for adding a bit more depth to your game. To view
#         details, just go to your Item Menu and press the Shift key!
#
#
#  Features:
#      - Display 10 lines of text for more info than other similar scripts
#      - Reads data from text files
#      - Skill Details
#      - Character Biography
#      - Shows custom pictures (Requested by LiTTleDRAgo)
#     
#  Planned Future Features:
#      - Unlimited lines
#      - Optional Detailed Stats
#      - and more!
#
#-------------------------------------------------------------------------------
#  How to set up:
#        You will need 5 text files named 'Item_Detail.rxdata',
#        'Weapon_Detail.rxdata', 'Armor_Detail.rxdata', 'Skill_Detail.rxdata',
#         and 'Actor_Detail.rxdata. These are simple .txt files renamed with
#         the .rxdata extension. The first 10 lines are reserved, but every 10
#         lines after that is used for each item. example:
#
#         lines 11-20 = object #1 in database(actors, skills, items, etc)
#
#-------------------------------------------------------------------------------
#  Version History
#      -0.5 Initial Completion
#      -0.6 Updated some code, bug fixes
#      -0.7 Added Skill Descriptions, Initial release
#      -0.8 Added Character Bios, modified code
#      -0.9 Added custom graphics display, modified code
#
#-------------------------------------------------------------------------------
#  Credits:
#      - Xuroth (for script)
#      - game_guy (for help with alias)
#      - DerVVulfman (help with basic coding and original idea)
#      - Blizzard
#      - ForeverZer0
#
#   Thanks to all the above scripters! Just by making your awesome scripts, you
#   all have inspired me to take up the art. Thanks for helping me with various
#   problems, and I hope to learn more from all of you!
#
#===============================================================================

#=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
##
##                             Configuration
##
#=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
#  For now, there are only a few constants that can be edited to customize the
#  the look. In future versions, there will be more to change as I add new
#  features.
#     TITLE_FONT     -Define which font to use for the object name
#     TITLE_SIZE     -font size for the object name
#     TITLE_COLOR    -Item name color (R, G, B, O)
#     
#     DESC_FONT      -Font style for the description text
#     DESC_SIZE      -Size of the text in the description
#     DESC_COLOR     -Color of Description text...
#
#     BIO_NAME       -String that should be displayed for actor biographies
#     DESC_NAME      -String for the 'Description:' header
#
#     USE_PIC        -Set to true to use a picture from "Graphics/Pictures"
#  Thats it for now. Enjoy!
#-------------------------------------------------------------------------------
module Xuroth
  DESC_FONT = 'Tahoma'
  DESC_SIZE = 20
  DESC_COLOR = Color.new (255, 255, 255, 255) #White is default
 
  TITLE_FONT = 'Tahoma'
  TITLE_SIZE = 24
  TITLE_COLOR = Color.new(0, 255, 0, 255) #Green by default
 
  BIO_NAME = 'Biography:'
  DESC_NAME = 'Description:'
  #Set the value below to true to use a graphic in the window. For item, weapons,
  #skills, and armors, just name the files exactly like the object in the
  #database, only lowercase. These MUST be in the Graphics/Pictures folder.
  #If the picture does not exist, the system should be fine. Pics must be .png!
  USE_PIC = true
end

#-------------------------------------------------------------------------------
#
#                           End of Configuration
#
#=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
class Window_Details < Window_Base
 
  #--------------------------------------------------
  # => Sets up the window
  #-------------------------------------------------- 
  def initialize
    super(0, 0, 640, 480) #call from Window_Base to create a window
    self.contents = Bitmap.new(width - 32, height - 32)    #set up the text
    self.contents.font.name = Xuroth::TITLE_FONT
    self.contents.font.size = Xuroth::TITLE_SIZE
    self.contents.font.color = Xuroth::TITLE_COLOR
    #z-layer makes the detail window appear overtop all the item windows
    self.z += 10
    @details = [] #declares a variable to hold the details information later
    #call the refresh_reset method
    refresh_reset
  end
 
  #--------------------------------------------------
  # => Resets the window so text doesn't get messy
  #-------------------------------------------------- 
  def refresh_reset
    #clears the window
    self.contents.clear
  end
 
  #--------------------------------------------------
  # => Refreshes the window with details
  #-------------------------------------------------- 
  def refresh
    #set a local variable to the global $selected_item value
    item = $selected_item.id
    @color = Xuroth::TITLE_COLOR
    #tests to see if item is an Item
    if $selected_item.is_a?(RPG::Item)
      #get the item's name
      item_name = $data_items[item].name
      #get the item's icon
      item_icon = $data_items[item].icon_name
      bitmap = RPG::Cache.icon(item_icon)
      #now draw the icon!
      self.contents.blt(5, 8, bitmap, Rect.new(0, 0, 24, 24), 255)
      #and set a variable to hold the file name. named the same as other
      #detail scripts in case you want to use this one (for some reason)
      #and dont want to re-write all your lore (though your formatting
      #will likely need to be edited.)
      @detail_file = File.open("Data/Item_Detail.rxdata")
      @desc_hdr = false #use DESCNAME Header
      if Xuroth::USE_PIC
         @picfilename = $data_items[item].name
           if @picfilename != nil
             if FileTest.exist?("Graphics/Pictures/#{@picfilename}.png")
                bitmap2 = RPG::Cache.picture("#{@picfilename}")
                rect2 = Rect.new(0, 0, bitmap2.width, bitmap2.height)
                self.contents.blt(600 - bitmap2.width - 32, 0, bitmap2, rect2)
              else
                @picfilename = ''
              end
           end
       end
    #tests to see if the item is a Weapon
    elsif $selected_item.is_a?(RPG::Weapon)
      #get the name, icon, and file name as before
      item_name = $data_weapons[item].name
      item_icon = $data_weapons[item].icon_name
      bitmap = RPG::Cache.icon(item_icon)
      #now draw the icon!
      self.contents.blt(5, 8, bitmap, Rect.new(0, 0, 24, 24), 255)
      @detail_file = File.open("Data/Weapon_Detail.rxdata")
      @desc_hdr = false #use DESCNAME Header
      if Xuroth::USE_PIC
         @picfilename = $data_weapons[item].name
           if @picfilename != nil
             if FileTest.exist?("Graphics/Pictures/#{@picfilename}.png")
                bitmap2 = RPG::Cache.picture("#{@picfilename}")
                rect2 = Rect.new(0, 0, bitmap2.width, bitmap2.height)
                self.contents.blt(600 - bitmap2.width - 32, 0, bitmap2, rect2)
              else
                @picfilename = ''
              end
           end
       end
    #tests to see if the item is an Armor
    elsif $selected_item.is_a?(RPG::Armor)
      #and again, fetch name and icon
      item_name = $data_armors[item].name
      item_icon = $data_armors[item].icon_name
      bitmap = RPG::Cache.icon(item_icon)
      #now draw the icon!
      self.contents.blt(5, 8, bitmap, Rect.new(0, 0, 24, 24), 255)
      @detail_file = File.open("Data/Armor_Detail.rxdata")
      @desc_hdr = false #use DESCNAME Header
      if Xuroth::USE_PIC
         @picfilename = $data_armors[item].name
           if @picfilename != nil
             if FileTest.exist?("Graphics/Pictures/#{@picfilename}.png")
                bitmap2 = RPG::Cache.picture("#{@picfilename}")
                rect2 = Rect.new(0, 0, bitmap2.width, bitmap2.height)
                self.contents.blt(600 - bitmap2.width - 32, 0, bitmap2, rect2)
              else
                @picfilename = ''
              end
           end
       end
    elsif $selected_item.is_a?(RPG::Skill)
      item_name = $data_skills[item].name
      item_icon = $data_skills[item].icon_name
      bitmap = RPG::Cache.icon(item_icon)
      #now draw the icon!
      self.contents.blt(5, 8, bitmap, Rect.new(0, 0, 24, 24), 255)
      @detail_file = File.open("Data/Skill_Detail.rxdata")
      @desc_hdr = false #use DESCNAME Header
      if Xuroth::USE_PIC
         @picfilename = $data_skills[item].name
           if @picfilename != nil
             if FileTest.exist?("Graphics/Pictures/#{@picfilename}.png")
                bitmap2 = RPG::Cache.picture("#{@picfilename}")
                rect2 = Rect.new(0, 0, bitmap2.width, bitmap2.height)
                self.contents.blt(600 - bitmap2.width - 32, 0, bitmap2, rect2)
              else
                @picfilename = ''
              end
           end
       end
    else    #Else, $selected_item must be a character.
      item_name = $game_party.actors[$selected_item].name
      actor = $game_party.actors[$selected_item]
      draw_actor_graphic(actor, 16, 48)
      @detail_file = File.open("Data/Actor_Detail.rxdata")
      @desc_hdr = true #Use the BIONAME Header
      if Xuroth::USE_PIC
         @picfilename = $game_party.actors[$selected_item].name
           if @picfilename != nil
             if FileTest.exist?("Graphics/Pictures/#{@picfilename}.png")
                bitmap2 = RPG::Cache.picture("#{@picfilename}")
                rect2 = Rect.new(0, 0, bitmap2.width, bitmap2.height)
                self.contents.blt(600 - bitmap2.width - 32, 0, bitmap2, rect2)
              else
                @picfilename = ''
              end
           end
       end

    end
    if item_name == nil
      item_name = 'Nobody'
    end
    self.contents.font.color = Xuroth::TITLE_COLOR
    self.contents.draw_text(32, 8, 256, 24, item_name)
    self.contents.font.color = Xuroth::DESC_COLOR
    #now call the method that actually gets and displays the detailed info!
    fetch_details(item)
    show_details(3, 72)
  end

  #--------------------------------------------------
  # => Gets Details and stores them into an array
  #--------------------------------------------------
  def fetch_details(item)
    #array that holds details:
    description =
    [
    item * 10,
    item * 10 + 1,
    item * 10 + 2,
    item * 10 + 3,
    item * 10 + 4,
    item * 10 + 5,
    item * 10 + 6,
    item * 10 + 7,
    item * 10 + 8,
    item * 10 + 9
    ]
    #stores all lines into variable
    @details = @detail_file.readlines
    #now set up !?Another?! variable used for processing the data.
    @desc = []
    #now set it to hold only 10 lines at a time!
    for i in 0..9
      @desc[i] = @details[description[i]]
    end
    #finished! now run the display details method!
    return
  end
 
  #--------------------------------------------------
  # => Displays the contents of the array as text
  #--------------------------------------------------
  def show_details(x, y)
    #draw the Description title
    self.contents.font.color = Xuroth::DESC_COLOR
    if @desc_hdr == true
      self.contents.draw_text(x, y + 96, 640, 32, Xuroth::BIO_NAME)
    else
      self.contents.draw_text(x, y + 96, 640, 32, Xuroth::DESC_NAME)
    end
    self.contents.font.color = Xuroth::DESC_COLOR
    #draw all 10 lines normally
      for i in 0..9
        if @desc[i] == nil #checks if i is nil. if so, fixes it!
          @desc[i] = ' '
        else
          self.contents.draw_text(x - 32, y + 128, 640, 32, @desc[i])
          y += 20
        end
      end
  #method end
  end
#class end
end

#===================================================================
# >>>  Scene_Item
#===================================================================
     # This edits several methods via alias
     # and adds a new method for checking
     # input.

class Scene_Item


alias detail_main main
  def main
   
    @detail_window = Window_Details.new
    @detail_window.visible = false
    @detail_window.active = false
    detail_main
    @detail_window.dispose
  end

  alias detail_update update
  def update
    detail_update
    $selected_item = @item_window.item
    if @item_window.active
      update_item
      return
    end
    if @detail_window.active
    update_details
      return
    end
  end

  def update_details
   if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      unless $game_party.item_can_use?(@item.id)
        @item_window.refresh
      end
      @item_window.active = true
      @detail_window.visible = false
      @detail_window.active = false
      @detail_window.refresh_reset
      return
    end
  end

 
  alias new_update_item update_item
  def update_item
    new_update_item
    if Input.trigger?(Input::A)
      # Below if-then statement checks for blank item, and cancels
      # the input.
      if $selected_item == nil
        return
      end     
      $game_system.se_play($data_system.decision_se)
      @detail_window.refresh
      @item_window.active = false     
      @detail_window.visible = true
      @detail_window.active = true
    end
  end
end

#===================================================================
# >>>  Scene_Skill
#===================================================================

class Scene_Skill

  alias skill_detail_main main
  def main
    @detail_window = Window_Details.new
    @detail_window.visible = false
    @detail_window.active = false
    skill_detail_main
    @detail_window.dispose
  end

  alias detail_update update
  def update
    detail_update
    $selected_item = @skill_window.skill
    if @skill_window.active
      update_skill
      return
    end
    if @detail_window.active
      update_details
      return
    end
  end

  def update_details
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      unless @actor.skill_can_use?(@skill.id)
        @skill_window.refresh
      end
      @skill_window.active = true
      @detail_window.visible = false
      @detail_window.active = false
      @detail_window.refresh_reset
      return
    end
  end

  alias new_update_skill update_skill
  def update_skill
    new_update_skill
    if Input.trigger?(Input::A)
      if $selected_item == nil
        return
      end
      $game_system.se_play($data_system.decision_se)
      @detail_window.refresh
      @skill_window.active = false
      @detail_window.visible = true
      @detail_window.active = true
    end
  end
end

#===================================================================
# >>>  Scene_Item
#===================================================================
class Scene_Status
  def main

    @detail_window = Window_Details.new
    @actor = $game_party.actors[@actor_index]
    $selected_item = @actor
    @status_window = Window_Status.new(@actor)
    @status_window.visible = true
    @status_window.active = true
    @detail_window.visible = false
    @detail_window.active = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @status_window.dispose
    @detail_window.dispose
  end
 
  alias actor_detail_update update
  def update
    actor_detail_update
    $selected_item = @actor_index
    if @status_window.active
      update_actor
      return
    end
    if @detail_window.active
      update_details
      return
    end
  end
 
    def update_details
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @status_window.active = true
      @detail_window.visible = false
      @detail_window.active = false
      @detail_window.refresh_reset
      return
    end
  end

  def update_actor
    if Input.trigger?(Input::A)
      if $selected_item == nil
        return
      end
      $game_system.se_play($data_system.decision_se)
      @detail_window.refresh
      @status_window.active = false
      @detail_window.visible = true
      @detail_window.active = true
    end
  end
end





Instructions

You need 4 text files to make this work. You need 5 text files to make this work. They have to be named "Armor_Detail.rxdata", "Item_Detail.rxdata", "Skill_Detail.rxdata",  "Weapon_Detail.rxdata" and "Actor_Details.rxdata"(without the quotes). Place these in your /Data folder.
Also, due to my scripting ability (or lack thereof), each item starts every 11th line. The first armor will display from line 11 to line 20 of the text file. The first ten lines of each file should be either empty or contain the placeholder text I included in the demo.
I will try to update this later to allow the script to automagically determine the number of lines, and possibly make the window scrollable. But for now, this is it.

To use this, just insert above main. It only edits Scene_Item and Scene_Skill so as long as its below those, it should work just fine.


Compatibility

Probably won't work with custom item windows or skill windows such as those used by fancy CMS'. This was designed from the DMS, and I am a n00b scripter after all. I may figure out a way to increase compatibility with CMS' later
Also, this script uses aliased methods and does not rewrite any existing methods, only adds to them.


Credits and Thanks


  • Xuroth (for making this script)

  • Jackatrades (for the original idea)

  • game_guy (for help with alias)

  • DerVVulfman (for help with basic coding and the original idea)

  • Blizzard (Inspiration)

  • ForeverZer0 (Inspiration and help with coding)

  • LiTTleDRAgo (requesting graphics)


Thanks to you guys, I was able to complete this system. You guys Rock!


Author's Notes

Remember: You need the text files re-named as .rxdata files. You can grab mine from the demo and edit them to match your game (if you use it)
I am reworking the code, so if any scripters have any advice on ways to improve the code, let me know!
v1.0 will have a redesigned window layout.
This is a VERY basic system. It has potential for more, but it is only my FIRST script.

Post any bugs you find here, and I will try to fix them... if I can.

Spaceman McConaughey


Xuroth

@Tuggernuts: Thanks!

If anyone has suggestions to improve the code, or suggestions to make the system better, feel free to post them. I plan to support my scripts, though it may take me a few days due to work.

By the way, this script, when completed will be a full fledged system capable of more than just "read a text file for x lines and put it in a window" (Also, when I say completed, the script will function, but compatibility is limited (with CMS'), but I have more feature ideas planned!)

Ryex

I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

LiTTleDRAgo

Quote from: Xuroth on March 10, 2011, 09:36:46 pm
@Tuggernuts: Thanks!

If anyone has suggestions to improve the code, or suggestions to make the system better, feel free to post them. I plan to support my scripts, though it may take me a few days due to work.

By the way, this script, when completed will be a full fledged system capable of more than just "read a text file for x lines and put it in a window" (Also, when I say completed, the script will function, but compatibility is limited (with CMS'), but I have more feature ideas planned!)


how about using custom picture as background?

Xuroth

@LliTTleDRAgo: That seems like a good idea. That would add some flair that other similar systems do not posess. I will update this soon.

in the next couple of days, ill update this to show custom pictures. Im at work and Ill be busy for the next couple of days. Expect the update on Monday or Tuesday at the latest.

EZ Destroyer

suggestions:

put more than 10 lines of information and be able 2 scroll down if exceeding the screen.

the word mythril shield(example) should be bigger and in a different colour.

Xuroth

March 12, 2011, 08:46:27 am #7 Last Edit: March 12, 2011, 08:55:41 am by Xuroth
I'm not sure how to make the window scrollable. Also, the way the text files are set up, its a nightmare to format them. The more lines to display, the more of a headache it is to set-up. I am brainstorming any ideas on how to rescript the system so that it can display more lines... I can edit the names to show up bigger. as for color, just look for where it says
D_ITEMCOLOR = Color.new(255, 255, 255, 255)

in the configuration area, and change the numbers in that. it is set up as (Red, Green, Blue, Opacity).

I'll probably do some research and figure out how to scroll the window. I probably won't add more lines, as I will move the description area down, give it its own window, and add other information above it.

ForeverZer0

If you make the window contents larger than the window, then add input for the controls to scroll the bitmap, it will work fine. Window_Base doesn't have the implementation built in, but Window_Selectable does. It will automatically add little arrows at the top/bottom to show that the window can be scrolled. I'm sure you can find some scripts around here that implement it for some good examples.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Xuroth

March 13, 2011, 04:46:01 pm #9 Last Edit: March 13, 2011, 09:02:30 pm by game_guy
alright, thanks Zer0.


BUMP!
Updated to 0.8!

Also, if any scripters out there have any ideas or suggestions to improve the code, I'd love to hear it. I am only a noob. Advice is welcome so I can learn and improve.


No double posting within 24 hours thank you! ~ G_G

Xuroth

updated to 0.9... just one step away from a full system!
@LiTTleDRAgo: I chose not to use custom pictures AS background, but I did feel that custom graphics should play a role. there fore the new script will look for .png files in your Graphics/Pictures folder that are named like the selected object.

This system may have a couple bugs in it, as quite a few appeared just before I was going to upload the demo. I updated the script, and it *should* work fine.

As always, bug reports or tips on how to improve this are welcome!!!