summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/spl-cast.cc
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-05-08 09:13:07 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-05-08 09:13:07 +0000
commit90a4b849d15c2e762dc00195a448e0caa642cbaf (patch)
tree54c63fc984d2fd84fda9eb4a4c7623eb3d97758b /crawl-ref/source/spl-cast.cc
parentc8dad26d1f8ad2c61d515bff20b58f8eeae5e9b2 (diff)
downloadcrawl-ref-90a4b849d15c2e762dc00195a448e0caa642cbaf.tar.gz
crawl-ref-90a4b849d15c2e762dc00195a448e0caa642cbaf.zip
Changed list_spells() somewhat. It's now a slider wraparound menu.
(Also changed the meaning of what some of the flags do to slider_menu, the default behaviour should be unaltered.) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1423 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/spl-cast.cc')
-rw-r--r--crawl-ref/source/spl-cast.cc154
1 files changed, 52 insertions, 102 deletions
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index c92df53d2e..b468cce37c 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -15,10 +15,8 @@
#include "AppHdr.h"
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
+#include <sstream>
+#include <iomanip>
#include "spl-cast.h"
@@ -128,119 +126,71 @@ static void surge_power(spell_type spell)
}
} // end surge_power()
-char list_spells(void)
+static std::string spell_full_description(spell_type spell)
{
- int j;
- int lines = 0;
- unsigned int anything = 0;
- unsigned int i;
- int ki;
- bool already = false;
+ std::ostringstream desc;
- const int num_lines = get_number_of_lines();
- cursor_control coff(false);
-
- clrscr();
+ desc << std::left;
- cprintf( " Your Spells Type Power Success Level" );
- lines++;
+ // spell name
+ desc << std::setw(30) << spell_title(spell);
- for (j = 0; j < 52; j++)
+ // spell schools
+ bool already = false;
+ for ( int i = 0; i <= SPTYP_LAST_EXPONENT; ++i)
{
- if (lines > num_lines - 2)
+ if (spell_typematch(spell, (1<<i)))
{
- gotoxy(1, num_lines);
- cprintf("-more-");
-
- ki = getch();
-
- if (ki == ESCAPE)
- {
- return (ESCAPE);
- }
-
- if (isalpha( ki ))
- {
- return (ki);
- }
+ if (already)
+ desc << '/';
+ desc << spelltype_short_name(1 << i);
+ already = true;
+ }
+ }
+
+ const int so_far = desc.str().length();
+ if ( so_far < 46 )
+ desc << std::string(46 - so_far, ' ');
- if (ki == 0)
- ki = getch();
+ // spell power, fail rate, level
+ desc << std::setw(14) << spell_power_string(spell)
+ << std::setw(12) << failure_rate_to_string(spell_fail(spell))
+ << spell_difficulty(spell);
- lines = 0;
- clrscr();
- gotoxy(1, 1);
- anything = 0;
- }
+ return desc.str();
+}
- const char letter = index_to_letter(j);
- const spell_type spell = get_spell_by_letter(letter);
+char list_spells()
+{
+ slider_menu spell_menu(MF_SINGLESELECT | MF_ANYPRINTABLE);
+ spell_menu.set_title(new MenuEntry(" Your Spells Type Power Success Level", MEL_TITLE));
+ spell_menu.set_highlighter(NULL);
+ 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)
{
- anything++;
-
- if (lines > 0)
- cprintf(EOL);
-
- lines++;
-
- cprintf( " %c - %s", letter, spell_title( spell ) );
- gotoxy(35, wherey());
-
- already = false;
-
- for (i = 0; i <= SPTYP_LAST_EXPONENT; i++)
- {
- if (spell_typematch( spell, (1 << i) ))
- {
- if (already)
- cprintf( "/" );
-
- cprintf( "%s", spelltype_short_name( 1 << i ) );
- already = true;
- }
- }
-
- char sval[16];
-
- // 35--48 is the spell schools
-
- gotoxy(51, wherey());
- cprintf("%s", spell_power_string(spell));
-
- //gotoxy(58, wherey());
- gotoxy(65, wherey());
-
- cprintf( "%s", failure_rate_to_string(spell_fail(spell)));
-
- gotoxy(77, wherey());
-
- itoa( spell_difficulty( spell ), sval, 10 );
- cprintf(sval);
+ MenuEntry* me = new MenuEntry(spell_full_description(spell),
+ MEL_ITEM, 0, letter);
+ spell_menu.add_entry(me);
}
- } // end of j loop
-
- if (anything > 0)
+ }
+
+ std::vector<MenuEntry*> sel = spell_menu.show();
+ redraw_screen();
+ if ( sel.empty() )
{
- ki = getch();
-
- if (ki >= 'A' && ki <= 'z')
- {
- return (ki);
- }
-
- if (ki == 0)
- ki = getch();
-
- return (anything);
+ return 0;
}
-
- // was 35
- ki = getch();
-
- return (ki);
-} // end list_spells()
+ else
+ {
+ ASSERT(sel.size() == 1);
+ ASSERT(sel[0]->hotkeys.size() == 1);
+ return sel[0]->hotkeys[0];
+ }
+}
static int apply_vehumet_wizardry_boost(spell_type spell, int chance)
{