Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor intelligence screen #3424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/ivis_opengl/pieblitfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,11 @@ void iV_DrawImageTc(AtlasImage image, AtlasImage imageTc, int x, int y, PIELIGHT
// Repeat a texture
void iV_DrawImageRepeatX(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Width, const glm::mat4 &modelViewProjection, bool enableHorizontalTilingSeamWorkaround, BatchedImageDrawRequests *pBatchedRequests)
{
if (Width <= 0)
{
return;
}

static BatchedImageDrawRequests localBatch;
if (pBatchedRequests == nullptr)
{
Expand Down Expand Up @@ -860,6 +865,11 @@ void iV_DrawImageRepeatX(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Width

void iV_DrawImageRepeatY(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Height, const glm::mat4 &modelViewProjection, BatchedImageDrawRequests* pBatchedRequests)
{
if (Height <= 0)
{
return;
}

static BatchedImageDrawRequests localBatch;
if (pBatchedRequests == nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/sound/openal_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ AUDIO_STREAM *sound_PlayStream(const char* fileName,
if (res < buffer_count)
{
// free unused buffers
debug(LOG_INFO, "freeing unused %i buffers", buffer_count - res);
debug(LOG_SOUND, "freeing unused %i buffers", buffer_count - res);
alDeleteBuffers(buffer_count - res, alBuffersIds + res);
if (sound_GetError() != AL_NO_ERROR) { goto _error_with_albuffers; }
}
Expand Down
70 changes: 70 additions & 0 deletions lib/widget/paneltabbutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
This file is part of Warzone 2100.
Copyright (C) 2023 Warzone 2100 Project

Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "lib/ivis_opengl/pieblitfunc.h"
#include "paneltabbutton.h"

constexpr int QCFORM_PANEL_TABS_PADDING = 20;
constexpr int QCFORM_PANEL_TABS_HEIGHT = 20;
const PIELIGHT WZCOL_PANELTABS_FILL_COLOR = pal_RGBA(25, 0, 110, 220);
const PIELIGHT WZCOL_PANELTABS_FILL_COLOR_DARK = pal_RGBA(10, 0, 70, 250);
const PIELIGHT WZCOL_PANELTABS_BORDER_LIGHT = pal_RGBA(255, 255, 255, 150);

std::shared_ptr<WzPanelTabButton> WzPanelTabButton::make(const WzString& text)
{
auto button = std::make_shared<WzPanelTabButton>();
button->setString(text);
button->FontID = font_regular;
int minButtonWidthForText = iV_GetTextWidth(text, button->FontID);
button->setGeometry(0, 0, minButtonWidthForText + QCFORM_PANEL_TABS_PADDING, QCFORM_PANEL_TABS_HEIGHT);
return button;
}

void WzPanelTabButton::display(int xOffset, int yOffset)
{
int x0 = x() + xOffset;
int y0 = y() + yOffset;
int x1 = x0 + width();
int y1 = y0 + height();

bool haveText = !pText.isEmpty();

bool isDown = (getState() & (WBUT_DOWN | WBUT_LOCK | WBUT_CLICKLOCK)) != 0;
bool isDisabled = (getState() & WBUT_DISABLE) != 0;
bool isHighlight = !isDisabled && ((getState() & WBUT_HIGHLIGHT) != 0);

// Display the button.
auto light_border = WZCOL_PANELTABS_BORDER_LIGHT;
auto fill_color = isDown || isDisabled ? WZCOL_PANELTABS_FILL_COLOR_DARK : WZCOL_PANELTABS_FILL_COLOR;
iV_ShadowBox(x0, y0, x1, y1, 0, isDown || isHighlight ? light_border : WZCOL_FORM_DARK, isDown || isHighlight ? light_border : WZCOL_FORM_DARK, fill_color);

if (haveText)
{
wzText.setText(pText, FontID);
int fw = wzText.width();
int fx = x0 + (width() - fw) / 2;
int fy = y0 + (height() - wzText.lineSize()) / 2 - wzText.aboveBase();
PIELIGHT textColor = (isDown) ? WZCOL_TEXT_BRIGHT : WZCOL_FORM_TEXT;
if (isDisabled)
{
textColor.byte.a = (textColor.byte.a / 2);
}
wzText.render(fx, fy, textColor);
}
}
37 changes: 37 additions & 0 deletions lib/widget/paneltabbutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
This file is part of Warzone 2100.
Copyright (C) 2023 Warzone 2100 Project

Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef __INCLUDED_LIB_WIDGET_PANEL_TAB_BUTTON_H__
#define __INCLUDED_LIB_WIDGET_PANEL_TAB_BUTTON_H__

#include "widget.h"
#include "button.h"
#include "lib/ivis_opengl/textdraw.h"

class WzPanelTabButton : public W_BUTTON
{
public:
static std::shared_ptr<WzPanelTabButton> make(const WzString& text);
public:
void display(int xOffset, int yOffset) override;
private:
WzText wzText;
};

#endif // __INCLUDED_LIB_WIDGET_PANEL_TAB_BUTTON_H__
1 change: 1 addition & 0 deletions lib/widget/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ void ScrollableTableWidget::displayRecursive(WidgetGraphicsContext const& contex
int y0 = y() + yOffset + scrollableList->y();
int y1 = y0 + scrollableList->height();

lines.clear();
lines.reserve(columnWidths.size());

// draw a line between every column widget
Expand Down
20 changes: 17 additions & 3 deletions lib/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,24 @@ void widgRegisterOverlayScreenOnTopOfScreen(const std::shared_ptr<W_SCREEN> &psS
else
{
// priorScreen does not exist in the overlays list, so it is probably the "regular" screen
// just insert this overlay at the bottom of the overlay list
// so use z-order 0
OverlayScreen newOverlay {psScreen, 0};
overlays.insert(overlays.end(), newOverlay);
overlaySet.insert(psScreen);
it = std::find_if(overlays.begin(), overlays.end(), [](const OverlayScreen& overlay) -> bool {
return overlay.zOrder == 0;
});
if (it != overlays.end())
{
// found existing screen with z-order 0
// insert *before* it in the list (i.e. "above" it, since overlays are stored in decreasing z-order)
overlays.insert(it, newOverlay);
overlaySet.insert(psScreen);
}
else
{
// just insert this overlay at the bottom of the overlay list
overlays.insert(overlays.end(), newOverlay);
overlaySet.insert(psScreen);
}
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,8 @@ bool intInitialise()
/* Shut down the in game interface */
void interfaceShutDown()
{
intRemoveIntelMapNoAnim(); // always call to ensure overlay screen is destroyed

if (replayOverlayScreen)
{
widgRemoveOverlayScreen(replayOverlayScreen);
Expand Down Expand Up @@ -1410,11 +1412,6 @@ INT_RETVAL intRunWidgets()
intRunOrder();
}

if (MultiMenuUp)
{
intRunMultiMenu();
}

/* Extra code for the design screen to deal with the shadow bar graphs */
if (intMode == INT_DESIGN)
{
Expand Down Expand Up @@ -1574,13 +1571,13 @@ INT_RETVAL intRunWidgets()
intProcessInGameOptions(retID);
break;
case INT_MULTIMENU:
intProcessMultiMenu(retID);
// no-op here
break;
case INT_DESIGN:
intProcessDesign(retID);
break;
case INT_INTELMAP:
intProcessIntelMap(retID);
// no-op here
break;
case INT_TRANSPORTER:
intProcessTransporter(retID);
Expand Down
54 changes: 1 addition & 53 deletions src/hci/quickchat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "lib/widget/scrollablelist.h"
#include "lib/widget/button.h"
#include "lib/widget/multibutform.h"
#include "lib/widget/paneltabbutton.h"
#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/ivis_opengl/piepalette.h"
#include "lib/netplay/netplay.h"
Expand Down Expand Up @@ -271,7 +272,7 @@
lastWidgetWidth = width();

int textX0 = xPos + QuickChatButtonHorizontalPadding;
int textY0 = yPos + (h - wzMessageText.lineSize()) / 2 - float(wzMessageText.aboveBase());

Check warning on line 275 in src/hci/quickchat.cpp

View workflow job for this annotation

GitHub Actions / Fedora :LATEST [GCC]

conversion from 'float' to 'int' may change value [-Wfloat-conversion]

Check warning on line 275 in src/hci/quickchat.cpp

View workflow job for this annotation

GitHub Actions / Arch :LATEST [GCC]

conversion from ‘float’ to ‘int’ may change value [-Wfloat-conversion]

Check warning on line 275 in src/hci/quickchat.cpp

View workflow job for this annotation

GitHub Actions / Fedora :LATEST [GCC -m32]

conversion from 'float' to 'int' may change value [-Wfloat-conversion]

Check warning on line 275 in src/hci/quickchat.cpp

View workflow job for this annotation

GitHub Actions / Arch :LATEST [Clang]

implicit conversion turns floating-point number into integer: 'float' to 'int' [-Wfloat-conversion]

Check warning on line 275 in src/hci/quickchat.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 20.04 [Clang]

implicit conversion turns floating-point number into integer: 'float' to 'int' [-Wfloat-conversion]

Check warning on line 275 in src/hci/quickchat.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 [Clang]

implicit conversion turns floating-point number into integer: 'float' to 'int' [-Wfloat-conversion]

int maxTextDisplayableWidth = w - (QuickChatButtonHorizontalPadding * 2);
isTruncated = maxTextDisplayableWidth < wzMessageText.width();
Expand Down Expand Up @@ -2006,59 +2007,6 @@
}
}

// MARK: -

constexpr int QCFORM_PANEL_TABS_PADDING = 20;

class WzPanelTabButton : public W_BUTTON
{
public:
static std::shared_ptr<WzPanelTabButton> make(const WzString& text)
{
auto button = std::make_shared<WzPanelTabButton>();
button->setString(text);
button->FontID = font_regular;
int minButtonWidthForText = iV_GetTextWidth(text, button->FontID);
button->setGeometry(0, 0, minButtonWidthForText + QCFORM_PANEL_TABS_PADDING, QCFORM_PANEL_TABS_HEIGHT);
return button;
}
public:
void display(int xOffset, int yOffset) override
{
int x0 = x() + xOffset;
int y0 = y() + yOffset;
int x1 = x0 + width();
int y1 = y0 + height();

bool haveText = !pText.isEmpty();

bool isDown = (getState() & (WBUT_DOWN | WBUT_LOCK | WBUT_CLICKLOCK)) != 0;
bool isDisabled = (getState() & WBUT_DISABLE) != 0;
bool isHighlight = !isDisabled && ((getState() & WBUT_HIGHLIGHT) != 0);

// Display the button.
auto light_border = WZCOL_QUICKCHAT_TABS_BORDER_LIGHT;
auto fill_color = isDown || isDisabled ? WZCOL_QUICKCHAT_TABS_FILL_COLOR_DARK : WZCOL_QUICKCHAT_TABS_FILL_COLOR;
iV_ShadowBox(x0, y0, x1, y1, 0, isDown || isHighlight ? light_border : WZCOL_FORM_DARK, isDown || isHighlight ? light_border : WZCOL_FORM_DARK, fill_color);

if (haveText)
{
wzText.setText(pText, FontID);
int fw = wzText.width();
int fx = x0 + (width() - fw) / 2;
int fy = y0 + (height() - wzText.lineSize()) / 2 - wzText.aboveBase();
PIELIGHT textColor = (isDown) ? WZCOL_TEXT_BRIGHT : WZCOL_FORM_TEXT;
if (isDisabled)
{
textColor.byte.a = (textColor.byte.a / 2);
}
wzText.render(fx, fy, textColor);
}
}
private:
WzText wzText;
};

// MARK: - WzQuickChatForm

void WzQuickChatForm::released(W_CONTEXT *context, WIDGET_KEY mouseButton)
Expand Down
31 changes: 27 additions & 4 deletions src/hci/teamstrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class TeamStrategyView: public W_FORM
void setUpdatingPlayers(bool enabled);
bool getUpdatingPlayer() { return updatingPlayers; }
std::shared_ptr<WzTeamStrategyColumnImagesManager> getSharedColumnImagesManager() const { return columnImagesManager; }
void setBackgroundColor(PIELIGHT color);

public:
virtual void display(int xOffset, int yOffset) override;
Expand All @@ -338,6 +339,7 @@ class TeamStrategyView: public W_FORM
std::shared_ptr<W_LABEL> noTeammatesLabel;
size_t playerNameColIdx = 0;
bool updatingPlayers = false;
PIELIGHT backgroundColor = pal_RGBA(0,0,0,0);
};

WzTeamStrategyColumnImagesManager::~WzTeamStrategyColumnImagesManager()
Expand Down Expand Up @@ -800,7 +802,12 @@ TeamStrategyView::~TeamStrategyView()

void TeamStrategyView::display(int xOffset, int yOffset)
{
// currently, do nothing
int x0 = x() + xOffset;
int y0 = y() + yOffset;
if (backgroundColor.rgba != 0)
{
pie_UniTransBoxFill(x0, y0, x0 + width(), y0 + height(), backgroundColor);
}
}

void TeamStrategyView::geometryChanged()
Expand Down Expand Up @@ -1079,6 +1086,11 @@ void TeamStrategyView::setUpdatingPlayers(bool enabled)
}
}

void TeamStrategyView::setBackgroundColor(PIELIGHT color)
{
backgroundColor = color;
}

std::pair<std::vector<size_t>, size_t> TeamStrategyView::getMaxTableColumnDataWidths()
{
size_t totalNeededColumnWidth = 0;
Expand Down Expand Up @@ -1118,8 +1130,7 @@ int32_t TeamStrategyView::idealHeight()
// Returns true if there are *any* teams with more than one human player
bool gameHasTeamStrategyView(bool allowAIs)
{
std::unordered_set<int32_t> teamsWitHumanPlayers;
std::vector<uint32_t> playersOnSameTeamAsSelectedPlayer;
std::unordered_set<int32_t> teamsWithIncludedPlayers;
for (int32_t player = 0; player < std::min<int32_t>(game.maxPlayers, MAX_PLAYERS); ++player)
{
// Check type of player
Expand All @@ -1129,7 +1140,7 @@ bool gameHasTeamStrategyView(bool allowAIs)
)
{
auto teamNumber = checkedGetPlayerTeam(player);
auto result = teamsWitHumanPlayers.insert(teamNumber);
auto result = teamsWithIncludedPlayers.insert(teamNumber);
if (!result.second)
{
// more than one included player on a team
Expand Down Expand Up @@ -1157,6 +1168,18 @@ bool transformTeamStrategyViewMode(const std::shared_ptr<WIDGET>& view, bool upd
return true;
}

bool teamStrategyViewSetBackgroundColor(const std::shared_ptr<WIDGET>& view, PIELIGHT color)
{
auto pTeamStrategyView = std::dynamic_pointer_cast<TeamStrategyView>(view);
if (!pTeamStrategyView)
{
return false;
}

pTeamStrategyView->setBackgroundColor(color);
return true;
}

void aiInformTeamOfStrategy(uint32_t aiPlayerIdx, const std::unordered_map<WEAPON_SUBCLASS, WzStrategyPlanningState>& weaponStrategy, const std::unordered_map<WzStrategyPlanningUnitTypes, WzStrategyPlanningState>& unitTypesStrategy)
{
ASSERT_OR_RETURN(, aiPlayerIdx < MAX_PLAYERS, "Invalid aiPlayerIdx: %" PRIu32, aiPlayerIdx);
Expand Down
1 change: 1 addition & 0 deletions src/hci/teamstrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ constexpr size_t WzStrategyPlanningUnitTypes_NUM_TYPES = 3;
bool gameHasTeamStrategyView(bool allowAIs = false);
std::shared_ptr<WIDGET> createTeamStrategyView(bool allowAIs = false);
bool transformTeamStrategyViewMode(const std::shared_ptr<WIDGET>& teamStrategyView, bool updatingPlayers);
bool teamStrategyViewSetBackgroundColor(const std::shared_ptr<WIDGET>& view, PIELIGHT color);

bool recvStrategyPlanUpdate(NETQUEUE queue);

Expand Down
11 changes: 9 additions & 2 deletions src/intdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,11 @@ IntFormAnimated::IntFormAnimated(bool openAnimate)
disableChildren = openAnimate;
}

void IntFormAnimated::closeAnimateDelete()
void IntFormAnimated::closeAnimateDelete(const W_ANIMATED_ON_CLOSE_FUNC& _onCloseAnimFinished)
{
currentAction = 3;
disableChildren = true;
onCloseAnimFinished = _onCloseAnimFinished;
}

bool IntFormAnimated::isClosing() const
Expand Down Expand Up @@ -727,7 +728,13 @@ void IntFormAnimated::display(int xOffset, int yOffset)
switch (currentAction)
{
case 2: disableChildren = false; break;
case 5: deleteLater(); break;
case 5:
deleteLater();
if (onCloseAnimFinished)
{
onCloseAnimFinished(*this);
}
break;
}
}

Expand Down
Loading
Loading