note
	description: "[
			Used to hold a BOARD_VIEW in the VITP vitp.program.
			]"
	author: "Jimmy J. Johnson"

class
	BOARD_TOOL

inherit

	VITP_TOOL
		redefine
			create_interface_objects,
			initialize,
			build_tool_bar,
			add_actions,
--			initialize_interface,
--			set_actions,
			set_target,
			draw,
			set_button_states
		end

	GAME_CONSTANTS
		undefine
			default_create,
			copy
		end

create
	make

feature {NONE} -- Initialization

	create_interface_objects
			-- Create objects to be used by `Current' in `initialize'
			-- Implemented by descendants to create attached objects
			-- in order to adhere to void-safety due to the implementation
            -- bridge pattern.
		do
			print ("BOARD_TOOL.create_interface_objects %N")
			Precursor {VITP_TOOL}
			print ("BOARD_TOOL.create_interface_objects  before creating board_view %N")
			create board_view.make (vitp)
			print ("BOARD_TOOL.create_interface_objects  after creating board_view %N")
			create repair_button
			create flip_raiders_button
			create commit_button
			create sop_button
			repair_button.set_pixmap (create {EV_PIXMAP}.make_with_pixel_buffer (Icon_tool_color_buffer))
			repair_button.set_tooltip ("Repair Units")
			flip_raiders_button.set_pixmap (create {EV_PIXMAP}.make_with_pixel_buffer (Icon_reset_diagram_color_buffer))
			flip_raiders_button.set_tooltip ("Flip Raiders")
			commit_button.set_pixmap (create {EV_PIXMAP}.make_with_pixel_buffer (Icon_client_link_buffer))
			commit_button.set_tooltip ("Commit and Advance")
			sop_button.set_text ("SOP Button fix me")
			print ("%T  end  BOARD_TOOL.create_interface_objects %N")
		end

	initialize
			-- Build the interface for this window
		do
			Precursor {VITP_TOOL}
			split_manager.extend (board_view)
			set_minimum_width (1000)
		end

	build_tool_bar
			-- Set up the user tool bar for this tool
		local
			vs: EV_VERTICAL_SEPARATOR
		do
			Precursor
--			tool_bar.extend (create {EV_VERTICAL_SEPARATOR})
--			tool_bar.extend (repair_button)
--			tool_bar.extend (flip_raiders_button)
			tool_bar.extend (sop_button)
				-- Separator between two buttons
			create vs
			tool_bar.extend (vs)
			tool_bar.disable_item_expand (vs)
			vs.set_minimum_width (20)
				-- Add button
			tool_bar.extend (commit_button)
			tool_bar.disable_item_expand (commit_button)
			create vs
			tool_bar.extend (vs)
			tool_bar.disable_item_expand (vs)
			vs.set_minimum_width (20)
		end

	add_actions
			-- Associate actions with the buttons
		do
			Precursor {VITP_TOOL}
			commit_button.select_actions.extend (agent on_commit)
			sop_button.select_actions.extend (agent on_execute)
		end

feature -- Access

	board_view: BOARD_VIEW
			-- Handle to the view corresponding to the first view created by the
			-- `view_manager' in `initialize'.
			-- Convinience feature.

	focused_view: VITP_CELL_VIEW
			-- The view that currently has the focus
		do
			Result := board_view
--			if japanese_chart_view.has_focus then
--				Result := japanese_chart_view
--			else
--				Result := board_view
--			end
		end

feature -- Element change

	set_target (a_game: like vitp)
			-- Change the value of `target' and add it to the `target_set' (the set
			-- of objects contained in this view.  The old target is removed from
			-- the set.
			-- This feature can be used as a pattern if a descendant wants to give
			-- special treatment to a single target.
		do
			Precursor {VITP_TOOL} (a_game)
			board_view.set_target (a_game)
		end

feature -- Basic operations

	draw
			-- Redraw the tool
		do
			Precursor {VITP_TOOL}
--			board_view.draw
			set_button_states
		end

	on_commit
			-- Action to be performed when the `commit_button' is pressed
		do
--			vitp.advance
--			board_view.on_advanced
			vitp.sequence_of_play.forth
			draw_views (vitp)
		end

	on_execute
			-- Perform the any action associated with the current step
			-- in the sequence of play.
		local
			sop: VITP_SEQUENCE_OF_PLAY
		do
			sop := vitp.sequence_of_play
			sop.execute_step_actions
			draw_views (vitp)
		end

feature {NONE} -- implementation

	set_button_states
			-- Enable or disable the buttons depending on the
			-- state of the view
		do
			Precursor {VITP_TOOL}
			set_added_buttons_states
		end

	set_added_buttons_states
			-- Enable or disable the buttons that this tool
			-- added to the tool bar.
		local
			sop: VITP_SEQUENCE_OF_PLAY
			s: GAME_STEP
			c: FONT_AND_COLOR_CONSTANTS
		do
			if is_view_empty  then
				repair_button.disable_sensitive
				flip_raiders_button.disable_sensitive
				commit_button.disable_sensitive
			else
				sop := vitp.sequence_of_play
				if not sop.is_off then
					sop_button.set_text (sop.full_name)
					create c
					if sop.is_japanese_player then
						sop_button.set_background_color (c.Japanese_unit_color)
						sop_button.set_foreground_color (c.black)
					elseif sop.is_allied_player then
						sop_button.set_background_color (c.us_unit_color)
						sop_button.set_foreground_color (c.white)
					end
					if sop.is_step_executable then
						sop_button.enable_sensitive
					else
						sop_button.disable_sensitive
					end
					if sop.is_step_completed then
						commit_button.enable_sensitive
					else
						commit_button.disable_sensitive
					end
				end
			end
		end

feature {NONE} -- Implementation

	sop_button: EV_BUTTON
			-- Button showing the current game step in the Sequence
			-- of play.  The background color corresponds to the active
			-- player (red for Japanese and blue for Allied).  This
			-- button is active when the `vitp'.`sequence_of_play'
			-- indicates that automatic actions are executable.

	repair_button: EV_TOOL_BAR_BUTTON
			-- Button to mark units for repair

	flip_raiders_button: EV_TOOL_BAR_BUTTON
			-- Button to flip from patroller to raider or back

	commit_button: EV_BUTTON	--EV_TOOL_BAR_BUTTON
			-- Button for player to indicate he is finished with the step

end
