Skip to content

Commit

Permalink
Some partially-working description code before a refactor to move the…
Browse files Browse the repository at this point in the history
… selected-item logic up into the cursor.
  • Loading branch information
rkettering committed Jul 18, 2017
1 parent 568662e commit 0a92918
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion data/object_prototypes/base/player_controlled.cfg
Expand Up @@ -214,7 +214,7 @@ properties: {
#-- item storage --#
item_list_complete: { type: "[class inventory_item]", init: "map([map]<- get_document('data/items.cfg'), construct('inventory_item', value))" },

active_item_name: { type: "string", default: 'buyable_tongue_extension' },
active_item_name: { type: "string", init: "'tongue_extension'" },



Expand Down
60 changes: 41 additions & 19 deletions data/objects/gui-components/inventory-screen/inventory_pane.cfg
Expand Up @@ -18,10 +18,10 @@ properties: {

#-------------------------- core behavior --------------------------#
initialize_parts: "commands :: [
map(map(frogatto.items_carried, value.id), 'item_name',
map(map(frogatto.items_carried, value.id), 'item_id',
add_object(object('inventory_pane.item_anchor', 0, 0, 1, {
item_name: item_name,
count: frogatto.number_of_item(item_name),
item_id: item_id,
count: frogatto.number_of_item(item_id),
parent: me,
relative_x: -182+74*positions[index][0],
relative_y: -155+72*positions[index][1],
Expand All @@ -34,6 +34,12 @@ properties: {
set(text_name_display.relative_y, 135),
],
[
add_object(text_description_display),
set(text_description_display.relative_x, -220),
set(text_description_display.relative_y, 195),
],
[
add_object(selector_cursor),
set(selector_cursor.relative_x, -80),
Expand All @@ -53,6 +59,19 @@ properties: {
align: 'center',
})",
},

text_description_display: {
type: "obj text_controller",
init: "object('text_controller', 0,0,1, {
parent: me,
use_absolute_screen_coordinates: true,
zorder: lib.zorder.get('overlaid_gui_dialog_gui_element'),
txt: ~description~,
font: 'door_label',
align: 'left',
})",
},


selector_cursor: {
type: "obj inventory_pane.selector_cursor",
Expand Down Expand Up @@ -112,7 +131,7 @@ object_type: [
4, value.x < x2 and abs(decimal(x2-value.x)/decimal(y2-value.y)) >= 0.5, //The initial </> comparison is a workaround a infinite math. the abs() is returning the absolute of -inf8, which is one more than inf7, so it wraps back around to -inf8. However, -1/0 is inverting inf7, coming out with -inf7, which is one more than -inf8 afaict.
6, value.x > x2 and abs(decimal(x2-value.x)/decimal(y2-value.y)) >= 0.5,
8, value.y < y2 and abs(decimal(x2-value.x)/decimal(y2-value.y)) <= 2.0,
) and if(selected_object, value.item_name != selected_object.item_name, true)),
) and if(selected_object, value.item_id != selected_object.item_id, true)),
-lib.math.length(
zip(scale, value.mid_xy, a*b),
[(midpoint_x - cursor_offset[0]) * scale[0], (midpoint_y - cursor_offset[1]) * scale[1]]
Expand Down Expand Up @@ -171,10 +190,10 @@ object_type: [
zorder: "@include data/zorder.cfg:overlaid_gui_dialog_gui_element_underlay",
properties: {
count: { type: "int" },
item_name: { type: "string", dynamic_initialization: true },
item_id: { type: "string", dynamic_initialization: true },
icon: { type: "obj inventory_pane.item_icon", dynamic_initialization: true },
is_active: "bool :: level.player.active_item_name = item_name",
is_active: "bool :: level.player.active_item_name = item_id",
is_selected: "bool :: parent.selector_cursor.selected_object = me
asserting parent is obj inventory_pane asserting parent",
Expand All @@ -184,7 +203,7 @@ object_type: [
//TODO: make this safe wrt complaining if the item is an invalid type.
activate: "commands :: [
set(level.player.active_item_name, item_name),
set(level.player.active_item_name, item_id),
]",
Expand Down Expand Up @@ -212,20 +231,23 @@ object_type: [
add_object(new_icon),
set(icon, new_icon),
] where new_icon = object('inventory_pane.item_icon', 0, 0, 1, {
animation: item_name,
animation: item_id,
parent: me,
relative_x: 0,
relative_y: -1,
})",
on_mouse_move: "parent.text_name_display.set_text(item_name)
asserting parent is obj inventory_pane asserting parent asserting item_name is string
where item_name = {
acquirable_attractor: object('buyable_acquirable_attractor'),
greater_mana_talisman: object('buyable_greater_mana_talisman'),
lesser_mana_talisman: object('buyable_lesser_mana_talisman'),
tongue_extension: object('buyable_tongue_extension'),
}[item_name].short_item_name",
on_mouse_move: "[
parent.text_name_display.set_text(item_name),
parent.text_description_display.set_text(parent.wrapped(item_desc, 52)),
]
asserting parent is obj inventory_pane asserting parent
where item_name = item_info.name
where item_desc = item_info.description

where item_info = level.player.active_item",
on_process: "[
if( is_active,
Expand All @@ -235,13 +257,13 @@ object_type: [
if( is_selected,
[
set(icon.relative_y, 7*sin(cycle*4) - 10),
if(icon.animation != item_name + '_active',
set(icon.animation, item_name + '_active'),
if(icon.animation != item_id + '_active',
set(icon.animation, item_id + '_active'),
)
],
[
set(icon.relative_y, -1),
set(icon.animation, item_name),
set(icon.animation, item_id),
]
),
]",
Expand Down

0 comments on commit 0a92918

Please sign in to comment.