Permalink
Browse files

moved battle menus to the new style

  • Loading branch information...
bgoodspeed committed Nov 2, 2010
1 parent 0947bff commit 4e5586b10f901396ade86570f72cb418917f933f
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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)
@@ -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
@@ -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
@@ -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
Oops, something went wrong.

0 comments on commit 4e5586b

Please sign in to comment.