Skip to content

Commit

Permalink
Merge pull request #2 from BurnZeZ/input-revamp
Browse files Browse the repository at this point in the history
Input revamp beginnings
  • Loading branch information
BurnZeZ authored and BurnZeZ committed Mar 3, 2013
2 parents ec0616d + d12045a commit 5fa706a
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 193 deletions.
38 changes: 21 additions & 17 deletions bionics.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "player.h"
#include "game.h"
#include "rng.h"
#include "keypress.h"
#include "input.h"
#include "item.h"
#include "bionics.h"
#include "line.h"
Expand Down Expand Up @@ -49,6 +49,7 @@ void player::activate_bionic(int b, game *g)
std::vector<std::string> bad;
WINDOW* w;
int dirx, diry, t, index;
InputEvent input;
unsigned int l;
item tmp_item;

Expand Down Expand Up @@ -200,7 +201,8 @@ void player::activate_bionic(int b, game *g)
case bio_lighter:
g->draw();
mvprintw(0, 0, "Torch in which direction?");
get_direction(g, dirx, diry, input());
input = get_input();
get_direction(dirx, diry, input);
if (dirx == -2) {
g->add_msg("Invalid direction.");
power_level += bionics[bio_lighter].power_cost;
Expand Down Expand Up @@ -252,7 +254,8 @@ void player::activate_bionic(int b, game *g)
case bio_emp:
g->draw();
mvprintw(0, 0, "Fire EMP in which direction?");
get_direction(g, dirx, diry, input());
input = get_input();
get_direction(dirx, diry, input);
if (dirx == -2) {
g->add_msg("Invalid direction.");
power_level += bionics[bio_emp].power_cost;
Expand Down Expand Up @@ -337,7 +340,8 @@ void player::activate_bionic(int b, game *g)
case bio_lockpick:
g->draw();
mvprintw(0, 0, "Unlock in which direction?");
get_direction(g, dirx, diry, input());
input = get_input();
get_direction(dirx, diry, input);
if (dirx == -2) {
g->add_msg("Invalid direction.");
power_level += bionics[bio_lockpick].power_cost;
Expand Down Expand Up @@ -430,12 +434,12 @@ bool player::install_bionics(game *g, it_bionic* type)
Installing this bionic will increase your total battery capacity by %d.\n\
Batteries are necessary for most bionics to function. They also require a\n\
charge mechanism, which must be installed from another CBM.", BATTERY_AMOUNT);
char ch;
InputEvent input;
wrefresh(w);
do
ch = getch();
while (ch != 'q' && ch != '\n' && ch != KEY_ESCAPE);
if (ch == '\n') {
input = get_input();
while (input != Confirm && input != Close);
if (input == Confirm) {
practice("electronics", (100 - chance_of_success) * 1.5);
practice("firstaid", (100 - chance_of_success) * 1.0);
practice("mechanics", (100 - chance_of_success) * 0.5);
Expand All @@ -457,7 +461,7 @@ charge mechanism, which must be installed from another CBM.", BATTERY_AMOUNT);
}

unsigned selection = 0;
char ch;
InputEvent input;

do {

Expand All @@ -474,10 +478,10 @@ charge mechanism, which must be installed from another CBM.", BATTERY_AMOUNT);
mvwprintz(w, 22, 0, c_ltblue, bionics[id].description.c_str());

wrefresh(w);
ch = input();
switch (ch) {
input = get_input();
switch (input) {

case 'j':
case DirectionS:
mvwprintz(w, 2 + selection, 0, (has_bionic(id) ? c_ltred : c_ltblue),
bionics[id].name.c_str());
if (selection == type->options.size() - 1)
Expand All @@ -486,7 +490,7 @@ charge mechanism, which must be installed from another CBM.", BATTERY_AMOUNT);
selection++;
break;

case 'k':
case DirectionN:
mvwprintz(w, 2 + selection, 0, (has_bionic(id) ? c_ltred : c_ltblue),
bionics[id].name.c_str());
if (selection == 0)
Expand All @@ -496,13 +500,13 @@ charge mechanism, which must be installed from another CBM.", BATTERY_AMOUNT);
break;

}
if (ch == '\n' && has_bionic(id)) {
if (input == Confirm && has_bionic(id)) {
popup("You already have a %s!", bionics[id].name.c_str());
ch = 'a';
input = Nothing;
}
} while (ch != '\n' && ch != 'q' && ch != KEY_ESCAPE);
} while (input != Cancel && input != Confirm);

if (ch == '\n') {
if (input == Confirm) {
practice("electronics", (100 - chance_of_success) * 1.5);
practice("firstaid", (100 - chance_of_success) * 1.0);
practice("mechanics", (100 - chance_of_success) * 0.5);
Expand Down
24 changes: 12 additions & 12 deletions crafting.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <string>
#include <sstream>
#include "keypress.h"
#include "input.h"
#include "game.h"
#include "options.h"
#include "output.h"
Expand Down Expand Up @@ -1076,7 +1076,7 @@ void game::craft()
int line = 0, xpos, ypos;
bool redraw = true;
bool done = false;
char ch;
InputEvent input;

inventory crafting_inv = crafting_inventory();

Expand Down Expand Up @@ -1248,29 +1248,29 @@ Press ? to describe object. Press <ENTER> to attempt to craft object.");
}

wrefresh(w_data);
ch = input();
switch (ch) {
case '<':
input = get_input();
switch (input) {
case DirectionUp:
if (tab == CC_WEAPON)
tab = CC_MISC;
else
tab = craft_cat(int(tab) - 1);
redraw = true;
break;
case '>':
case DirectionDown:
if (tab == CC_MISC)
tab = CC_WEAPON;
else
tab = craft_cat(int(tab) + 1);
redraw = true;
break;
case 'j':
case DirectionS:
line++;
break;
case 'k':
case DirectionN:
line--;
break;
case '\n':
case Confirm:
if (!available[line])
popup("You can't do that!");
else
Expand All @@ -1290,7 +1290,7 @@ Press ? to describe object. Press <ENTER> to attempt to craft object.");
done = true;
}
break;
case '?':
case Help:
tmp = item(itypes[current[line]->result], 0);
full_screen_popup(tmp.info(true).c_str());
redraw = true;
Expand All @@ -1300,7 +1300,7 @@ Press ? to describe object. Press <ENTER> to attempt to craft object.");
line = current.size() - 1;
else if (line >= current.size())
line = 0;
} while (ch != KEY_ESCAPE && ch != 'q' && ch != 'Q' && !done);
} while (input != Cancel && !done);

werase(w_head);
werase(w_data);
Expand Down Expand Up @@ -1789,7 +1789,7 @@ void game::consume_tools(std::vector<component> tools)
void game::disassemble()
{
char ch = inv("Disassemble item:");
if (ch == KEY_ESCAPE) {
if (ch == 27) {
add_msg("Never mind.");
return;
}
Expand Down

0 comments on commit 5fa706a

Please sign in to comment.