Merge lp:~nomeata/widelands/plot-improvements into lp:widelands

Proposed by Joachim Breitner
Status: Superseded
Proposed branch: lp:~nomeata/widelands/plot-improvements
Merge into: lp:widelands
Diff against target: 138 lines (+29/-19)
2 files modified
src/wui/plot_area.cc (+21/-12)
src/wui/plot_area.h (+8/-7)
To merge this branch: bzr merge lp:~nomeata/widelands/plot-improvements
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+81392@code.launchpad.net

This proposal has been superseded by a proposal from 2011-11-06.

Description of the change

This should be the fix for #886709. Good morning by the way.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/wui/plot_area.cc'
2--- src/wui/plot_area.cc 2011-11-05 18:24:22 +0000
3+++ src/wui/plot_area.cc 2011-11-06 10:40:34 +0000
4@@ -58,7 +58,8 @@
5 :
6 UI::Panel (parent, x, y, w, h),
7 m_time (TIME_GAME),
8-m_plotmode(PLOTMODE_ABSOLUTE)
9+m_plotmode(PLOTMODE_ABSOLUTE),
10+m_game_time_id(0)
11 {}
12
13
14@@ -115,6 +116,7 @@
15 case UNIT_HOUR: return _("h");
16 case UNIT_MIN: return _("min");
17 }
18+ return "invalid";
19 }
20
21 uint32_t WUIPlot_Area::ms_to_unit(UNIT unit, uint32_t ms) {
22@@ -123,26 +125,31 @@
23 case UNIT_HOUR: return ms / hours;
24 case UNIT_MIN: return ms / minutes;
25 }
26+ return -1;
27 }
28
29 std::vector<std::string> WUIPlot_Area::get_labels() {
30 std::vector<std::string> labels;
31+ for (int32_t i = 0; i < m_game_time_id; i++) {
32+ UNIT unit = get_suggested_unit(time_in_ms[i]);
33+ uint32_t val = ms_to_unit(unit, time_in_ms[i]);
34+ labels.push_back(boost::lexical_cast<std::string>(val) + get_unit_name(unit));
35+ }
36+ labels.push_back(_("game"));
37+ return labels;
38+}
39+
40+/**
41+ * Find the last predefined time span that is less than the game time
42+ */
43+void WUIPlot_Area::calc_game_time_id() {
44 uint32_t game_time = get_game_time();
45 uint32_t i = 0;
46-
47- for (i = 0; i < 7; i++) {
48- if (time_in_ms[i] < game_time) {
49- UNIT unit = get_suggested_unit(time_in_ms[i]);
50- uint32_t val = ms_to_unit(unit, time_in_ms[i]);
51- labels.push_back(boost::lexical_cast<std::string>(val) + get_unit_name(unit));
52- }
53+ for (i = 0; i < 7 && time_in_ms[i] <= game_time; i++) {
54 }
55- labels.push_back(_("game"));
56- m_game_label = i;
57- return labels;
58+ m_game_time_id = i;
59 }
60
61-
62 /*
63 * Draw this. This is the main function
64 */
65@@ -379,6 +386,8 @@
66 m_plotdata[id].dataset = data;
67 m_plotdata[id].showplot = false;
68 m_plotdata[id].plotcolor = color;
69+
70+ calc_game_time_id();
71 }
72
73 /*
74
75=== modified file 'src/wui/plot_area.h'
76--- src/wui/plot_area.h 2011-11-05 21:32:08 +0000
77+++ src/wui/plot_area.h 2011-11-06 10:40:34 +0000
78@@ -42,7 +42,6 @@
79 TIME_EIGHT_HOURS,
80 TIME_16_HOURS,
81 TIME_GAME,
82- TIME_LAST,
83 };
84 enum UNIT {
85 UNIT_MIN,
86@@ -66,13 +65,14 @@
87 m_time = id;
88 }
89
90- void set_time_int(int32_t time) {
91- if (time == m_game_label)
92+ void set_time_id(int32_t time) {
93+ if (time == m_game_time_id)
94 set_time(TIME_GAME);
95 else
96 set_time(static_cast<TIME>(time));
97 };
98 TIME get_time() {return static_cast<TIME>(m_time); };
99+ int32_t get_game_time_id() {return m_game_time_id; };
100 void set_sample_rate(uint32_t id); // in milliseconds
101
102 void register_plot_data
103@@ -86,6 +86,7 @@
104 private:
105 uint32_t get_game_time();
106 uint32_t get_plot_time();
107+ void calc_game_time_id();
108 UNIT get_suggested_unit(uint32_t game_time);
109 std::string get_unit_name(UNIT unit);
110 uint32_t ms_to_unit(UNIT unit, uint32_t ms);
111@@ -96,10 +97,10 @@
112 RGBColor plotcolor;
113 };
114 std::vector<__plotdata> m_plotdata;
115- int32_t m_time; // How much do you want to list
116+ TIME m_time; // How much do you want to list
117 int32_t m_sample_rate;
118 int32_t m_plotmode;
119- int32_t m_game_label; // what label is used for TIME_GAME
120+ int32_t m_game_time_id; // what label is used for TIME_GAME
121 };
122
123 /**
124@@ -119,13 +120,13 @@
125 (parent,
126 x, y, w, h,
127 plot_area.get_labels(),
128- plot_area.get_time(),
129+ plot_area.get_game_time_id(),
130 background_picture_id,
131 tooltip_text,
132 cursor_size,
133 enabled)
134 {
135- changedto->set(&plot_area, &WUIPlot_Area::set_time_int);
136+ changedto->set(&plot_area, &WUIPlot_Area::set_time_id);
137 }
138 };
139

Subscribers

People subscribed via source and target branches

to status/vote changes: