Feature #1950 » 1950.v3.patch
| client/gui-qt/dialogs.cpp | ||
|---|---|---|
|
utile = ptile;
|
||
|
pix = nullptr;
|
||
|
show_line = 0;
|
||
|
highligh_num = -1;
|
||
|
highlight_num = -1;
|
||
|
ufont.setItalic(true);
|
||
|
info_font = *fc_font::instance()->get_font(fonts::notify_label);
|
||
|
update_units();
|
||
|
h_pix = nullptr;
|
||
|
s_pix = nullptr;
|
||
|
create_pixmap();
|
||
|
p = mapFromGlobal(QCursor::pos());
|
||
|
cw = new close_widget(this);
|
||
| ... | ... | |
|
units_select::~units_select()
|
||
|
{
|
||
|
delete h_pix;
|
||
|
delete s_pix;
|
||
|
delete pix;
|
||
|
delete cw;
|
||
|
}
|
||
| ... | ... | |
|
isosize = 0.5;
|
||
|
}
|
||
|
update_units();
|
||
|
if (unit_list.count() > 0) {
|
||
|
if (!tileset_is_isometric(tileset)) {
|
||
|
item_size.setWidth(tileset_unit_width(tileset));
|
||
|
item_size.setHeight(tileset_unit_width(tileset));
|
||
|
} else {
|
||
|
item_size.setWidth(tileset_unit_width(tileset) * isosize);
|
||
|
item_size.setHeight(tileset_unit_width(tileset) * isosize);
|
||
|
}
|
||
|
more = false;
|
||
|
if (h_pix != nullptr) {
|
||
|
delete h_pix;
|
||
|
}
|
||
|
h_pix = new QPixmap(item_size.width(), item_size.height());
|
||
|
h_pix->fill(palette().color(QPalette::HighlightedText));
|
||
|
if (unit_count < 5) {
|
||
|
row_count = 1;
|
||
|
pix = new QPixmap((unit_list.size()) * item_size.width(),
|
||
|
item_size.height());
|
||
|
} else if (unit_count < 9) {
|
||
|
row_count = 2;
|
||
|
pix = new QPixmap(4 * item_size.width(), 2 * item_size.height());
|
||
|
} else {
|
||
|
row_count = 3;
|
||
|
if (unit_count > 12) {
|
||
|
more = true;
|
||
|
}
|
||
|
pix = new QPixmap(4 * item_size.width(), 3 * item_size.height());
|
||
|
}
|
||
|
pix->fill(Qt::transparent);
|
||
|
foreach(punit, unit_list) {
|
||
|
unit_pixmap = qtg_canvas_create(tileset_unit_width(tileset),
|
||
|
tileset_unit_height(tileset));
|
||
|
unit_pixmap->map_pixmap.fill(Qt::transparent);
|
||
|
put_unit(punit, unit_pixmap, 1.0, 0, 0);
|
||
|
img = unit_pixmap->map_pixmap.toImage();
|
||
|
crop = zealous_crop_rect(img);
|
||
|
cropped_img = img.copy(crop);
|
||
|
if (utile != nullptr && unit_list_size(utile->units) > 0) {
|
||
|
if (!tileset_is_isometric(tileset)) {
|
||
|
img = cropped_img.scaled(tileset_unit_width(tileset),
|
||
|
tileset_unit_width(tileset),
|
||
|
Qt::KeepAspectRatio,
|
||
|
Qt::SmoothTransformation);
|
||
|
item_size.setWidth(tileset_unit_width(tileset));
|
||
|
item_size.setHeight(tileset_unit_width(tileset));
|
||
|
} else {
|
||
|
img = cropped_img.scaled(tileset_unit_width(tileset) * isosize,
|
||
|
tileset_unit_width(tileset) * isosize,
|
||
|
Qt::KeepAspectRatio,
|
||
|
Qt::SmoothTransformation);
|
||
|
item_size.setWidth(tileset_unit_width(tileset) * isosize);
|
||
|
item_size.setHeight(tileset_unit_width(tileset) * isosize);
|
||
|
}
|
||
|
pixc = QPixmap::fromImage(img);
|
||
|
pixp = new QPixmap(pixc);
|
||
|
pix_list.push_back(pixp);
|
||
|
qtg_canvas_free(unit_pixmap);
|
||
|
}
|
||
|
a = qMin(item_size.width() / 4, 12);
|
||
|
x = 0, y = -item_size.height(), i = -1;
|
||
|
p.begin(pix);
|
||
|
ufont.setPixelSize(a);
|
||
|
p.setFont(ufont);
|
||
|
pen.setColor(palette().color(QPalette::Text));
|
||
|
p.setPen(pen);
|
||
|
while (!pix_list.isEmpty()) {
|
||
|
more = false;
|
||
|
if (h_pix != nullptr) {
|
||
|
delete h_pix;
|
||
|
}
|
||
|
if (s_pix != nullptr) {
|
||
|
delete s_pix;
|
||
|
}
|
||
|
h_pix = new QPixmap(item_size.width(), item_size.height());
|
||
|
h_pix->fill(palette().color(QPalette::HighlightedText));
|
||
|
s_pix = new QPixmap(item_size.width(), item_size.height());
|
||
|
s_pix->fill(palette().color(QPalette::BrightText));
|
||
|
if (unit_list_size(utile->units) < 5) {
|
||
|
row_count = 1;
|
||
|
pix = new QPixmap(unit_list_size(utile->units) * item_size.width(),
|
||
|
item_size.height());
|
||
|
} else if (unit_list_size(utile->units) < 9) {
|
||
|
row_count = 2;
|
||
|
pix = new QPixmap(4 * item_size.width(), 2 * item_size.height());
|
||
|
} else {
|
||
|
row_count = 3;
|
||
|
if (unit_list_size(utile->units) > 12) {
|
||
|
more = true;
|
||
|
}
|
||
|
pix = new QPixmap(4 * item_size.width(), 3 * item_size.height());
|
||
|
}
|
||
|
pix->fill(Qt::transparent);
|
||
|
unit_list_iterate(utile->units, punit) {
|
||
|
unit_pixmap = qtg_canvas_create(tileset_unit_width(tileset),
|
||
|
tileset_unit_height(tileset));
|
||
|
unit_pixmap->map_pixmap.fill(Qt::transparent);
|
||
|
put_unit(punit, unit_pixmap, 1.0, 0, 0);
|
||
|
img = unit_pixmap->map_pixmap.toImage();
|
||
|
crop = zealous_crop_rect(img);
|
||
|
cropped_img = img.copy(crop);
|
||
|
if (!tileset_is_isometric(tileset)) {
|
||
|
img = cropped_img.scaled(tileset_unit_width(tileset),
|
||
|
tileset_unit_width(tileset),
|
||
|
Qt::KeepAspectRatio,
|
||
|
Qt::SmoothTransformation);
|
||
|
} else {
|
||
|
img = cropped_img.scaled(tileset_unit_width(tileset) * isosize,
|
||
|
tileset_unit_width(tileset) * isosize,
|
||
|
Qt::KeepAspectRatio,
|
||
|
Qt::SmoothTransformation);
|
||
|
}
|
||
|
pixc = QPixmap::fromImage(img);
|
||
|
pixp = new QPixmap(pixc);
|
||
|
pix_list.push_back(pixp);
|
||
|
qtg_canvas_free(unit_pixmap);
|
||
|
} unit_list_iterate_end;
|
||
|
a = qMin(item_size.width() / 4, 12);
|
||
|
x = 0, y = -item_size.height(), i = (show_line * 4) - 1;
|
||
|
p.begin(pix);
|
||
|
ufont.setPixelSize(a);
|
||
|
p.setFont(ufont);
|
||
|
while (!pix_list.isEmpty()
|
||
|
&& (punit = unit_list_get(utile->units, ++i)) != nullptr) {
|
||
|
tmp_pix = pix_list.takeFirst();
|
||
|
i++;
|
||
|
if (i % 4 == 0) {
|
||
|
x = 0;
|
||
|
y = y + item_size.height();
|
||
|
}
|
||
|
punit = unit_list.at(i);
|
||
|
Q_ASSERT(punit != nullptr);
|
||
|
if (i == highligh_num) {
|
||
|
pen.setColor(palette().color(QPalette::Text));
|
||
|
if (i == highlight_num) {
|
||
|
p.drawPixmap(x, y, *h_pix);
|
||
|
p.drawPixmap(x, y, *tmp_pix);
|
||
|
} else {
|
||
|
p.drawPixmap(x, y, *tmp_pix);
|
||
|
}
|
||
|
if (highlights.contains(i)) {
|
||
|
p.drawPixmap(x, y, *s_pix);
|
||
|
pen.setColor(palette().color(QPalette::HighlightedText));
|
||
|
}
|
||
|
p.drawPixmap(x, y, *tmp_pix);
|
||
|
if (client_is_global_observer() || unit_owner(punit) == client.conn.playing) {
|
||
|
int rate, f;
|
||
| ... | ... | |
|
}
|
||
|
// TRANS: MP = Movement points
|
||
|
str = QString(_("MP:")) + str;
|
||
|
p.setPen(pen);
|
||
|
p.drawText(x, y + item_size.height() - 4, str);
|
||
|
}
|
||
| ... | ... | |
|
void units_select::mouseMoveEvent(QMouseEvent *event)
|
||
|
{
|
||
|
int a, b;
|
||
|
int old_h;
|
||
|
int old_hn = highlight_num;
|
||
|
QFontMetrics fm(info_font);
|
||
|
QPoint pos = event->pos();
|
||
|
int x = pos.x();
|
||
|
int y = pos.y();
|
||
|
old_h = highligh_num;
|
||
|
highligh_num = -1;
|
||
|
if (x > width() - 11
|
||
|
if (row_count <= 0
|
||
|
|| x > width() - 11
|
||
|
|| y > height() - fm.height() - 5
|
||
|
|| y < fm.height() + 3 || x < 11) {
|
||
|
// Do nothing if mouse is on border, just skip next if
|
||
|
} else if (row_count > 0) {
|
||
|
highlight_num = -1;
|
||
|
} else {
|
||
|
a = (x - 10) / item_size.width();
|
||
|
b = (y - fm.height() - 3) / item_size.height();
|
||
|
highligh_num = b * 4 + a;
|
||
|
highlight_num = b * 4 + a + show_line * 4;
|
||
|
}
|
||
|
if (highlight_num >= unit_list_size(utile->units)) {
|
||
|
highlight_num = -1;
|
||
|
}
|
||
|
if (old_h != highligh_num) {
|
||
|
if (old_hn != highlight_num) {
|
||
|
create_pixmap();
|
||
|
update();
|
||
|
}
|
||
| ... | ... | |
|
***************************************************************************/
|
||
|
void units_select::mousePressEvent(QMouseEvent *event)
|
||
|
{
|
||
|
struct unit *punit;
|
||
|
if (event->button() == Qt::RightButton) {
|
||
|
if (event->button() == Qt::RightButton
|
||
|
|| (highlights.size() == 0 && highlight_num == -1)) {
|
||
|
was_destroyed = true;
|
||
|
close();
|
||
|
destroy();
|
||
|
}
|
||
|
if (event->button() == Qt::LeftButton && highligh_num != -1) {
|
||
|
update_units();
|
||
|
if (highligh_num >= unit_list.count()) {
|
||
|
return;
|
||
|
} else if (event->button() == Qt::LeftButton) {
|
||
|
fc_assert_ret(highlight_num < unit_list_size(utile->units));
|
||
|
if (event->modifiers() & Qt::ShiftModifier && highlight_num != -1) {
|
||
|
if (highlights.size() == 0) {
|
||
|
highlights.append(highlight_num);
|
||
|
} else if (highlight_num != highlights.back()) {
|
||
|
int start = highlight_num;
|
||
|
int stop = highlights.back();
|
||
|
int delta = (start < stop) ? 1 : -1;
|
||
|
while (start != stop) {
|
||
|
if (!highlights.contains(start)) {
|
||
|
highlights.append(start);
|
||
|
}
|
||
|
start = start + delta;
|
||
|
}
|
||
|
}
|
||
|
create_pixmap();
|
||
|
update();
|
||
|
} else if (event->modifiers() & Qt::ControlModifier
|
||
|
&& highlight_num != -1) {
|
||
|
if (!highlights.contains(highlight_num)) {
|
||
|
highlights.append(highlight_num);
|
||
|
} else {
|
||
|
highlights.removeAll(highlight_num);
|
||
|
}
|
||
|
punit = unit_list.at(highligh_num);
|
||
|
create_pixmap();
|
||
|
update();
|
||
|
} else {
|
||
|
int i;
|
||
|
bool first_add = true;
|
||
|
if (highlight_num != -1 && !highlights.contains(highlight_num)) {
|
||
|
highlights.append(highlight_num);
|
||
|
}
|
||
|
foreach(i, highlights) {
|
||
|
if (i >= 0 && i < unit_list_size(utile->units)) {
|
||
|
struct unit *punit = unit_list_get(utile->units, i);
|
||
|
if (first_add) {
|
||
|
unit_focus_set(punit);
|
||
|
first_add = false;
|
||
|
} else {
|
||
|
unit_focus_add(punit);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
was_destroyed = true;
|
||
|
close();
|
||
|
destroy();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
} else {
|
||
|
f_size = &point_size;
|
||
|
}
|
||
|
if (highligh_num != -1 && highligh_num < unit_list.count()) {
|
||
|
if (highlight_num != -1 && highlight_num < unit_list_size(utile->units)) {
|
||
|
struct astring addition = ASTRING_INIT;
|
||
|
punit = unit_list.at(highligh_num);
|
||
|
punit = unit_list_get(utile->units, highlight_num);
|
||
|
unit_activity_astr(punit, &addition);
|
||
|
// TRANS: HP - hit points
|
||
| ... | ... | |
|
painter->setPen(pen);
|
||
|
painter->setFont(info_font);
|
||
|
painter->drawText(10, h, str);
|
||
|
if (highligh_num != -1 && highligh_num < unit_list.count()) {
|
||
|
if (highlight_num != -1 && highlight_num < unit_list_size(utile->units)) {
|
||
|
painter->drawText(10, height() - 5, str2);
|
||
|
}
|
||
|
// Draw scroll
|
||
|
if (more) {
|
||
|
int maxl = ((unit_count - 1) / 4) + 1;
|
||
|
int maxl = ((unit_list_size(utile->units) - 1) / 4) + 1;
|
||
|
float page_height = 3.0f / maxl;
|
||
|
float page_start = (static_cast<float>(show_line)) / maxl;
|
||
|
pen.setColor(palette().color(QPalette::HighlightedText));
|
||
| ... | ... | |
|
destroy();
|
||
|
}
|
||
|
/***********************************************************************//**
|
||
|
Updates unit list on tile
|
||
|
***************************************************************************/
|
||
|
void units_select::update_units()
|
||
|
{
|
||
|
int i = 1;
|
||
|
struct unit_list *punit_list;
|
||
|
unit_count = 0;
|
||
|
if (utile == nullptr) {
|
||
|
struct unit *punit = head_of_units_in_focus();
|
||
|
if (punit) {
|
||
|
utile = unit_tile(punit);
|
||
|
}
|
||
|
}
|
||
|
unit_list.clear();
|
||
|
if (utile != nullptr) {
|
||
|
punit_list = utile->units;
|
||
|
if (punit_list != nullptr) {
|
||
|
unit_list_iterate(utile->units, punit) {
|
||
|
unit_count++;
|
||
|
if (i > show_line * 4)
|
||
|
unit_list.push_back(punit);
|
||
|
i++;
|
||
|
} unit_list_iterate_end;
|
||
|
}
|
||
|
}
|
||
|
if (unit_list.count() == 0) {
|
||
|
close();
|
||
|
}
|
||
|
}
|
||
|
/***********************************************************************//**
|
||
|
Close event for units_select, restores focus to map
|
||
|
***************************************************************************/
|
||
| ... | ... | |
|
void units_select::wheelEvent(QWheelEvent *event)
|
||
|
{
|
||
|
int nr;
|
||
|
int old_sl = show_line;
|
||
|
if (!more && utile == nullptr) {
|
||
|
return;
|
||
|
}
|
||
|
nr = qCeil(static_cast<qreal>(unit_list_size(utile->units)) / 4) - 3;
|
||
|
if (event->angleDelta().y() < 0) {
|
||
|
show_line++;
|
||
|
show_line = qMin(show_line, nr);
|
||
|
show_line = qMin(show_line + 1, nr);
|
||
|
} else {
|
||
|
show_line--;
|
||
|
show_line = qMax(0, show_line);
|
||
|
show_line = qMax(0, show_line - 1);
|
||
|
}
|
||
|
if (old_sl != show_line && highlight_num > -1) {
|
||
|
highlight_num = qMax(-1, highlight_num + (4 * (show_line - old_sl)));
|
||
|
if (highlight_num >= unit_list_size(utile->units)) {
|
||
|
highlight_num = -1;
|
||
|
}
|
||
|
}
|
||
|
update_units();
|
||
|
create_pixmap();
|
||
|
update();
|
||
|
event->accept();
|
||
| ... | ... | |
|
***************************************************************************/
|
||
|
void units_select::keyPressEvent(QKeyEvent *event)
|
||
|
{
|
||
|
if (event->key() == Qt::Key_Escape) {
|
||
|
switch(event->key()) {
|
||
|
case Qt::Key_Escape:
|
||
|
was_destroyed = true;
|
||
|
close();
|
||
|
destroy();
|
||
|
event->accept();
|
||
|
break;
|
||
|
case Qt::Key_Enter:
|
||
|
case Qt::Key_Return:
|
||
|
{
|
||
|
int i;
|
||
|
bool first_add = true;
|
||
|
foreach(i, highlights) {
|
||
|
if (i >= 0 && i < unit_list_size(utile->units)) {
|
||
|
struct unit *punit = unit_list_get(utile->units, i);
|
||
|
if (first_add) {
|
||
|
unit_focus_set(punit);
|
||
|
first_add = false;
|
||
|
} else {
|
||
|
unit_focus_add(punit);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
was_destroyed = true;
|
||
|
close();
|
||
|
destroy();
|
||
|
event->accept();
|
||
|
break;
|
||
|
case Qt::Key_A:
|
||
|
if (event->modifiers() & Qt::ControlModifier) {
|
||
|
int i = 0;
|
||
|
highlights.clear();
|
||
|
while (i < unit_list_size(utile->units)) {
|
||
|
highlights.append(i);
|
||
|
++i;
|
||
|
}
|
||
|
create_pixmap();
|
||
|
update();
|
||
|
event->accept();
|
||
|
} else {
|
||
|
event->ignore();
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
event->ignore();
|
||
|
break;
|
||
|
}
|
||
|
QWidget::keyPressEvent(event);
|
||
|
}
|
||
|
/***********************************************************************//**
|
||
| client/gui-qt/dialogs.h | ||
|---|---|---|
|
Q_OBJECT
|
||
|
QPixmap *pix;
|
||
|
QPixmap *h_pix; // pixmap for highlighting
|
||
|
QPixmap *s_pix; // pixmap for selected
|
||
|
QSize item_size; // size of each pixmap of unit
|
||
|
QList<unit*> unit_list; /** storing units only for drawing, for rest units
|
||
|
* iterate utile->units */
|
||
|
QFont ufont;
|
||
|
QFont info_font;
|
||
|
int row_count;
|
||
| ... | ... | |
|
units_select(struct tile *ptile, QWidget *parent);
|
||
|
~units_select();
|
||
|
void update_menu();
|
||
|
void update_units();
|
||
|
void create_pixmap();
|
||
|
tile *utile;
|
||
|
protected:
|
||
| ... | ... | |
|
private:
|
||
|
bool more;
|
||
|
int show_line;
|
||
|
int highligh_num;
|
||
|
int unit_count;
|
||
|
int highlight_num;
|
||
|
QList<int> highlights;
|
||
|
};
|
||
|
/**************************************************************************
|
||
| client/gui-qt/fc_client.cpp | ||
|---|---|---|
|
void fc_client::update_unit_sel()
|
||
|
{
|
||
|
if (unit_sel != nullptr) {
|
||
|
unit_sel->update_units();
|
||
|
unit_sel->create_pixmap();
|
||
|
unit_sel->update();
|
||
|
}
|
||
| client/gui-qt/gui_main.cpp | ||
|---|---|---|
|
**************************************************************************/
|
||
|
void qtg_real_focus_units_changed(void)
|
||
|
{
|
||
|
if (gui()->unit_sel != nullptr && gui()->unit_sel->isVisible()) {
|
||
|
gui()->unit_sel->update_units();
|
||
|
}
|
||
|
if (gui()->gtd != nullptr && gui()->gtd->isVisible()) {
|
||
|
gui()->gtd->update_dlg();
|
||
|
}
|
||
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »