Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

finally got rid of old hideous menu code

  • Loading branch information...
commit 1a2b6df407f597d6d2e3898ca83db227b14ac54b 1 parent b3ebff7
@bgoodspeed authored
View
23 lib/battle/battle_menu_helper.rb
@@ -1,23 +0,0 @@
-class BattleMenuHelper < MenuHelper
- def initialize(battle, screen, layer,text_helper, sections, cursor_x, cursor_y, cursor_main_color=:blue, cursor_inactive_color=:white)
- super(screen, layer,text_helper, sections, cursor_x, cursor_y, cursor_main_color, cursor_inactive_color)
- @battle = battle
- end
-
- def current_cursor_member_ready?
- @battle.party.members[@cursor_position].ready?
- end
-
- def color_for_current_section_cursor
- if current_cursor_member_ready?
- @cursor_main_color
- else
- @cursor_inactive_color
- end
- end
- def enter_current_cursor_location(game)
- super(game) if current_cursor_member_ready?
- end
-
-
-end
View
31 lib/battle/menu/attack_menu_action.rb
@@ -1,31 +0,0 @@
-class AttackMenuAction < MenuAction
- def initialize(text, battle_layer, menu_helper)
- super(text, AttackAction.new)
- @battle_layer = battle_layer
- @menu_helper = menu_helper
- end
-
- def activate(party_member_index, game, action_idx, subsection_position=nil, option_position=nil)
- @menu_helper.set_active_subsection(action_idx)
-
- return false unless subsection_position
- battle = @battle_layer.battle
-
- hero = battle.player.party.members[party_member_index]
- target = battle.current_battle_participant(subsection_position)
- puts "I am going to attack #{target}"
- @action.perform(hero, target)
- msg = "attacked for #{hero.damage} damage"
-# msg += "hero #{hero} killed #{battle.monster}" if battle.monster.dead?
- game.add_notification(BattleScreenNotification.new("Attacked for #{hero.damage}"))
- false
- end
-
- def size
- @battle_layer.participants.size
- end
-
- def details
- false
- end
-end
View
11 lib/battle/menu/end_battle_menu_action.rb
@@ -1,11 +0,0 @@
-
-class EndBattleMenuAction < MenuAction
- def initialize(text, battle_layer)
- super(text)
- @battle_layer = battle_layer
- end
-
- def activate(menu_idx, game, submenu_idx)
- @battle_layer.end_battle
- end
-end
View
55 lib/battle/menu/item_menu_action.rb
@@ -1,55 +0,0 @@
-
-class ItemMenuAction < MenuAction
-
- include Rubygame
-
- def initialize(text, battle_layer, menu_helper, game)
- super(text, ItemAction.new)
- @battle_layer = battle_layer
- @menu_helper = menu_helper
- @game = game
- end
-
- def activate(party_member_index, game, action_idx, subsection_position=nil, option_position=nil)
- @menu_helper.set_active_subsection(action_idx)
-
- return false unless subsection_position
- return true unless option_position
-
- battle = @battle_layer.battle
- hero = battle.player.party.members[party_member_index]
- item = battle.inventory_item_at(subsection_position)
- target = battle.current_battle_participant(option_position)
- puts "target is: #{option_position}->#{target}"
- @action.perform(hero, target, item)
- game.add_notification(BattleScreenNotification.new("Item used: #{item}"))
- false
- end
-
- def option_at(idx)
- @battle_layer.participants
- end
-
- def size
- @battle_layer.inventory.size
- end
-
- def info
- @game.inventory_info
- end
-
- def surface_for(posn)
- false
- end
-
-
- def details
- info_lines = info.collect {|item| item.to_info}
- s = Surface.new([@@STATUS_WIDTH, @@STATUS_HEIGHT])
- s.fill(:purple)
- @menu_helper.render_text_to(s, info_lines, TextRenderingConfig.new(0, 0, 0,@@MENU_LINE_SPACING))
- s
- end
-
-
-end
View
25 lib/game_requirements.rb
@@ -89,27 +89,6 @@
require 'lib/menu/cursor_helper'
require 'lib/menu/menu_layer_config'
-#TODO delete this
-require 'lib/menu/noop_action'
-require 'lib/menu/menu_helper'
-require 'lib/menu/menu_action'
-require 'lib/menu/menu_section'
-require 'lib/menu/menu_sections'
-require 'lib/menu/abstract_actor_menu_action'
-require 'lib/menu/hero_menu_section'
-require 'lib/menu/inventory_display_action'
-require 'lib/menu/key_inventory_display_action'
-require 'lib/menu/level_up_action'
-require 'lib/menu/sort_inventory_action'
-require 'lib/menu/status_display_action'
-require 'lib/menu/update_equipment_action'
-require 'lib/menu/menu_helper'
-require 'lib/menu/menu_layer_config'
-require 'lib/menu/save_load_menu_action'
-require 'lib/menu/save_menu_action'
-require 'lib/menu/load_menu_action'
-
-#to here
require 'lib/text/text_rendering_config'
require 'lib/text/text_rendering_helper'
@@ -140,11 +119,7 @@
require 'lib/battle/battle_readiness_helper'
require 'lib/battle/battle_victory_helper'
require 'lib/battle/battle_hud'
-require 'lib/battle/battle_menu_helper'
require 'lib/battle/battle_participant_cursor_text_rendering_config'
-require 'lib/battle/menu/attack_menu_action'
-require 'lib/battle/menu/end_battle_menu_action'
-require 'lib/battle/menu/item_menu_action'
require 'lib/battle/menu/selectors/battle_skill_menu_selector'
require 'lib/battle/menu/selectors/battle_ready_party_menu_selector'
View
4 lib/layers/battle_layer.rb
@@ -51,8 +51,8 @@ def menu_layer_config
mlc.main_menu_text = TextRenderingConfig.new(@@MENU_TEXT_INSET, @@MENU_TEXT_WIDTH, @layer.h - 125, 0)
mlc.section_menu_text = TextRenderingConfig.new(@@MENU_TEXT_INSET, @@MENU_TEXT_WIDTH, @layer.h - 150, 0)
mlc.in_section_cursor = TextRenderingConfig.new(@@MENU_TEXT_INSET , @@MENU_TEXT_WIDTH, @layer.h - 175, 0)
- mlc.in_subsection_cursor = BattleParticipantCursorTextRenderingConfig.new([AttackMenuAction], 2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
- mlc.in_option_section_cursor = BattleParticipantCursorTextRenderingConfig.new([ItemMenuAction], 2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
+ mlc.in_subsection_cursor = BattleParticipantCursorTextRenderingConfig.new([AttackBattleMenuAction], 2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
+ mlc.in_option_section_cursor = BattleParticipantCursorTextRenderingConfig.new([UseBattleItemBattleMenuAction], 2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
mlc.main_cursor = TextRenderingConfig.new(@@MENU_TEXT_INSET , @@MENU_TEXT_WIDTH, @layer.h - 100, 0)
mlc.layer_inset_on_screen = [@@LAYER_INSET,@@LAYER_INSET]
mlc.details_inset_on_layer = [@@MENU_DETAILS_INSET_X, @@MENU_DETAILS_INSET_Y]
View
33 lib/menu/abstract_actor_menu_action.rb
@@ -1,33 +0,0 @@
-
-
-class AbstractActorMenuAction
- include Rubygame
- extend Forwardable
- def initialize(actor, menu_helper)
- @actor = actor
- @menu_helper = menu_helper
- end
- def text
- @actor.name
- end
- def section_by_index(idx)
- puts "hrm, maybe should be picking a certain status line"
- end
- def display_actor_status_info
- info_lines = @actor.status_info
- s = Surface.new([@@STATUS_WIDTH, @@STATUS_HEIGHT])
- s.fill(:green)
- @menu_helper.render_text_to(s, info_lines, TextRenderingConfig.new(0, 0, 0,@@MENU_LINE_SPACING))
- s
- end
- def has_subsections?
- true
- end
-
-
- def draw(menu_layer_config, game, text_rendering_helper, layer, screen)
- display_actor_status_info.blit(layer, menu_layer_config.details_inset_on_layer)
- end
-
- alias_method :name, :text
-end
View
10 lib/menu/hero_menu_section.rb
@@ -1,10 +0,0 @@
-
-
-class HeroMenuSection < MenuSection
- def initialize(hero, content)
- super(hero.name, content)
- @hero = hero
- end
-end
-
-
View
105 lib/menu/inventory_display_action.rb
@@ -1,105 +0,0 @@
-
-class HeroWrapper
- def initialize(game, item, member)
- @game = game
- @item = item
- @member = member
- end
-
- def name
- @member.name
- end
- def section_by_index(idx)
- self #TODO this is odd..
- end
-
-end
-
-class InventoryDisplayWrapper
- def initialize(game, item)
- @game = game
- @item = item
- end
- def party_members
- @game.party_members
- end
-
- def section_by_index(idx)
- HeroWrapper.new(@game, @item, party_members[idx])
- end
-
-end
-
-class InventoryDisplayAction
- include Rubygame
-
- attr_reader :text
- alias_method :name, :text
- def initialize(text, game, menu_helper)
- @text = text
- @game = game
- @menu_helper = menu_helper
- @selected_option = nil
- end
-
- def has_subsections?
- true
- end
-
- def section_by_index(idx)
- InventoryDisplayWrapper.new(@game, info[idx])
- end
-
- def activate(cursor_position, game, section_position, subsection_position=nil, option_position=nil)
- if !option_position.nil?
- item = info[subsection_position]
- target = party_members[option_position]
- target.consume_item(item) #TODO this is similar to ItemAction refactor
- elsif subsection_position.nil?
- @menu_helper.set_active_subsection(section_position)
- end
- return !subsection_position.nil?
- end
- def surface_for(posn)
- item = info[posn]
- s = Surface.new([@@STATUS_WIDTH, @@STATUS_HEIGHT])
- s.fill(:white)
- member_names = party_members.collect {|m| m.name}
- @menu_helper.render_text_to(s,member_names , TextRenderingConfig.new(0, 0, 0,@@MENU_LINE_SPACING))
- s
-
- end
-
- def option_at(idx=nil)
- if idx.nil?
- party_members
- else
- party_members[idx]
- end
- end
-
- def party_members
- @game.party_members
- end
-
- def info
- @game.inventory_info
- end
-
- def details
- info_lines = info.collect {|item| item.to_info}
- s = Surface.new([@@STATUS_WIDTH, @@STATUS_HEIGHT])
- s.fill(:yellow)
- @menu_helper.render_text_to(s, info_lines, TextRenderingConfig.new(0, 0, 0,@@MENU_LINE_SPACING))
- s
- end
-
- def size
- info.size
- end
-
- def draw(menu_layer_config, game, text_rendering_helper, layer, screen)
- details.blit(layer, menu_layer_config.details_inset_on_layer)
- end
-
-end
View
3  lib/menu/key_inventory_display_action.rb
@@ -1,3 +0,0 @@
-
-class KeyInventoryDisplayAction < InventoryDisplayAction
-end
View
19 lib/menu/level_up_action.rb
@@ -1,19 +0,0 @@
-
-class LevelUpAction < AbstractActorMenuAction
-
- def size
- 2 #TODO this should come from the size of the attribute set
- end
-
- alias_method :details, :display_actor_status_info
-
- def activate(cursor_position, game, section_position, subsection_position=nil, option_position=nil)
- @menu_helper.set_active_subsection(section_position)
- if !subsection_position.nil?
- @actor.consume_level_up(subsection_position)
- end
- false
- end
-
-
-end
View
14 lib/menu/load_menu_action.rb
@@ -1,14 +0,0 @@
-
-class LoadMenuAction < SaveLoadMenuAction
- def activate(menu_idx, game, submenu_idx)
- slot = save_slot(submenu_idx)
- puts "load from #{slot}"
-
- data = IO.readlines(slot)
-
- rebuilt = JSON.parse(data.join(" "))
- puts "got rebuilt: #{rebuilt.class} "
- ReloaderHelper.new.replace(game, rebuilt)
- game.add_notification(WorldScreenNotification.new("Loaded from #{slot}"))
- end
-end
View
14 lib/menu/menu_action.rb
@@ -1,14 +0,0 @@
-
-class MenuAction
- attr_reader :text
- alias_method :name, :text
- def initialize(text, action=NoopAction.new)
- @text = text
- @action = action
- end
-
- def activate(main_menu_idx, game, submenu_idx)
- puts "This is a no-op action: #{@text}"
- end
-end
-
View
86 lib/menu/menu_helper.rb
@@ -1,86 +0,0 @@
-#TODO this class should be broken up
-class MenuHelper
- include Rubygame
-
- def initialize(screen, layer,text_helper, sections, cursor_x, cursor_y, cursor_main_color=:blue, cursor_inactive_color=:white)
- @layer = layer
- @text_rendering_helper = text_helper
- @screen = screen
- replace_sections(sections)
- end
-
- def reset_indices
- @menu_sections.reset_indices
- end
-
- def current_menu_entries
- @menu_sections.section_names
- end
-
- def current_selected_menu_entry_name
- @menu_sections.cursor_selected_entry_name
- end
-
- def move_cursor_down
- move_cursor(1)
- end
-
- def move_cursor(dir)
- @menu_sections.move_cursor(dir)
- end
-
- def move_cursor_up
- move_cursor(-1)
- end
- def enter_current_cursor_location(game)
- @menu_sections.activate(game)
- end
- def cancel_action
- @menu_sections.cancel
- end
- def replace_sections(sections)
- @menu_sections = sections
- end
- #TODO this is odd to have in the api for this class... reconsider
- def render_text_to_layer(text, conf)
- @text_rendering_helper.render_lines_to_layer( text, conf)
- end
- def render_text_to(surface, text, conf)
- @text_rendering_helper.render_lines_to(surface, text, conf)
- end
- def draw(menu_layer_config, game)
- @menu_sections.draw(menu_layer_config, game, @text_rendering_helper, @layer, @screen)
-# #render_text_to_layer( @text_lines, menu_layer_config.main_menu_text)
-# #@cursor.fill(color_for_current_section_cursor)
-# if @show_section
-# render_text_to_layer(active_section.text_contents, menu_layer_config.section_menu_text)
-# conf = menu_layer_config.in_section_cursor
-#
-# if subsection_active?(@section_position)
-# surf = active_subsection.details
-# conf = menu_layer_config.in_subsection_cursor
-#
-# surf.blit(@layer, menu_layer_config.details_inset_on_layer) if surf
-# @cursor.fill(:black)
-#
-# if @needs_option
-# conf = menu_layer_config.in_option_section_cursor
-# optsurf = active_subsection.surface_for(@subsection_position)
-# optsurf.blit(@layer, menu_layer_config.options_inset_on_layer) if optsurf
-# @cursor.blit(@layer, conf.cursor_offsets_at(@option_position, game, active_subsection))
-# else
-# @cursor.blit(@layer, conf.cursor_offsets_at(@subsection_position, game, active_subsection))
-# end
-# else
-# @cursor.blit(@layer, conf.cursor_offsets_at(@section_position, game, active_subsection))
-# end
-# else
-#
-# conf = menu_layer_config.main_cursor
-# puts "top level: #{active_section}"
- #@cursor.blit(@layer, conf.cursor_offsets_at(@cursor_position, game, active_section))
-# end
-# @layer.blit(@screen, menu_layer_config.layer_inset_on_screen)
- end
-
-end
View
33 lib/menu/menu_section.rb
@@ -1,33 +0,0 @@
-class MenuSection
-
- attr_reader :text, :content
-
- def has_subsections?
- true
- end
-
- def size
- @content.size
- end
- def initialize(text, content)
- @text = text
- @content = content
- end
-
-
- def content_at(i)
- @content.section_by_index(i)
- end
- def text_contents
- @content.collect {|ma| ma.text}
- end
-
- def draw(menu_layer_config, game, text_rendering_helper, layer, screen)
- @content.draw(menu_layer_config, game, text_rendering_helper, layer, screen)
- end
-
- alias_method :name, :text
- alias_method :section_by_index, :content_at
-
-
-end
View
92 lib/menu/menu_sections.rb
@@ -1,92 +0,0 @@
-# To change this template, choose Tools | Templates
-# and open the template in the editor.
-
-class MenuSections
- include Rubygame
- extend Forwardable
-
- def_delegators :@cursor_helper, :move_cursor
-
- def initialize(cursor_helper, section_depth, sections_offset, sections)
- @sections = sections
- @section_depth = section_depth
- @cursor_helper = cursor_helper
- @activated = false
- @sections_offset = sections_offset
- end
-
- def activate(game)
- #TODO maybe check here for the type and required depth?
- @activated = true
- @cursor_helper.activate
- end
-
- def section_by_index(idx)
- if @sections.is_a?(MenuSections)
- @sections.section_by_index(idx)
- else
- @sections[idx]
- end
-
- end
-
- def size
- @sections.size
- end
-
- def cancel
- @cursor_helper.cancel
- end
-
- def name
- @sections.first.text
- end
-
- def cursor_selected_entry_name
- @cursor_helper.selected_amongst(self).name
- end
- def active_section
- @sections[@cursor_helper.position]
- end
-
- def color_for_current_section_cursor
- :blue #TODO update this
- end
-
- def text
- @sections.collect { |s| s.text }
- end
-
- def section_names
- text
- end
-
- def reset_indices
- @cursor_helper.reset_indices
- end
-
- def move_cursor(dir)
- @cursor_helper.move_cursor(dir, self)
- end
-
- def section_within_depth(d)
- @section_depth <= d
- end
-
- def draw(menu_layer_config, game, text_rendering_helper, layer, screen)
- return unless section_within_depth(@cursor_helper.depth)
-
- text_rendering_helper.render_lines_to_layer( text, @sections_offset)
- #TODO move cursor drawing into menu layer/menu helper
- @cursor_helper.draw_at_depth(layer, menu_layer_config, game, active_section)
- pos_at_depth = @sections[@cursor_helper.position_at_depth(@section_depth)]
- if pos_at_depth.has_subsections?
- pos_at_depth.draw(menu_layer_config, game, text_rendering_helper, layer, screen)
- end
- layer.blit(screen, menu_layer_config.layer_inset_on_screen)
-
- end
-
-
-
-end
View
6 lib/menu/noop_action.rb
@@ -1,6 +0,0 @@
-
-class NoopAction
- def perform(src,dest)
- puts "nothing to do, noop action" #TODO consume readiness?
- end
-end
View
11 lib/menu/save_load_menu_action.rb
@@ -1,11 +0,0 @@
-
-class SaveLoadMenuAction < MenuAction
-
- def has_subsections?
- false
- end
-
- def save_slot(idx)
- "save-slot-#{idx}.json"
- end
-end
View
16 lib/menu/save_menu_action.rb
@@ -1,16 +0,0 @@
-
-class SaveMenuAction < SaveLoadMenuAction
- def activate(menu_idx, game, submenu_idx)
- puts "saving: #{game.player}"
- json = JSON.generate(game.player)
- slot = save_slot(submenu_idx)
- save_file = File.open(slot, "w")
- save_file.puts json
- save_file.close
- puts "saving to slot #{submenu_idx}, json data is: "
- puts "player was at #{game.player.px} and #{game.player.py} at save time"
- puts "save action believes the menu layer to be active? #{game.universe.menu_layer.active}"
- game.toggle_menu
- game.add_notification(WorldScreenNotification.new("Saved to #{slot}"))
- end
-end
View
17 lib/menu/sort_inventory_action.rb
@@ -1,17 +0,0 @@
-
-class SortInventoryAction
- attr_reader :text
- def initialize(text, game, menu_helper)
- @text = text
- @game = game
- @menu_helper = menu_helper
- end
- def activate(cursor_position, game, section_position)
- puts "TODO re-sort inventory"
- end
-
- def has_subsections?
- false
- end
-
-end
View
15 lib/menu/status_display_action.rb
@@ -1,15 +0,0 @@
-
-
-class StatusDisplayAction < AbstractActorMenuAction
- def size
- 1
- end
-
- def activate(cursor_position, game, section_position, subsection_position=nil, option_position=nil)
- @menu_helper.set_active_subsection(section_position)
- false
- end
-
-
- alias_method :details, :display_actor_status_info
-end
View
51 lib/menu/update_equipment_action.rb
@@ -1,51 +0,0 @@
-
-class UpdateEquipmentAction < AbstractActorMenuAction
-
- def initialize(actor, menu_helper, game)
- super(actor, menu_helper)
- @game = game
- end
-
- def activate(cursor_position, game, section_position, subsection_position=nil, option_position=nil)
- @menu_helper.set_active_subsection(section_position)
- unless option_position.nil?
- new_gear = inventory[option_position]
-
- @actor.equip_in_slot_index(subsection_position, new_gear)
- end
- true
- end
-
- def option_at(idx)
- inventory
- end
-
- def equipment
- @actor.equipment_info
- end
- def details
- info_lines = equipment
- s = Surface.new([@@STATUS_WIDTH, @@STATUS_HEIGHT])
- s.fill(:yellow)
- @menu_helper.render_text_to(s, info_lines, TextRenderingConfig.new(0, 0, 0,@@MENU_LINE_SPACING))
- s
- end
-
- def inventory
- @game.inventory.inventory_info
- end
-
- def surface_for(posn)
- info_lines = inventory.collect {|i| i.to_info}
- s = Surface.new([@@STATUS_WIDTH, @@STATUS_HEIGHT])
- s.fill(:yellow)
- @menu_helper.render_text_to(s, info_lines, TextRenderingConfig.new(0, 0, 0,@@MENU_LINE_SPACING))
- s
- end
-
- def size
- @actor.equipment_info.size
- end
-
-
-end
Please sign in to comment.
Something went wrong with that request. Please try again.