# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Battle Victory HUD on Map ║ Version: 1.04 ║
# ║ Author: Roninator2 ║ ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function: ║ Date Created ║
# ║ Show Number of Battles Won ╠════════════════════╣
# ║ on the Current Map ║ 17 Oct 2022 ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Allows to display Battles won on this map on screen ║
# ║ Requested by Tw0Face ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions: ║
# ║ Adjust the settings to your preference ║
# ║ Use <no battle hud> in the map note for not show ║
# ║ the window or just leave the data for the map blank ║
# ║ ║
# ║ Adjust the Data section for each map ║
# ║ Map_Data = { # instructions down below ║
# ╚══════════════════════════════════════════════════════════╝
# ╔═════════════════════════════════════╗
# ║ Terms of use: ║
# ║ Free for all uses in RPG Maker ║
# ╚═════════════════════════════════════╝
module R2_BATTLE_WON_HUD
# Configure options
Battle_Map_Var = 5 # Variable used to track map battles
Battle_Switch = 5 # Switch used to increase battles value
OFF_Switch = 4 # turns off the display
Count_Random = 6 # switch to turn on if you wish to count
# random battles as well as evented ones.
Hud_X = 0 # Hud X Position
Hud_Y = 0 # Hud Y Position
Hud_Width = Graphics.width # Hud Width
Hud_Height = 48 # Hud Height
Window_Opacity = 0 # window visibility, does not affect contents
Window_Back_Opacity = 0 # Window background opacity
Window_Graphic = "Window" # Window Graphic file to use
Use_Shadow_Back = true # changes to use a shaded background
Shadow_Opacity = 180 # set the darkness of the background
Shadow_Opacity1 = 80 # set the darkness of the background
Shadow_Opacity2 = 250 # set the darkness of the background
Shade_Type = 1 # set the shade type for the background of the window
# 0 = three layers from inside to out.
# 1 = two layers from left to right
Shade_Colours_Red = 0 # Set colour for Red in shade
Shade_Colours_Green = 0 # Set colour for Green in shade
Shade_Colours_Blue = 0 # Set colour for Blue in shade
Font = "Arial"
Font_Size = 20
Battle_Text = "Battles Won:"
Text_Offset = 10
module Data
Map_Data = {
# map id => [total battles, battle icon, map icon]
1 => [5, 110, 120], # don't forget the comma
2 => [2, 50, 75],
4 => [15, 10, 25],
}
end
end
# ╔══════════════════════════════════════════════════════════╗
# ║ End of Configuration ║
# ╚══════════════════════════════════════════════════════════╝
#--------------------------------------------------------------------------
# * Battle Won Hud Window
#--------------------------------------------------------------------------
class Battles_Won_Hud_Window < Window_Base
#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------
def initialize(id)
@hud_id = id
x = R2_BATTLE_WON_HUD::Hud_X
y = R2_BATTLE_WON_HUD::Hud_Y
w = R2_BATTLE_WON_HUD::Hud_Width
h = R2_BATTLE_WON_HUD::Hud_Height
super(x,y,w,h)
self.windowskin = Cache.system(R2_BATTLE_WON_HUD::Window_Graphic)
self.opacity = R2_BATTLE_WON_HUD::Window_Opacity
self.back_opacity = R2_BATTLE_WON_HUD::Window_Back_Opacity
self.contents_opacity = 255
@updated_battles = false
refresh
end
#--------------------------------------------------------------------------
# * Create Background Bitmap
#--------------------------------------------------------------------------
def create_back_battle_shade
@shade_battle_bitmap = Bitmap.new(R2_BATTLE_WON_HUD::Hud_Width, R2_BATTLE_WON_HUD::Hud_Height)
rect = Rect.new(0, 0, width, height)
rect1 = Rect.new(0, 0, width, 12)
rect2 = Rect.new(0, 12, width, height - 24)
rect3 = Rect.new(0, height - 12, width, 12)
r = R2_BATTLE_WON_HUD::Shade_Colours_Red
g = R2_BATTLE_WON_HUD::Shade_Colours_Green
b = R2_BATTLE_WON_HUD::Shade_Colours_Blue
if R2_BATTLE_WON_HUD::Shade_Type == 0
@shade_battle_bitmap.gradient_fill_rect(rect1, back_colour2(r, g, b), back_colour1(r, g, b), true)
@shade_battle_bitmap.fill_rect(rect2, back_colour3(r, g, b))
@shade_battle_bitmap.gradient_fill_rect(rect3, back_colour1(r, g, b), back_colour2(r, g, b), true)
else
@shade_battle_bitmap.gradient_fill_rect(rect, back_colour1(r, g, b), back_colour2(r, g, b))
end
@shade_battle_sprite = Sprite.new
@shade_battle_sprite.bitmap = @shade_battle_bitmap
@shade_battle_sprite.z = z - 1
@shade_battle_sprite.y = R2_BATTLE_WON_HUD::Hud_Y
@shade_battle_sprite.x = R2_BATTLE_WON_HUD::Hud_X
end
#--------------------------------------------------------------------------
# * Get Background Color 1
#--------------------------------------------------------------------------
def back_colour1(r, g, b)
Color.new(r, g, b, R2_BATTLE_WON_HUD::Shadow_Opacity)
end
#--------------------------------------------------------------------------
# * Get Background Color 2
#--------------------------------------------------------------------------
def back_colour2(r, g, b)
Color.new(r, g, b, R2_BATTLE_WON_HUD::Shadow_Opacity1)
end
#--------------------------------------------------------------------------
# * Get Background Color 3
#--------------------------------------------------------------------------
def back_colour3(r, g, b)
Color.new(r, g, b, R2_BATTLE_WON_HUD::Shadow_Opacity2)
end
#--------------------------------------------------------------------------
# * Battle Data
#--------------------------------------------------------------------------
def battle_data
data = R2_BATTLE_WON_HUD::Data::Map_Data[@hud_id]
dispose_back_battle_bitmap if data.nil?
return if data.nil?
maxbat = data[0]
bicon = data[1]
micon = data[2]
offset = R2_BATTLE_WON_HUD::Text_Offset
map = load_data(sprintf("Data/Map%03d.rvdata2", @hud_id))
mname = map.display_name
x = R2_BATTLE_WON_HUD::Hud_X
y = R2_BATTLE_WON_HUD::Hud_Y
battles = $game_variables[R2_BATTLE_WON_HUD::Battle_Map_Var][@hud_id]
text1 = R2_BATTLE_WON_HUD::Battle_Text
draw_icon(bicon, x + 5, y, true)
text = "#{text1} #{battles}/#{maxbat}"
width = text.size * (contents.font.size / 2)
draw_text(x + 40, y - offset, width, R2_BATTLE_WON_HUD::Hud_Height, text, 0)
mwdth = mname.size * (contents.font.size / 2)
x = R2_BATTLE_WON_HUD::Hud_Width - mwdth - 40
x -= 10 if mwdth == 0
draw_icon(micon, x, y, true)
draw_text(x + 40, y - offset, mwdth, R2_BATTLE_WON_HUD::Hud_Height, mname, 0)
end
#--------------------------------------------------------------------------
# * Dispose Background Bitmap
#--------------------------------------------------------------------------
def dispose
super
dispose_back_battle_bitmap
end
#--------------------------------------------------------------------------
# * Free Background Bitmap
#--------------------------------------------------------------------------
def dispose_back_battle_bitmap
@shade_battle_bitmap.dispose if @shade_battle_bitmap
@shade_battle_sprite.dispose if @shade_battle_sprite
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
clear_data
return if $game_switches[R2_BATTLE_WON_HUD::OFF_Switch] == true
create_back_battle_shade if self.visible == true
font = R2_BATTLE_WON_HUD::Font
font_size = R2_BATTLE_WON_HUD::Font_Size
self.contents.font = Font.new(font, font_size)
battle_data
@updated_battles = false
end
#--------------------------------------------------------------------------
# * Hud Data Changed
#--------------------------------------------------------------------------
def hud_data_changed
return true if @updated_battles == true
return false
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias r2_hud_update_battle_hud update
def update
refresh if hud_data_changed
r2_hud_update_battle_hud
end
#--------------------------------------------------------------------------
# * New Map ID
#--------------------------------------------------------------------------
def new_map_id(id)
@hud_id = id
@updated_battles = true
$game_variables[R2_BATTLE_WON_HUD::Battle_Map_Var][@hud_id] = 0 if $game_variables[R2_BATTLE_WON_HUD::Battle_Map_Var][@hud_id].nil?
end
#--------------------------------------------------------------------------
# * Add Battles Won
#--------------------------------------------------------------------------
def add_battles_won
@updated_battles = true
$game_variables[R2_BATTLE_WON_HUD::Battle_Map_Var] = [] if $game_variables[R2_BATTLE_WON_HUD::Battle_Map_Var] == 0
$game_variables[R2_BATTLE_WON_HUD::Battle_Map_Var][@hud_id] = 0 if $game_variables[R2_BATTLE_WON_HUD::Battle_Map_Var][@hud_id] == nil
$game_variables[R2_BATTLE_WON_HUD::Battle_Map_Var][@hud_id] += 1
end
#--------------------------------------------------------------------------
# * Clear Data
#--------------------------------------------------------------------------
def clear_data
self.contents.clear
dispose_back_battle_bitmap
end
#--------------------------------------------------------------------------
# * Visible?
#--------------------------------------------------------------------------
def visible?
self.visible
end
end
#--------------------------------------------------------------------------
# * BattleManager
#--------------------------------------------------------------------------
module BattleManager
class << self
alias battle_hud_victory_add process_victory
alias battle_hud_victory_encounter on_encounter
alias battle_hud_victory_init init_members
end
#--------------------------------------------------------------------------
# * Process Victory
#--------------------------------------------------------------------------
def self.process_victory
battle_hud_victory_add
return if ($game_switches[R2_BATTLE_WON_HUD::Count_Random] == false) && (@rand_enc) == true
$game_switches[R2_BATTLE_WON_HUD::Battle_Switch] = true
end
#--------------------------------------------------------------------------
# * Initialize Members Data
#--------------------------------------------------------------------------
def self.init_members
@rand_enc = false
battle_hud_victory_init
end
#--------------------------------------------------------------------------
# * On Encounter
#--------------------------------------------------------------------------
def self.on_encounter
battle_hud_victory_encounter
@rand_enc = true
end
end
#--------------------------------------------------------------------------
# * Game Map
#--------------------------------------------------------------------------
class Game_Map
def map
@map
end
end
#--------------------------------------------------------------------------
# * Scene Map
#--------------------------------------------------------------------------
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# * Start
#--------------------------------------------------------------------------
alias r2_battle_won_hud_start start
def start
r2_battle_won_hud_start
battle_hud
end
#--------------------------------------------------------------------------
# * Battle Hud
#--------------------------------------------------------------------------
def battle_hud
@battles_won_hud = Battles_Won_Hud_Window.new($game_map.map_id)
check_battle_hud_visible
end
#--------------------------------------------------------------------------
# * Battle Hud Visible
#--------------------------------------------------------------------------
def check_battle_hud_visible
@battles_won_hud.visible = !$game_map.map.note.include?("<no battle hud>")
@battles_won_hud.refresh
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias r2_map_update_battle_won_hud update
def update
r2_map_update_battle_won_hud
if Input.trigger?(:L)
sw = R2_BATTLE_WON_HUD::OFF_Switch
$game_switches[sw] = !$game_switches[sw]
end
battle_won_hud_update if $game_switches[R2_BATTLE_WON_HUD::Battle_Switch] == true
@battles_won_hud.refresh if @battles_won_hud.visible?
end
#--------------------------------------------------------------------------
# * Battle Won Hud Update
#--------------------------------------------------------------------------
def battle_won_hud_update
@battles_won_hud.add_battles_won
$game_switches[R2_BATTLE_WON_HUD::Battle_Switch] = false if $game_switches[R2_BATTLE_WON_HUD::Battle_Switch] == true
return if @battles_won_hud.visible == false
@battles_won_hud.refresh
end
#--------------------------------------------------------------------------
# * Pre Processing for Transferring Player
#--------------------------------------------------------------------------
alias r2_battle_hud_visible_transfer_pre pre_transfer
def pre_transfer
battle_won_hud_update if $game_switches[R2_BATTLE_WON_HUD::Battle_Switch] == true
@battles_won_hud.update
r2_battle_hud_visible_transfer_pre
end
#--------------------------------------------------------------------------
# * Post Processing for Transferring Player
#--------------------------------------------------------------------------
alias r2_battle_hud_visible_transfer_post post_transfer
def post_transfer
check_battle_hud_visible
@battles_won_hud.clear_data
r2_battle_hud_visible_transfer_post
@battles_won_hud.new_map_id($game_map.map_id)
@battles_won_hud.update
end
end