Make the automap actually work

- Except that it's showing just black and white instead of the proper terrain pictures
- Fixed towns not initializing some flags, such as defy_mapping, causing them to be true when they shouldn't be
- Fix Ellipse shapes not being correctly positioned
This commit is contained in:
2014-04-14 21:16:35 -04:00
parent 121273bf57
commit 3c3ed04ca7
12 changed files with 93 additions and 199 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 KiB

After

Width:  |  Height:  |  Size: 234 KiB

View File

@@ -1312,7 +1312,7 @@ bool handle_action(sf::Event event)
// MARK: Handle non-PC stuff (like monsters) if the party actually did something
if (did_something == true) {
draw_map(mini_map,5);
draw_map(true); // TODO: Might be possible to only do this in certain circumstances?
play_ambient_sound();
if ((overall_mode >= MODE_COMBAT) && (overall_mode < MODE_TALKING)) {

View File

@@ -28,6 +28,7 @@
#include <array>
#include <boost/lexical_cast.hpp>
#include "cursors.h"
#include "winutil.h"
extern short stat_window,which_combat_type,current_pc;
extern eGameMode overall_mode;
@@ -1236,8 +1237,10 @@ short get_num_of_items(short max_num)
void init_mini_map() {
// TODO: I'm not sure if the bounds in the DLOG resource included the titlebar height; perhaps the actual height should be a little less
mini_map.create(sf::VideoMode(296,277), "Map", sf::Style::Titlebar | sf::Style::Close);
mini_map.setVisible(false);
mini_map.setPosition(sf::Vector2i(52,62));
mini_map.setVisible(false);
setWindowFloating(mini_map, true);
makeFrontWindow(mainPtr);
}
void make_cursor_watch()

View File

@@ -64,6 +64,7 @@ short on_monst_menu[256];
signed char dir_x_dif[9] = {0,1,1,1,0,-1,-1,-1,0};
signed char dir_y_dif[9] = {-1,-1,0,1,1,1,0,-1,0};
extern bool map_visible;
bool game_run_before = false;
bool give_intro_hint = true;
bool in_scen_debug = false;
@@ -94,9 +95,6 @@ bool first_update = true,anim_onscreen = false,frills_on = true,sys_7_avail,supp
short stat_window = 0,store_modifier;
bool monsters_going = false,boom_anim_active = false;
short give_delays = 0;
bool modeless_exists[18] = {false,false,false,false,false,false,
false,false,false,false,false,false,
false,false,false,false,false,false};
sf::RenderWindow mini_map;
//RECT d_rects[80];
@@ -332,8 +330,14 @@ void Handle_One_Event()
event_in_dialog = handle_dialog_event();
if (event_in_dialog == false)
if(!mainPtr.waitEvent(event)) {
// TODO: Actually, this is probably an error, so maybe it should be handled as such.
if(map_visible && mini_map.pollEvent(event)){
if(event.type == sf::Event::Closed) {
mini_map.setVisible(false);
map_visible = false;
} else if(event.type == sf::Event::GainedFocus)
makeFrontWindow(mainPtr);
}
if(!mainPtr.pollEvent(event)) {
flushingInput = false;
mainPtr.display();
return;
@@ -374,8 +378,8 @@ void Handle_One_Event()
break;
case sf::Event::GainedFocus:
Handle_Activate();
Handle_Update();
makeFrontWindow(mainPtr);
break;
case sf::Event::Closed:
@@ -414,13 +418,6 @@ void Handle_One_Event()
mainPtr.display(); // TODO: I'm assuming this needs to be SOMEWHERE, at least.
}
void Handle_Activate()
{
if (isFrontWindow(mainPtr))
mainPtr.setActive();
}
// TODO: Not sure what to do here
bool handle_dialog_event()
{
@@ -459,10 +456,6 @@ bool handle_dialog_event()
void Handle_Update()
{
// TODO: What about updating other windows? Particularly the minimap
sf::RenderWindow& the_window = mainPtr;
if (&the_window == &mainPtr) {
if (in_startup_mode == true) {
/*if (first_startup_update == true)
first_startup_update = false;
@@ -484,7 +477,9 @@ void Handle_Update()
else //refresh_screen(0);
redraw_screen();
}
}
if(map_visible) draw_map(false);
else mini_map.setVisible(false);
}

View File

@@ -5,7 +5,6 @@ int main(void);
void Initialize(void);
void Set_Window_Drag_Bdry();
void Handle_One_Event();
void Handle_Activate();
bool handle_dialog_event() ;
void Handle_Update();
void Mouse_Pressed();

View File

@@ -1390,7 +1390,7 @@ void teleport_party(short x,short y,short mode)
do_explosion_anim(5,2);
end_missile_anim();
}
draw_map(mini_map,5);
draw_map(true);
}
@@ -1758,7 +1758,7 @@ void push_things()////
univ.town.p_loc = l;
update_explored(l);
ter = univ.town->terrain(univ.town.p_loc.x,univ.town.p_loc.y);
draw_map(mini_map,5);
draw_map(true);
if (univ.town.is_barrel(univ.town.p_loc.x,univ.town.p_loc.y)) {
univ.town.set_barrel(univ.town.p_loc.x,univ.town.p_loc.y,false);
ASB("You smash the barrel.");
@@ -1796,7 +1796,7 @@ void push_things()////
draw_terrain(0);
pc_pos[i] = l;
update_explored(l);
draw_map(mini_map,5);
draw_map(true);
if (univ.town.is_barrel(pc_pos[i].x,pc_pos[i].y)) {
univ.town.set_barrel(pc_pos[i].x,pc_pos[i].y,false);
ASB("You smash the barrel.");
@@ -2806,7 +2806,7 @@ void townmode_spec(short which_mode,cSpecial cur_node,short cur_spec_type,
if(scenario.ter_types[spec.ex2a].special == TER_SPEC_CONVEYOR)
belt_present = true;
*redraw = true;
draw_map(mini_map,10);
draw_map(true);
break;
case SPEC_TOWN_SWAP_TER:
if (coord_to_ter(spec.ex1a,spec.ex1b) == spec.ex2a){
@@ -2820,7 +2820,7 @@ void townmode_spec(short which_mode,cSpecial cur_node,short cur_spec_type,
belt_present = true;
}
*redraw = 1;
draw_map(mini_map,10);
draw_map(true);
break;
case SPEC_TOWN_TRANS_TER:
ter = coord_to_ter(spec.ex1a,spec.ex1b);
@@ -2828,7 +2828,7 @@ void townmode_spec(short which_mode,cSpecial cur_node,short cur_spec_type,
if(scenario.ter_types[spec.ex2a].special == TER_SPEC_CONVEYOR)
belt_present = true;
*redraw = 1;
draw_map(mini_map,10);
draw_map(true);
break;
case SPEC_TOWN_MOVE_PARTY:
if (is_combat()) {
@@ -3209,7 +3209,7 @@ void rect_spec(short which_mode,cSpecial cur_node,short cur_spec_type,
if(scenario.ter_types[spec.sd1].special == TER_SPEC_CONVEYOR)
belt_present = true;
*redraw = true;
draw_map(mini_map,10);
draw_map(true);
}
break;
case SPEC_RECT_SWAP_TER:
@@ -3218,14 +3218,14 @@ void rect_spec(short which_mode,cSpecial cur_node,short cur_spec_type,
if(scenario.ter_types[spec.sd2].special == TER_SPEC_CONVEYOR)
belt_present = true;
*redraw = true;
draw_map(mini_map,10);
draw_map(true);
}
else if (coord_to_ter(i,j) == spec.sd2){
set_terrain(l,spec.sd1);
if(scenario.ter_types[spec.sd1].special == TER_SPEC_CONVEYOR)
belt_present = true;
*redraw = true;
draw_map(mini_map,10);
draw_map(true);
}
break;
case SPEC_RECT_TRANS_TER:
@@ -3234,7 +3234,7 @@ void rect_spec(short which_mode,cSpecial cur_node,short cur_spec_type,
if(scenario.ter_types[scenario.ter_types[ter].trans_to_what].special == TER_SPEC_CONVEYOR)
belt_present = true;
*redraw = true;
draw_map(mini_map,10);
draw_map(true);
break;
case SPEC_RECT_LOCK:
ter = coord_to_ter(i,j);
@@ -3243,7 +3243,7 @@ void rect_spec(short which_mode,cSpecial cur_node,short cur_spec_type,
if(scenario.ter_types[scenario.ter_types[ter].trans_to_what].special == TER_SPEC_CONVEYOR)
belt_present = true;
*redraw = true;
draw_map(mini_map,10);
draw_map(true);
}
break;
case SPEC_RECT_UNLOCK:
@@ -3253,7 +3253,7 @@ void rect_spec(short which_mode,cSpecial cur_node,short cur_spec_type,
if(scenario.ter_types[scenario.ter_types[ter].trans_to_what].special == TER_SPEC_CONVEYOR)
belt_present = true;
*redraw = true;
draw_map(mini_map,10);
draw_map(true);
break;
}
}

View File

@@ -112,9 +112,8 @@ short town_force = 200,store_which_shop,store_min,store_max,store_shop,store_sel
short sell_offset = 0;
location town_force_loc;
bool shop_button_active[12];
RECT map_title_rect = {8,50,20,300};
// RECT map_bar_rect = {285,47,301,218};
RECT map_bar_rect = {2,230,10,400};
RECT map_title_rect = {3,50,15,300};
RECT map_bar_rect = {15,50,27,300};
unsigned char map_graphic_placed[8][64]; // keeps track of what's been filled on map
void force_town_enter(short which_town,location where_start)
@@ -1334,6 +1333,7 @@ short get_town_spec_id(location where)
return i;
}
// TODO: I don't think we need this
void clear_map()
{
RECT map_world_rect(map_gworld);
@@ -1344,19 +1344,12 @@ void clear_map()
// draw_map(mini_map,11);
fill_rect(map_gworld, map_world_rect, sf::Color::Black);
draw_map(mini_map,10);
}
// TODO: Eliminate the flag, always do full redraw
void draw_map (sf::RenderWindow& the_dialog, short the_item)
//the_item; // Being sneaky - if this gets value of 5, this is not a full restore -
// just update near party, if it gets 11, blank out middle and leave
// No redrawing in gworld
// If a 10, do a regular full restore
// Also, can get a 5 even when the window is not up, so have to make
// sure dialog exists before accessing it.
void draw_map(bool need_refresh)
{
if(!map_visible) return;
short i,j,pic,pic2;
RECT the_rect,map_world_rect = {0,0,384,384};
location where;
@@ -1375,31 +1368,13 @@ void draw_map (sf::RenderWindow& the_dialog, short the_item)
RECT area_to_put_on_map_rect;
RECT custom_from;
//if (forcing_map_button_redraw == true) {
// forcing_map_button_redraw = false;
// return;
// }
if (the_item == 4) {
draw_surroundings = true;
the_item = 5;
}
if ((map_visible == false) && (the_item == 5) && (need_map_full_refresh == true))
return;
if ((map_visible == false) && (the_item == 10)) {
need_map_full_refresh = true;
return;
}
if ((map_visible == true) && (the_item != 11) && (need_map_full_refresh == true)) {
need_map_full_refresh = false;
the_item = 10;
}
if (the_item == 10) {
if(need_refresh) {
for (i = 0; i < 8; i++)
for (j = 0; j < 64; j++)
map_graphic_placed[i][j] = 0;
// TODO: I suspect we don't need to save this info
}
town_map_adj.x = 0;
@@ -1425,9 +1400,7 @@ void draw_map (sf::RenderWindow& the_dialog, short the_item)
view_rect.right = view_rect.left + 40;
view_rect.top = minmax(0,24,univ.town.p_loc.y - 20);
view_rect.bottom = view_rect.top + 40;
if (the_item == 5)
redraw_rect = view_rect;
else redraw_rect = big_rect;
redraw_rect = big_rect;
total_size = 64;
break;
case 1:
@@ -1463,87 +1436,26 @@ void draw_map (sf::RenderWindow& the_dialog, short the_item)
if (is_combat())
draw_pcs = false;
map_gworld.setActive();
TEXT.font = "Geneva";
if(map_visible) {
//GetDialogItem(the_dialog, 5, &the_type, &the_handle, &the_rect);
//map_rect = the_rect;
}
if (the_item == 11) {
fill_rect(map_gworld, map_world_rect, sf::Color::Black);
draw_pcs = false;
const char* title_string = "Your map:";
bool canMap = true;
if ((is_combat()) && (which_combat_type == 0)) {
title_string = "No map in combat.";
canMap = false;
}
/* else if ((is_combat()) && (which_combat_type == 0)) {
if (map_visible == true) {
PaintRect(&map_world_rect);
//GetDialogItem (the_dialog, 4, &the_type, &the_handle, &the_rect);
//SetDialogItemText (the_handle, comb_mess);
//FillCRect(&map_bar_rect,bg[4]);
//char_win_draw_string( mini_map,
// map_bar_rect,"No map in combat.",0,12);
draw_pcs = false;
}
else {
SetPort(old_port);
return;
}
} */
else if ((is_town()) && ((univ.town.num == -1) || (univ.town.num == -1)))
{
if(map_visible) {
tileImage(mini_map, map_bar_rect,bg_gworld,bg[4]);
win_draw_string(mini_map,map_bar_rect,"No map here.",0,12);
draw_pcs = false;
map_gworld.setActive();
}
else {
mainPtr.setActive();
return;
}
title_string = "No map here.";
canMap = false;
}else if((is_town() && univ.town->defy_mapping)) {
if(map_visible) {
tileImage(mini_map, map_bar_rect,bg_gworld,bg[4]);
win_draw_string(mini_map,map_bar_rect,"This place defies mapping.",0,12);
draw_pcs = false;
map_gworld.setActive();
}
else {
mainPtr.setActive();
return;
}
title_string = "This place defies mapping.";
canMap = false;
}
else {
if(map_visible) {
//SetPort(the_dialog);
//FillCRect(&map_bar_rect,bg[4]);
else if(need_refresh) {
map_gworld.setActive();
//char_win_draw_string( mini_map,
// map_bar_rect,"Hit Escape to close.",0,12);
}
if (the_item == 10) {
fill_rect(map_gworld, map_world_rect, sf::Color::Black);
}
// Now, if doing just partial restore, crop redraw_rect to save time.
if (the_item == 5) {
if ((is_out()) || ((is_combat()) && (which_combat_type == 0)) ||
((overall_mode == MODE_TALKING) && (store_pre_talk_mode == 0)) ||
((overall_mode == MODE_SHOPPING) && (store_pre_shop_mode == 0)))
kludge = global_to_local(univ.party.p_loc);
else if (is_combat())
kludge = pc_pos[current_pc];
else kludge = univ.town.p_loc;
redraw_rect.left = max(0,kludge.x - 4);
redraw_rect.right = min(view_rect.right,kludge.x + 5);
redraw_rect.top = max(0,kludge.y - 4);
redraw_rect.bottom = min(view_rect.bottom,kludge.y + 5);
}
// Now, if shopping or talking, just don't touch anything.
if ((overall_mode == MODE_SHOPPING) || (overall_mode == MODE_TALKING))
@@ -1557,10 +1469,8 @@ void draw_map (sf::RenderWindow& the_dialog, short the_item)
else out_mode = false;
area_to_put_on_map_rect = redraw_rect;
if (the_item == 10) {
area_to_put_on_map_rect.top = area_to_put_on_map_rect.left = 0;
area_to_put_on_map_rect.right = area_to_put_on_map_rect.bottom = total_size;
}
area_to_put_on_map_rect.right = area_to_put_on_map_rect.bottom = total_size;
for (where.x= area_to_put_on_map_rect.left; where.x < area_to_put_on_map_rect.right; where.x++)
for (where.y= area_to_put_on_map_rect.top; where.y < area_to_put_on_map_rect.bottom; where.y++)
@@ -1635,40 +1545,40 @@ void draw_map (sf::RenderWindow& the_dialog, short the_item)
}
}
map_gworld.display();
}
mini_map.setActive();
// Now place terrain map gworld
if (map_visible == true) {
TEXT.font = "Geneva";
TEXT.font = "Silom";
TEXT.pointSize = 10;;
TEXT.style = sf::Text::Bold;
TEXT.style = sf::Text::Regular;
if ((draw_surroundings == true) || (the_item != 5)) { // redraw much stuff
the_rect = RECT(the_dialog);
the_rect = RECT(mini_map);
tileImage(mini_map, the_rect,bg_gworld,bg[4]);
cPict theGraphic(the_dialog);
cPict theGraphic(mini_map);
theGraphic.setBounds(dlogpicrect);
theGraphic.setPict(21, PIC_DLOG);
theGraphic.setFormat(TXT_FRAME, false);
theGraphic.draw();
TEXT.colour = sf::Color::White;
win_draw_string(mini_map, map_title_rect,"Your map: (Hit Escape to close.)",0,12);
win_draw_string(mini_map, map_title_rect,title_string,0,12);
win_draw_string(mini_map, map_bar_rect,"(Hit Escape to close.)",0,12);
TEXT.colour = sf::Color::Black;
/*SetPort( the_dialog);
GetDialogItem(the_dialog, 1, &the_type, &the_handle, &the_rect);
/*SetPort( mini_map);
GetDialogItem(mini_map, 1, &the_type, &the_handle, &the_rect);
PenSize(3,3);
InsetRect(&the_rect, -4, -4);
FrameRoundRect(&the_rect, 16, 16);
PenSize(1,1); */
}
rect_draw_some_item(map_gworld.getTexture(),area_to_draw_from,map_gworld,area_to_draw_on);
}
if(canMap) {
rect_draw_some_item(map_gworld.getTexture(),area_to_draw_from,mini_map,area_to_draw_on);
// Now place PCs and monsters
if ((draw_pcs == true) && (map_visible == true)) {
if(draw_pcs) {
if ((is_town()) && (PSD[SDF_PARTY_DETECT_LIFE] > 0))
for (i = 0; i < univ.town->max_monst(); i++)
if (univ.town.monst[i].active > 0) {
@@ -1688,9 +1598,8 @@ void draw_map (sf::RenderWindow& the_dialog, short the_item)
map_graphic_placed[where.x / 8][where.y] =
map_graphic_placed[where.x / 8][where.y] & ~((unsigned char)(s_pow(2,where.x % 8)));
// TODO: Where to draw this? On the_dialog? On map_gworld?
fill_rect(the_dialog, draw_rect, sf::Color::Green);
frame_circle(the_dialog, draw_rect, sf::Color::Blue);
fill_rect(mini_map, draw_rect, sf::Color::Green);
frame_circle(mini_map, draw_rect, sf::Color::Blue);
}
}
if ((overall_mode != MODE_SHOPPING) && (overall_mode != MODE_TALKING)) {
@@ -1706,14 +1615,17 @@ void draw_map (sf::RenderWindow& the_dialog, short the_item)
draw_rect.bottom = draw_rect.top + 6;
map_graphic_placed[where.x / 8][where.y] =
map_graphic_placed[where.x / 8][where.y] & ~((unsigned char)(s_pow(2,where.x % 8)));
// TODO: Where to draw this? On the_dialog? On map_gworld?
fill_rect(the_dialog, draw_rect, sf::Color::Red);
frame_circle(the_dialog, draw_rect, sf::Color::Black);
fill_rect(mini_map, draw_rect, sf::Color::Red);
frame_circle(mini_map, draw_rect, sf::Color::Black);
}
}
}
TEXT.colour = sf::Color::Black;
mini_map.display();
// Now exit gracefully
mainPtr.setActive();
@@ -1732,41 +1644,16 @@ bool is_door(location destination)
void display_map()
{
// Show the automap if it's not already visible
if(map_visible) return;
short the_type;
RECT the_rect;
RECT dlogpicrect = {6,6,42,42};
mini_map.setVisible(true);
map_visible = true;
makeFrontWindow(mini_map, false);
draw_map(mini_map,10);
// the_rect = mini_map->portRect;
// FillCRect(&the_rect,bg[4]);
cPict theGraphic(mini_map);
theGraphic.setBounds(dlogpicrect);
theGraphic.setPict(21, PIC_DLOG);
theGraphic.setFormat(TXT_FRAME, true);
theGraphic.draw();
win_draw_string( mini_map,
map_title_rect,"Your map:",0,12);
// TODO: This looks... possibly important...
#if 0
#ifndef EXILE_BIG_GUNS
GetDialogItem( modeless_dialogs[5], 5, &the_type, &the_handle, &the_rect);
SetDialogItem( modeless_dialogs[5], 5, the_type, (Handle)draw_map, &the_rect);
GetDialogItem( modeless_dialogs[5], 4, &the_type, &the_handle, &the_rect);
SetDialogItem( modeless_dialogs[5], 4, the_type, (Handle)draw_map, &the_rect);
#endif
#ifdef EXILE_BIG_GUNS
if (map_draw_UPP == NULL)
map_draw_UPP = NewUserItemProc(draw_map);
GetDialogItem( modeless_dialogs[5], 5, &the_type, &the_handle, &the_rect);
SetDialogItem( modeless_dialogs[5], 5, the_type, (Handle)map_draw_UPP, &the_rect);
GetDialogItem( modeless_dialogs[5], 4, &the_type, &the_handle, &the_rect);
SetDialogItem( modeless_dialogs[5], 4, the_type, (Handle)map_draw_UPP, &the_rect);
#endif
#endif
draw_map(true);
makeFrontWindow(mainPtr);
}
void check_done() {

View File

@@ -26,7 +26,7 @@ void erase_specials();
void erase_out_specials();
short get_town_spec_id(location where);
void clear_map();
void draw_map (sf::RenderWindow& the_dialog, short the_item);
void draw_map(bool need_refresh);
bool is_door(location destination);
void display_map();
void check_done();

View File

@@ -76,6 +76,7 @@ cTown& cTown::operator = (legacy::town_record_type& old){
for(i = 0; i < 100; i++)
specials[i] = old.specials[i];
difficulty = old.difficulty;
strong_barriers = defy_scrying = defy_mapping = false;
return *this;
}
@@ -137,6 +138,7 @@ cTown::cTown(short size){
specials[i] = cSpecial();
}
difficulty = 0;
strong_barriers = defy_scrying = defy_mapping = false;
}
char(& cTown::town_strs(short i))[256]{

View File

@@ -843,7 +843,7 @@ public:
sf::Vector2f getPoint(unsigned int i) const override {
int t = i * divSz;
return sf::Vector2f(a*sin(t), b*cos(t));
return sf::Vector2f(a + a*sin(t), b + b*cos(t));
}
// TODO: Additional functions?

View File

@@ -17,6 +17,8 @@ namespace fs = boost::filesystem; // TODO: Centralize this alias
bool isFrontWindow(sf::Window& win);
void makeFrontWindow(sf::Window& win);
void setWindowFloating(sf::Window& win, bool floating);
void init_fileio();
fs::path nav_get_party();

View File

@@ -21,15 +21,21 @@ bool isFrontWindow(sf::Window& win) {
return false;
}
void makeFrontWindow(sf::Window& win, bool acceptKeyInput) {
void makeFrontWindow(sf::Window& win) {
sf::WindowHandle handle = win.getSystemHandle();
id nsHandle = id(handle);
if([nsHandle isKindOfClass: [NSWindow class]]) {
[nsHandle orderFrontRegardless];
if(acceptKeyInput) {
[nsHandle makeMainWindow];
[nsHandle makeKeyWindow];
}
[nsHandle makeMainWindow];
[nsHandle makeKeyWindow];
}
}
void setWindowFloating(sf::Window& win, bool floating) {
sf::WindowHandle handle = win.getSystemHandle();
id nsHandle = id(handle);
if([nsHandle isKindOfClass: [NSWindow class]]) {
[nsHandle setLevel: floating ? NSFloatingWindowLevel : NSNormalWindowLevel];
}
}