Skip to content
Browse files

moved battle menus to the new style

  • Loading branch information...
1 parent 0947bff commit 4e5586b10f901396ade86570f72cb418917f933f @bgoodspeed committed Nov 2, 2010
View
8 features/battle.feature
@@ -3,7 +3,13 @@ Feature: battle
As a player on the worldmap
I want to start a battle
-Scenario: start a fight
+Scenario: start a fight artificially
+ Given I am at 320, 240
+ And I start a fight
+ When 2 ticks have passed
+ Then I should be in a battle
+
+Scenario: start a fight on the world map for real
Given I am at 320, 240
And I press 'Down' for 48 ticks
And 70 ticks have passed
View
5 features/step_definitions/walkthrough_steps.rb
@@ -111,3 +111,8 @@ def press(what)
@g.current_selected_menu_entry_name.should == "Slot #{arg1}"
end
+
+Given /^I start a fight$/ do
+ monster = MonsterFactory.new.make_monster(@g.player, @g.universe)
+ @g.start_battle(monster)
+end
View
15 lib/battle/menu/actions/accept_battle_outcome_menu_action.rb
@@ -0,0 +1,15 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class AcceptBattleOutcomeMenuAction
+ attr_reader :dependencies, :name, :game
+ include BattleSelectorDependencyHelper
+
+ def initialize(game)
+ @game = game
+ @name = "Battle Spoils"
+ @dependencies = [
+ BattleAcceptSpoilsMenuSelector.new(game)
+ ]
+ end
+end
View
17 lib/battle/menu/actions/attack_battle_menu_action.rb
@@ -0,0 +1,17 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class AttackBattleMenuAction
+ attr_reader :dependencies, :name, :game
+ include BattleSelectorDependencyHelper
+
+
+ def initialize(game)
+ @game = game
+ @name = "Attack"
+ @dependencies = [
+ BattleReadyPartyMenuSelector.new(game),
+ BattleTargetsMenuSelector.new(game)
+ ]
+ end
+end
View
10 lib/battle/menu/actions/battle_selector_dependency_helper.rb
@@ -0,0 +1,10 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+module BattleSelectorDependencyHelper
+ include BaseSelectorDependencyHelper
+ def text_rendering_helper_from(game)
+ game.battle_layer.text_rendering_helper
+ end
+
+end
View
16 lib/battle/menu/actions/flee_battle_menu_action.rb
@@ -0,0 +1,16 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class FleeBattleMenuAction
+ attr_reader :dependencies, :name, :game
+ include BattleSelectorDependencyHelper
+
+ def initialize(game)
+ @game = game
+ @name = "Flee"
+ @dependencies = [
+ BattleReadyPartyMenuSelector.new(game)
+ ]
+ end
+
+end
View
17 lib/battle/menu/actions/use_battle_item_battle_menu_action.rb
@@ -0,0 +1,17 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class UseBattleItemBattleMenuAction
+ attr_reader :dependencies, :name, :game
+ include BattleSelectorDependencyHelper
+
+ def initialize(game)
+ @game = game
+ @name = "Items"
+ @dependencies = [
+ BattleReadyPartyMenuSelector.new(game),
+ BattleFilteredInventoryMenuSelector.new(game),
+ BattleTargetsMenuSelector.new(game)
+ ]
+ end
+end
View
19 lib/battle/menu/actions/use_skill_battle_menu_action.rb
@@ -0,0 +1,19 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class UseSkillBattleMenuAction
+ attr_reader :dependencies, :name, :game
+ include BattleSelectorDependencyHelper
+
+
+ def initialize(game)
+ @game = game
+ @name = "Skills"
+ @dependencies = [
+ BattleReadyPartyMenuSelector.new(game),
+ BattleSkillMenuSelector.new(game),
+
+ BattleTargetsMenuSelector.new(game)
+ ]
+ end
+end
View
8 lib/battle/menu/selectors/battle_accept_spoils_menu_selector.rb
@@ -0,0 +1,8 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class BattleAcceptSpoilsMenuSelector
+ def initialize(g)
+
+ end
+end
View
8 lib/battle/menu/selectors/battle_filtered_inventory_menu_selector.rb
@@ -0,0 +1,8 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class BattleFilteredInventoryMenuSelector
+ def initialize(g)
+
+ end
+end
View
13 lib/battle/menu/selectors/battle_ready_party_menu_selector.rb
@@ -0,0 +1,13 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class BattleReadyPartyMenuSelector
+ include DrawableElementMenuSelectorHelper
+ def initialize(game)
+ @game = game
+ end
+
+ def elements
+ @game.battle_ready_party_members
+ end
+end
View
8 lib/battle/menu/selectors/battle_skill_menu_selector.rb
@@ -0,0 +1,8 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class BattleSkillMenuSelector
+ def initialize(g)
+
+ end
+end
View
15 lib/battle/menu/selectors/battle_targets_menu_selector.rb
@@ -0,0 +1,15 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class BattleTargetsMenuSelector
+ include DrawableElementMenuSelectorHelper
+
+ def initialize(game)
+ @game = game
+ end
+
+ def elements
+ @game.battle_ready_party_members
+ end
+
+end
View
3 lib/domain/game.rb
@@ -70,6 +70,9 @@ def battle_completed
end
+ def start_battle(monster)
+ battle_layer.start_battle(self, universe, player, monster)
+ end
def rebuild_hud
@hud = @factory.make_hud(@screen, @player, @universe)
View
8 lib/factories/game_internals_factory.rb
@@ -79,13 +79,7 @@ def make_world1
end
def make_monster(player,universe)
- monster_inv = Inventory.new(255)
- monster_inv.add_item(1, GameItemFactory.potion)
- monattrib = CharacterAttribution.new(
- CharacterState.new(CharacterAttributes.new(3, 0, 1, 0, 0, 0, 0, 0)),
- EquipmentHolder.new)
- monai = ArtificialIntelligence.new(RepeatingPathFollower.new("DRUL", 80), BattleStrategy.new([BattleTactic.new("Enemy: Any -> Attack")]))
- Monster.new(player,universe,"monster.png", 400,660, @@MONSTER_X, @@MONSTER_Y, monster_inv, monattrib, monai)
+ MonsterFactory.new.make_monster(player, universe)
end
def make_npc(player, universe)
View
14 lib/factories/monster_factory.rb
@@ -0,0 +1,14 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class MonsterFactory
+ def make_monster(player,universe)
+ monster_inv = Inventory.new(255)
+ monster_inv.add_item(1, GameItemFactory.potion)
+ monattrib = CharacterAttribution.new(
+ CharacterState.new(CharacterAttributes.new(3, 0, 1, 0, 0, 0, 0, 0)),
+ EquipmentHolder.new)
+ monai = ArtificialIntelligence.new(RepeatingPathFollower.new("DRUL", 80), BattleStrategy.new([BattleTactic.new("Enemy: Any -> Attack")]))
+ Monster.new(player,universe,"monster.png", 400,660, @@MONSTER_X, @@MONSTER_Y, monster_inv, monattrib, monai)
+ end
+end
View
18 lib/game_requirements.rb
@@ -40,6 +40,7 @@
require 'lib/items/equipment/equipment_holder'
+require 'lib/factories/monster_factory'
require 'lib/factories/game_item_factory'
require 'lib/factories/world_state_factory'
require 'lib/factories/game_internals_factory'
@@ -68,6 +69,7 @@
require 'lib/menu/selectors/selections'
+require 'lib/menu/selectors/drawable_element_menu_selector_helper'
require 'lib/menu/selectors/static_menu_selector'
require 'lib/menu/selectors/equipment_slot_menu_selector'
require 'lib/menu/selectors/filtered_inventory_menu_selector'
@@ -76,6 +78,7 @@
require 'lib/menu/selectors/save_slot_menu_selector'
require 'lib/menu/selectors/stat_line_menu_selector'
+require 'lib/menu/actions/base_selector_dependency_helper'
require 'lib/menu/actions/selector_dependency_helper'
require 'lib/menu/actions/equip_item_in_member_slot_menu_action'
require 'lib/menu/actions/level_up_stat_menu_action'
@@ -143,6 +146,21 @@
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'
+require 'lib/battle/menu/selectors/battle_targets_menu_selector'
+require 'lib/battle/menu/selectors/battle_filtered_inventory_menu_selector'
+require 'lib/battle/menu/selectors/battle_accept_spoils_menu_selector'
+
+require 'lib/battle/menu/actions/battle_selector_dependency_helper'
+require 'lib/battle/menu/actions/accept_battle_outcome_menu_action'
+require 'lib/battle/menu/actions/attack_battle_menu_action'
+require 'lib/battle/menu/actions/use_battle_item_battle_menu_action'
+require 'lib/battle/menu/actions/use_skill_battle_menu_action'
+require 'lib/battle/menu/actions/flee_battle_menu_action'
+
+
+
require 'lib/palettes/i_s_b_p_entry'
require 'lib/palettes/s_b_p_entry'
require 'lib/palettes/c_i_s_b_p_entry'
View
76 lib/layers/battle_layer.rb
@@ -6,34 +6,49 @@ class BattleLayer < AbstractLayer
extend Forwardable
def_delegators :@battle, :participants, :current_battle_participant_offset
def_delegators :@game, :inventory
- attr_reader :battle
+ attr_reader :battle, :text_rendering_helper
include EventHandler::HasEventHandler
def initialize(screen, game)
super(screen, screen.w - 50, screen.h - 50)
@layer.fill(:orange)
@text_rendering_helper = TextRenderingHelper.new(@layer, @font)
@battle = nil
- @menu_helper = nil
@game = game
@battle_hud = BattleHud.new(@screen, @text_rendering_helper, @layer)
- sections = [MenuSection.new("Exp",[EndBattleMenuAction.new("Confirm", self)]),
- MenuSection.new("Items", [EndBattleMenuAction.new("Confirm", self)])]
- @end_of_battle_menu_helper = MenuHelper.new(screen, @layer, @text_rendering_helper, sections, @@MENU_LINE_SPACING,@@MENU_LINE_SPACING)
+
+ @cursor_helper = CursorHelper.new([20,20]) #TODO these constants should be extracted
+
+# sections = [MenuSection.new("Exp",[EndBattleMenuAction.new("Confirm", self)]),
+# MenuSection.new("Items", [EndBattleMenuAction.new("Confirm", self)])]
+# @end_of_battle_menu_helper = MenuHelper.new(screen, @layer, @text_rendering_helper, sections, @@MENU_LINE_SPACING,@@MENU_LINE_SPACING)
make_magic_hooks({ClockTicked => :update})
end
def update( event )
return unless @battle and !@battle.over?
dt = event.seconds # Time since last update
@battle.accumulate_readiness(dt)
end
+
+ def rebuild_menu
+ @menu = TaskMenu.new(@game, [
+ AttackBattleMenuAction.new(@game),
+ UseBattleItemBattleMenuAction.new(@game),
+ UseSkillBattleMenuAction.new(@game),
+ FleeBattleMenuAction.new(@game) ])
+
+ @end_menu = TaskMenu.new(@game, [
+ AcceptBattleOutcomeMenuAction.new(@game)
+ ])
+
+ end
def start_battle(game, universe, player, monster)
@active = true
@battle = Battle.new(game, universe, player, monster, self)
- @menu_helper = BattleMenuHelper.new(@battle, @screen, @layer, @text_rendering_helper, [], @@MENU_LINE_SPACING,@@MENU_LINE_SPACING)
+# @menu_helper = BattleMenuHelper.new(@battle, @screen, @layer, @text_rendering_helper, [], @@MENU_LINE_SPACING,@@MENU_LINE_SPACING)
- sections = player.party.collect {|hero| HeroMenuSection.new(hero, [AttackMenuAction.new("Attack", self, @menu_helper), ItemMenuAction.new("Item", self, @menu_helper, @game)])}
- @menu_helper.replace_sections(sections)
+ # sections = player.party.collect {|hero| HeroMenuSection.new(hero, [AttackMenuAction.new("Attack", self, @menu_helper), ItemMenuAction.new("Item", self, @menu_helper, @game)])}
+ # @menu_helper.replace_sections(sections)
end
def end_battle
@active = false
@@ -64,43 +79,50 @@ def end_battle_menu_layer_config
mlc.layer_inset_on_screen = [@@LAYER_INSET,@@LAYER_INSET]
mlc
end
+
+ def menu
+ @menu
+ end
def draw()
@layer.fill(:orange)
if @battle.over?
if @battle.player_alive?
- @end_of_battle_menu_helper.draw(end_battle_menu_layer_config, @game)
+ @end_of_battle_menu.draw(end_battle_menu_layer_config, @game)
else
puts "you died ... game should be over... whatever"
- @end_of_battle_menu_helper.draw(end_battle_menu_layer_config, @game)
+ @end_of_battle_menu..draw(end_battle_menu_layer_config, @game)
end
else
@battle.monster.draw_to(@layer)
- @menu_helper.draw(menu_layer_config, @game)
+ rebuild_menu
+ menu.draw(menu_layer_config, @cursor_helper.path, @cursor_helper.currently_selected)
+ @cursor_helper.draw_at_depth(@layer, menu_layer_config, @game, nil)
+ @layer.blit(@screen, menu_layer_config.layer_inset_on_screen)
@battle_hud.draw(menu_layer_config, @game, @battle)
end
end
- def enter_current_cursor_location(game)
- if @battle.over?
- @end_of_battle_menu_helper.enter_current_cursor_location(game)
- else
- @menu_helper.enter_current_cursor_location(game)
- end
+ def move_cursor_up(e)
+ @cursor_helper.move_cursor_up(menu)
+ end
+ def move_cursor_down(e)
+ @cursor_helper.move_cursor_down(menu)
end
- def move_cursor_down
- send_action_to_target(:move_cursor_down)
+ def enter_current_cursor_location(e)
+ @cursor_helper.activate(menu)
end
- def move_cursor_up
- send_action_to_target(:move_cursor_up)
+ def current_selected_menu_entry_name
+ @cursor_helper.current_selected_menu_entry_name(menu)
end
- def cancel_action
- send_action_to_target(:cancel_action)
+ #TODO might have to rebuild menu here and in there check for the battle being over to deal with
+ # having a different end of battle menu
+ def current_menu_entries
+ @cursor_helper.current_menu_entries(menu)
end
- def send_action_to_target(sym)
- target = @battle.over? ? @end_of_battle_menu_helper : @menu_helper
- target.send(sym)
- end
+
+
+
end
View
53 lib/menu/actions/base_selector_dependency_helper.rb
@@ -0,0 +1,53 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+module BaseSelectorDependencyHelper
+ def element_at(idx, selections)
+ dependencies[idx]
+ end
+
+ def satisfied_by?(selections)
+ dependencies.each { |the_dependency|
+ return false unless selections.satisfy?(the_dependency)
+ }
+ true
+ end
+
+ def navigate_path(path)
+ dependencies[path.size]
+ end
+
+ def navigate_path_to_select(path, selections)
+ dependencies[path.size - 1].element_at(path[path.size - 1], selections)
+ end
+
+ def selection_match?(selections)
+ selections.has_selected?(self.class)
+ end
+
+ def selected_and_satisfied_by?(selections)
+ selection_match?(selections) && satisfied_by?(selections)
+ end
+
+ def path_or_dep_size(path)
+ [path.size, dependencies.size].min
+ end
+ def draw_deps(menu_layer_config, path, index, selections)
+ trh = text_rendering_helper_from(game)
+ path_or_dep_size(path).times {|dependency_index|
+ dependencies[dependency_index].draw(
+ menu_layer_config.selector_menu_text_config_at_depth(dependency_index),
+ trh, selections)
+ }
+ end
+
+ def draw(menu_layer_config, path, index, selections)
+ trh = text_rendering_helper_from(game)
+ trh.render_lines_to_layer( [name], menu_layer_config.main_menu_text.offset_by(index))
+
+ if selection_match?(selections)
+ draw_deps(menu_layer_config, path, index, selections)
+ end
+ end
+
+end
View
52 lib/menu/actions/selector_dependency_helper.rb
@@ -1,51 +1,7 @@
module SelectorDependencyHelper
- def element_at(idx, selections)
- dependencies[idx]
- end
-
- def satisfied_by?(selections)
- dependencies.each { |the_dependency|
- return false unless selections.satisfy?(the_dependency)
- }
- true
- end
-
- def navigate_path(path)
- dependencies[path.size]
- end
-
- def navigate_path_to_select(path, selections)
- dependencies[path.size - 1].element_at(path[path.size - 1], selections)
- end
-
- def selection_match?(selections)
- selections.has_selected?(self.class)
- end
-
- def selected_and_satisfied_by?(selections)
- selection_match?(selections) && satisfied_by?(selections)
- end
-
- def path_or_dep_size(path)
- [path.size, dependencies.size].min
- end
-
- def draw_deps(menu_layer_config, path, index, selections)
- trh = game.menu_layer.text_rendering_helper
- path_or_dep_size(path).times {|dependency_index|
- dependencies[dependency_index].draw(
- menu_layer_config.selector_menu_text_config_at_depth(dependency_index),
- trh, selections)
- }
- end
-
- def draw(menu_layer_config, path, index, selections)
- trh = game.menu_layer.text_rendering_helper
- trh.render_lines_to_layer( [name], menu_layer_config.main_menu_text.offset_by(index))
-
- if selection_match?(selections)
- draw_deps(menu_layer_config, path, index, selections)
- end
- end
+ include BaseSelectorDependencyHelper
+ def text_rendering_helper_from(game)
+ game.menu_layer.text_rendering_helper
+ end
end
View
24 lib/menu/selectors/drawable_element_menu_selector_helper.rb
@@ -0,0 +1,24 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+module DrawableElementMenuSelectorHelper
+
+ def element_names(selections)
+ elements.collect {|el| el.name }
+ end
+
+ def size(selectios=nil)
+ elements.size
+ end
+
+ def select_element_at(idx, selections)
+ elements[idx]
+ end
+
+ alias_method :element_at, :select_element_at
+ def draw(config, text_rendering_helper, currently_selected)
+ member_names = elements.collect {|m| m.name}
+ text_rendering_helper.render_lines_to_layer( member_names, config)
+ end
+
+end
View
18 lib/menu/selectors/inventory_filter_menu_selector.rb
@@ -15,6 +15,7 @@ def initialize
end
class InventoryFilterMenuSelector
+ include DrawableElementMenuSelectorHelper
attr_accessor :menu_item
def initialize(game)
@game = game
@@ -25,26 +26,11 @@ def selection_type
InventoryFilter
end
- def filters
+ def elements
[InventoryFilter.new, KeyItemInventoryFilter.new]
end
- alias_method :elements, :filters
- def select_element_at(idx, selections)
- elements[idx]
- end
- def element_names(selections)
- elements.collect {|el| el.name }
- end
-
alias_method :element_at, :select_element_at
- def size(selectios=nil)
- filters.size
- end
- def draw(config, text_rendering_helper, currently_selected)
- member_names = elements.collect {|m| m.name}
- text_rendering_helper.render_lines_to_layer( member_names, config)
- end
end
View
24 lib/menu/selectors/party_menu_selector.rb
@@ -3,7 +3,7 @@
class PartyMenuSelector
extend Forwardable
-
+ include DrawableElementMenuSelectorHelper
attr_accessor :menu_item
def_delegators :@menu_item, :name
@@ -15,34 +15,14 @@ def size(selections=nil)
elements.size
end
- def party_members
+ def elements
@game.party_members
end
def selection_type
Hero
end
- def select_element_at(idx, selections)
- rv = elements[idx]
- raise "invalid party member selection: #{idx} of #{elements.size}" if rv.nil?
- rv
- end
-
- alias_method :elements, :party_members
- def element_at(idx, selections)
- rv = elements[idx]
- raise "invalid party member selection: #{idx} of #{elements.size}" if rv.nil?
- rv
- end
- def element_names(selections)
- elements.collect {|e| e.name}
- end
-
- def draw(config, text_rendering_helper, currently_selected)
- member_names = elements.collect {|m| m.name}
- text_rendering_helper.render_lines_to_layer( member_names, config)
- end
end
View
11 lib/menu/selectors/save_slot_menu_selector.rb
@@ -11,7 +11,7 @@ def initialize(name, filename, idx)
class SaveSlotMenuSelector
attr_accessor :menu_item
-
+ include DrawableElementMenuSelectorHelper
@@NUM_SLOTS = 5
def initialize(game)
@@ -28,14 +28,5 @@ def elements
def save_slot(idx)
SaveSlot.new("Slot #{idx + 1}" ,"save-slot-#{idx}.json", idx)
end
- def select_element_at(idx, selections)
- elements[idx]
- end
-
- alias_method :element_at, :select_element_at
- def draw(config, text_rendering_helper, currently_selected)
- member_names = elements.collect {|m| m.name}
- text_rendering_helper.render_lines_to_layer( member_names, config)
- end
end

0 comments on commit 4e5586b

Please sign in to comment.
Something went wrong with that request. Please try again.