Author: mir3x
Date: Sun Nov 20 23:20:18 2016
New Revision: 34591

URL: http://svn.gna.org/viewcvs/freeciv?rev=34591&view=rev
Log:
Qt client - show new turn information on map

See patch #8004


Modified:
    branches/S2_6/client/gui-qt/fc_client.cpp
    branches/S2_6/client/gui-qt/fc_client.h
    branches/S2_6/client/gui-qt/hudwidget.cpp
    branches/S2_6/client/gui-qt/hudwidget.h
    branches/S2_6/client/gui-qt/menu.cpp
    branches/S2_6/client/gui-qt/menu.h

Modified: branches/S2_6/client/gui-qt/fc_client.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/fc_client.cpp?rev=34591&r1=34590&r2=34591&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/fc_client.cpp   (original)
+++ branches/S2_6/client/gui-qt/fc_client.cpp   Sun Nov 20 23:20:18 2016
@@ -356,6 +356,7 @@
     overview_size_changed();
     update_sidebar_tooltips();
     real_science_report_dialog_update();
+    show_new_turn_info();
     break;
   case PAGE_SCENARIO:
     update_scenarios_page();
@@ -640,6 +641,11 @@
   if (s.contains("splitter3")) {
     qt_settings.city_splitter3 = s.value("splitter3").toByteArray();
   }
+  if (s.contains("new_turn_text")) {
+    qt_settings.show_new_turn_text = s.value("new_turn_text").toBool();
+  } else {
+    qt_settings.show_new_turn_text = true;
+  }
   qt_settings.player_repo_sort_col = -1;
   qt_settings.city_repo_sort_col = -1;
 
@@ -670,6 +676,7 @@
   s.setValue("minimap_y", qt_settings.minimap_y);
   s.setValue("minimap_width", qt_settings.minimap_width);
   s.setValue("minimap_height", qt_settings.minimap_height);
+  s.setValue("new_turn_text", qt_settings.show_new_turn_text);
   write_shortcuts();
 }
 

Modified: branches/S2_6/client/gui-qt/fc_client.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/fc_client.h?rev=34591&r1=34590&r2=34591&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/fc_client.h     (original)
+++ branches/S2_6/client/gui-qt/fc_client.h     Sun Nov 20 23:20:18 2016
@@ -127,6 +127,7 @@
   int chat_x_pos;
   int chat_y_pos;
   int player_repo_sort_col;
+  bool show_new_turn_text;
   Qt::SortOrder player_report_sort;
   int city_repo_sort_col;
   Qt::SortOrder city_report_sort;

Modified: branches/S2_6/client/gui-qt/hudwidget.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/hudwidget.cpp?rev=34591&r1=34590&r2=34591&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/hudwidget.cpp   (original)
+++ branches/S2_6/client/gui-qt/hudwidget.cpp   Sun Nov 20 23:20:18 2016
@@ -32,6 +32,7 @@
 
 // common
 #include "movement.h"
+#include "research.h"
 #include "unitlist.h"
 #include "tile.h"
 #include "unit.h"
@@ -45,6 +46,9 @@
 #include "qtg_cxxside.h"
 #include "sprite.h"
 
