summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-09-10 15:58:46 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-09-10 15:58:46 +0000
commit1d23ad9eae6203fcabc6b1f9a933174bc907f2a9 (patch)
tree8182fbaccc51eecf655ed3feda605e4fff97ad67
parent383d392c17f076384fc37e631b6506739ca634fe (diff)
downloadcrawl-ref-1d23ad9eae6203fcabc6b1f9a933174bc907f2a9.tar.gz
crawl-ref-1d23ad9eae6203fcabc6b1f9a933174bc907f2a9.zip
Add an inventory-like region for the Tiles version to make spells
clickable. '_' toggles between inventory and spell display. Actual tiles are still missing, but everything works as it should. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@10648 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/acr.cc5
-rw-r--r--crawl-ref/source/cmd-keys.h3
-rw-r--r--crawl-ref/source/command.cc1
-rw-r--r--crawl-ref/source/describe.cc45
-rw-r--r--crawl-ref/source/describe.h1
-rw-r--r--crawl-ref/source/enum.h3
-rw-r--r--crawl-ref/source/externs.h3
-rw-r--r--crawl-ref/source/initfile.cc1
-rw-r--r--crawl-ref/source/spl-cast.cc71
-rw-r--r--crawl-ref/source/spl-cast.h2
-rw-r--r--crawl-ref/source/tilereg.cc69
-rw-r--r--crawl-ref/source/tilesdl.cc58
-rw-r--r--crawl-ref/source/tilesdl.h1
13 files changed, 204 insertions, 59 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index fedea2c60f..7100ef161a 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -1352,6 +1352,11 @@ void process_command( command_type cmd )
case CMD_EDIT_PLAYER_TILE:
tiles.draw_doll_edit();
break;
+
+ case CMD_TOGGLE_SPELL_DISPLAY:
+ Options.tile_display_spells = !Options.tile_display_spells;
+ tiles.update_inventory();
+ break;
#endif
case CMD_OPEN_DOOR_UP_RIGHT: _open_door( 1, -1); break;
diff --git a/crawl-ref/source/cmd-keys.h b/crawl-ref/source/cmd-keys.h
index 6f7a32c19f..d680c708ed 100644
--- a/crawl-ref/source/cmd-keys.h
+++ b/crawl-ref/source/cmd-keys.h
@@ -1,5 +1,6 @@
#ifdef USE_TILE
{'-', CMD_EDIT_PLAYER_TILE},
+{'_', CMD_TOGGLE_SPELL_DISPLAY},
#endif
{'b', CMD_MOVE_DOWN_LEFT},
{'h', CMD_MOVE_LEFT},
@@ -87,7 +88,9 @@
{'%', CMD_RESISTS_SCREEN},
{',', CMD_PICKUP},
{':', CMD_MAKE_NOTE},
+#ifndef USE_TILE
{'_', CMD_READ_MESSAGES},
+#endif
{';', CMD_INSPECT_FLOOR},
{'^', CMD_DISPLAY_RELIGION},
{'#', CMD_CHARACTER_DUMP},
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index 76e8ac5479..b0a7df2bba 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -2171,6 +2171,7 @@ static void _add_formatted_keyhelp(column_composer &cols)
"<w>=</w> : reassign inventory/spell letters\n"
// No online play for tiles, so this replacement is reasonable. (jpeg)
#ifdef USE_TILE
+ "<w>_</w> : toggle inventory/spells\n"
"<w>-</w> : select player doll"
#else
"<w>_</w> : read messages (online play only)"
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index e6853746ca..08afab6671 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -2387,22 +2387,16 @@ void inscribe_item(item_def &item, bool proper_prompt)
}
}
-//---------------------------------------------------------------
-//
-// describe_spell
-//
-// Describes (most) every spell in the game.
-//
-//---------------------------------------------------------------
-void describe_spell(spell_type spelled, const item_def* item)
-{
- std::string description;
+bool _get_spell_description(const spell_type spell, std::string &description,
+ const item_def* item = NULL)
+{
description.reserve(500);
- description += spell_title( spelled );
+ description = spell_title( spell );
description += "$$";
- const std::string long_descrip = getLongDescription(spell_title(spelled));
+ const std::string long_descrip = getLongDescription(spell_title(spell));
+
if (!long_descrip.empty())
description += long_descrip;
else
@@ -2416,8 +2410,7 @@ void describe_spell(spell_type spelled, const item_def* item)
#endif
}
- bool can_mem = false;
- if (you_cannot_memorise(spelled))
+ if (you_cannot_memorise(spell))
{
description += "$$";
description += "You cannot memorise or cast this spell because you "
@@ -2427,12 +2420,32 @@ void describe_spell(spell_type spelled, const item_def* item)
}
else if (item && item->base_type == OBJ_BOOKS && in_inventory(*item))
{
- can_mem = true;
description += "$$";
description += "(M)emorise this spell.";
+ return (true);
}
+ return (false);
+}
- print_description(description);
+void get_spell_desc(const spell_type spell, describe_info &inf)
+{
+ std::string desc;
+ _get_spell_description(spell, desc);
+ inf.body << desc;
+}
+
+//---------------------------------------------------------------
+//
+// describe_spell
+//
+// Describes (most) every spell in the game.
+//
+//---------------------------------------------------------------
+void describe_spell(spell_type spelled, const item_def* item)
+{
+ std::string desc;
+ bool can_mem = _get_spell_description(spelled, desc, item);
+ print_description(desc);
mouse_control mc(MOUSE_MODE_MORE);
diff --git a/crawl-ref/source/describe.h b/crawl-ref/source/describe.h
index 7696f03da6..18ff36e1d6 100644
--- a/crawl-ref/source/describe.h
+++ b/crawl-ref/source/describe.h
@@ -96,6 +96,7 @@ void get_monster_db_desc(const monsters &item, describe_info &inf,
/* ***********************************************************************
* called from: item_use - spl-cast
* *********************************************************************** */
+void get_spell_desc(const spell_type spell, describe_info &inf);
void describe_spell(spell_type spelled, const item_def* item = NULL);
// last updated 13oct2003 {darshan}
diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h
index 2abaf37186..cb650f9920 100644
--- a/crawl-ref/source/enum.h
+++ b/crawl-ref/source/enum.h
@@ -555,7 +555,8 @@ enum command_type
#ifdef USE_TILE
CMD_EDIT_PLAYER_TILE,
CMD_MIN_TILE = CMD_EDIT_PLAYER_TILE,
- CMD_MAX_TILE = CMD_MIN_TILE,
+ CMD_TOGGLE_SPELL_DISPLAY,
+ CMD_MAX_TILE = CMD_TOGGLE_SPELL_DISPLAY,
#endif
// Repeat previous command
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index 00c9f7384f..8133b12125 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -2112,7 +2112,7 @@ public:
// How much more eager greedy-explore is for items than to explore.
int explore_item_greed;
- // Some experimental improvments to explore
+ // Some experimental improvements to explore
bool explore_improved;
std::vector<sound_mapping> sound_mappings;
@@ -2230,6 +2230,7 @@ public:
int tile_key_repeat_delay;
int tile_tooltip_ms;
tag_pref tile_tag_pref;
+ bool tile_display_spells;
#endif
typedef std::map<std::string, std::string> opt_map;
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index fc2dd4102a..41d3b3c024 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -946,6 +946,7 @@ void game_options::reset_options()
tile_key_repeat_delay = 200;
tile_tooltip_ms = 500;
tile_tag_pref = crawl_state.arena ? TAGPREF_NAMED : TAGPREF_ENEMY;
+ tile_display_spells = false;
#endif
// map each colour to itself as default
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index 79a6c369cf..a58e66ff1f 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -661,7 +661,7 @@ static int _get_dist_to_nearest_monster()
}
// Returns false if spell failed, and true otherwise.
-bool cast_a_spell(bool check_range)
+bool cast_a_spell(bool check_range, spell_type spell)
{
if (!you.spell_no)
{
@@ -686,52 +686,55 @@ bool cast_a_spell(bool check_range)
const int minRange = _get_dist_to_nearest_monster();
- int keyin = 0;
-
- while (true)
+ if (spell == SPELL_NO_SPELL)
{
- if (keyin == 0)
+ int keyin = 0;
+
+ while (true)
{
- mpr("Cast which spell? (? or * to list) ", MSGCH_PROMPT);
+ if (keyin == 0)
+ {
+ mpr("Cast which spell? (? or * to list) ", MSGCH_PROMPT);
- keyin = get_ch();
- }
+ keyin = get_ch();
+ }
- if (keyin == '?' || keyin == '*')
- {
- keyin = list_spells(true, false, minRange);
- if (!keyin)
- keyin = ESCAPE;
+ if (keyin == '?' || keyin == '*')
+ {
+ keyin = list_spells(true, false, minRange);
+ if (!keyin)
+ keyin = ESCAPE;
- if (!crawl_state.doing_prev_cmd_again)
- redraw_screen();
+ if (!crawl_state.doing_prev_cmd_again)
+ redraw_screen();
- if (isalpha(keyin) || keyin == ESCAPE)
- break;
+ if (isalpha(keyin) || keyin == ESCAPE)
+ break;
+ else
+ mesclr();
+
+ keyin = 0;
+ }
else
- mesclr();
+ break;
+ }
- keyin = 0;
+ if (keyin == ESCAPE)
+ {
+ canned_msg( MSG_OK );
+ return (false);
}
- else
- break;
- }
- if (keyin == ESCAPE)
- {
- canned_msg( MSG_OK );
- return (false);
- }
+ if (!isalpha(keyin))
+ {
+ mpr("You don't know that spell.");
+ crawl_state.zero_turns_taken();
+ return (false);
+ }
- if (!isalpha(keyin))
- {
- mpr("You don't know that spell.");
- crawl_state.zero_turns_taken();
- return (false);
+ spell = get_spell_by_letter( keyin );
}
- const spell_type spell = get_spell_by_letter( keyin );
-
if (spell == SPELL_NO_SPELL)
{
mpr("You don't know that spell.");
diff --git a/crawl-ref/source/spl-cast.h b/crawl-ref/source/spl-cast.h
index 63d2276251..bece3831e2 100644
--- a/crawl-ref/source/spl-cast.h
+++ b/crawl-ref/source/spl-cast.h
@@ -64,7 +64,7 @@ void exercise_spell( spell_type spell_ex, bool spc, bool divide );
/* ***********************************************************************
* called from: acr
* *********************************************************************** */
-bool cast_a_spell( bool check_range );
+bool cast_a_spell( bool check_range, spell_type spell = SPELL_NO_SPELL );
bool maybe_identify_staff( item_def &item, spell_type spell = SPELL_NO_SPELL );
diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc
index 6b6d467761..dadf97d0e1 100644
--- a/crawl-ref/source/tilereg.cc
+++ b/crawl-ref/source/tilereg.cc
@@ -28,6 +28,8 @@ REVISION("$Rev$");
#include "player.h"
#include "religion.h"
#include "spells3.h"
+#include "spl-cast.h"
+#include "spl-util.h"
#include "stuff.h"
#include "terrain.h"
#include "transfor.h"
@@ -1616,7 +1618,11 @@ void InventoryRegion::render()
const coord_def max_pos(ex, ey);
std::string desc = "";
- if (floor && is_valid_item(mitm[idx]))
+ if (Options.tile_display_spells)
+ {
+ desc = spell_title((spell_type) idx);
+ }
+ else if (floor && is_valid_item(mitm[idx]))
desc = mitm[idx].name(DESC_PLAIN);
else if (!floor && is_valid_item(you.inv[idx]))
desc = you.inv[idx].name(DESC_INVENTORY_EQUIP);
@@ -1784,6 +1790,26 @@ void InventoryRegion::place_cursor(const coord_def &cursor)
m_dirty = true;
}
+static int _handle_spells_mouse(MouseEvent &event, int idx, int item_idx)
+{
+ const spell_type spell = (spell_type) idx;
+ if (event.button == MouseEvent::LEFT)
+ {
+ you.last_clicked_item = item_idx;
+ if (!cast_a_spell(true, spell))
+ flush_input_buffer( FLUSH_ON_FAILURE );
+ return CK_MOUSE_CMD;
+ }
+ else if (event.button == MouseEvent::RIGHT)
+ {
+ you.last_clicked_item = item_idx;
+ describe_spell(spell);
+ redraw_screen();
+ return CK_MOUSE_CMD;
+ }
+ return 0;
+}
+
int InventoryRegion::handle_mouse(MouseEvent &event)
{
int cx, cy;
@@ -1807,12 +1833,16 @@ int InventoryRegion::handle_mouse(MouseEvent &event)
return 0;
int idx = m_items[item_idx].idx;
+
+ if (m_items[item_idx].key == 0 && Options.tile_display_spells)
+ return _handle_spells_mouse(event, idx, item_idx);
+
bool on_floor = m_items[item_idx].flag & TILEI_FLAG_FLOOR;
ASSERT(idx >= 0);
// TODO enne - this is all really only valid for the on-screen inventory
- // Do we subclass inventoryregion for the onscreen and offscreen versions?
+ // Do we subclass InventoryRegion for the onscreen and offscreen versions?
char key = m_items[item_idx].key;
if (key)
return key;
@@ -1913,6 +1943,16 @@ static bool _can_use_item(const item_def &item, bool equipped)
return (true);
}
+void _update_spell_tip_text(std::string& tip, int flag)
+{
+ if (flag & TILEI_FLAG_MELDED)
+ tip = "You cannot cast this spell right now.";
+ else
+ tip = "[L-Click] Cast (z)";
+
+ tip += "\n[R-Click] Describe (I)";
+}
+
bool InventoryRegion::update_tip_text(std::string& tip)
{
if (m_cursor == NO_CURSOR)
@@ -1929,6 +1969,12 @@ bool InventoryRegion::update_tip_text(std::string& tip)
bool display_actions = (m_items[item_idx].key == 0
&& mouse_control::current_mode() == MOUSE_MODE_COMMAND);
+ if (display_actions && Options.tile_display_spells)
+ {
+ _update_spell_tip_text(tip, m_items[item_idx].flag);
+ return (true);
+ }
+
// TODO enne - should the command keys here respect keymaps?
if (m_items[item_idx].flag & TILEI_FLAG_FLOOR)
@@ -2153,6 +2199,19 @@ bool InventoryRegion::update_tip_text(std::string& tip)
return (true);
}
+void _update_spell_alt_text(std::string &alt, int idx)
+{
+ const spell_type spell = (spell_type) idx;
+
+ describe_info inf;
+ get_spell_desc(spell, inf);
+
+ alt_desc_proc proc(crawl_view.msgsz.x, crawl_view.msgsz.y);
+ process_description<alt_desc_proc>(proc, inf);
+
+ proc.get_string(alt);
+}
+
bool InventoryRegion::update_alt_text(std::string &alt)
{
if (m_cursor == NO_CURSOR)
@@ -2167,7 +2226,13 @@ bool InventoryRegion::update_alt_text(std::string &alt)
{
return (false);
}
+
int idx = m_items[item_idx].idx;
+ if (m_items[item_idx].key == 0 && Options.tile_display_spells)
+ {
+ _update_spell_alt_text(alt, idx);
+ return (true);
+ }
const item_def *item;
if (m_items[item_idx].flag & TILEI_FLAG_FLOOR)
diff --git a/crawl-ref/source/tilesdl.cc b/crawl-ref/source/tilesdl.cc
index 6f12ddb31b..a3c72e7de2 100644
--- a/crawl-ref/source/tilesdl.cc
+++ b/crawl-ref/source/tilesdl.cc
@@ -11,6 +11,7 @@ REVISION("$Rev$");
#include "message.h"
#include "mon-util.h"
#include "player.h"
+#include "spl-util.h"
#include "state.h"
#include "stuff.h"
#include "tiles.h"
@@ -1431,13 +1432,62 @@ static void _fill_item_info(InventoryTile &desc, const item_def &item)
desc.flag |= TILEI_FLAG_FLOOR;
}
-void TilesFramework::update_inventory()
+void TilesFramework::update_spells()
{
std::vector<InventoryTile> inv;
+ for (int i = 0; i < 52; ++i)
+ {
+ const char letter = index_to_letter(i);
+ const spell_type spell = get_spell_by_letter(letter);
+ if (spell == SPELL_NO_SPELL)
+ continue;
+
+ InventoryTile desc;
+// desc.tile = tileidx_spell(item);
+ desc.tile = TILE_ERROR;
+ desc.idx = (int) spell;
+
+ // If an equipped artefact prevents teleportation, the following spells
+ // cannot be cast.
+ if ((spell == SPELL_BLINK || spell == SPELL_CONTROLLED_BLINK
+ || spell == SPELL_TELEPORT_SELF)
+ && scan_artefacts(ARTP_PREVENT_TELEPORTATION, false))
+ {
+ desc.flag |= TILEI_FLAG_MELDED;
+ }
+ else if (spell_mana(spell) > you.magic_points)
+ desc.flag |= TILEI_FLAG_MELDED;
+
+ inv.push_back(desc);
+ }
+ const int mx = m_region_inv->mx;
+ const int my = m_region_inv->my;
+
+ const unsigned int max_spells = std::min(22, mx*my);
+ while (inv.size() < max_spells)
+ {
+ InventoryTile desc;
+// if ((int)inv.size() >= max_pack_items)
+// desc.flag |= TILEI_FLAG_INVALID;
+ inv.push_back(desc);
+ }
+ m_region_inv->update(inv.size(), &inv[0]);
+}
+
+void TilesFramework::update_inventory()
+{
if (!Options.tile_show_items || crawl_state.arena)
return;
+ if (Options.tile_display_spells)
+ {
+ update_spells();
+ return;
+ }
+
+ std::vector<InventoryTile> inv;
+
// item.base_type <-> char conversion table
const static char *obj_syms = ")([/%#?=!#+\\0}x";
@@ -1478,7 +1528,7 @@ void TilesFramework::update_inventory()
}
// First, normal inventory
- for (int i = 0; i < ENDOFPACK; i++)
+ for (int i = 0; i < ENDOFPACK; ++i)
{
if ((int)inv.size() >= max_pack_items)
break;
@@ -1495,7 +1545,7 @@ void TilesFramework::update_inventory()
_fill_item_info(desc, you.inv[i]);
desc.idx = i;
- for (int eq = 0; eq < NUM_EQUIP; eq++)
+ for (int eq = 0; eq < NUM_EQUIP; ++eq)
{
if (you.equip[eq] == i)
{
@@ -1521,7 +1571,7 @@ void TilesFramework::update_inventory()
{
// Fill out part of this row.
int fill = remaining - num_ground;
- for (int i = 0; i < fill; i++)
+ for (int i = 0; i < fill; ++i)
{
InventoryTile desc;
if ((int)inv.size() >= max_pack_items)
diff --git a/crawl-ref/source/tilesdl.h b/crawl-ref/source/tilesdl.h
index 1913ebbf8b..e122525cbb 100644
--- a/crawl-ref/source/tilesdl.h
+++ b/crawl-ref/source/tilesdl.h
@@ -106,6 +106,7 @@ public:
void update_minimap(int gx, int gy, map_feature f);
void clear_minimap();
void update_minimap_bounds();
+ void update_spells();
void update_inventory();
void set_need_redraw();