diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d05e9bb5..a17238b33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,6 +266,7 @@ ADD_LIBRARY(OurCoreLib OBJECT src/ui-object.c src/ui-options.c src/ui-output.c + src/ui-player-properties.c src/ui-player.c src/ui-prefs.c src/ui-score.c diff --git a/src/Makefile.inc b/src/Makefile.inc index d7a2db4e8..d0b948d83 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -189,25 +189,25 @@ depgen: z-file.h list-tvals.h list-object-flags.h list-kind-flags.h list-stats.h \ list-object-modifiers.h list-elements.h list-origins.h player-attack.h \ cmd-core.h cmds.h cave.h list-square-flags.h list-terrain-flags.h \ - list-effects.h game-input.h init.h datafile.h parser.h \ - list-parser-errors.h mon-desc.h monster.h target.h mon-predicate.h \ - mon-timed.h list-mon-timed.h mon-blows.h player.h guid.h option.h \ - list-options.h list-player-flags.h list-mon-temp-flags.h \ - list-mon-race-flags.h list-mon-spells.h mon-make.h mon-spell.h \ - mon-util.h mon-msg.h list-mon-message.h obj-desc.h obj-knowledge.h \ - angband.h z-color.h z-util.h config.h game-event.h message.h \ - list-message.h obj-util.h player-calcs.h player-history.h \ - list-history-types.h player-timed.h list-player-timed.h player-util.h \ - project.h list-projections.h trap.h list-trap-flags.h + list-effects.h game-input.h player.h guid.h option.h list-options.h \ + list-player-flags.h init.h datafile.h parser.h list-parser-errors.h \ + mon-desc.h monster.h target.h mon-predicate.h mon-timed.h \ + list-mon-timed.h mon-blows.h list-mon-temp-flags.h list-mon-race-flags.h \ + list-mon-spells.h mon-make.h mon-spell.h mon-util.h mon-msg.h \ + list-mon-message.h obj-desc.h obj-knowledge.h angband.h z-color.h \ + z-util.h config.h game-event.h message.h list-message.h obj-util.h \ + player-calcs.h player-history.h list-history-types.h player-timed.h \ + list-player-timed.h player-util.h project.h list-projections.h trap.h \ + list-trap-flags.h ./effect-handler-general.o: effect-handler-general.c cave.h z-type.h \ h-basic.h z-bitflag.h z-form.h z-virt.h list-square-flags.h \ list-terrain-flags.h effect-handler.h effects.h source.h object.h \ z-quark.h z-dice.h z-rand.h z-expression.h obj-properties.h z-file.h \ list-tvals.h list-object-flags.h list-kind-flags.h list-stats.h \ list-object-modifiers.h list-elements.h list-origins.h player-attack.h \ - cmd-core.h cmds.h list-effects.h game-input.h game-world.h generate.h \ - monster.h target.h mon-predicate.h mon-timed.h list-mon-timed.h \ - mon-blows.h player.h guid.h option.h list-options.h list-player-flags.h \ + cmd-core.h cmds.h list-effects.h game-input.h player.h guid.h option.h \ + list-options.h list-player-flags.h game-world.h generate.h monster.h \ + target.h mon-predicate.h mon-timed.h list-mon-timed.h mon-blows.h \ list-mon-temp-flags.h list-mon-race-flags.h list-mon-spells.h \ list-room-flags.h init.h datafile.h parser.h list-parser-errors.h \ mon-desc.h mon-lore.h z-textblock.h mon-make.h mon-summon.h mon-util.h \ @@ -224,16 +224,17 @@ depgen: list-kind-flags.h list-stats.h list-object-modifiers.h list-elements.h \ list-origins.h player-attack.h cmd-core.h cmds.h cave.h \ list-square-flags.h list-terrain-flags.h list-effects.h effect-handler.h \ - game-input.h mon-summon.h monster.h target.h mon-predicate.h mon-timed.h \ - list-mon-timed.h mon-blows.h player.h guid.h option.h list-options.h \ - list-player-flags.h list-mon-temp-flags.h list-mon-race-flags.h \ - list-mon-spells.h player-history.h angband.h z-color.h z-util.h config.h \ - game-event.h message.h list-message.h list-history-types.h \ - player-timed.h list-player-timed.h player-util.h project.h \ - list-projections.h trap.h list-trap-flags.h -./effects-info.o: effects-info.c effects-info.h z-textblock.h z-file.h \ - h-basic.h effects.h source.h z-type.h object.h z-quark.h z-bitflag.h \ - z-form.h z-virt.h z-dice.h z-rand.h z-expression.h obj-properties.h \ + game-input.h player.h guid.h option.h list-options.h list-player-flags.h \ + init.h datafile.h parser.h list-parser-errors.h mon-make.h monster.h \ + target.h mon-predicate.h mon-timed.h list-mon-timed.h mon-blows.h \ + list-mon-temp-flags.h list-mon-race-flags.h list-mon-spells.h \ + mon-summon.h obj-gear.h list-equip-slots.h player-history.h angband.h \ + z-color.h z-util.h config.h game-event.h message.h list-message.h \ + list-history-types.h player-timed.h list-player-timed.h player-util.h \ + project.h list-projections.h trap.h list-trap-flags.h +./effects-info.o: effects-info.c effects-info.h z-dice.h h-basic.h z-rand.h \ + z-expression.h z-textblock.h z-file.h effects.h source.h z-type.h \ + object.h z-quark.h z-bitflag.h z-form.h z-virt.h obj-properties.h \ list-tvals.h list-object-flags.h list-kind-flags.h list-stats.h \ list-object-modifiers.h list-elements.h list-origins.h player-attack.h \ cmd-core.h cmds.h cave.h list-square-flags.h list-terrain-flags.h \ @@ -860,15 +861,16 @@ depgen: list-object-modifiers.h object.h z-quark.h z-dice.h z-expression.h \ list-elements.h list-origins.h option.h list-options.h \ list-player-flags.h cmd-core.h cmds.h cave.h list-square-flags.h \ - list-terrain-flags.h game-world.h init.h datafile.h parser.h \ - list-parser-errors.h mon-lore.h z-textblock.h monster.h target.h \ + list-terrain-flags.h game-world.h generate.h monster.h target.h \ mon-predicate.h mon-timed.h list-mon-timed.h mon-blows.h \ - list-mon-temp-flags.h list-mon-race-flags.h list-mon-spells.h mon-make.h \ - obj-curse.h obj-design.h obj-gear.h list-equip-slots.h obj-ignore.h \ - list-ignore-types.h obj-init.h obj-knowledge.h obj-make.h obj-pile.h \ - obj-tval.h obj-util.h player-birth.h player-calcs.h player-history.h \ - list-history-types.h player-quest.h player-spell.h player-timed.h \ - list-player-timed.h player-util.h savefile.h + list-mon-temp-flags.h list-mon-race-flags.h list-mon-spells.h \ + list-room-flags.h init.h datafile.h parser.h list-parser-errors.h \ + mon-lore.h z-textblock.h mon-make.h obj-curse.h obj-design.h obj-gear.h \ + list-equip-slots.h obj-ignore.h list-ignore-types.h obj-init.h \ + obj-knowledge.h obj-make.h obj-pile.h obj-tval.h obj-util.h \ + player-birth.h player-calcs.h player-history.h list-history-types.h \ + player-quest.h player-spell.h player-timed.h list-player-timed.h \ + player-util.h savefile.h ./player-calcs.o: player-calcs.c angband.h h-basic.h z-bitflag.h z-form.h \ z-virt.h z-color.h z-util.h z-rand.h config.h game-event.h z-type.h \ message.h list-message.h player.h guid.h obj-properties.h z-file.h \ @@ -916,8 +918,7 @@ depgen: list-object-modifiers.h object.h z-quark.h z-dice.h z-expression.h \ list-elements.h list-origins.h option.h list-options.h \ list-player-flags.h game-input.h cmd-core.h player-calcs.h \ - player-history.h list-history-types.h player-properties.h ui-input.h \ - ui-event.h ui-term.h ui-menu.h ui-output.h z-textblock.h + player-history.h list-history-types.h player-properties.h ./player-quest.o: player-quest.c angband.h h-basic.h z-bitflag.h z-form.h \ z-virt.h z-color.h z-util.h z-rand.h config.h game-event.h z-type.h \ message.h list-message.h player.h guid.h obj-properties.h z-file.h \ @@ -945,10 +946,9 @@ depgen: cmd-core.h effects.h source.h player-attack.h cmds.h list-effects.h \ init.h datafile.h parser.h list-parser-errors.h monster.h target.h \ mon-predicate.h mon-timed.h list-mon-timed.h mon-blows.h \ - list-mon-temp-flags.h list-mon-race-flags.h list-mon-spells.h mon-make.h \ - obj-gear.h list-equip-slots.h obj-tval.h obj-util.h player-calcs.h \ - player-spell.h player-timed.h list-player-timed.h player-util.h \ - project.h list-projections.h + list-mon-temp-flags.h list-mon-race-flags.h list-mon-spells.h obj-tval.h \ + obj-util.h player-calcs.h player-spell.h player-timed.h \ + list-player-timed.h player-util.h project.h list-projections.h ./player-timed.o: player-timed.c angband.h h-basic.h z-bitflag.h z-form.h \ z-virt.h z-color.h z-util.h z-rand.h config.h game-event.h z-type.h \ message.h list-message.h player.h guid.h obj-properties.h z-file.h \ @@ -1038,7 +1038,7 @@ depgen: list-object-modifiers.h object.h z-quark.h z-dice.h z-expression.h \ list-elements.h list-origins.h option.h list-options.h \ list-player-flags.h cave.h list-square-flags.h list-terrain-flags.h \ - mon-make.h monster.h target.h mon-predicate.h mon-timed.h \ + cmd-core.h mon-make.h monster.h target.h mon-predicate.h mon-timed.h \ list-mon-timed.h mon-blows.h list-mon-temp-flags.h list-mon-race-flags.h \ list-mon-spells.h mon-util.h mon-msg.h list-mon-message.h obj-chest.h \ obj-desc.h obj-gear.h list-equip-slots.h obj-ignore.h \ @@ -1164,9 +1164,9 @@ depgen: mon-predicate.h mon-timed.h list-mon-timed.h mon-blows.h \ list-mon-temp-flags.h list-mon-race-flags.h list-mon-spells.h obj-gear.h \ list-equip-slots.h obj-util.h player-attack.h player-calcs.h \ - player-timed.h list-player-timed.h player-util.h ui-command.h \ - ui-display.h ui-event.h ui-help.h ui-input.h ui-term.h ui-keymap.h \ - ui-map.h ui-menu.h ui-output.h z-textblock.h ui-options.h obj-ignore.h \ + player-timed.h list-player-timed.h player-util.h ui-command.h ui-term.h \ + ui-event.h ui-display.h ui-help.h ui-input.h ui-keymap.h ui-map.h \ + ui-menu.h ui-output.h z-textblock.h ui-options.h obj-ignore.h \ list-ignore-types.h ui-player.h ui-prefs.h ui-target.h ./ui-context.o: ui-context.c angband.h h-basic.h z-bitflag.h z-form.h \ z-virt.h z-color.h z-util.h z-rand.h config.h game-event.h z-type.h \ @@ -1260,13 +1260,13 @@ depgen: cmd-core.h object.h z-quark.h z-dice.h z-rand.h z-expression.h \ obj-properties.h z-file.h list-tvals.h list-object-flags.h \ list-kind-flags.h list-stats.h list-object-modifiers.h list-elements.h \ - list-origins.h game-world.h init.h datafile.h parser.h \ - list-parser-errors.h obj-desc.h obj-gear.h player.h guid.h option.h \ - list-options.h list-player-flags.h list-equip-slots.h obj-ignore.h \ - list-ignore-types.h obj-info.h z-textblock.h obj-tval.h ui-entry.h \ - ui-entry-renderers.h ui-entry-combiner.h ui-equip-cmp.h ui-event.h \ - ui-input.h game-event.h ui-term.h ui-object.h ui-menu.h ui-output.h \ - z-color.h z-util.h + list-origins.h player.h guid.h option.h list-options.h \ + list-player-flags.h game-world.h init.h datafile.h parser.h \ + list-parser-errors.h obj-desc.h obj-gear.h list-equip-slots.h \ + obj-ignore.h list-ignore-types.h obj-info.h z-textblock.h obj-tval.h \ + ui-entry.h ui-entry-renderers.h ui-entry-combiner.h ui-equip-cmp.h \ + ui-event.h ui-input.h game-event.h ui-term.h ui-object.h ui-menu.h \ + ui-output.h z-color.h z-util.h ./ui-event.o: ui-event.c angband.h h-basic.h z-bitflag.h z-form.h z-virt.h \ z-color.h z-util.h z-rand.h config.h game-event.h z-type.h message.h \ list-message.h player.h guid.h obj-properties.h z-file.h list-tvals.h \ @@ -1287,11 +1287,11 @@ depgen: list-mon-race-flags.h list-mon-spells.h list-room-flags.h grafmode.h \ init.h mon-lore.h z-textblock.h mon-make.h obj-knowledge.h obj-util.h \ player-attack.h player-calcs.h player-path.h player-properties.h \ - player-util.h savefile.h ui-birth.h ui-command.h ui-context.h ui-input.h \ - ui-event.h ui-term.h ui-death.h ui-display.h ui-game.h ui-help.h \ - ui-init.h ui-keymap.h ui-knowledge.h ui-map.h ui-object.h ui-output.h \ - ui-player.h ui-prefs.h ui-spell.h ui-score.h ui-signals.h ui-spoil.h \ - ui-target.h ui-wizard.h + player-util.h savefile.h ui-birth.h ui-command.h ui-term.h ui-event.h \ + ui-context.h ui-input.h ui-death.h ui-display.h ui-game.h ui-help.h \ + ui-init.h ui-keymap.h ui-knowledge.h ui-map.h ui-menu.h ui-output.h \ + ui-object.h ui-player.h ui-prefs.h ui-spell.h ui-score.h ui-signals.h \ + ui-spoil.h ui-target.h ui-wizard.h ./ui-help.o: ui-help.c angband.h h-basic.h z-bitflag.h z-form.h z-virt.h \ z-color.h z-util.h z-rand.h config.h game-event.h z-type.h message.h \ list-message.h player.h guid.h obj-properties.h z-file.h list-tvals.h \ @@ -1330,10 +1330,11 @@ depgen: list-terrain-flags.h cmd-core.h game-input.h game-world.h init.h \ datafile.h parser.h list-parser-errors.h obj-gear.h list-equip-slots.h \ obj-util.h player-calcs.h player-path.h savefile.h target.h \ - mon-predicate.h ui-command.h ui-context.h ui-input.h ui-event.h \ - ui-term.h ui-curse.h ui-display.h ui-effect.h ui-help.h ui-keymap.h \ + mon-predicate.h ui-command.h ui-term.h ui-event.h ui-context.h \ + ui-input.h ui-curse.h ui-display.h ui-effect.h ui-help.h ui-keymap.h \ ui-knowledge.h ui-map.h ui-menu.h ui-output.h z-textblock.h ui-object.h \ - ui-player.h ui-prefs.h ui-signals.h ui-spell.h ui-target.h + ui-player-properties.h ui-player.h ui-prefs.h ui-signals.h ui-spell.h \ + ui-target.h ./ui-keymap.o: ui-keymap.c angband.h h-basic.h z-bitflag.h z-form.h \ z-virt.h z-color.h z-util.h z-rand.h config.h game-event.h z-type.h \ message.h list-message.h player.h guid.h obj-properties.h z-file.h \ @@ -1431,8 +1432,8 @@ depgen: obj-gear.h list-equip-slots.h obj-ignore.h list-ignore-types.h \ obj-info.h z-textblock.h obj-knowledge.h obj-make.h obj-pile.h \ obj-tval.h obj-util.h player-calcs.h player-spell.h player-timed.h \ - list-player-timed.h player-util.h ui-command.h ui-display.h ui-game.h \ - ui-input.h ui-event.h ui-term.h ui-keymap.h ui-menu.h ui-output.h \ + list-player-timed.h player-util.h ui-command.h ui-term.h ui-event.h \ + ui-display.h ui-game.h ui-input.h ui-keymap.h ui-menu.h ui-output.h \ ui-object.h ui-options.h ui-prefs.h ./ui-options.o: ui-options.c angband.h h-basic.h z-bitflag.h z-form.h \ z-virt.h z-color.h z-util.h z-rand.h config.h game-event.h z-type.h \ @@ -1455,6 +1456,15 @@ depgen: list-player-flags.h cave.h list-square-flags.h list-terrain-flags.h \ player-calcs.h ui-input.h cmd-core.h ui-event.h ui-term.h ui-output.h \ z-textblock.h +./ui-player-properties.o: ui-player-properties.c angband.h h-basic.h \ + z-bitflag.h z-form.h z-virt.h z-color.h z-util.h z-rand.h config.h \ + game-event.h z-type.h message.h list-message.h player.h guid.h \ + obj-properties.h z-file.h list-tvals.h list-object-flags.h \ + list-kind-flags.h list-stats.h list-object-modifiers.h object.h \ + z-quark.h z-dice.h z-expression.h list-elements.h list-origins.h \ + option.h list-options.h list-player-flags.h game-input.h cmd-core.h \ + player-properties.h ui-input.h ui-event.h ui-term.h ui-menu.h \ + ui-output.h z-textblock.h ./ui-player.o: ui-player.c angband.h h-basic.h z-bitflag.h z-form.h \ z-virt.h z-color.h z-util.h z-rand.h config.h game-event.h z-type.h \ message.h list-message.h player.h guid.h obj-properties.h z-file.h \ @@ -1465,10 +1475,10 @@ depgen: list-terrain-flags.h init.h datafile.h parser.h list-parser-errors.h \ obj-curse.h obj-desc.h obj-gear.h list-equip-slots.h obj-info.h \ z-textblock.h obj-knowledge.h obj-util.h player-attack.h cmd-core.h \ - player-calcs.h player-timed.h list-player-timed.h player-util.h \ - ui-display.h ui-entry.h ui-entry-renderers.h ui-entry-combiner.h \ - ui-history.h ui-input.h ui-event.h ui-term.h ui-menu.h ui-output.h \ - ui-object.h ui-player.h + player-calcs.h player-properties.h player-timed.h list-player-timed.h \ + player-util.h ui-display.h ui-entry.h ui-entry-renderers.h \ + ui-entry-combiner.h ui-history.h ui-input.h ui-event.h ui-term.h \ + ui-menu.h ui-output.h ui-object.h ui-player.h ./ui-prefs.o: ui-prefs.c angband.h h-basic.h z-bitflag.h z-form.h z-virt.h \ z-color.h z-util.h z-rand.h config.h game-event.h z-type.h message.h \ list-message.h player.h guid.h obj-properties.h z-file.h list-tvals.h \ @@ -1509,8 +1519,9 @@ depgen: list-object-modifiers.h object.h z-quark.h z-dice.h z-expression.h \ list-elements.h list-origins.h option.h list-options.h \ list-player-flags.h cave.h list-square-flags.h list-terrain-flags.h \ - cmds.h cmd-core.h game-input.h obj-tval.h obj-util.h player-calcs.h \ - player-spell.h ui-menu.h ui-output.h ui-event.h ui-term.h z-textblock.h \ + cmds.h cmd-core.h effects.h source.h player-attack.h list-effects.h \ + effects-info.h z-textblock.h game-input.h obj-tval.h obj-util.h \ + player-calcs.h player-spell.h ui-menu.h ui-output.h ui-event.h ui-term.h \ ui-spell.h ./ui-spoil.o: ui-spoil.c angband.h h-basic.h z-bitflag.h z-form.h z-virt.h \ z-color.h z-util.h z-rand.h config.h game-event.h z-type.h message.h \ @@ -1593,7 +1604,7 @@ depgen: list-mon-timed.h mon-blows.h list-mon-temp-flags.h list-mon-race-flags.h \ list-mon-spells.h list-room-flags.h init.h datafile.h parser.h \ list-parser-errors.h mon-make.h obj-pile.h obj-tval.h obj-util.h \ - player-util.h ui-command.h wizard.h + player-util.h ui-command.h ui-term.h ui-event.h wizard.h ./buildid.o: buildid.c buildid.h ./z-bitflag.o: z-bitflag.c z-bitflag.h h-basic.h z-form.h z-virt.h ./z-color.o: z-color.c h-basic.h z-color.h z-util.h diff --git a/src/Makefile.src b/src/Makefile.src index ca08123bb..660b6448c 100644 --- a/src/Makefile.src +++ b/src/Makefile.src @@ -200,6 +200,7 @@ ANGFILES = \ ui-object.o \ ui-options.o \ ui-output.o \ + ui-player-properties.o \ ui-player.o \ ui-prefs.o \ ui-score.o \ diff --git a/src/game-input.c b/src/game-input.c index eb04bb552..95032949d 100644 --- a/src/game-input.c +++ b/src/game-input.c @@ -19,6 +19,7 @@ #include "angband.h" #include "cmd-core.h" #include "game-input.h" +#include "player.h" bool (*get_string_hook)(const char *prompt, char *buf, size_t len); int (*get_quantity_hook)(const char *prompt, int max); @@ -41,6 +42,10 @@ bool (*confirm_debug_hook)(void); void (*get_panel_hook)(int *min_y, int *min_x, int *max_y, int *max_x); bool (*panel_contains_hook)(unsigned int y, unsigned int x); bool (*map_is_visible_hook)(void); +void (*view_abilities_hook)(struct player_ability *ability_list, + int num_abilities); +bool (*gain_specialty_hook)(int *pick); +void (*interact_with_specialties_hook)(void); /** * Prompt for a string from the user. @@ -289,3 +294,36 @@ bool map_is_visible(void) else return true; } + +/** + * Browse player abilities + */ +void view_ability_menu(struct player_ability *ability_list, + int num_abilities) +{ + /* Ask the UI for it */ + if (view_abilities_hook) + view_abilities_hook(ability_list, num_abilities); +} + +/** + * Interact with player abilities + */ +bool gain_specialty_menu(int *pick) +{ + /* Ask the UI for it */ + if (gain_specialty_hook) + return gain_specialty_hook(pick); + else + return false; +} + +/** + * Interact with player abilities + */ +void interact_with_specialties(void) +{ + /* Ask the UI for it */ + if (interact_with_specialties_hook) + interact_with_specialties_hook(); +} diff --git a/src/game-input.h b/src/game-input.h index 4a28e37e5..9673276c4 100644 --- a/src/game-input.h +++ b/src/game-input.h @@ -20,6 +20,7 @@ #define INCLUDED_GAME_INPUT_H #include "cmd-core.h" +#include "player.h" /** * Bit flags for get_item() function @@ -61,6 +62,10 @@ extern bool (*confirm_debug_hook)(void); extern void (*get_panel_hook)(int *min_y, int *min_x, int *max_y, int *max_x); extern bool (*panel_contains_hook)(unsigned int y, unsigned int x); extern bool (*map_is_visible_hook)(void); +extern void (*view_abilities_hook)(struct player_ability *ability_list, + int num_abilities); +extern bool (*gain_specialty_hook)(int *pick); +extern void (*interact_with_specialties_hook)(void); bool get_string(const char *prompt, char *buf, size_t len); int get_quantity(const char *prompt, int max); @@ -83,5 +88,9 @@ void get_panel(int *min_y, int *min_x, int *max_y, int *max_x); bool confirm_debug(void); bool panel_contains(unsigned int y, unsigned int x); bool map_is_visible(void); +void view_ability_menu(struct player_ability *ability_list, + int num_abilities); +bool gain_specialty_menu(int *pick); +void interact_with_specialties(void); #endif /* INCLUDED_GAME_INPUT_H */ diff --git a/src/player-properties.c b/src/player-properties.c index aeee9dcc8..c87c67e82 100644 --- a/src/player-properties.c +++ b/src/player-properties.c @@ -22,20 +22,12 @@ #include "player-calcs.h" #include "player-history.h" #include "player-properties.h" -#include "ui-input.h" -#include "ui-menu.h" +#include "game-input.h" /** * ------------------------------------------------------------------------ - * Ability data structures and utilities + * Ability utilities * ------------------------------------------------------------------------ */ -enum { - PLAYER_FLAG_NONE, - PLAYER_FLAG_SPECIAL, - PLAYER_FLAG_RACE, - PLAYER_FLAG_CLASS -}; - struct player_ability *lookup_ability(const char *type, int index, int value) { struct player_ability *ability; @@ -80,199 +72,18 @@ bool race_has_ability(const struct player_race *race, /** * ------------------------------------------------------------------------ - * Code for gaining specialty abilities + * Code for gaining specialty abilities and viewing all abilities * ------------------------------------------------------------------------ */ -/** - * Specialty ability menu data struct - */ -struct spec_menu_data { - int *specialties; - int spec_known; - int selected_spec; -}; - -/** - * Check if we can gain a specialty ability -BR- - */ -static bool check_specialty_gain(int specialty) -{ - /* Can't learn it if we already know it */ - if (pf_has(player->specialties, specialty)) { - return false; - } - - /* Is it allowed for this class? */ - if (pf_has(player->class->specialties, specialty)) { - return true; - } - - return false; -} - -/** - * Gain specialty code - */ - -static char gain_spec_tag(struct menu *menu, int oid) -{ - return I2A(oid); -} - -/** - * Display an entry on the gain specialty menu - */ -static void gain_spec_display(struct menu *menu, int oid, bool cursor, int row, - int col, int width) -{ - struct spec_menu_data *d = menu_priv(menu); - int idx = d->specialties[oid]; - uint8_t attr = (cursor ? COLOUR_L_GREEN : COLOUR_GREEN); - struct player_ability *ability = lookup_ability("player", idx, 0); - - /* Print it */ - c_put_str(attr, ability->name, row, col); - -} - -/** - * Deal with events on the gain specialty menu - */ -static bool gain_spec_action(struct menu *menu, const ui_event *e, int oid) -{ - struct spec_menu_data *d = menu_priv(menu); - static int i; - if (oid) - i = oid; - - if (e->type == EVT_SELECT) { - d->selected_spec = d->specialties[i]; - return false; - } - - return true; -} - - -/** - * Show spell long description when browsing - */ -static void gain_spec_menu_browser(int oid, void *data, const region *loc) -{ - struct spec_menu_data *d = data; - int idx = d->specialties[oid]; - struct player_ability *ability = lookup_ability("player", idx, 0); - - /* Redirect output to the screen */ - text_out_hook = text_out_to_screen; - text_out_wrap = 60; - text_out_indent = loc->col - 1; - text_out_pad = 1; - - - clear_from(loc->row + loc->page_rows); - Term_gotoxy(loc->col, loc->row + loc->page_rows + 1); - text_out_to_screen(COLOUR_DEEP_L_BLUE, (char *) ability->desc); - - /* Reset */ - text_out_pad = 0; - text_out_indent = 0; - text_out_wrap = 0; -} - -/** - * Display list available specialties. - */ -static bool gain_spec_menu(int *pick) -{ - struct menu menu; - menu_iter menu_f = { gain_spec_tag, 0, gain_spec_display, - gain_spec_action, 0 - }; - ui_event evt = { 0 }; - struct spec_menu_data *d = mem_alloc(sizeof *d); - region loc = { 0, 0, 70, -99 }; - bool done = false; - - size_t i; - - char buf[80]; - - /* Count the learnable specialties */ - d->spec_known = 0; - for (i = 0; i < PF_MAX; i++) { - if (check_specialty_gain(i)) { - d->spec_known++; - } - } - - /* We are out of specialties - should never happen */ - if (!d->spec_known) { - msg("No specialties available."); - screen_load(); - return false; - } - - /* Find the learnable specialties */ - d->specialties = mem_zalloc(d->spec_known * sizeof(int)); - d->spec_known = 0; - for (i = 0; i < PF_MAX; i++) { - if (check_specialty_gain(i)) { - d->specialties[d->spec_known] = i; - d->spec_known++; - } - } - - /* Save the screen and clear it */ - screen_save(); - clear_from(0); - - /* Prompt choices */ - strnfmt(buf, sizeof(buf), - "(Specialties: %c-%c, ESC=exit) Gain which specialty (%d available)? ", - I2A(0), I2A(d->spec_known - 1), player->upkeep->new_specialties); - - /* Set up the menu */ - menu_init(&menu, MN_SKIN_SCROLL, &menu_f); - menu.title = buf; - menu_setpriv(&menu, d->spec_known, d); - loc.page_rows = d->spec_known + 2; - menu.browse_hook = gain_spec_menu_browser; - menu.flags = MN_DBL_TAP; - region_erase_bordered(&loc); - menu_layout(&menu, &loc); - - while (!done) { - evt = menu_select(&menu, EVT_SELECT, true); - done = (evt.type == EVT_ESCAPE); - if (!done && (d->selected_spec)) { - int idx = d->selected_spec; - struct player_ability *ability = lookup_ability("player", idx, 0); - region_erase_bordered(&loc); - menu_layout(&menu, &loc); - done = get_check(format("Definitely choose %s? ", - ability->name)); - } - } - - if (evt.type != EVT_ESCAPE) - *pick = d->selected_spec; - - /* Load screen */ - screen_load(); - - return (evt.type != EVT_ESCAPE); -} - /** * Gain a new specialty ability * Adapted from birth.c get_player_choice -BR- */ -static void gain_specialty(void) +void gain_specialty(void) { int pick; /* Make one choice */ - if (gain_spec_menu(&pick)) { + if (gain_specialty_menu(&pick)) { char buf[120]; struct player_ability *ability = lookup_ability("player", pick, 0); @@ -292,136 +103,19 @@ static void gain_specialty(void) /* Redraw Study Status */ player->upkeep->redraw |= (PR_STUDY); } - - /* exit */ - return; } -/** - * ------------------------------------------------------------------------ - * Code for viewing race and class abilities - * ------------------------------------------------------------------------ */ -int num_abilities; -struct player_ability ability_list[32]; - - -static char view_ability_tag(struct menu *menu, int oid) -{ - return I2A(oid); -} - -/** - * Display an entry on the gain ability menu - */ -static void view_ability_display(struct menu *menu, int oid, bool cursor, - int row, int col, int width) -{ - char buf[80]; - uint8_t color; - struct player_ability *choices = menu->menu_data; - - switch (choices[oid].group) { - case PLAYER_FLAG_SPECIAL: - { - strnfmt(buf, sizeof(buf), "Specialty Ability: %s", - choices[oid].name); - color = COLOUR_GREEN; - break; - } - case PLAYER_FLAG_CLASS: - { - strnfmt(buf, sizeof(buf), "Class: %s", - choices[oid].name); - color = COLOUR_UMBER; - break; - } - case PLAYER_FLAG_RACE: - { - strnfmt(buf, sizeof(buf), "Racial: %s", - choices[oid].name); - color = COLOUR_ORANGE; - break; - } - default: - { - my_strcpy(buf, "Mysterious", sizeof(buf)); - color = COLOUR_PURPLE; - } - } - - /* Print it */ - c_put_str(cursor ? COLOUR_WHITE : color, buf, row, col); - -} - - -/** - * Show ability long description when browsing - */ -static void view_ability_menu_browser(int oid, void *data, const region *loc) -{ - struct player_ability *choices = data; - - /* Redirect output to the screen */ - text_out_hook = text_out_to_screen; - text_out_wrap = 60; - text_out_indent = loc->col - 1; - text_out_pad = 1; - - clear_from(loc->row + loc->page_rows); - Term_gotoxy(loc->col, loc->row + loc->page_rows); - text_out_c(COLOUR_L_BLUE, "\n%s\n", (char *) choices[oid].desc); - - /* XXX */ - text_out_pad = 0; - text_out_indent = 0; - text_out_wrap = 0; -} - -/** - * Display list available specialties. - */ -static void view_ability_menu(void) -{ - struct menu menu; - menu_iter menu_f = { view_ability_tag, 0, view_ability_display, 0, 0 }; - region loc = { 0, 0, 70, -99 }; - char buf[80]; - - /* Save the screen and clear it */ - screen_save(); - - /* Prompt choices */ - strnfmt(buf, sizeof(buf), - "Race, class, and specialty abilities (%c-%c, ESC=exit): ", - I2A(0), I2A(num_abilities - 1)); - - /* Set up the menu */ - menu_init(&menu, MN_SKIN_SCROLL, &menu_f); - menu.header = buf; - menu_setpriv(&menu, num_abilities, ability_list); - loc.page_rows = num_abilities + 1; - menu.flags = MN_DBL_TAP; - menu.browse_hook = view_ability_menu_browser; - region_erase_bordered(&loc); - menu_layout(&menu, &loc); - - menu_select(&menu, 0, false); - - /* Load screen */ - screen_load(); - - return; -} /** * Browse known abilities -BR- */ -static void view_abilities(void) +void view_abilities(void) { int i; struct player_ability *ability; + int num_abilities = 0; + struct player_ability ability_list[32]; /* Count the number of specialties we know */ num_abilities = 0; @@ -451,9 +145,8 @@ static void view_abilities(void) } /* View choices until user exits */ - view_ability_menu(); + view_ability_menu(ability_list, num_abilities); - /* exit */ return; } @@ -463,31 +156,9 @@ static void view_abilities(void) */ void do_cmd_abilities(void) { - ui_event answer; - /* Might want to gain a new ability or browse old ones */ if (player->upkeep->new_specialties > 0) { - /* Interact and choose. */ - while (get_com_ex - ("View abilities or Learn specialty (l/v/ESC)?", &answer)) { - /* New ability */ - if ((answer.key.code == 'L') || (answer.key.code == 'l')) { - gain_specialty(); - break; - } - - /* View Current */ - if ((answer.key.code == 'V') || (answer.key.code == 'v')) { - view_abilities(); - break; - } - - /* Exit */ - else if (answer.key.code == ESCAPE) - break; - - - } + interact_with_specialties(); } else { /* View existing specialties is the only option */ view_abilities(); diff --git a/src/player-properties.h b/src/player-properties.h index 9d04ebd71..75054c6eb 100644 --- a/src/player-properties.h +++ b/src/player-properties.h @@ -20,11 +20,20 @@ #ifndef PLAYER_PROPS_H #define PLAYER_PROPS_H +enum { + PLAYER_FLAG_NONE, + PLAYER_FLAG_SPECIAL, + PLAYER_FLAG_RACE, + PLAYER_FLAG_CLASS +}; + struct player_ability *lookup_ability(const char *type, int index, int value); bool class_has_ability(const struct player_class *class, struct player_ability *ability); bool race_has_ability(const struct player_race *race, struct player_ability *ability); +void gain_specialty(void); +void view_abilities(void); void do_cmd_abilities(void); #endif /* !PLAYER_PROPS_H */ diff --git a/src/ui-input.c b/src/ui-input.c index ba4e3ceeb..4d03c4c6e 100644 --- a/src/ui-input.c +++ b/src/ui-input.c @@ -40,6 +40,7 @@ #include "ui-menu.h" #include "ui-object.h" #include "ui-output.h" +#include "ui-player-properties.h" #include "ui-player.h" #include "ui-prefs.h" #include "ui-signals.h" @@ -1616,6 +1617,9 @@ void textui_input_init(void) get_panel_hook = textui_get_panel; panel_contains_hook = textui_panel_contains; map_is_visible_hook = textui_map_is_visible; + view_abilities_hook = textui_view_ability_menu; + gain_specialty_hook = textui_gain_spec_menu; + interact_with_specialties_hook = textui_interact_with_specialties; } diff --git a/src/ui-player-properties.c b/src/ui-player-properties.c new file mode 100644 index 000000000..09eda83bc --- /dev/null +++ b/src/ui-player-properties.c @@ -0,0 +1,357 @@ +/** + * \file ui-player-properties.c + * \brief UI for lass and race abilities + * + * Copyright (c) 1997-2020 Ben Harrison, James E. Wilson, Robert A. Koeneke, + * Leon Marrick, Bahman Rabii, Nick McConnell + * + * This work is free software; you can redistribute it and/or modify it + * under the terms of either: + * + * a) the GNU General Public License as published by the Free Software + * Foundation, version 2, or + * + * b) the "Angband licence": + * This software may be copied and distributed for educational, research, + * and not for profit purposes provided that this copyright and statement + * are included in all such copies. Other copyrights may also apply. + */ + +#include "angband.h" +#include "game-input.h" +#include "player-properties.h" +#include "ui-input.h" +#include "ui-menu.h" + +/** + * ------------------------------------------------------------------------ + * Code for viewing race and class abilities + * ------------------------------------------------------------------------ */ + +static char view_ability_tag(struct menu *menu, int oid) +{ + return I2A(oid); +} + +/** + * Display an entry on the gain ability menu + */ +static void view_ability_display(struct menu *menu, int oid, bool cursor, + int row, int col, int width) +{ + char buf[80]; + uint8_t color; + struct player_ability *choices = menu->menu_data; + + switch (choices[oid].group) { + case PLAYER_FLAG_SPECIAL: + { + strnfmt(buf, sizeof(buf), "Specialty Ability: %s", + choices[oid].name); + color = COLOUR_GREEN; + break; + } + case PLAYER_FLAG_CLASS: + { + strnfmt(buf, sizeof(buf), "Class: %s", + choices[oid].name); + color = COLOUR_UMBER; + break; + } + case PLAYER_FLAG_RACE: + { + strnfmt(buf, sizeof(buf), "Racial: %s", + choices[oid].name); + color = COLOUR_ORANGE; + break; + } + default: + { + my_strcpy(buf, "Mysterious", sizeof(buf)); + color = COLOUR_PURPLE; + } + } + + /* Print it */ + c_put_str(cursor ? COLOUR_WHITE : color, buf, row, col); + +} + + +/** + * Show ability long description when browsing + */ +static void view_ability_menu_browser(int oid, void *data, const region *loc) +{ + struct player_ability *choices = data; + + /* Redirect output to the screen */ + text_out_hook = text_out_to_screen; + text_out_wrap = 60; + text_out_indent = loc->col - 1; + text_out_pad = 1; + + clear_from(loc->row + loc->page_rows); + Term_gotoxy(loc->col, loc->row + loc->page_rows); + text_out_c(COLOUR_L_BLUE, "\n%s\n", (char *) choices[oid].desc); + + /* XXX */ + text_out_pad = 0; + text_out_indent = 0; + text_out_wrap = 0; +} + +/** + * Display list available specialties. + */ +void textui_view_ability_menu(struct player_ability *ability_list, + int num_abilities) +{ + struct menu menu; + menu_iter menu_f = { view_ability_tag, 0, view_ability_display, 0, 0 }; + region loc = { 0, 0, 70, -99 }; + char buf[80]; + + /* Save the screen and clear it */ + screen_save(); + + /* Prompt choices */ + strnfmt(buf, sizeof(buf), + "Race and class abilities (%c-%c, ESC=exit): ", + I2A(0), I2A(num_abilities - 1)); + + /* Set up the menu */ + menu_init(&menu, MN_SKIN_SCROLL, &menu_f); + menu.header = buf; + menu_setpriv(&menu, num_abilities, ability_list); + loc.page_rows = num_abilities + 1; + menu.flags = MN_DBL_TAP; + menu.browse_hook = view_ability_menu_browser; + region_erase_bordered(&loc); + menu_layout(&menu, &loc); + + menu_select(&menu, 0, false); + + /* Load screen */ + screen_load(); + + return; +} + +/** + * ------------------------------------------------------------------------ + * Code for gaining specialties + * ------------------------------------------------------------------------ */ +/** + * Specialty ability menu data struct + */ +struct spec_menu_data { + int *specialties; + int spec_known; + int selected_spec; +}; + +/** + * Check if we can gain a specialty ability -BR- + */ +static bool check_specialty_gain(int specialty) +{ + /* Can't learn it if we already know it */ + if (pf_has(player->specialties, specialty)) { + return false; + } + + /* Is it allowed for this class? */ + if (pf_has(player->class->specialties, specialty)) { + return true; + } + + return false; +} + +/** + * Gain specialty code + */ + +static char gain_spec_tag(struct menu *menu, int oid) +{ + return I2A(oid); +} + +/** + * Display an entry on the gain specialty menu + */ +static void gain_spec_display(struct menu *menu, int oid, bool cursor, int row, + int col, int width) +{ + struct spec_menu_data *d = menu_priv(menu); + int idx = d->specialties[oid]; + uint8_t attr = (cursor ? COLOUR_L_GREEN : COLOUR_GREEN); + struct player_ability *ability = lookup_ability("player", idx, 0); + + /* Print it */ + c_put_str(attr, ability->name, row, col); + +} + +/** + * Deal with events on the gain specialty menu + */ +static bool gain_spec_action(struct menu *menu, const ui_event *e, int oid) +{ + struct spec_menu_data *d = menu_priv(menu); + static int i; + if (oid) + i = oid; + + if (e->type == EVT_SELECT) { + d->selected_spec = d->specialties[i]; + return false; + } + + return true; +} + + +/** + * Show spell long description when browsing + */ +static void gain_spec_menu_browser(int oid, void *data, const region *loc) +{ + struct spec_menu_data *d = data; + int idx = d->specialties[oid]; + struct player_ability *ability = lookup_ability("player", idx, 0); + + /* Redirect output to the screen */ + text_out_hook = text_out_to_screen; + text_out_wrap = 60; + text_out_indent = loc->col - 1; + text_out_pad = 1; + + + clear_from(loc->row + loc->page_rows); + Term_gotoxy(loc->col, loc->row + loc->page_rows + 1); + text_out_to_screen(COLOUR_DEEP_L_BLUE, (char *) ability->desc); + + /* Reset */ + text_out_pad = 0; + text_out_indent = 0; + text_out_wrap = 0; +} + +/** + * Display list available specialties. + */ +bool textui_gain_spec_menu(int *pick) +{ + struct menu menu; + menu_iter menu_f = { gain_spec_tag, 0, gain_spec_display, + gain_spec_action, 0 + }; + ui_event evt = { 0 }; + struct spec_menu_data *d = mem_alloc(sizeof *d); + region loc = { 0, 0, 70, -99 }; + bool done = false; + + size_t i; + + char buf[80]; + + /* Count the learnable specialties */ + d->spec_known = 0; + for (i = 0; i < PF_MAX; i++) { + if (check_specialty_gain(i)) { + d->spec_known++; + } + } + + /* We are out of specialties - should never happen */ + if (!d->spec_known) { + msg("No specialties available."); + screen_load(); + return false; + } + + /* Find the learnable specialties */ + d->specialties = mem_zalloc(d->spec_known * sizeof(int)); + d->spec_known = 0; + for (i = 0; i < PF_MAX; i++) { + if (check_specialty_gain(i)) { + d->specialties[d->spec_known] = i; + d->spec_known++; + } + } + + /* Save the screen and clear it */ + screen_save(); + clear_from(0); + + /* Prompt choices */ + strnfmt(buf, sizeof(buf), + "(Specialties: %c-%c, ESC=exit) Gain which specialty (%d available)? ", + I2A(0), I2A(d->spec_known - 1), player->upkeep->new_specialties); + + /* Set up the menu */ + menu_init(&menu, MN_SKIN_SCROLL, &menu_f); + menu.title = buf; + menu_setpriv(&menu, d->spec_known, d); + loc.page_rows = d->spec_known + 2; + menu.browse_hook = gain_spec_menu_browser; + menu.flags = MN_DBL_TAP; + region_erase_bordered(&loc); + menu_layout(&menu, &loc); + + while (!done) { + evt = menu_select(&menu, EVT_SELECT, true); + done = (evt.type == EVT_ESCAPE); + if (!done && (d->selected_spec)) { + int idx = d->selected_spec; + struct player_ability *ability = lookup_ability("player", idx, 0); + region_erase_bordered(&loc); + menu_layout(&menu, &loc); + done = get_check(format("Definitely choose %s? ", + ability->name)); + } + } + + if (evt.type != EVT_ESCAPE) + *pick = d->selected_spec; + + /* Load screen */ + screen_load(); + + return (evt.type != EVT_ESCAPE); +} + +/** + * ------------------------------------------------------------------------ + * Main ability interaction function + * ------------------------------------------------------------------------ */ +/** + * Gain a new specialty ability + * Adapted from birth.c get_player_choice -BR- + */ +void textui_interact_with_specialties(void) +{ + ui_event answer; + + /* Interact and choose. */ + while (get_com_ex + ("View abilities or Learn specialty (l/v/ESC)?", &answer)) { + /* New ability */ + if ((answer.key.code == 'L') || (answer.key.code == 'l')) { + gain_specialty(); + break; + } + + /* View Current */ + if ((answer.key.code == 'V') || (answer.key.code == 'v')) { + view_abilities(); + break; + } + + /* Exit */ + if (answer.key.code == ESCAPE) + break; + } +} diff --git a/src/ui-player-properties.h b/src/ui-player-properties.h new file mode 100644 index 000000000..fb7f6e38e --- /dev/null +++ b/src/ui-player-properties.h @@ -0,0 +1,23 @@ +/** + * \file ui-player-properties.c + * \brief UI for lass and race abilities + * + * Copyright (c) 1997-2020 Ben Harrison, James E. Wilson, Robert A. Koeneke, + * Leon Marrick, Bahman Rabii, Nick McConnell + * + * This work is free software; you can redistribute it and/or modify it + * under the terms of either: + * + * a) the GNU General Public License as published by the Free Software + * Foundation, version 2, or + * + * b) the "Angband licence": + * This software may be copied and distributed for educational, research, + * and not for profit purposes provided that this copyright and statement + * are included in all such copies. Other copyrights may also apply. + */ + +void textui_view_ability_menu(struct player_ability *ability_list, + int num_abilities); +bool textui_gain_spec_menu(int *pick); +void textui_interact_with_specialties(void); diff --git a/src/win/vs2019/Angband.vcxproj b/src/win/vs2019/Angband.vcxproj index 1060349fe..6eb9a1638 100644 --- a/src/win/vs2019/Angband.vcxproj +++ b/src/win/vs2019/Angband.vcxproj @@ -285,6 +285,7 @@ xcopy $(MSBuildProjectDirectory)\lib\* $(OutDir)lib\ /DESY /exclude:$(MSBuildPro + @@ -455,6 +456,7 @@ xcopy $(MSBuildProjectDirectory)\lib\* $(OutDir)lib\ /DESY /exclude:$(MSBuildPro + diff --git a/src/win/vs2019/Angband.vcxproj.filters b/src/win/vs2019/Angband.vcxproj.filters index afb2e5d03..af0f3c792 100644 --- a/src/win/vs2019/Angband.vcxproj.filters +++ b/src/win/vs2019/Angband.vcxproj.filters @@ -399,6 +399,9 @@ Source Files + + Source Files + Source Files @@ -905,6 +908,9 @@ Header Files + + Header Files + Header Files