+extern "C" {
+  const char *calendar_text(void);
+}
 static QString popup_terrain_info(struct tile *ptile);
 
 /***************************************************************************
@@ -218,6 +222,115 @@
   }
   p.end();
   event->accept();
+}
+
+/****************************************************************************
+  Hud text constructor takes text to display and time
+****************************************************************************/
+hud_text::hud_text(QString s, int time_secs,
+                   QWidget *parent) : QWidget(parent)
+{
+  int size;
+
+  text = s;
+  timeout = time_secs;
+
+  setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog
+                | Qt::FramelessWindowHint);
+  f_text = *fc_font::instance()->get_font(fonts::default_font);
+  f_text.setBold(true);
+  f_text.setCapitalization(QFont::SmallCaps);
+  size = f_text.pointSize();
+  if (size > 0) {
+    f_text.setPointSize(size * 2);
+  } else {
+    size = f_text.pixelSize();
+    f_text.setPixelSize(size * 2);
+  }
+  fm_text = new QFontMetrics(f_text);
+  m_animate_step = 0;
+  m_timer.start();
+  startTimer(46);
+  setAttribute(Qt::WA_TranslucentBackground);
+  setAttribute(Qt::WA_ShowWithoutActivating);
+  setFocusPolicy(Qt::NoFocus);
+}
+
+/****************************************************************************
+  Shows hud text
+****************************************************************************/
+void hud_text::show_me()
+{
+  show();
+  center_me();
+}
+
+/****************************************************************************
+  Moves to top center parent widget and sets size new size
+****************************************************************************/
+void hud_text::center_me()
+{
+  int w;
+  QPoint p;
+  w = width();
+  if (bound_rect.isEmpty() == false) {
+    setFixedSize(bound_rect.width(), bound_rect.height());
+  }
+  p = QPoint((parentWidget()->width() - w) / 2,
+             parentWidget()->height() / 10);
+  p = parentWidget()->mapToGlobal(p);
+  move(p);
+}
+
+/****************************************************************************
+  Destructor for hud text
+****************************************************************************/
+hud_text::~hud_text()
+{
+  delete fm_text;
+}
+
+/****************************************************************************
+  Timer event, closes widget after timeout
+****************************************************************************/
+void hud_text::timerEvent(QTimerEvent *event)
+{
+  m_animate_step = m_timer.elapsed() / 40;
+  if (m_timer.elapsed() > timeout * 1000) {
+    close();
+    deleteLater();
+  }
+  update();
+}
+
+/****************************************************************************
+  Paint event for custom hud_text
+****************************************************************************/
+void hud_text::paintEvent(QPaintEvent *event)
+{
+  QPainter p;
+  QRect rfull;
+  QColor c1;
+  QColor c2;
+  float opacity;
+
+  center_me();
+  if (m_timer.elapsed() < timeout * 500) {
+    opacity = static_cast<float>(m_timer.elapsed())/(timeout * 300);
+  } else {
+    opacity = static_cast<float>(5000 - m_timer.elapsed())/(timeout * 200);
+  }
+  opacity = qMin(1.0f, opacity);
+  opacity = qMax(0.0f, opacity);
+  rfull = QRect(0 , 0, width(), height());
+  c1 = QColor(Qt::white);
+  c1.setAlphaF(c1.alphaF() * opacity);
+  p.begin(this);
+  p.setFont(f_text);
+  p.setPen(c1);
+  p.drawText(rfull, Qt::AlignCenter, text, &bound_rect);
+
+  p.end();
 }
 
 /****************************************************************************
@@ -1404,3 +1517,45 @@
   ret = ret + QString(_("Defence bonus: %1%")).arg(terr->defense_bonus);
   return ret;
 }
+
+/****************************************************************************
+  Shows new turn information with big font
+****************************************************************************/
+void show_new_turn_info()
+{
+  QString s;
+  hud_text *ht;
+  QList<hud_text *> close_list;
+  struct research *research;
+  int i;
+
+  if (client_has_player() == false
+      || gui()->qt_settings.show_new_turn_text == false) {
+    return;
+  }
+  close_list = gui()->mapview_wdg->findChildren<hud_text *>();
+  for (i = 0; i < close_list.size(); ++i) {
+    close_list.at(i)->close();
+    close_list.at(i)->deleteLater();
+  }
+  research = research_get(client_player());
+  s = QString(_("Year: %1 (Turn: %2)"))
+      .arg(calendar_text()).arg(game.info.turn) + "\n";
+  s = s + QString(nation_plural_for_player(client_player()));
+  s = s + " - " + QString(_("Population: %1"))
+      .arg(population_to_text(civ_population(client.conn.playing)));
+  if (research->researching != A_UNKNOWN
+      && research->researching != A_UNSET
+      && research->researching != A_NONE) {
+    s = s + "\n" + QString(research_advance_name_translation(research,
+                           research->researching)) +
+        " (" + QString::number(research->bulbs_researched) + "/"
+        + QString::number(research->client.researching_cost) + ")";
+  }
+  s = s + "\n" + science_dialog_text() + "\n";
+  s = s + QString(_("Gold: %1 (+%2)"))
+      .arg(client.conn.playing->economic.gold)
+      .arg(player_get_expected_income(client.conn.playing));
+  ht = new hud_text(s, 5, gui()->mapview_wdg);
+  ht->show_me();
+}

