Introduce scrollbar for the terrain palette in the scenario editor

This commit is contained in:
2015-02-07 14:47:48 -05:00
parent 965dcc1201
commit c3143c3a6e
4 changed files with 54 additions and 22 deletions

View File

@@ -68,7 +68,7 @@ extern cTown* town;
extern short mode_count,to_create; extern short mode_count,to_create;
extern ter_num_t template_terrain[64][64]; extern ter_num_t template_terrain[64][64];
extern cScenario scenario; extern cScenario scenario;
extern std::shared_ptr<cScrollbar> right_sbar; extern std::shared_ptr<cScrollbar> right_sbar, pal_sbar;
extern cOutdoors* current_terrain; extern cOutdoors* current_terrain;
extern location cur_out; extern location cur_out;
extern sf::RenderWindow mainPtr; extern sf::RenderWindow mainPtr;
@@ -132,8 +132,8 @@ void init_screen_locs() {
for(i = 0; i < 256; i++) { for(i = 0; i < 256; i++) {
terrain_rects[i] = terrain_rect_base; terrain_rects[i] = terrain_rect_base;
terrain_rects[i].offset(3 + (i % 17) * (terrain_rect_base.right + 1), terrain_rects[i].offset(3 + (i % 16) * (terrain_rect_base.right + 1),
3 + (i / 17) * (terrain_rect_base.bottom + 1)); 3 + (i / 16) * (terrain_rect_base.bottom + 1));
} }
} }
@@ -1002,7 +1002,7 @@ bool handle_action(location the_point,sf::Event /*event*/) {
} }
else { else {
edit_ter_type(i); edit_ter_type(i);
set_up_terrain_buttons(); set_up_terrain_buttons(true);
} }
place_location(); place_location();
} }
@@ -2103,6 +2103,7 @@ void set_up_main_screen() {
set_lb(NLS - 1,LB_TEXT,LB_NO_ACTION,"Copyright 1997, All rights reserved."); set_lb(NLS - 1,LB_TEXT,LB_NO_ACTION,"Copyright 1997, All rights reserved.");
overall_mode = MODE_MAIN_SCREEN; overall_mode = MODE_MAIN_SCREEN;
right_sbar->show(); right_sbar->show();
pal_sbar->hide();
shut_down_menus(4); shut_down_menus(4);
shut_down_menus(3); shut_down_menus(3);
redraw_screen(); redraw_screen();
@@ -2122,10 +2123,11 @@ void start_town_edit() {
set_lb(NLS - 1,LB_TEXT,LB_RETURN,"Back to Main Menu"); set_lb(NLS - 1,LB_TEXT,LB_RETURN,"Back to Main Menu");
overall_mode = MODE_DRAWING; overall_mode = MODE_DRAWING;
editing_town = true; editing_town = true;
set_up_terrain_buttons(); set_up_terrain_buttons(true);
shut_down_menus(4); shut_down_menus(4);
shut_down_menus(2); shut_down_menus(2);
right_sbar->hide(); right_sbar->hide();
pal_sbar->show();
set_string("Drawing mode",(char*)scenario.ter_types[current_terrain_type].name.c_str()); set_string("Drawing mode",(char*)scenario.ter_types[current_terrain_type].name.c_str());
place_location(); place_location();
copied_spec = -1; copied_spec = -1;
@@ -2151,8 +2153,9 @@ void start_out_edit() {
set_lb(NLS - 1,LB_TEXT,LB_RETURN,"Back to Main Menu"); set_lb(NLS - 1,LB_TEXT,LB_RETURN,"Back to Main Menu");
overall_mode = MODE_DRAWING; overall_mode = MODE_DRAWING;
editing_town = false; editing_town = false;
set_up_terrain_buttons(); set_up_terrain_buttons(true);
right_sbar->hide(); right_sbar->hide();
pal_sbar->show();
shut_down_menus(4); shut_down_menus(4);
shut_down_menus(1); shut_down_menus(1);
redraw_screen(); redraw_screen();
@@ -2169,8 +2172,9 @@ void start_out_edit() {
void start_terrain_editing() { void start_terrain_editing() {
right_sbar->hide(); right_sbar->hide();
pal_sbar->show();
overall_mode = MODE_EDIT_TYPES; overall_mode = MODE_EDIT_TYPES;
set_up_terrain_buttons(); set_up_terrain_buttons(true);
place_location(); place_location();
set_lb(NLS - 3,LB_CLEAR,LB_NO_ACTION,"",true); set_lb(NLS - 3,LB_CLEAR,LB_NO_ACTION,"",true);
@@ -2185,6 +2189,7 @@ void start_monster_editing(short just_redo_text) {
if(just_redo_text == 0) { if(just_redo_text == 0) {
overall_mode = MODE_MAIN_SCREEN; overall_mode = MODE_MAIN_SCREEN;
right_sbar->show(); right_sbar->show();
pal_sbar->hide();
right_sbar->setPosition(0); right_sbar->setPosition(0);
reset_rb(); reset_rb();
@@ -2211,6 +2216,7 @@ void start_item_editing(short just_redo_text) {
draw_full = true; draw_full = true;
overall_mode = MODE_MAIN_SCREEN; overall_mode = MODE_MAIN_SCREEN;
right_sbar->show(); right_sbar->show();
pal_sbar->hide();
right_sbar->setPosition(0); right_sbar->setPosition(0);
reset_rb(); reset_rb();
@@ -2236,6 +2242,7 @@ void start_special_item_editing() {
draw_full = true; draw_full = true;
overall_mode = MODE_MAIN_SCREEN; overall_mode = MODE_MAIN_SCREEN;
right_sbar->show(); right_sbar->show();
pal_sbar->hide();
right_sbar->setPosition(0); right_sbar->setPosition(0);
reset_rb(); reset_rb();
@@ -2256,6 +2263,7 @@ void start_quest_editing() {
set_up_main_screen(); set_up_main_screen();
overall_mode = MODE_MAIN_SCREEN; overall_mode = MODE_MAIN_SCREEN;
right_sbar->show(); right_sbar->show();
pal_sbar->hide();
right_sbar->setPosition(0); right_sbar->setPosition(0);
reset_rb(); reset_rb();
right_sbar->setMaximum(num_options - NRSONPAGE); right_sbar->setMaximum(num_options - NRSONPAGE);
@@ -2277,6 +2285,7 @@ void start_shops_editing() {
set_up_main_screen(); set_up_main_screen();
overall_mode = MODE_MAIN_SCREEN; overall_mode = MODE_MAIN_SCREEN;
right_sbar->show(); right_sbar->show();
pal_sbar->hide();
right_sbar->setPosition(0); right_sbar->setPosition(0);
reset_rb(); reset_rb();
right_sbar->setMaximum(num_options - NRSONPAGE); right_sbar->setMaximum(num_options - NRSONPAGE);
@@ -2307,6 +2316,7 @@ void start_string_editing(short mode,short just_redo_text) {
draw_full = true; draw_full = true;
overall_mode = MODE_MAIN_SCREEN; overall_mode = MODE_MAIN_SCREEN;
right_sbar->show(); right_sbar->show();
pal_sbar->hide();
reset_rb(); reset_rb();
right_sbar->setMaximum(num_strs(mode) - NRSONPAGE); right_sbar->setMaximum(num_strs(mode) - NRSONPAGE);
@@ -2369,6 +2379,7 @@ void start_special_editing(short mode,short just_redo_text) {
draw_full = true; draw_full = true;
overall_mode = MODE_MAIN_SCREEN; overall_mode = MODE_MAIN_SCREEN;
right_sbar->show(); right_sbar->show();
pal_sbar->hide();
reset_rb(); reset_rb();
right_sbar->setMaximum(num_specs + 1 - NRSONPAGE); right_sbar->setMaximum(num_specs + 1 - NRSONPAGE);
@@ -2416,6 +2427,7 @@ void start_dialogue_editing(short restoring) {
draw_full = true; draw_full = true;
overall_mode = MODE_MAIN_SCREEN; overall_mode = MODE_MAIN_SCREEN;
right_sbar->show(); right_sbar->show();
pal_sbar->hide();
if(restoring == 0) { if(restoring == 0) {
right_sbar->setPosition(0); right_sbar->setPosition(0);

View File

@@ -49,7 +49,7 @@ extern rectangle left_button[NLS];
extern rectangle right_buttons[NRSONPAGE]; extern rectangle right_buttons[NRSONPAGE];
extern rectangle right_scrollbar_rect; extern rectangle right_scrollbar_rect;
extern rectangle right_area_rect; extern rectangle right_area_rect;
extern std::shared_ptr<cScrollbar> right_sbar; extern std::shared_ptr<cScrollbar> right_sbar, pal_sbar;
extern bool left_buttons_active,right_buttons_active; extern bool left_buttons_active,right_buttons_active;
extern std::array<lb_t,NLS> left_button_status; extern std::array<lb_t,NLS> left_button_status;
@@ -415,6 +415,7 @@ void draw_main_screen() {
//rect_draw_some_item(terrain_buttons_gworld,terrain_buttons_rect, //rect_draw_some_item(terrain_buttons_gworld,terrain_buttons_rect,
// terrain_buttons_gworld,draw_rect,0,1); // terrain_buttons_gworld,draw_rect,0,1);
place_location(); place_location();
pal_sbar->draw();
} }
@@ -482,33 +483,40 @@ void draw_rb_slot (short which,short mode) {
win_draw_string(mainPtr,text_rect,right_button_status[which].label,eTextMode::WRAP,style); win_draw_string(mainPtr,text_rect,right_button_status[which].label,eTextMode::WRAP,style);
} }
void set_up_terrain_buttons() { void set_up_terrain_buttons(bool reset) {
short i,j,pic,small_i; short i,j,pic,small_i;
rectangle ter_from,ter_from_base = {0,0,36,28}; rectangle ter_from,ter_from_base = {0,0,36,28};
rectangle tiny_from,tiny_to; rectangle tiny_from,tiny_to;
rectangle palette_from,palette_to = palette_button_base; rectangle palette_from,palette_to = palette_button_base;
if(reset) pal_sbar->setPosition(0);
pal_sbar->setMaximum((scenario.ter_types.size() / 16) - 15);
if(overall_mode != MODE_EDIT_TYPES)
pal_sbar->setMaximum(pal_sbar->getMaximum() - 1);
tileImage(terrain_buttons_gworld,terrain_buttons_rect,bg[17]); tileImage(terrain_buttons_gworld,terrain_buttons_rect,bg[17]);
frame_rect(terrain_buttons_gworld, terrain_buttons_rect, sf::Color::Black); frame_rect(terrain_buttons_gworld, terrain_buttons_rect, sf::Color::Black);
int first = pal_sbar->getPosition() * 16;
int end = min(first + 256, scenario.ter_types.size());
// first make terrain buttons // first make terrain buttons
switch(draw_mode){ switch(draw_mode){
case DRAW_TERRAIN: case DRAW_TERRAIN:
for(i = 0; i < scenario.ter_types.size(); i++) { for(i = first; i < end; i++) {
ter_from = ter_from_base; ter_from = ter_from_base;
pic = scenario.ter_types[i].picture; pic = scenario.ter_types[i].picture;
if(pic >= 1000) { if(pic >= 1000) {
sf::Texture* source_gworld; sf::Texture* source_gworld;
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic % 1000); graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic % 1000);
rect_draw_some_item(*source_gworld, rect_draw_some_item(*source_gworld,
ter_from,terrain_buttons_gworld,terrain_rects[i]); ter_from,terrain_buttons_gworld,terrain_rects[i - first]);
} }
else if(pic < 960) { else if(pic < 960) {
pic = pic % 50; pic = pic % 50;
ter_from.offset(28 * (pic % 10), 36 * (pic / 10)); ter_from.offset(28 * (pic % 10), 36 * (pic / 10));
rect_draw_some_item(terrain_gworld[scenario.ter_types[i].picture/50], rect_draw_some_item(terrain_gworld[scenario.ter_types[i].picture/50],
ter_from,terrain_buttons_gworld,terrain_rects[i]); ter_from,terrain_buttons_gworld,terrain_rects[i - first]);
} }
else { else {
pic = (pic - 560) % 50; pic = (pic - 560) % 50;
@@ -517,19 +525,13 @@ void set_up_terrain_buttons() {
ter_from.top = 36 * (pic % 5); ter_from.top = 36 * (pic % 5);
ter_from.bottom = ter_from.top + 36; ter_from.bottom = ter_from.top + 36;
rect_draw_some_item(anim_gworld, rect_draw_some_item(anim_gworld,
ter_from,terrain_buttons_gworld,terrain_rects[i]); ter_from,terrain_buttons_gworld,terrain_rects[i - first]);
} }
small_i = get_small_icon(i); small_i = get_small_icon(i);
// if(i == 82)
// small_i = 3;
// if(i == 83)
// small_i = 2;
// if((i == 7) || (i == 10) || (i == 13) || (i == 16))
// small_i = 23;
tiny_from = base_small_button_from; tiny_from = base_small_button_from;
tiny_from.offset(7 * (small_i % 10),7 * (small_i / 10)); tiny_from.offset(7 * (small_i % 10),7 * (small_i / 10));
tiny_to = terrain_rects[i]; tiny_to = terrain_rects[i - first];
tiny_to.top = tiny_to.bottom - 7; tiny_to.top = tiny_to.bottom - 7;
tiny_to.left = tiny_to.right - 7; tiny_to.left = tiny_to.right - 7;
if(small_i > 0 && small_i < 255) if(small_i > 0 && small_i < 255)

View File

@@ -11,7 +11,7 @@ void draw_lb();
void draw_lb_slot (short which,short mode) ; void draw_lb_slot (short which,short mode) ;
void draw_rb(); void draw_rb();
void draw_rb_slot (short which,short mode) ; void draw_rb_slot (short which,short mode) ;
void set_up_terrain_buttons(); void set_up_terrain_buttons(bool reset);
void draw_terrain(); void draw_terrain();
void draw_monsts(); void draw_monsts();
rectangle get_item_template_rect (short type_wanted); rectangle get_item_template_rect (short type_wanted);

View File

@@ -30,7 +30,7 @@ bool diff_depth_ok = false,mouse_button_held = false,editing_town = false;
short cur_viewing_mode = 0; short cur_viewing_mode = 0;
short cen_x, cen_y; short cen_x, cen_y;
eScenMode overall_mode = MODE_INTRO_SCREEN; eScenMode overall_mode = MODE_INTRO_SCREEN;
std::shared_ptr<cScrollbar> right_sbar; std::shared_ptr<cScrollbar> right_sbar, pal_sbar;
short mode_count = 0; short mode_count = 0;
cOutdoors* current_terrain; cOutdoors* current_terrain;
short pixel_depth,old_depth = 8; short pixel_depth,old_depth = 8;
@@ -52,6 +52,7 @@ void ding();
cScenario scenario; cScenario scenario;
rectangle right_sbar_rect; rectangle right_sbar_rect;
extern rectangle terrain_buttons_rect;
//Changed to ISO C specified argument and return type. //Changed to ISO C specified argument and return type.
int main(int, char* argv[]) { int main(int, char* argv[]) {
@@ -137,6 +138,14 @@ void Initialize(void) {
right_sbar->setBounds(right_sbar_rect); right_sbar->setBounds(right_sbar_rect);
right_sbar->setPageSize(NRSONPAGE - 1); right_sbar->setPageSize(NRSONPAGE - 1);
right_sbar->hide(); right_sbar->hide();
rectangle pal_sbar_rect = terrain_buttons_rect;
pal_sbar_rect.offset(RIGHT_AREA_UL_X,RIGHT_AREA_UL_Y);
pal_sbar_rect.left = pal_sbar_rect.right - 16;
pal_sbar_rect.height() = 17 * 16;
pal_sbar.reset(new cScrollbar(mainPtr));
pal_sbar->setBounds(pal_sbar_rect);
pal_sbar->setPageSize(16);
pal_sbar->hide();
} }
void Handle_One_Event() { void Handle_One_Event() {
@@ -496,6 +505,8 @@ static void handleUpdateWhileScrolling(volatile bool& doneScrolling) {
sf::sleep(sf::milliseconds(10)); sf::sleep(sf::milliseconds(10));
// TODO: redraw_screen should probably take the argument specifying what to update // TODO: redraw_screen should probably take the argument specifying what to update
redraw_screen(/*REFRESH_RIGHT_BAR*/); redraw_screen(/*REFRESH_RIGHT_BAR*/);
if(overall_mode < MODE_MAIN_SCREEN || overall_mode == MODE_EDIT_TYPES)
set_up_terrain_buttons(false);
} }
} }
@@ -509,6 +520,13 @@ void Mouse_Pressed() {
doneScrolling = true; doneScrolling = true;
updater.join(); updater.join();
redraw_screen(/*REFRESH_RIGHT_BAR*/); redraw_screen(/*REFRESH_RIGHT_BAR*/);
} else if(pal_sbar->isVisible() && mousePos.in(pal_sbar->getBounds())) {
std::thread updater(std::bind(handleUpdateWhileScrolling, std::ref(doneScrolling)));
pal_sbar->handleClick(mousePos);
doneScrolling = true;
updater.join();
redraw_screen(/*REFRESH_RIGHT_BAR*/);
set_up_terrain_buttons(false);
} }
else // ordinary click else // ordinary click
All_Done = handle_action(loc(event.mouseButton.x,event.mouseButton.y),event); All_Done = handle_action(loc(event.mouseButton.x,event.mouseButton.y),event);