Skip to content

Commit

Permalink
Add resizing code for kart selection
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJellyfish committed May 4, 2024
1 parent 0266b03 commit 3a0a2ea
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/guiengine/widgets/player_kart_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,19 @@ void PlayerKartWidget::onUpdate(float delta)
if (m_h < target_h) m_h = target_h;
}

updateSize();
// When coming from the overworld, we must rebuild the preview scene at
// least once, since the scene is being cleared by leaving the overworld
if (m_not_updated_yet)
{
m_model_view->clearRttProvider();
m_not_updated_yet = false;
}
} // onUpdate

// -------------------------------------------------------------------------
void PlayerKartWidget::updateSize()
{
setSize(m_x, m_y, m_w, m_h);

if (m_player_ident_spinner != NULL)
Expand Down Expand Up @@ -580,15 +593,7 @@ void PlayerKartWidget::onUpdate(float delta)
kart_name_y,
kart_name_w,
kart_name_h);

// When coming from the overworld, we must rebuild the preview scene at
// least once, since the scene is being cleared by leaving the overworld
if (m_not_updated_yet)
{
m_model_view->clearRttProvider();
m_not_updated_yet = false;
}
} // onUpdate
} // updateSize

// -------------------------------------------------------------------------
/** Event callback */
Expand Down
11 changes: 11 additions & 0 deletions src/guiengine/widgets/player_kart_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ namespace GUIEngine
long m_magic_number;
#endif

// -------------------------------------------------------------------------
void updateSize();
public:

LEAK_CHECK()
Expand Down Expand Up @@ -166,6 +168,15 @@ namespace GUIEngine
virtual GUIEngine::EventPropagation onSpinnerConfirmed();
// -------------------------------------------------------------------------
void enableHandicapForNetwork();
// -------------------------------------------------------------------------
void updateSizeNow(int x, int y, int w, int h)
{
target_x = m_x = x;
target_y = m_y = y;
target_w = m_w = w;
target_h = m_h = h;
updateSize();
}
}; // PlayerKartWidget
}

Expand Down
31 changes: 31 additions & 0 deletions src/states_screens/kart_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,3 +1639,34 @@ bool KartSelectionScreen::useContinueButton() const
#pragma mark -
#endif

// ----------------------------------------------------------------------------
void KartSelectionScreen::onResize()
{
// Remove dispatcher from m_widgets before calculateLayout otherwise a
// dummy button is shown in kart screen
bool removed_dispatcher = false;
if (m_widgets.contains(m_dispatcher))
{
m_widgets.remove(m_dispatcher);
removed_dispatcher = true;
}
Screen::onResize();
if (removed_dispatcher)
m_widgets.push_back(m_dispatcher);
if (m_multiplayer)
{
if (m_kart_widgets.size() < 2)
addMultiplayerMessage();
if (m_kart_widgets.empty())
return;
}
Widget* fullarea = getWidget("playerskarts");
int split_width = fullarea->m_w / m_kart_widgets.size();
if (m_multiplayer && m_kart_widgets.size() == 1)
split_width /= 2;
for (unsigned i = 0; i < m_kart_widgets.size(); i++)
{
m_kart_widgets[i].updateSizeNow(fullarea->m_x + split_width * i,
fullarea->m_y, split_width, fullarea->m_h);
}
} // onResize
2 changes: 2 additions & 0 deletions src/states_screens/kart_selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class KartSelectionScreen : public GUIEngine::Screen
* class GUIEngine::Screen */
virtual bool onEscapePressed() OVERRIDE;

virtual void onResize() OVERRIDE;

}; // KartSelectionScreen

//!----------------------------------------------------------------------------
Expand Down

0 comments on commit 3a0a2ea

Please sign in to comment.