init
This commit is contained in:
56
jj_vitp/Interface/widgets/unit_widgets/air_unit_widget.e
Normal file
56
jj_vitp/Interface/widgets/unit_widgets/air_unit_widget.e
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
note
|
||||
description: "[
|
||||
A widget connecting interface to an AIR_UNIT for use in Victory in the Pacific.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
AIR_UNIT_WIDGET
|
||||
|
||||
inherit
|
||||
|
||||
ATTACK_UNIT_WIDGET
|
||||
redefine
|
||||
position_widgets,
|
||||
unit_color,
|
||||
target_imp
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
position_widgets
|
||||
-- Redefined to make smaller than the attack widget
|
||||
do
|
||||
Precursor {ATTACK_UNIT_WIDGET}
|
||||
scale (0.7)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
unit_color: EV_COLOR
|
||||
-- Get the color to paint the tile based on the unit's nationality
|
||||
do
|
||||
if unit.nationality = {NATIONALITY_CONSTANTS}.Japanese then
|
||||
Result := Japanese_air_unit_color
|
||||
elseif unit.nationality = {NATIONALITY_CONSTANTS}.us then
|
||||
Result := US_air_unit_color
|
||||
else
|
||||
check
|
||||
should_not_happen: False
|
||||
end
|
||||
Result := Green
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
target_imp: detachable AIR_UNIT
|
||||
-- Anchor for the `target' represented by Current
|
||||
|
||||
end
|
111
jj_vitp/Interface/widgets/unit_widgets/allied_air_unit_widget.e
Normal file
111
jj_vitp/Interface/widgets/unit_widgets/allied_air_unit_widget.e
Normal file
@@ -0,0 +1,111 @@
|
||||
note
|
||||
description: "[
|
||||
An {VITP_WIDGET} representing the Allied air units.
|
||||
Redefined from {AIR_UNIT_WIDGET} in order to add, color,
|
||||
and position the pictures for the other aircraft
|
||||
on the tile.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
date: "3/3/24"
|
||||
copyright: "Copyright (c) 2021, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum v2 (http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
class
|
||||
ALLIED_AIR_UNIT_WIDGET
|
||||
|
||||
inherit
|
||||
|
||||
AIR_UNIT_WIDGET
|
||||
redefine
|
||||
create_interface_objects,
|
||||
extend_widgets,
|
||||
position_widgets,
|
||||
set_widget_order,
|
||||
paint
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
create_interface_objects
|
||||
-- Create attributes
|
||||
do
|
||||
Precursor {AIR_UNIT_WIDGET}
|
||||
-- create empty polygons for the extra plane
|
||||
create picture_2
|
||||
end
|
||||
|
||||
extend_widgets
|
||||
-- Put widgets into Current. This cannot be done
|
||||
-- in `create_interface_object', because cannot call
|
||||
-- `extend' feature until all objects [in descendants]
|
||||
-- are also created.
|
||||
local
|
||||
list: ARRAYED_LIST [EV_COORDINATE]
|
||||
do
|
||||
Precursor {AIR_UNIT_WIDGET}
|
||||
extend (picture_2)
|
||||
-- Precursor adds points to `picture', not do other one
|
||||
list := silhouette_coordinates (unit)
|
||||
from list.start
|
||||
until list.after
|
||||
loop
|
||||
-- `extend_point' adds a copy of the point
|
||||
picture_2.extend_point (list.item)
|
||||
list.forth
|
||||
end
|
||||
end
|
||||
|
||||
position_widgets
|
||||
-- Move Current and contained widgets to correct
|
||||
-- location and set their sizes
|
||||
do
|
||||
Precursor {AIR_UNIT_WIDGET}
|
||||
-- The scale coming through the Precursor from
|
||||
-- {ATTACK_UNIT_WIDGET} is "scale (0.1)" which makes
|
||||
-- placement of the planes too fine, therefore, this
|
||||
-- feature scales the widget back up, moves the sub-
|
||||
-- widgets, then scales back down.
|
||||
scale (10)
|
||||
picture.scale (0.07) -- lead
|
||||
picture_2.scale (0.07) -- right wingman
|
||||
-- Rotate the planes 90 degrees
|
||||
picture.rotate (Pi/2)
|
||||
picture_2.rotate (Pi/2)
|
||||
-- Position the planes
|
||||
picture.set_x_y (tile.x - 28, tile.y - 5)
|
||||
picture_2.set_x_y (tile.x + 28, tile.y - 5)
|
||||
-- Scale back down
|
||||
scale (0.1)
|
||||
end
|
||||
|
||||
set_widget_order
|
||||
-- Ensure the widgets are ordered properly
|
||||
-- (i.e. whose on top?)
|
||||
do
|
||||
Precursor {AIR_UNIT_WIDGET}
|
||||
bring_to_front (picture_2)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
paint
|
||||
-- Set the colors for the `tile'
|
||||
do
|
||||
Precursor
|
||||
-- Cyan so I could tell which plane was which
|
||||
picture.set_foreground_color (adjusted_color (Black))
|
||||
picture.set_background_color (adjusted_color (Black))
|
||||
picture_2.set_foreground_color (adjusted_color (Black))
|
||||
picture_2.set_background_color (adjusted_color (Black))
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
picture_2: EV_MODEL_POLYGON
|
||||
-- The silhouette (or shape) of the 2nd airplane
|
||||
-- on the tile
|
||||
|
||||
end
|
@@ -0,0 +1,65 @@
|
||||
note
|
||||
description: "[
|
||||
A widget connecting interface to an AMPHIBIOUS_UNIT for use in VITP.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
AMPHIBIOUS_UNIT_WIDGET
|
||||
|
||||
inherit
|
||||
|
||||
ATTACK_UNIT_WIDGET
|
||||
redefine
|
||||
position_widgets,
|
||||
-- build_picture,
|
||||
unit_color,
|
||||
target_imp
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
position_widgets
|
||||
-- Redefined to make smaller than the attack widget
|
||||
do
|
||||
Precursor {ATTACK_UNIT_WIDGET}
|
||||
scale (0.7)
|
||||
picture.scale (0.13)
|
||||
picture.set_x_y (tile.x, tile.y)
|
||||
end
|
||||
|
||||
-- build_picture
|
||||
-- -- Build the `picture'.
|
||||
-- do
|
||||
-- -- The `silhouette_table' contains a function for
|
||||
-- -- the `Amphibious_symbol' indexed by the Yokosuka.
|
||||
---- picture.copy (silhouette (game.yokosuka))
|
||||
---- picture.add_points (game.yokosuka)
|
||||
-- end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
unit_color: EV_COLOR
|
||||
-- Get the color to paint the tile based on the unit's nationality
|
||||
do
|
||||
if unit.nationality = {NATIONALITY_CONSTANTS}.japanese then
|
||||
Result := Japanese_air_unit_color
|
||||
elseif unit.nationality = {NATIONALITY_CONSTANTS}.us then
|
||||
Result := US_air_unit_color
|
||||
else
|
||||
Result := Green
|
||||
check
|
||||
should_not_happen: False
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
target_imp: detachable AMPHIBIOUS_UNIT
|
||||
-- Anchor for the `target' represented by Current
|
||||
|
||||
end
|
569
jj_vitp/Interface/widgets/unit_widgets/attack_unit_widget.e
Normal file
569
jj_vitp/Interface/widgets/unit_widgets/attack_unit_widget.e
Normal file
@@ -0,0 +1,569 @@
|
||||
note
|
||||
description: "[
|
||||
Connects an attack unit to a Eiffel Vision widget.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
deferred class
|
||||
ATTACK_UNIT_WIDGET
|
||||
|
||||
inherit
|
||||
|
||||
VITP_WIDGET
|
||||
rename
|
||||
target as unit
|
||||
redefine
|
||||
create_interface_objects,
|
||||
extend_widgets,
|
||||
build_widgets,
|
||||
set_fonts_and_colors,
|
||||
position_widgets,
|
||||
set_widget_order,
|
||||
-- build_bounding_figure,
|
||||
add_actions,
|
||||
-- position_sub_widgets,
|
||||
set_target,
|
||||
paint,
|
||||
position_on_figure,
|
||||
target_imp
|
||||
end
|
||||
|
||||
inherit {NONE}
|
||||
|
||||
SILHOUETTE_CONSTANTS
|
||||
undefine
|
||||
default_create
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
create_interface_objects
|
||||
-- Create attributes
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
create tile
|
||||
create border.make (default_tile_size, default_tile_size, border_size)
|
||||
create bonus_circle
|
||||
create air_bonus_circle
|
||||
create anchor
|
||||
create gunnery_factor_mt
|
||||
create defense_factor_mt
|
||||
create speed_factor_mt
|
||||
create air_strike_factor_mt
|
||||
-- create picture.make_with_coordinates (silhouette_coordinates (unit))
|
||||
create picture
|
||||
end
|
||||
|
||||
extend_widgets
|
||||
-- Put widgets into Current. This cannot be done
|
||||
-- in `create_interface_object', because cannot call
|
||||
-- `extend' feature until all objects [in descendants]
|
||||
-- are also created.
|
||||
local
|
||||
list: ARRAYED_LIST [EV_COORDINATE]
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
extend (tile)
|
||||
extend (border)
|
||||
extend (bonus_circle)
|
||||
extend (air_bonus_circle)
|
||||
extend (anchor)
|
||||
extend (picture)
|
||||
text_group.extend (gunnery_factor_mt)
|
||||
text_group.extend (defense_factor_mt)
|
||||
text_group.extend (speed_factor_mt)
|
||||
text_group.extend (air_strike_factor_mt)
|
||||
-- Add points to the `tile'
|
||||
tile.extend_point (create {EV_COORDINATE}.make (0, 0))
|
||||
tile.extend_point (create {EV_COORDINATE}.make (default_tile_size.rounded, 0))
|
||||
tile.extend_point (create {EV_COORDINATE}.make (default_tile_size.rounded, default_tile_size.rounded))
|
||||
tile.extend_point (create {EV_COORDINATE}.make (0, default_tile_size.rounded))
|
||||
-- Add points to `picture'
|
||||
list := silhouette_coordinates (unit)
|
||||
from list.start
|
||||
until list.after
|
||||
loop
|
||||
-- `extend_point' adds a copy of the point
|
||||
picture.extend_point (list.item)
|
||||
list.forth
|
||||
end
|
||||
end
|
||||
|
||||
build_widgets
|
||||
-- Now that widgets were created in `create_interface_objects'
|
||||
-- and added to Current in `extend_widgets', build up the
|
||||
-- widgets by adding internal structure to each widget.
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
end
|
||||
|
||||
set_fonts_and_colors
|
||||
-- Set the default fonts for any text widgets and set
|
||||
-- the default colors for any contained widgets.
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
name_mt.set_font (Unit_name_font)
|
||||
gunnery_factor_mt.set_font (Unit_speed_font)
|
||||
defense_factor_mt.set_font (Unit_speed_font)
|
||||
speed_factor_mt.set_font (Unit_speed_font)
|
||||
air_strike_factor_mt.set_font (unit_air_font)
|
||||
end
|
||||
|
||||
position_widgets
|
||||
-- Move Current and contained widgets to correct
|
||||
-- location and set their sizes
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
-- center_widget_on_other (picture, tile)
|
||||
picture.set_x_y (tile.x, tile.y)
|
||||
-- Set size and position for circles
|
||||
bonus_circle.set_point_a_position (tile.x - 70, tile.y + 30)
|
||||
bonus_circle.set_point_b_position (tile.x - 30, tile.y + 70)
|
||||
air_bonus_circle.set_point_a_position (tile.x + 45, tile.y - 55)
|
||||
air_bonus_circle.set_point_b_position (tile.x + 85, tile.y - 15)
|
||||
-- -- Center name and defense factor to start
|
||||
name_mt.set_text (unit.name)
|
||||
name_mt.set_x_y (tile.x, tile.y - 77)
|
||||
gunnery_factor_mt.set_x_y (tile.x - 75, tile.y + 70)
|
||||
defense_factor_mt.set_x_y (tile.x - 5, tile.y + 70)
|
||||
speed_factor_mt.set_x_y (tile.x + 60, tile.y + 70)
|
||||
air_strike_factor_mt.set_x_y (tile.x + 65, tile.y - 40)
|
||||
anchor.scale (0.5)
|
||||
anchor.set_x_y (tile.x - 60, tile.y - 60)
|
||||
text_group.scale (0.80)
|
||||
scale (0.1)
|
||||
end
|
||||
|
||||
set_widget_order
|
||||
-- Ensure the widgets are ordered properly
|
||||
-- (i.e. whose on top?)
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
bring_to_front (anchor)
|
||||
bring_to_front (text_group)
|
||||
bring_to_front (picture)
|
||||
|
||||
-- dot.hide
|
||||
end
|
||||
|
||||
build_tile
|
||||
-- Create the `tile
|
||||
do
|
||||
tile.extend_point (create {EV_COORDINATE}.make (0, 0))
|
||||
tile.extend_point (create {EV_COORDINATE}.make (default_tile_size.rounded, 0))
|
||||
tile.extend_point (create {EV_COORDINATE}.make (default_tile_size.rounded, default_tile_size.rounded))
|
||||
tile.extend_point (create {EV_COORDINATE}.make (0, default_tile_size.rounded))
|
||||
ensure
|
||||
correct_point_count: tile.point_count = 4
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- build_bounding_figure
|
||||
-- -- Add points to the `jj_bounding_figure'.
|
||||
-- -- Redefined to use the tile edges as the bounding area
|
||||
-- do
|
||||
-- if has (jj_bounding_figure) then
|
||||
-- prune_all (jj_bounding_figure)
|
||||
-- end
|
||||
-- create jj_bounding_figure
|
||||
-- extend (jj_bounding_figure)
|
||||
-- jj_bounding_figure.extend_point (tile.point_array.item (0))
|
||||
-- jj_bounding_figure.extend_point (tile.point_array.item (1))
|
||||
-- jj_bounding_figure.extend_point (tile.point_array.item (2))
|
||||
-- jj_bounding_figure.extend_point (tile.point_array.item (3))
|
||||
-- jj_bounding_figure.enable_closed
|
||||
-- jj_bounding_figure.set_line_width (2)
|
||||
-- jj_bounding_figure.hide
|
||||
-- end
|
||||
|
||||
add_actions
|
||||
-- Add delayed function calls to the widgets
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
set_pebble (unit)
|
||||
set_accept_cursor ((create {EV_STOCK_PIXMAPS}).hyperlink_cursor)
|
||||
-- set_pebble_function (agent on_get_pebble)
|
||||
-- pick_actions.extend (agent on_picked)
|
||||
-- pointer_button_press_actions.extend (agent on_clicked)
|
||||
-- tile.pick_actions.extend (agent on_picked (unit, ?, ?))
|
||||
-- picture.pick_actions.extend (agent on_picked (unit, ?, ?))
|
||||
end
|
||||
|
||||
on_clicked (a_x, a_y, button: INTEGER;
|
||||
a_x_tilt, a_y_tilt, a_pressure: DOUBLE;
|
||||
a_screen_x, a_screen_y: INTEGER)
|
||||
-- React to a button click for testing
|
||||
do
|
||||
io.put_string ("ATTACK_UNIT_WIDGET.on_clicked: on " + unit.name + "%N")
|
||||
if attached vitp_world as bw then
|
||||
-- bw.on_notify_button_pressed (a_unit, a_x, a_y, button)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
default_tile_size: REAL_64 = 200.0
|
||||
-- Size used for building Current, resizing after built
|
||||
|
||||
tile_size: REAL_64
|
||||
-- The size of the `tile' after finished scaling Current
|
||||
do
|
||||
Result := tile.i_th_point_x (2) - tile.i_th_point_x (1)
|
||||
end
|
||||
|
||||
color: EV_COLOR
|
||||
-- The color of the `tile'
|
||||
do
|
||||
if attached tile.background_color as c then
|
||||
Result := c
|
||||
else
|
||||
Result := Green
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_target (a_target: like unit)
|
||||
-- Set up Current based on `a_target'
|
||||
local
|
||||
s: REAL_64
|
||||
ax, ay, o_set: REAL_64
|
||||
t: EV_MODEL_TRANSFORMATION
|
||||
do
|
||||
Precursor {VITP_WIDGET} (a_target)
|
||||
gunnery_factor_mt.set_text (unit.gunnery_factor.out)
|
||||
defense_factor_mt.set_text (unit.defense_factor.out)
|
||||
speed_factor_mt.set_text (unit.speed_factor.out)
|
||||
air_strike_factor_mt.set_text (unit.airstrike_factor.out)
|
||||
paint
|
||||
-- pick_actions.wipe_out
|
||||
-- pointer_button_press_actions.extend (agent on_clicked (unit, ?,?,?,?,?,?,?,?))
|
||||
-- pick_actions.extend (agent on_picked (unit, ?, ?))
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
paint
|
||||
-- Set the colors for the `tile'
|
||||
local
|
||||
c: EV_COLOR
|
||||
bc: EV_COLOR
|
||||
ac: EV_COLOR
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
c := unit_color
|
||||
bc := border_color
|
||||
bonus_circle.hide
|
||||
air_bonus_circle.hide
|
||||
if unit.attack_bonus then
|
||||
if unit.airstrike_factor > 0 then
|
||||
air_bonus_circle.show
|
||||
else
|
||||
bonus_circle.show
|
||||
end
|
||||
end
|
||||
if is_flipped then
|
||||
ac := adjusted_color (white)
|
||||
tile.set_background_color (ac)
|
||||
border.set_color (ac)
|
||||
if is_flat then
|
||||
border.hide
|
||||
tile.set_foreground_color (bc)
|
||||
else
|
||||
border.show
|
||||
border.paint
|
||||
end
|
||||
picture.set_foreground_color (bc)
|
||||
picture.set_background_color (bc)
|
||||
-- paint the circle even if it is not shown
|
||||
bonus_circle.set_foreground_color (bc)
|
||||
bonus_circle.remove_background_color
|
||||
air_bonus_circle.set_foreground_color (bc)
|
||||
air_bonus_circle.remove_background_color
|
||||
else
|
||||
ac := adjusted_color (c)
|
||||
tile.set_background_color (ac)
|
||||
border.set_color (ac)
|
||||
if is_flat then
|
||||
border.hide
|
||||
else
|
||||
border.show
|
||||
border.paint
|
||||
end
|
||||
-- picture.set_color (adjusted_color (Dark_grey))
|
||||
picture.set_foreground_color (adjusted_color (Black))
|
||||
picture.set_background_color (adjusted_color (Black))
|
||||
bonus_circle.set_foreground_color (adjusted_color (White))
|
||||
bonus_circle.set_background_color (adjusted_color (White))
|
||||
air_bonus_circle.set_foreground_color (adjusted_color (White))
|
||||
air_bonus_circle.set_background_color (adjusted_color (White))
|
||||
end
|
||||
paint_text
|
||||
-- Remove the line from around the polygon
|
||||
tile.set_line_width (0)
|
||||
-- Draw the anchor if the ship is in port
|
||||
if game.ports.has (unit.location.name) then
|
||||
anchor.show
|
||||
anchor.set_foreground_color (adjusted_color (Silver))
|
||||
anchor.set_background_color (adjusted_color (Silver))
|
||||
-- anchor.set_color (Silver)
|
||||
-- anchor.set_color (Green)
|
||||
-- anchor.set_color (Yellow)
|
||||
-- anchor.set_color (Steel)
|
||||
-- anchor.set_color (Cyan)
|
||||
-- anchor.set_color (Chrome)
|
||||
-- anchor.set_color (Bronze)
|
||||
else
|
||||
anchor.hide
|
||||
end
|
||||
end
|
||||
|
||||
paint_text
|
||||
-- Set the color of the text fields
|
||||
local
|
||||
c: EV_COLOR
|
||||
do
|
||||
c := adjusted_color (foreground_color)
|
||||
if is_flipped then
|
||||
c := adjusted_color (background_color)
|
||||
c := adjusted_color (Black)
|
||||
else
|
||||
c := adjusted_color (Black)
|
||||
end
|
||||
name_mt.set_foreground_color (c)
|
||||
gunnery_factor_mt.set_foreground_color (c)
|
||||
defense_factor_mt.set_foreground_color (c)
|
||||
speed_factor_mt.set_foreground_color (c)
|
||||
air_strike_factor_mt.set_foreground_color (c)
|
||||
if unit.attack_bonus and unit.airstrike_factor > 0 then
|
||||
air_strike_factor_mt.show
|
||||
else
|
||||
air_strike_factor_mt.hide
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_flipped: BOOLEAN
|
||||
-- Is the back of the tile showing?
|
||||
|
||||
is_flat: BOOLEAN
|
||||
-- Should Current be drawn as a flat tile?
|
||||
|
||||
feature -- Status setting
|
||||
|
||||
flip
|
||||
-- Toggle the flip status
|
||||
do
|
||||
io.put_string ("ATTACK_UNIT_WIDGET.flip_tile %N")
|
||||
if is_flipped then
|
||||
set_unflipped
|
||||
else
|
||||
set_flipped
|
||||
end
|
||||
paint
|
||||
end
|
||||
|
||||
set_flipped
|
||||
-- Show the back of the tile
|
||||
do
|
||||
is_flipped := True
|
||||
paint
|
||||
end
|
||||
|
||||
set_unflipped
|
||||
-- Show the front of the tile
|
||||
do
|
||||
is_flipped := False
|
||||
paint
|
||||
end
|
||||
|
||||
set_flat
|
||||
-- Cause the widget to be painted as a flat tile
|
||||
do
|
||||
is_flat := True
|
||||
paint
|
||||
end
|
||||
|
||||
set_raised
|
||||
-- Cause the widget to be painted as a 3-d tile
|
||||
do
|
||||
is_flat := False
|
||||
paint
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
position_on_figure (ax, ay: INTEGER_32): BOOLEAN
|
||||
-- Is the point on (`ax', `ay') on this figure?
|
||||
do
|
||||
-- Result := ax >= tile.i_th_point_x (1) and ax <= tile.i_th_point_x (2) and
|
||||
-- ay >= tile.i_th_point_y (1) and ay <= tile.i_th_point_y (3)
|
||||
Result := tile.position_on_figure (ax, ay)
|
||||
end
|
||||
|
||||
feature {NONE} -- Actions
|
||||
|
||||
-- prepick_operations
|
||||
-- -- Feature called by `on_picked' when a pick-and-put (PNP)
|
||||
-- -- operation starts (i.e. when a right-click occurs).
|
||||
-- -- Because the operations must have started in Current, the
|
||||
-- -- pebble in transport must be `unit' which is from Current.
|
||||
-- local
|
||||
-- sop: VITP_SEQUENCE_OF_PLAY
|
||||
-- s: LINKED_SET [PORT]
|
||||
-- v: VIEW
|
||||
-- lin: LINEAR [VIEW]
|
||||
-- do
|
||||
-- print ("{ATTACK_UNIT_WIDGET}.prepick_operations %N")
|
||||
--print ("%T {ATTACK_UNIT_WIDGET}.prepick_operations: unit = " + unit.name + "%N")
|
||||
-- sop := game.sequence_of_play
|
||||
-- if sop.is_reinforcement_step then
|
||||
-- -- Get ports to which `unit' may move ...
|
||||
-- s := unit.reinforceable_ports
|
||||
-- -- ... and add drop agent for the widgets
|
||||
-- lin := linear_with_set (s)
|
||||
--print ("%T {ATTACK_UNIT_WIDGET}.prepick_operations: lin.is_empty = " + lin.is_empty.out + "%N")
|
||||
-- from lin.start
|
||||
-- until lin.after
|
||||
-- loop
|
||||
-- v := lin.item
|
||||
-- check attached {PORT_WIDGET} v as pw then
|
||||
--print ("%T {ATTACK_UNIT_WIDGET}.prepick_operations: " + pw.generating_type.name + " }.port.name = " + pw.port.name + "%N")
|
||||
-- end
|
||||
--print ("%T {ATTACK_UNIT_WIDGET}.prepick_operations: about to dim view %N")
|
||||
-- v.set_completely_dimmed
|
||||
-- if attached {JJ_PICK_AND_DROPABLE} v as d then
|
||||
-- d.drop_actions.extend (agent on_drop_target)
|
||||
-- end
|
||||
---- v.paint add feature to VIEW; call when dimmed
|
||||
-- lin.forth
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- on_drop_target (a_unit: ATTACK_UNIT)
|
||||
-- -- React when `a_unit' is dropped on Current
|
||||
-- do
|
||||
-- print ("{ATTACK_UNIT_WIDGET}.on_drop_target %N")
|
||||
-- end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
gunnery_text: STRING
|
||||
do
|
||||
if attached {AIR_UNIT} unit then
|
||||
Result := unit.airstrike_factor.out
|
||||
else
|
||||
Result := unit.gunnery_factor.out
|
||||
end
|
||||
end
|
||||
|
||||
defense_text: STRING
|
||||
do
|
||||
Result := unit.defense_factor.out
|
||||
end
|
||||
|
||||
speed_text: STRING
|
||||
do
|
||||
if attached {AIR_UNIT} unit or attached {SUBMARINE} unit then
|
||||
Result := "*"
|
||||
else
|
||||
Result := unit.speed_factor.out
|
||||
end
|
||||
end
|
||||
|
||||
air_text: STRING
|
||||
do
|
||||
if attached {AIR_UNIT} unit then
|
||||
Result := ""
|
||||
elseif unit.airstrike_factor < 1 then
|
||||
Result := ""
|
||||
else
|
||||
Result := unit.airstrike_factor.out
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
unit_color: EV_COLOR
|
||||
-- Get the color to paint the tile based on the unit's nationality
|
||||
do
|
||||
if unit.nationality = game.japanese then
|
||||
Result := Japanese_unit_color
|
||||
elseif unit.nationality = game.us then
|
||||
Result := US_unit_color
|
||||
elseif unit.nationality = game.british then
|
||||
Result := British_unit_color
|
||||
elseif unit.nationality = game.dutch or unit.nationality = game.australian then
|
||||
Result := Dutch_unit_color
|
||||
else
|
||||
check
|
||||
should_not_happen: False
|
||||
end
|
||||
Result := Green
|
||||
end
|
||||
end
|
||||
|
||||
border_color: EV_COLOR
|
||||
-- Get the color to paint the boarder of the tile
|
||||
do
|
||||
if unit.nationality = game.japanese then
|
||||
Result := Japanese_unit_boarder_color
|
||||
elseif unit.nationality = game.us then
|
||||
Result := US_unit_color
|
||||
elseif unit.nationality = game.british then
|
||||
Result := British_unit_color
|
||||
elseif unit.nationality = game.dutch or unit.nationality = game.australian then
|
||||
Result := Dutch_unit_color
|
||||
else
|
||||
check
|
||||
should_not_happen: False
|
||||
end
|
||||
Result := Green
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
target_imp: detachable ATTACK_UNIT
|
||||
-- Anchor for the `target' represented by Current
|
||||
|
||||
tile: EV_MODEL_POLYGON
|
||||
-- The square on which to place other widgets
|
||||
|
||||
picture: SILHOUETTE --EV_MODEL_POLYGON
|
||||
-- The polygon (or shape) of the unit on the tile
|
||||
|
||||
bonus_circle: EV_MODEL_ELLIPSE
|
||||
-- The circle around the gunnery factor if unit has a bonus
|
||||
|
||||
air_bonus_circle: EV_MODEL_ELLIPSE
|
||||
-- The circle around the air factor if unit has a bonus
|
||||
|
||||
border: BORDER
|
||||
-- The borders of the tile, giving a raised appearance
|
||||
|
||||
border_size: REAL_64
|
||||
-- The size to make the boarder
|
||||
do
|
||||
Result := Default_tile_size / 10
|
||||
end
|
||||
|
||||
anchor: ANCHOR -- attribute create Result.make (unit) end
|
||||
-- Indicates if a unit is in port
|
||||
|
||||
gunnery_factor_mt: EV_MODEL_TEXT
|
||||
-- Widget for the `gunnery_factor' of the `unit' text
|
||||
|
||||
defense_factor_mt: EV_MODEL_TEXT
|
||||
-- Widget for the `defense_factor' of the `unit' text
|
||||
|
||||
speed_factor_mt: EV_MODEL_TEXT
|
||||
-- Widget for the `speed' of the `unit' text
|
||||
|
||||
air_strike_factor_mt: EV_MODEL_TEXT
|
||||
-- Widget for the `air_strike_factor' of the `unit' text
|
||||
|
||||
end
|
@@ -0,0 +1,126 @@
|
||||
note
|
||||
description: "[
|
||||
An {VITP_WIDGET} representing the Japanese air units.
|
||||
Redefined from {AIR_UNIT_WIDGET} in order to add, color,
|
||||
and position the pictures for the two other aircraft
|
||||
on the tile.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
date: "3/3/24"
|
||||
copyright: "Copyright (c) 2021, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum v2 (http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
class
|
||||
JAPANESE_AIR_UNIT_WIDGET
|
||||
|
||||
inherit
|
||||
|
||||
AIR_UNIT_WIDGET
|
||||
redefine
|
||||
create_interface_objects,
|
||||
extend_widgets,
|
||||
position_widgets,
|
||||
set_widget_order,
|
||||
paint
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
create_interface_objects
|
||||
-- Create attributes
|
||||
do
|
||||
Precursor {AIR_UNIT_WIDGET}
|
||||
-- create empty polygons for the extra two picturs
|
||||
create picture_2
|
||||
create picture_3
|
||||
end
|
||||
|
||||
extend_widgets
|
||||
-- Put widgets into Current. This cannot be done
|
||||
-- in `create_interface_object', because cannot call
|
||||
-- `extend' feature until all objects [in descendants]
|
||||
-- are also created.
|
||||
local
|
||||
list: ARRAYED_LIST [EV_COORDINATE]
|
||||
do
|
||||
Precursor {AIR_UNIT_WIDGET}
|
||||
extend (picture_2)
|
||||
extend (picture_3)
|
||||
-- Precursor adds points to `picture', not do other two
|
||||
list := silhouette_coordinates (unit)
|
||||
from list.start
|
||||
until list.after
|
||||
loop
|
||||
-- `extend_point' adds a copy of the point
|
||||
picture_2.extend_point (list.item)
|
||||
picture_3.extend_point (list.item)
|
||||
list.forth
|
||||
end
|
||||
end
|
||||
|
||||
position_widgets
|
||||
-- Move Current and contained widgets to correct
|
||||
-- location and set their sizes
|
||||
do
|
||||
Precursor {AIR_UNIT_WIDGET}
|
||||
-- The scale coming through the Precursor from
|
||||
-- {ATTACK_UNIT_WIDGET} is "scale (0.1)" which makes
|
||||
-- placement of the planes too fine, therefore, this
|
||||
-- feature scales the widget back up, moves the sub-
|
||||
-- widgets, then scales back down.
|
||||
scale (10)
|
||||
-- Scale the planes
|
||||
picture.scale (0.06) -- lead
|
||||
picture_2.scale (0.06) -- left wingman
|
||||
picture_3.scale (0.06) -- right wingman
|
||||
-- Rotate the planes 90 degrees
|
||||
picture.rotate (Pi/2)
|
||||
picture_2.rotate (Pi/2)
|
||||
picture_3.rotate (Pi/2)
|
||||
-- Position the planes
|
||||
picture.set_x_y (tile.x, tile.y - 8)
|
||||
picture_2.set_x_y (tile.x - 36, tile.y + 5)
|
||||
picture_3.set_x_y (tile.x + 36, tile.y + 5)
|
||||
-- Scale back down
|
||||
scale (0.1)
|
||||
end
|
||||
|
||||
set_widget_order
|
||||
-- Ensure the widgets are ordered properly
|
||||
-- (i.e. whose on top?)
|
||||
do
|
||||
Precursor {AIR_UNIT_WIDGET}
|
||||
bring_to_front (picture_2)
|
||||
bring_to_front (picture_3)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
paint
|
||||
-- Set the colors for the `tile'
|
||||
do
|
||||
Precursor
|
||||
-- Cyan so I could tell which plane was which
|
||||
picture.set_foreground_color (adjusted_color (Black))
|
||||
picture.set_background_color (adjusted_color (Black))
|
||||
picture_2.set_foreground_color (adjusted_color (Black))
|
||||
picture_2.set_background_color (adjusted_color (Black))
|
||||
picture_3.set_foreground_color (adjusted_color (Black))
|
||||
picture_3.set_background_color (adjusted_color (Black))
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
picture_2: SILHOUETTE --EV_MODEL_POLYGON
|
||||
-- The silhouette (or shape) of the 2nd airplane
|
||||
-- on the tile
|
||||
|
||||
picture_3: SILHOUETTE --EV_MODEL_POLYGON
|
||||
-- The silhouette (or shape) of the 3rd airplane
|
||||
-- on the tile
|
||||
|
||||
|
||||
end
|
74
jj_vitp/Interface/widgets/unit_widgets/ship_widget.e
Normal file
74
jj_vitp/Interface/widgets/unit_widgets/ship_widget.e
Normal file
@@ -0,0 +1,74 @@
|
||||
note
|
||||
description: "[
|
||||
A widget connecting interface to a SHIP for use in Victory
|
||||
in the Pacific.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
SHIP_WIDGET
|
||||
|
||||
inherit
|
||||
|
||||
ATTACK_UNIT_WIDGET
|
||||
rename
|
||||
unit as ship
|
||||
redefine
|
||||
position_widgets,
|
||||
add_actions,
|
||||
target_imp
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
position_widgets
|
||||
-- Move Current and contained widgets to correct
|
||||
-- location and set their sizes
|
||||
do
|
||||
Precursor {ATTACK_UNIT_WIDGET}
|
||||
picture.scale (0.1)
|
||||
end
|
||||
|
||||
feature -- Status setting
|
||||
|
||||
set_raiding
|
||||
-- Change status of this `ship' to `is_raiding'.
|
||||
do
|
||||
ship.set_raiding
|
||||
draw_views (ship)
|
||||
end
|
||||
|
||||
set_patrolling
|
||||
-- Change the status of the `ship' to not `is_raiding'
|
||||
do
|
||||
ship.set_patrolling
|
||||
draw_views (ship)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
add_actions
|
||||
-- Add agent (i.e. actions) to the ship widget
|
||||
do
|
||||
Precursor {ATTACK_UNIT_WIDGET}
|
||||
-- set_pebble_function (agent on_get_pebble)
|
||||
-- No, do not add action to flip raider here,
|
||||
-- do it in the {BOARD_VIEW}
|
||||
-- pointer_double_press_actions.force_extend (agent flip_tile)
|
||||
end
|
||||
|
||||
target_imp: detachable SHIP
|
||||
-- Anchor for the `target' represented by Current
|
||||
|
||||
invariant
|
||||
|
||||
-- is_flipped_implication: is_flipped implies ship.is_raiding
|
||||
|
||||
end
|
65
jj_vitp/Interface/widgets/unit_widgets/submarine_widget.e
Normal file
65
jj_vitp/Interface/widgets/unit_widgets/submarine_widget.e
Normal file
@@ -0,0 +1,65 @@
|
||||
note
|
||||
description: "[
|
||||
A widget connecting interface to a {SUBMARINE} for use in VITP.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
SUBMARINE_WIDGET
|
||||
|
||||
inherit
|
||||
|
||||
ATTACK_UNIT_WIDGET
|
||||
rename
|
||||
unit as submarine
|
||||
redefine
|
||||
position_widgets,
|
||||
unit_color,
|
||||
paint,
|
||||
target_imp
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
position_widgets
|
||||
-- Move Current and contained widgets to correct
|
||||
-- location and set their sizes
|
||||
do
|
||||
Precursor {ATTACK_UNIT_WIDGET}
|
||||
picture.scale (0.1)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
paint
|
||||
-- Set the colors for the `tile'
|
||||
do
|
||||
Precursor {ATTACK_UNIT_WIDGET}
|
||||
bonus_circle.set_foreground_color (japanese_unit_color)
|
||||
bonus_circle.set_background_color (japanese_unit_color)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
unit_color: EV_COLOR
|
||||
-- Get the color to paint the tile based on the unit's nationality
|
||||
do
|
||||
if submarine.nationality = {NATIONALITY_CONSTANTS}.Japanese then
|
||||
Result := Japanese_submarine_color
|
||||
elseif submarine.nationality = {NATIONALITY_CONSTANTS}.us then
|
||||
Result := US_submarine_color
|
||||
else
|
||||
check
|
||||
should_not_happen: False
|
||||
end
|
||||
Result := Green
|
||||
end
|
||||
end
|
||||
|
||||
target_imp: detachable SUBMARINE
|
||||
-- Anchor for the `target' represented by Current
|
||||
|
||||
end
|
590
jj_vitp/Interface/widgets/unit_widgets/task_force_widget.e
Normal file
590
jj_vitp/Interface/widgets/unit_widgets/task_force_widget.e
Normal file
@@ -0,0 +1,590 @@
|
||||
note
|
||||
description: "[
|
||||
A widget that holds and displays a set of {ATTACK_UNIT}
|
||||
moving as a single unit contained in the `task_force'.
|
||||
It allows the units to be arrange in various ways.
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
|
||||
class
|
||||
TASK_FORCE_WIDGET
|
||||
|
||||
inherit
|
||||
|
||||
VITP_WIDGET
|
||||
rename
|
||||
target as task_force
|
||||
redefine
|
||||
create_interface_objects,
|
||||
build_widgets,
|
||||
-- build_bounding_figure,
|
||||
add_actions,
|
||||
set_dimming_level,
|
||||
set_target,
|
||||
show,
|
||||
center_on_dot,
|
||||
paint,
|
||||
-- on_pointer_enter,
|
||||
-- on_pointer_leave,
|
||||
wipe_out,
|
||||
target_imp
|
||||
end
|
||||
|
||||
create
|
||||
default_create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
create_interface_objects
|
||||
-- Create attributes
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
create unit_widgets.make (10)
|
||||
column_count := 12
|
||||
end
|
||||
|
||||
build_widgets
|
||||
-- Set up the widgets in Current.
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
-- build_arrows
|
||||
-- build_south_arrow
|
||||
-- build_east_arrow
|
||||
-- build_west_arrow
|
||||
-- build_north_east_arrow
|
||||
-- prune_all (dot)
|
||||
end
|
||||
|
||||
-- build_bounding_figure
|
||||
-- -- Add points to the `jj_bounding_figure'.
|
||||
-- -- The default builds a polygon from the `bounding_box'.
|
||||
-- do
|
||||
-- Precursor {VITP_WIDGET}
|
||||
-- -- Add points to the `jj_bounding_figure' to give it six points
|
||||
-- -- which can later be set to coincide with points from the
|
||||
-- -- contained units
|
||||
-- jj_bounding_figure.extend_point (create {EV_COORDINATE}.make (0, 0))
|
||||
-- jj_bounding_figure.extend_point (create {EV_COORDINATE}.make (0, 0))
|
||||
-- jj_bounding_figure.disable_events_sended_to_group
|
||||
-- end
|
||||
|
||||
add_actions
|
||||
-- Add callbacks to Current
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
pointer_double_press_actions.extend (agent on_double_press)
|
||||
jj_defining_figure.pointer_enter_actions.extend (agent on_enter_bounding_figure)
|
||||
jj_defining_figure.pointer_leave_actions.extend (agent on_leave_bounding_figure)
|
||||
-- bounding_figure.pointer_double_press_actions.extend (agent on_pointer_double_pressed_bounding_figure)
|
||||
jj_defining_figure.pointer_button_press_actions.extend (agent on_button_press_bounding_figure)
|
||||
-- bounding_figure.pointer_motion_actions.extend (agent on_pointer_motion_bounding_figure)
|
||||
-- bounding_figure.pointer_button_release_actions.extend (agent on_button_release_actions_bounding_figure)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_stacked: BOOLEAN
|
||||
-- Are the units to be arranged [with some offset] on top \
|
||||
-- of each other? If not they will be tiled.
|
||||
-- Set by `stack' and `tile'
|
||||
|
||||
is_expanded: BOOLEAN
|
||||
-- Should the units be overlapped less [greater offset]
|
||||
-- when `is_stacked'?
|
||||
-- Set by `expand' and `collapse'.
|
||||
|
||||
expected_rows: INTEGER
|
||||
-- The number of rows in which Current tries to arrange its widgets
|
||||
|
||||
feature -- Status seting
|
||||
|
||||
stack
|
||||
-- Stack units on top of each other
|
||||
do
|
||||
is_stacked := True
|
||||
jj_defining_figure.hide
|
||||
position_attack_unit_widgets
|
||||
end
|
||||
|
||||
tile
|
||||
-- Do not stack the units
|
||||
do
|
||||
is_stacked := False
|
||||
jj_defining_figure.show
|
||||
position_attack_unit_widgets
|
||||
end
|
||||
|
||||
expand
|
||||
-- Spead stacked units a little more
|
||||
do
|
||||
is_expanded := True
|
||||
position_attack_unit_widgets
|
||||
end
|
||||
|
||||
collapse
|
||||
-- Stack the units a little closer together
|
||||
do
|
||||
is_expanded := False
|
||||
position_attack_unit_widgets
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
point_on_bounding_figure (ax, ay: INTEGER): BOOLEAN
|
||||
-- Is this point on the `jj_bounding_figure'?
|
||||
-- Can be used to prevent actions intended only for Current
|
||||
do
|
||||
Result := jj_defining_figure.position_on_figure (ax, ay)
|
||||
end
|
||||
|
||||
has_widget (a_widget: ATTACK_UNIT_WIDGET): BOOLEAN
|
||||
-- Does Current contain `a_widget'?
|
||||
do
|
||||
Result := unit_widgets.has_item (a_widget)
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
set_target (a_task_force: like task_force)
|
||||
-- Change `task_force' to `a_task_force'
|
||||
do
|
||||
Precursor {VITP_WIDGET} (a_task_force)
|
||||
populate
|
||||
end
|
||||
|
||||
prune_widget (a_widget: ATTACK_UNIT_WIDGET)
|
||||
-- Remove `a_widget' from Current.
|
||||
do
|
||||
unit_widgets.start
|
||||
unit_widgets.prune (a_widget)
|
||||
end
|
||||
|
||||
wipe_out
|
||||
-- Move all unit_widgets back to the `board_world';
|
||||
-- Current removes itself from the `board_world'
|
||||
local
|
||||
w: ATTACK_UNIT_WIDGET
|
||||
do
|
||||
unit_widgets.wipe_out
|
||||
-- Clean widgets from Current and put back in board
|
||||
-- check attached {BOARD_VIEW} board_world as bw then
|
||||
-- from unit_widgets.start
|
||||
-- until unit_widgets.after
|
||||
-- loop
|
||||
-- w := unit_widgets.item_for_iteration
|
||||
-- prune_all (w)
|
||||
-- bw.extend (w)
|
||||
-- unit_widgets.forth
|
||||
-- end
|
||||
-- unit_widgets.wipe_out
|
||||
-- bw.task_force_widgets.remove (task_force)
|
||||
-- bw.prune_all (Current)
|
||||
-- end
|
||||
end
|
||||
|
||||
populate
|
||||
-- Ensure the widgets corresponding to the `task_force' units
|
||||
-- and none others are in Current
|
||||
local
|
||||
w: ATTACK_UNIT_WIDGET
|
||||
u: ATTACK_UNIT
|
||||
-- bw: VITP_WORLD
|
||||
do
|
||||
check attached vitp_world as bw then
|
||||
---- check attached {BOARD_TOOL} parent_tool as bt then
|
||||
---- bw := bt.board_view.world
|
||||
-- from bw.attack_widgets.start
|
||||
-- until bw.attack_widgets.after
|
||||
-- loop
|
||||
-- w := bw.attack_widgets.item_for_iteration
|
||||
-- u := w.unit
|
||||
-- if task_force.has (u) and not unit_widgets.has (u)then
|
||||
-- -- world.place_widget_at_units_location (w)
|
||||
-- unit_widgets.extend (w, u)
|
||||
-- bw.prune_all (w)
|
||||
-- extend (w)
|
||||
-- end
|
||||
-- if not task_force.has (u) and unit_widgets.has (u) then
|
||||
-- unit_widgets.remove (u)
|
||||
-- prune_all (w)
|
||||
-- bw.extend (w)
|
||||
-- end
|
||||
-- bw.attack_widgets.forth
|
||||
-- end
|
||||
-- if task_force.count = 1 then
|
||||
-- w := unit_widgets.widget (task_force.first)
|
||||
-- prune_all (w)
|
||||
-- bw.extend (w)
|
||||
-- end
|
||||
end
|
||||
end
|
||||
|
||||
show
|
||||
-- Ensure show is requested for each widget in Current
|
||||
do
|
||||
from unit_widgets.start
|
||||
until unit_widgets.after
|
||||
loop
|
||||
unit_widgets.item_for_iteration.show
|
||||
unit_widgets.forth
|
||||
end
|
||||
end
|
||||
|
||||
center_on_dot (a_dot: EV_MODEL_DOT)
|
||||
-- Place the center of the first ship on `a_dot'
|
||||
local
|
||||
-- u: ATTACK_UNIT_WIDGET
|
||||
do
|
||||
check attached {ATTACK_UNIT_WIDGET} unit_widgets.item (task_force.i_th (1)) as u then
|
||||
u.center_on_dot (a_dot)
|
||||
end
|
||||
position_attack_unit_widgets
|
||||
end
|
||||
|
||||
position_attack_unit_widgets
|
||||
-- Position the widgets in a stack or tiled
|
||||
local
|
||||
w, prev_w: ATTACK_UNIT_WIDGET
|
||||
i: INTEGER
|
||||
p: EV_COORDINATE
|
||||
r, c, n: INTEGER
|
||||
a2: ARRAY2 [detachable ATTACK_UNIT_WIDGET]
|
||||
do
|
||||
io.put_string ("TASK_FORCE_WIDGET.position_widgets: %N")
|
||||
-- populate
|
||||
-- Place widgets in stack or tiled
|
||||
if is_stacked then
|
||||
from
|
||||
unit_widgets.start
|
||||
prev_w := unit_widgets.item_for_iteration
|
||||
unit_widgets.forth
|
||||
until unit_widgets.after
|
||||
loop
|
||||
w := unit_widgets.item_for_iteration
|
||||
w.align_midpoints_with_offset (prev_w, 0.1, -0.1)
|
||||
prev_w := w
|
||||
unit_widgets.forth
|
||||
end
|
||||
else
|
||||
column_count := column_count.min (task_force.count)
|
||||
expected_rows := task_force.count // column_count
|
||||
if task_force.count \\ column_count > 0 then
|
||||
expected_rows := expected_rows + 1
|
||||
end
|
||||
-- Use `a2' to memoize the widgets as they are accessed
|
||||
create a2.make_filled (Void, expected_rows, column_count)
|
||||
from
|
||||
c := 1
|
||||
r := 1
|
||||
n := 2
|
||||
w := unit_widgets.widget (task_force.i_th (1))
|
||||
a2.put (w, 1, 1)
|
||||
until n > task_force.count
|
||||
loop
|
||||
-- Get the widget to place
|
||||
w := unit_widgets.widget (task_force.i_th (n))
|
||||
c := c + 1
|
||||
if c > column_count then
|
||||
c := 1
|
||||
r := r + 1
|
||||
end
|
||||
-- Get widget with which to align `w'
|
||||
if c = 1 then
|
||||
check attached a2.item (r - 1, c) as pw then
|
||||
prev_w := pw
|
||||
w.align_lefts (prev_w)
|
||||
w.align_top_to_others_bottom (prev_w)
|
||||
end
|
||||
else
|
||||
check attached a2.item (r, c - 1) as pw then
|
||||
prev_w := pw
|
||||
w.align_tops (prev_w)
|
||||
w.align_left_to_others_right (prev_w)
|
||||
end
|
||||
end
|
||||
a2.put (w, r, c)
|
||||
n := n + 1
|
||||
end
|
||||
end
|
||||
-- Position the `jj_bounding_figure' based on the widget positions
|
||||
position_bounding_figure
|
||||
end
|
||||
|
||||
position_bounding_figure
|
||||
-- Size the box to just fit around the positioned widgets
|
||||
local
|
||||
w: ATTACK_UNIT_WIDGET
|
||||
p: EV_COORDINATE
|
||||
bb: like bounding_box
|
||||
min_x, max_x: REAL_64
|
||||
min_y, max_y: REAL_64
|
||||
o_set: REAL_64
|
||||
do
|
||||
-- Find the extend of the widgets
|
||||
min_x := {REAL_32}.Max_value
|
||||
max_x := {REAL_32}.Min_value
|
||||
min_y := {REAL_32}.Max_value
|
||||
max_y := {REAL_32}.Min_value
|
||||
from unit_widgets.start
|
||||
until unit_widgets.after
|
||||
loop
|
||||
w := unit_widgets.item_for_iteration
|
||||
bb := w.bounding_box
|
||||
if bb.upper_left.x_precise < min_x then
|
||||
min_x := bb.upper_left.x_precise
|
||||
end
|
||||
if bb.upper_left.y_precise < min_y then
|
||||
min_y := bb.upper_left.y_precise
|
||||
end
|
||||
if bb.lower_right.x_precise > max_x then
|
||||
max_x := bb.lower_right.x_precise
|
||||
end
|
||||
if bb.lower_right.y_precise > max_y then
|
||||
max_y := bb.lower_right.y_precise
|
||||
end
|
||||
unit_widgets.forth
|
||||
end
|
||||
-- Position the `jj_bounding_figure' based on the contained widgets
|
||||
-- Remember, point_array is a {SPECIAL} indexed from zero.
|
||||
-- Set point 1
|
||||
o_set := jj_defining_figure.line_width / 2
|
||||
w := top_left_unit_widget
|
||||
p := jj_defining_figure.point_array.at (0)
|
||||
p.set_precise (w.point.x_precise - o_set, w.point.y_precise - o_set)
|
||||
-- point 2
|
||||
w := top_right_unit_widget
|
||||
p := jj_defining_figure.point_array.at (1)
|
||||
p.set_precise (w.point.x_precise, w.point.y_precise - o_set)
|
||||
-- point 3
|
||||
p := jj_defining_figure.point_array.at (2)
|
||||
p.set_precise (w.point.x_precise + w.size_values.x_precise + o_set, w.point.y_precise - o_set)
|
||||
-- point 4
|
||||
w := bottom_right_unit_widget
|
||||
p := jj_defining_figure.point_array.at (3)
|
||||
p.set_precise (w.point.x_precise + w.size_values.x_precise + o_set, w.point.y_precise + w.size_values.y_precise + o_set)
|
||||
-- point 5
|
||||
w := last_unit_widget
|
||||
p := jj_defining_figure.point_array.at (4)
|
||||
p.set_precise (w.point.x_precise + w.size_values.x_precise + o_set, w.point.y_precise + w.size_values.y_precise + o_set)
|
||||
-- point 6
|
||||
w := bottom_left_unit_widget
|
||||
p := jj_defining_figure.point_array.at (5)
|
||||
p.set_precise (w.point.x_precise - o_set, w.point.y_precise + w.size_values.y_precise + o_set)
|
||||
-- -- Also place the text at top left
|
||||
-- create p.make_precise (min_x, min_y)
|
||||
-- text_widget.center_on_point (p)
|
||||
end
|
||||
|
||||
top_left_unit_widget: ATTACK_UNIT_WIDGET
|
||||
-- The widget positioned at the top left when `is_tiled' and the bottom widget
|
||||
-- when `is_stacked'. (It corresponds to the first unit in the `task_force'.)
|
||||
do
|
||||
-- check attached {WIDGET_FACTORY} board_world as bw then
|
||||
-- Result := bw.attack_widgets.widget (task_force.i_th (1))
|
||||
-- end
|
||||
Result := unit_widgets.widget (task_force.i_th (1))
|
||||
end
|
||||
|
||||
top_right_unit_widget: ATTACK_UNIT_WIDGET
|
||||
-- The widget positioned at the top-right when `is_tiled' and `is_stacked'.
|
||||
do
|
||||
-- check attached {WIDGET_FACTORY} board_world as bw then
|
||||
-- if is_stacked then
|
||||
-- Result := bw.attack_widgets.widget (task_force.i_th (task_force.count))
|
||||
-- else
|
||||
-- Result := bw.attack_widgets.widget (task_force.i_th (column_count))
|
||||
-- end
|
||||
-- end
|
||||
if is_stacked then
|
||||
Result := unit_widgets.widget (task_force.i_th (task_force.count))
|
||||
else
|
||||
Result := unit_widgets.widget (task_force.i_th (column_count))
|
||||
end
|
||||
end
|
||||
|
||||
bottom_right_unit_widget: ATTACK_UNIT_WIDGET
|
||||
-- The widget positioned at the bottom-right.
|
||||
local
|
||||
r: INTEGER
|
||||
i: INTEGER
|
||||
do
|
||||
-- check attached {WIDGET_FACTORY} board_world as bw then
|
||||
-- if is_stacked then
|
||||
-- Result := bw.attack_widgets.widget (task_force.i_th (1))
|
||||
-- else
|
||||
-- r := task_force.count // column_count
|
||||
-- i := r * column_count
|
||||
-- Result := bw.attack_widgets.widget (task_force.i_th (i))
|
||||
-- end
|
||||
-- end
|
||||
if is_stacked then
|
||||
Result := unit_widgets.widget (task_force.i_th (1))
|
||||
else
|
||||
r := task_force.count // column_count
|
||||
i := r * column_count
|
||||
Result := unit_widgets.widget (task_force.i_th (i))
|
||||
end
|
||||
end
|
||||
|
||||
bottom_left_unit_widget: ATTACK_UNIT_WIDGET
|
||||
-- The widget positioned at the bottom-left
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
-- check attached {WIDGET_FACTORY} board_world as bw then
|
||||
-- if is_stacked then
|
||||
-- Result := bw.attack_widgets.widget (task_force.i_th (1))
|
||||
-- else
|
||||
-- i := (expected_rows - 1) * column_count + 1
|
||||
-- if i > task_force.count then
|
||||
-- i := 1
|
||||
-- end
|
||||
-- Result := bw.attack_widgets.widget (task_force.i_th (i))
|
||||
-- end
|
||||
-- end
|
||||
if is_stacked then
|
||||
Result := unit_widgets.widget (task_force.i_th (1))
|
||||
else
|
||||
i := (expected_rows - 1) * column_count + 1
|
||||
if i > task_force.count then
|
||||
i := 1
|
||||
end
|
||||
Result := unit_widgets.widget (task_force.i_th (i))
|
||||
end
|
||||
end
|
||||
|
||||
last_unit_widget: ATTACK_UNIT_WIDGET
|
||||
-- The widget at the bottom
|
||||
do
|
||||
-- check attached {WIDGET_FACTORY} board_world as bw then
|
||||
-- if is_stacked then
|
||||
-- Result := bw.attack_widgets.widget (task_force.i_th (1))
|
||||
-- else
|
||||
-- Result := bw.attack_widgets.widget (task_force.i_th (task_force.count))
|
||||
-- end
|
||||
-- end
|
||||
if is_stacked then
|
||||
Result := unit_widgets.widget (task_force.i_th (1))
|
||||
else
|
||||
Result := unit_widgets.widget (task_force.i_th (task_force.count))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
paint
|
||||
-- Set the colors for the widgets in Current
|
||||
do
|
||||
Precursor {VITP_WIDGET}
|
||||
from unit_widgets.start
|
||||
until unit_widgets.after
|
||||
loop
|
||||
unit_widgets.item_for_iteration.paint
|
||||
unit_widgets.forth
|
||||
end
|
||||
end
|
||||
|
||||
set_dimming_level (a_level: like dimming_level)
|
||||
-- Change the `dimming_level'
|
||||
do
|
||||
-- Precursor {MOVEABLE_WIDGET} (a_level)
|
||||
if is_stacked then
|
||||
from unit_widgets.start
|
||||
until unit_widgets.after
|
||||
loop
|
||||
unit_widgets.item_for_iteration.set_dimming_level (a_level)
|
||||
unit_widgets.forth
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fill_widgets
|
||||
-- Nothing to do here.
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Actions
|
||||
|
||||
on_double_press (ax: INTEGER; ay: INTEGER; a_button: INTEGER;
|
||||
x_tilt: DOUBLE; y_tilt: DOUBLE; pressure: DOUBLE;
|
||||
a_screen_x: INTEGER; a_screen_y: INTEGER)
|
||||
-- React to a double press on Current, toggling `is_stacked'.
|
||||
do
|
||||
if is_stacked then
|
||||
tile
|
||||
else
|
||||
stack
|
||||
end
|
||||
end
|
||||
|
||||
-- on_pointer_enter
|
||||
-- -- React to the pointer entering Current by showing
|
||||
-- -- the `jj_bounding_figure' if not `is_stacked'
|
||||
-- do
|
||||
-- io.put_string ("TASK_FORCE_WIDGET.on_enter %N")
|
||||
-- if not is_stacked then
|
||||
-- jj_bounding_figure.show
|
||||
-- end
|
||||
-- Precursor {VITP_WIDGET}
|
||||
-- end
|
||||
|
||||
-- on_pointer_leave
|
||||
-- -- React to the pointer leaving Current by hiding
|
||||
-- -- the `jj_bounding_figure'
|
||||
-- do
|
||||
-- io.put_string ("TASK_FORCE_WIDGET.on_leave %N")
|
||||
-- jj_bounding_figure.hide
|
||||
-- Precursor {VITP_WIDGET}
|
||||
-- end
|
||||
|
||||
on_enter_bounding_figure
|
||||
-- React to the pointer entering the bounding figure
|
||||
do
|
||||
io.put_string ("TASK_FORCE_WIDGET.on_enter_bounding_figure %N")
|
||||
if not is_stacked then
|
||||
jj_defining_figure.show
|
||||
bring_to_front (jj_defining_figure)
|
||||
end
|
||||
end
|
||||
|
||||
on_leave_bounding_figure
|
||||
-- React to the pointer leaving the bounding figure
|
||||
do
|
||||
io.put_string ("TASK_FORCE_WIDGET.on_leave_bounding_figure %N")
|
||||
-- bounding_figure.hide
|
||||
end
|
||||
|
||||
on_button_press_bounding_figure (ax: INTEGER; ay: INTEGER; a_button: INTEGER; x_tilt: DOUBLE; y_tilt: DOUBLE;
|
||||
pressure: DOUBLE; a_screen_x: INTEGER; a_screen_y: INTEGER)
|
||||
-- React to a button press on the `jj_bounding_figure'
|
||||
do
|
||||
io.put_string ("TASK_FORCE_WIDGET}.on_button_pressed_bounding_figure: button = " + a_button.out)
|
||||
if a_button = 1 then
|
||||
column_count := (column_count - 1).max (1)
|
||||
position_widgets
|
||||
elseif a_button = 3 then
|
||||
column_count := (column_count + 1)
|
||||
position_widgets
|
||||
else
|
||||
io.put_string (" reacting to button ??? %N")
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
column_count: INTEGER
|
||||
-- The number of columns in which Current tries to arrange its widgets
|
||||
|
||||
target_imp: detachable TASK_FORCE
|
||||
-- Anchor for `target'
|
||||
|
||||
unit_widgets: VITP_WIDGET_TABLE [ATTACK_UNIT_WIDGET, ATTACK_UNIT]
|
||||
-- Table to associate a widget with a unit
|
||||
|
||||
invariant
|
||||
|
||||
-- in_this_view: not unit_widgets.is_empty implies across unit_widgets as uw all view.has (uw.item_for_iteration) end
|
||||
-- same_widget_and_unit_counts: attached item_imp implies task_force.count = unit_widgets.count
|
||||
|
||||
end
|
Reference in New Issue
Block a user