185 lines
4.3 KiB
Plaintext
185 lines
4.3 KiB
Plaintext
note
|
|
description: "[
|
|
Widget representing an area on the game board (such as a
|
|
land mass or port.)
|
|
]"
|
|
author: "Jimmy J. Johnson"
|
|
|
|
deferred class
|
|
LOCATION_WIDGET
|
|
|
|
inherit
|
|
|
|
VITP_WIDGET
|
|
rename
|
|
target as location
|
|
redefine
|
|
create_interface_objects,
|
|
-- initialize,
|
|
extend_widgets,
|
|
build_widgets,
|
|
set_widget_order,
|
|
add_actions,
|
|
-- defining_figure,
|
|
paint,
|
|
on_button_pressed,
|
|
-- on_pointer_leave,
|
|
target_imp
|
|
end
|
|
|
|
feature {NONE} -- Initialization
|
|
|
|
create_interface_objects
|
|
-- Initialize attributes
|
|
do
|
|
create land
|
|
land_color := Default_land_color
|
|
Precursor {VITP_WIDGET}
|
|
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.
|
|
do
|
|
Precursor {VITP_WIDGET}
|
|
extend (land)
|
|
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}
|
|
build_land
|
|
end
|
|
|
|
set_widget_order
|
|
-- Ensure the widgets are ordered properly
|
|
-- (i.e. whose on top?)
|
|
do
|
|
Precursor {VITP_WIDGET}
|
|
bring_to_front (land)
|
|
bring_to_front (text_group)
|
|
end
|
|
|
|
add_actions
|
|
-- Make Current react to events
|
|
do
|
|
Precursor {VITP_WIDGET}
|
|
pointer_button_press_actions.extend (agent on_button_pressed)
|
|
pointer_button_release_actions.extend (agent on_button_released)
|
|
pointer_leave_actions.extend (agent on_pointer_leave)
|
|
end
|
|
|
|
build_land
|
|
-- Create any land masses in Current
|
|
do
|
|
end
|
|
|
|
feature -- Access
|
|
|
|
-- defining_figure: EV_MODEL
|
|
-- -- The figure to be used to determine if other figures
|
|
-- -- overlap this one or for capturing mouse events
|
|
-- do
|
|
-- Result := land
|
|
-- end
|
|
|
|
feature -- Basic operations
|
|
|
|
paint
|
|
-- Set the colors for the land and other areas
|
|
local
|
|
bc, c: EV_COLOR
|
|
do
|
|
Precursor {VITP_WIDGET}
|
|
bc := adjusted_color (Land_boundary_color)
|
|
c := adjusted_color (land_color)
|
|
from land.start
|
|
until land.exhausted
|
|
loop
|
|
check attached {EV_MODEL_POLYGON} land.item as p then
|
|
p.set_foreground_color (bc)
|
|
p.set_background_color (c)
|
|
end
|
|
land.forth
|
|
end
|
|
end
|
|
|
|
feature {NONE} -- Implementation (actions)
|
|
|
|
on_button_pressed (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 by brightening the location.
|
|
-- -- Notify `board_world' that Current was clicked
|
|
-- -- This allows the `board_world' to handle the click *and* to know the
|
|
-- -- widget on which the click occurred.
|
|
local
|
|
-- u_list: LINKED_SET [VITP_MOVEABLE]
|
|
g: EV_MODEL_GROUP
|
|
do
|
|
io.put_string ("LOCATION_WIDGET.on_button_press -- " + location.name + "%N")
|
|
g := group
|
|
is_highlighting := True
|
|
-- is_highlighting.set_item (true)
|
|
-- focused_widgets.extend (Current)
|
|
set_dimming_level ({DIMABLE}.Bright)
|
|
paint
|
|
-- -- Also, brighten all units that are at this location
|
|
-- check attached board_world as bw then
|
|
-- u_list := location.units
|
|
-- from u_list.start
|
|
-- until u_list.after
|
|
-- loop
|
|
-- check attached {ATTACK_UNIT_WIDGET} bw.attack_widgets.item (u_list.item) as w then
|
|
-- focused_widgets.extend (w)
|
|
-- w.set_dimming_level ({DIMABLE}.Bright)
|
|
-- w.paint
|
|
-- end
|
|
-- u_list.forth
|
|
-- end
|
|
-- end
|
|
end
|
|
|
|
on_button_released (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 release event
|
|
do
|
|
if is_highlighting then
|
|
is_highlighting := false
|
|
restore_dimming_level
|
|
paint
|
|
end
|
|
end
|
|
|
|
on_pointer_leave
|
|
-- React to the pointer leaving the area [in case the
|
|
-- button was pressed and dragged off Current].
|
|
do
|
|
if is_highlighting then
|
|
is_highlighting := false
|
|
restore_dimming_level
|
|
paint
|
|
end
|
|
-- Precursor {VITP_NAMED_WIDGET}
|
|
end
|
|
|
|
feature {NONE} -- Implementation
|
|
|
|
is_highlighting: BOOLEAN
|
|
-- Is the location set brighter than normal?
|
|
|
|
land: EV_MODEL_WORLD
|
|
-- To draw the land area(s) in Current
|
|
|
|
land_color: EV_COLOR
|
|
-- The color with which to draw the land
|
|
|
|
target_imp: detachable LOCATION
|
|
-- Anchor for the `target' represented by Current
|
|
|
|
end
|