Redo scenario button-list management to use std::string and enums, making it more robust in case of layout changes

- Also fix LEDs defaulting to a wrapped label
This commit is contained in:
2015-02-01 02:44:09 -05:00
parent 4efcb08932
commit a41468eea8
5 changed files with 225 additions and 224 deletions

View File

@@ -3,6 +3,8 @@
#include <cstdio>
#include "scen.global.h"
#include <array>
#include <string>
#include "graphtool.hpp"
#include "scen.graphics.h"
#include <cmath>
@@ -16,69 +18,47 @@ extern rectangle right_buttons[NRSONPAGE];
rectangle right_scrollbar_rect;
rectangle right_area_rect;
extern short current_rs_top;
char strings_ls[NLS][40];
char strings_rs[NRS][40];
bool left_buttons_active = 1,right_buttons_active = 0;
extern short left_button_status[NLS]; // 0 - clear, 1 - text, 2 - title text, 3 - tabbed text, +10 - button
extern short right_button_status[NRS];
extern std::array<lb_t,NLS> left_button_status;
extern std::array<rb_t,NRS> right_button_status;
extern std::shared_ptr<cScrollbar> right_sbar;
// Button status:
// 0 - clear
// 1000 + x - terrain type x
// 2000 + x - monster type x
// 3000 + x - item type x
// 4000 + x - global special node
// 5000 + x - out special node
// 6000 + x - town special node
// 7000 + x - global string x
// 8000 + x - out string x
// 9000 + x - town string x
// 10000 + x - scen. special item x
// 11000 + x - journal entry x
// 12000 + x - dialogue node x
// 13000 + x - basic dialogue node x
// 14000 + x - outdoor sign x
// 15000 + x - town sign x
// 16000 + x - quest x
// for following, lb stands for left button(s)
void init_lb() {
short i;
for(i = 0; i < NLS; i++) {
left_button_status[i] = 0;
strcpy((char *) strings_ls[i], "");
left_button_status[i] = {LB_CLEAR, LB_NO_ACTION, ""};
}
}
void reset_lb() {
short i;
for(i = 0; i < NLS; i++) {
left_button_status[i] = 0;
left_button_status[i] = {LB_CLEAR, LB_NO_ACTION, ""};
draw_lb_slot(i,0);
}
}
// is slot >= 0, force that slot
// if -1, use 1st free slot
void set_lb(short slot, short mode, const char *label, short do_draw) {
void set_lb(short slot, eLBMode mode, eLBAction action, std::string label, bool do_draw) {
short i;
if(slot < 0) {
for(i = 0; i < NLS; i++)
if(left_button_status[i] == 0) {
if(left_button_status[i].mode == LB_CLEAR) {
slot = i;
i = NLS + 5000;
}
if(i < NLS + 5000)
return;
}
left_button_status[slot] = mode;
sprintf((char *)strings_ls[slot], "%-50.50s", label);
strings_ls[slot][39] = 0;
if(do_draw > 0)
left_button_status[slot].mode = mode;
left_button_status[slot].action = action;
left_button_status[slot].label = label;
if(do_draw)
draw_lb_slot(slot,0);
}
@@ -90,8 +70,7 @@ void init_rb() {
right_sbar->setPosition(0);
for(i = 0; i < NRS; i++) {
right_button_status[i] = 0;
strcpy((char *) strings_rs[i], "");
right_button_status[i] = {RB_CLEAR, 0, ""};
}
}
@@ -99,7 +78,7 @@ void reset_rb() {
short i;
for(i = 0; i < NRS; i++) {
right_button_status[i] = 0;
right_button_status[i] = {RB_CLEAR, 0, ""};
}
draw_rb();
right_sbar->setMaximum(0);
@@ -108,36 +87,26 @@ void reset_rb() {
// is slot >= 0, force that slot
// if -1, use 1st free slot
void set_rb(short slot, short mode, const char *label, short do_draw) {
void set_rb(short slot, eRBAction action, int n, std::string label, bool do_draw) {
short i;
if(slot < 0) {
for(i = 0; i < NRS; i++)
if(right_button_status[i] == 0) {
if(right_button_status[i].action == RB_CLEAR) {
slot = i;
i = NRS + 5000;
}
if(i < NRS + 5000)
return;
}
right_button_status[slot] = mode;
sprintf((char *)strings_rs[slot], "%s", label);
strings_rs[slot][39] = 0;
for(i = 0; i < 39; i++)
if(strings_rs[slot][i] == '|')
strings_rs[slot][i] = ' ';
if(do_draw > 0)
draw_rb_slot(slot,0);
/*for(i = 0; i < NRS; i++)
if(right_button_status[i] != 0)
highest_used = i;
if(highest_used < NRSONPAGE - 1) {
SetControlMaximum(right_sbar,0);
current_rs_top = 0;
right_button_status[slot].action = action;
right_button_status[slot].i = n;
right_button_status[slot].label = label;
for(char& c : right_button_status[slot].label) {
if(c == '|')
c = ' ';
}
else {
SetControlMaximum(right_sbar,highest_used - NRSONPAGE - 1);
//SetControlValue(right_sbar,new_setting);
}*/
if(do_draw)
draw_rb_slot(slot,0);
}