Modified: branches/S2_6/client/gui-qt/hudwidget.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/hudwidget.h?rev=34591&r1=34590&r2=34591&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/hudwidget.h     (original)
+++ branches/S2_6/client/gui-qt/hudwidget.h     Sun Nov 20 23:20:18 2016
@@ -38,7 +38,9 @@
 struct tile;
 struct unit;
 
+void show_new_turn_info();
 bool has_player_unit_type(Unit_type_id utype);
+
 /****************************************************************************
   Custom message box with animated background
 ****************************************************************************/
@@ -70,6 +72,31 @@
 };
 
 /****************************************************************************
+  Class for showing text on screen
+****************************************************************************/
+class hud_text: public QWidget
+{
+  Q_OBJECT
+public:
+  hud_text(QString s, int time_secs, QWidget *parent);
+  ~hud_text();
+  void show_me();
+protected:
+  void paintEvent(QPaintEvent *event);
+  void timerEvent(QTimerEvent *event);
+private:
+  void center_me();
+  QRect bound_rect;
+  int timeout;
+  int m_animate_step;
+  QString text;
+  QElapsedTimer m_timer;
+  QFontMetrics *fm_text;
+  QFont f_text;
+  QFont f_title;
+};
+
+/****************************************************************************
   Custom input box with animated background
 ****************************************************************************/
 class hud_input_box: public QDialog

Modified: branches/S2_6/client/gui-qt/menu.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/menu.cpp?rev=34591&r1=34590&r2=34591&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/menu.cpp        (original)
+++ branches/S2_6/client/gui-qt/menu.cpp        Sun Nov 20 23:20:18 2016
@@ -73,6 +73,7 @@
 {
   gui()->rallies.run();
   real_menus_update();
+  show_new_turn_info();
   last_center_enemy = 0;
   last_center_capital = 0;
   last_center_player_city = 0;
@@ -853,6 +854,11 @@
   minimap_status->setChecked(true);
   connect(minimap_status, SIGNAL(triggered()), this,
           SLOT(slot_minimap_view()));
+  osd_status = menu->addAction(_("Show new turn information"));
+  osd_status->setCheckable(true);
+  osd_status->setChecked(gui()->qt_settings.show_new_turn_text);
+  connect(osd_status, SIGNAL(triggered()), this,
+          SLOT(slot_show_new_turn_text()));
   lock_status = menu->addAction(_("Lock interface"));
   lock_status->setCheckable(true);
   lock_status->setShortcut(QKeySequence(shortcut_to_string(
@@ -2620,6 +2626,18 @@
 }
 
 /****************************************************************
+  Action "Show/Dont show new turn info"
+*****************************************************************/
+void mr_menu::slot_show_new_turn_text()
+{
+  if (osd_status->isChecked()) {
+    gui()->qt_settings.show_new_turn_text = true;
+  } else {
+    gui()->qt_settings.show_new_turn_text = false;
+  }
+}
+
+/****************************************************************
   Action "SHOW BORDERS"
 *****************************************************************/
 void mr_menu::slot_borders()

Modified: branches/S2_6/client/gui-qt/menu.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/menu.h?rev=34591&r1=34590&r2=34591&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/menu.h  (original)
+++ branches/S2_6/client/gui-qt/menu.h  Sun Nov 20 23:20:18 2016
@@ -266,6 +266,7 @@
   QString shortcut_2_menustring(int sid);
   QAction *minimap_status;
   QAction *lock_status;
+  QAction *osd_status;
   QAction *chat_status;
   QAction *messages_status;
   bool delayed_order;
@@ -327,6 +328,7 @@
   /*used by view menu*/
   void slot_center_view();
   void slot_minimap_view();
+  void slot_show_new_turn_text();
   void slot_fullscreen();
   void slot_lock();
   void slot_city_outlines();


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to