widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #04186
[Merge] lp:~widelands-dev/widelands/bug-653308 into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-653308 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #653308 in widelands: "The attack dialog is not updating the number of possible attackers"
https://bugs.launchpad.net/widelands/+bug/653308
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-653308/+merge/265931
The attack box now updates itself when more / less soldiers are available. Sliders now update the cursor at once when the min/max value is changed.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-653308 into lp:widelands.
=== modified file 'src/ui_basic/slider.cc'
--- src/ui_basic/slider.cc 2014-11-27 12:02:08 +0000
+++ src/ui_basic/slider.cc 2015-07-27 07:21:22 +0000
@@ -113,8 +113,10 @@
*/
void Slider::set_max_value(int32_t new_max) {
assert(m_min_value <= new_max);
- if (m_max_value != new_max)
+ if (m_max_value != new_max) {
+ calc_cursor_pos();
update();
+ }
m_max_value = new_max;
set_value(m_value);
}
@@ -126,8 +128,10 @@
*/
void Slider::set_min_value(int32_t new_min) {
assert(m_max_value >= new_min);
- if (m_min_value != new_min)
+ if (m_min_value != new_min) {
+ calc_cursor_pos();
update();
+ }
m_min_value = new_min;
set_value(m_value);
}
=== modified file 'src/wui/attack_box.cc'
--- src/wui/attack_box.cc 2015-03-30 08:45:09 +0000
+++ src/wui/attack_box.cc 2015-07-27 07:21:22 +0000
@@ -30,6 +30,8 @@
#include "graphic/text_constants.h"
#include "logic/soldier.h"
+constexpr int32_t kUpdateTime = 1000; // 1 second, gametime
+
AttackBox::AttackBox
(UI::Panel * parent,
Widelands::Player * player,
@@ -44,7 +46,9 @@
m_node(target),
m_slider_soldiers(nullptr),
m_text_soldiers(nullptr),
- m_add_soldiers(nullptr)
+ m_less_soldiers(nullptr),
+ m_add_soldiers(nullptr),
+ lastupdate_(0)
{
init();
}
@@ -52,6 +56,7 @@
AttackBox::~AttackBox() {
delete m_slider_soldiers;
delete m_text_soldiers;
+ delete m_less_soldiers;
delete m_add_soldiers;
}
@@ -119,6 +124,17 @@
return *button;
}
+/*
+ * Update available soldiers
+ */
+void AttackBox::think() {
+ int32_t const gametime = m_pl->egbase().get_gametime();
+ if ((gametime - lastupdate_) > kUpdateTime) {
+ update_attack();
+ lastupdate_ = gametime;
+ }
+}
+
void AttackBox::update_attack() {
assert(m_slider_soldiers);
assert(m_text_soldiers);
@@ -127,8 +143,9 @@
int32_t max_attackers = get_max_attackers();
- if (m_slider_soldiers->get_max_value() != max_attackers)
+ if (m_slider_soldiers->get_max_value() != max_attackers) {
m_slider_soldiers->set_max_value(max_attackers);
+ }
m_slider_soldiers->set_enabled(max_attackers > 0);
m_add_soldiers->set_enabled(max_attackers > m_slider_soldiers->get_value());
=== modified file 'src/wui/attack_box.h'
--- src/wui/attack_box.h 2015-03-26 18:45:52 +0000
+++ src/wui/attack_box.h 2015-07-27 07:21:22 +0000
@@ -76,6 +76,7 @@
void (AttackBox::*fn)(),
const std::string & tooltip_text);
+ void think() override;
void update_attack();
void send_less_soldiers();
void send_more_soldiers();
@@ -90,6 +91,9 @@
UI::Button * m_less_soldiers;
UI::Button * m_add_soldiers;
+
+ /// The last time the information in this Panel got updated
+ uint32_t lastupdate_;
};
#endif // end of include guard: WL_WUI_ATTACK_BOX_H
Follow ups