Skip to content

Commit de953ca

Browse files
committed
Save/restore mostly working
1 parent 50ab6b6 commit de953ca

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

exult.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -938,10 +938,15 @@ int Modal_gump
938938
int escaped = 0;
939939
// Get area to repaint when done.
940940
Rectangle box = gwin->get_gump_rect(gump);
941-
box.enlarge(6);
941+
box.enlarge(2);
942+
box = gwin->clip_to_win(box);
943+
// Create buffer to backup background.
944+
Image_buffer *back = gwin->get_win()->create_buffer(box.w, box.h);
942945
#ifdef MOUSE
943946
mouse->hide(); // Turn off mouse.
944947
#endif
948+
// Save background.
949+
gwin->get_win()->get(back, box.x, box.y);
945950
gump->paint(gwin); // Paint gump.
946951
gwin->show();
947952
do
@@ -951,7 +956,7 @@ int Modal_gump
951956
mouse->hide(); // Turn off mouse.
952957
#endif
953958
SDL_Event event;
954-
while (!escaped && SDL_PollEvent(&event))
959+
while (!escaped && !gump->is_done() && SDL_PollEvent(&event))
955960
escaped = !Handle_gump_event(gump, event);
956961
#ifdef MOUSE
957962
mouse->show(); // Re-display mouse.
@@ -960,9 +965,13 @@ int Modal_gump
960965
}
961966
while (!gump->is_done() && !escaped);
962967
mouse->hide();
963-
gwin->paint(box); // Paint over gump.
968+
// Restore background.
969+
gwin->get_win()->put(back, box.x, box.y);
970+
delete back;
964971
mouse->set_shape(saveshape);
965972
mouse->show();
973+
gwin->set_painted();
974+
gwin->show();
966975
return (!escaped);
967976
}
968977

gamedat.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,24 @@ static long Savefile
137137
in.seekg(0, ios::end); // Get to end so we can get length.
138138
long len = in.tellg();
139139
in.seekg(0, ios::beg);
140+
char namebuf[13]; // First write 13-byte name.
141+
memset(namebuf, 0, sizeof(namebuf));
142+
char *base = strchr(fname, '/');// Want the base name.
143+
if (!base)
144+
base = strchr(fname, '\\');
145+
if (base)
146+
base++;
147+
else
148+
base = fname;
149+
strncpy(namebuf, base, sizeof(namebuf));
150+
out.write(namebuf, sizeof(namebuf));
140151
char *buf = new char[len]; // Get it all at once.
141152
in.read(buf, len);
142153
out.write(buf, len);
143154
delete buf;
144-
if (in.good())
155+
if (!in.good())
145156
cerr << "Exult: Error reading '" << fname << "'\n";
146-
return len;
157+
return len + 13; // Include filename.
147158
}
148159

149160
/*

gumps.cc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ short File_gump_object::btn_cols[3] = {94, 163, 232};
8181
short File_gump_object::textx = 237, File_gump_object::texty = 14,
8282
File_gump_object::texth = 13;
8383

84-
short Yesno_gump_object::yesx = 10; //++++++Guessing.
84+
short Yesno_gump_object::yesx = 63;
8585
short Yesno_gump_object::yesnoy = 44;
86-
short Yesno_gump_object::nox = 30; //++++++Guessing.
86+
short Yesno_gump_object::nox = 84;
8787

8888

8989
/*
@@ -566,7 +566,7 @@ void Gump_object::initialize
566566
checkx = 8; checky = 70;
567567
break;
568568
case YESNOBOX:
569-
object_area = Rectangle(4, 4, 40, 40); //++++++Guessing.
569+
object_area = Rectangle(8, 8, 112, 24);
570570
// No checkmark.
571571
break;
572572
default:
@@ -1574,6 +1574,7 @@ void File_gump_object::load
15741574
return;
15751575
Game_window *gwin = Game_window::get_game_window();
15761576
gwin->restore_gamedat(num); // Aborts if unsuccessful.
1577+
gwin->read(); // And read the files in.
15771578
done = 1;
15781579
restored = 1;
15791580
}
@@ -1597,7 +1598,8 @@ void File_gump_object::save
15971598
if (!Yesno_gump_object::ask(
15981599
"Okay to overwrite existing saved game?"))
15991600
return;
1600-
if (gwin->save_gamedat(num, focus->get_text()))
1601+
if (gwin->write() && // First flush to 'gamedat'.
1602+
gwin->save_gamedat(num, focus->get_text()))
16011603
cout << "Saved game #" << num << " successfully.\n";
16021604
}
16031605

@@ -1766,12 +1768,12 @@ void File_gump_object::key_down
17661768
focus->set_cursor(focus->get_length());
17671769
return;
17681770
}
1771+
if (chr < ' ')
1772+
return; // Ignore other special chars.
17691773
if (isascii(chr))
17701774
{
17711775
int old_length = focus->get_length();
17721776
focus->insert(chr);
1773-
delete buttons[0]; // Can't load now.
1774-
buttons[0] = 0;
17751777
// Added first character? Need
17761778
// 'Save' button.
17771779
if (!old_length && focus->get_length() && !buttons[1])
@@ -1781,6 +1783,12 @@ void File_gump_object::key_down
17811783
paint_button(Game_window::get_game_window(),
17821784
buttons[1]);
17831785
}
1786+
if (buttons[0]) // Can't load now.
1787+
{
1788+
delete buttons[0];
1789+
buttons[0] = 0;
1790+
paint(Game_window::get_game_window());
1791+
}
17841792
}
17851793
}
17861794

@@ -1824,6 +1832,9 @@ void Yesno_gump_object::paint
18241832
// Paint buttons.
18251833
paint_button(gwin, yes_button);
18261834
paint_button(gwin, no_button);
1835+
// Paint text.
1836+
gwin->paint_text_box(2, text, x + object_area.x, y + object_area.y,
1837+
object_area.w, object_area.h, 2);
18271838
}
18281839

18291840
/*

0 commit comments

Comments
 (0)