Commit a3075010 authored by Gerhard Stein's avatar Gerhard Stein Committed by Gerhard Stein

Preparing some code for settings to carry out from the launcher.

parent 3a8ba181
......@@ -14,8 +14,9 @@ public:
/**
* @brief isInside Is given coordinate inside the button?
*/
bool isInside(const int _x, const int _y) const
*/
template<class T>
bool isInside(const T _x, const T _y) const
{
return
x <= _x && _x < x + w &&
......@@ -69,9 +70,7 @@ public:
/**
* @brief GsVirtualInput basic constructor, just setup some variables.
*/
GsVirtualInput() :
mEnabled(true),
mTranslucency(0.5f) {}
GsVirtualInput() {}
virtual ~GsVirtualInput() {}
......@@ -117,11 +116,11 @@ public:
protected:
bool mEnabled;
bool mEnabled = true;
GsSurface mOverlay;
float mTranslucency;
float mTranslucency = 0.5f;
};
......
......@@ -263,14 +263,21 @@ Uint32 GsFont::getFGColor()
// the given color
std::array<SDL_Color, 16> color;
auto fontSfc = mpFontSurface[0]->getSDLSurface();
auto palette = fontSfc->format->palette;
memcpy( color.data(), palette->colors, color.size()*sizeof(SDL_Color) );
auto palette = fontSfc->format->palette;
SDL_PixelFormat *pPixelformat = gVideoDriver.getBlitSurface()->format;
if(palette)
{
memcpy( color.data(), palette->colors, color.size()*sizeof(SDL_Color) );
// Change palette colors to the desired one
return SDL_MapRGB(pPixelformat, color[15].r, color[15].g, color[15].b);
}
else
{
return SDL_MapRGB(pPixelformat, 0x0, 0x0, 0x0);
}
}
void GsFont::createTextSurface(GsSurface &sfc,
......
......@@ -263,7 +263,8 @@ std::vector<GsSprite> &GsGraphics::getSpriteVec(const int var)
GsSprite &GsGraphics::getSpecialSpriteRef(const std::string &name)
{ return mSpecialSpriteMap[name]; }
GsFont &GsGraphics::getFont(Uint8 index) { return Font.at(index); }
GsFont &GsGraphics::getFont(Uint8 index)
{ return Font.at(index); }
GsBitmap *GsGraphics::getBitmapFromStr(const std::string &name) const
{
......
......@@ -182,7 +182,14 @@ public:
SDL_FillRect( mpSurface, &mpSurface->clip_rect, SDL_MapRGBA( mpSurface->format, r, g, b, a ) );
}
void fillRGBA(const GsRect<Uint16> &rect, const Uint8 r, const Uint8 g, const Uint8 b, const Uint8 a)
void fillRGBA(const GsColor &color)
{
fillRGBA( color.r, color.g, color.b, color.a );
}
void fillRGBA(const GsRect<Uint16> &rect,
const Uint8 r, const Uint8 g, const Uint8 b, const Uint8 a)
{
fill( rect, mapRGBA(r,g,b,a) );
}
......
......@@ -80,7 +80,7 @@ void GsButton::drawNoStyle(SDL_Rect& lRect)
{
GsWeakSurface blitsfc(gVideoDriver.getBlitSurface());
int lComp;
int lComp = 0xFF;
// Set as default a grey border
Uint32 borderColor = blitsfc.mapRGBA( 0xBB, 0xBB, 0xBB, 0xFF);
......@@ -120,10 +120,6 @@ void GsButton::drawNoStyle(SDL_Rect& lRect)
lComp = 0xFF - (lightRatio*(0xFF-0xDF)/255);
}
}
else
{
lComp = 0xFF;
}
auto lcompf = float(lComp);
......@@ -144,11 +140,13 @@ void GsButton::drawNoStyle(SDL_Rect& lRect)
if(mEnabled) // If the button is enabled use the normal text, otherwise the highlighted color
{
Font.drawFontCentered( blitsfc.getSDLSurface(), mText, lRect.x, lRect.w, lRect.y, lRect.h, false );
Font.drawFontCentered( blitsfc.getSDLSurface(), mText,
lRect.x, lRect.w, lRect.y, lRect.h, false );
}
else
{
Font.drawFontCentered( blitsfc.getSDLSurface(), mText, lRect.x, lRect.w, lRect.y, lRect.h, true );
Font.drawFontCentered( blitsfc.getSDLSurface(), mText,
lRect.x, lRect.w, lRect.y, lRect.h, true );
}
}
......
......@@ -23,7 +23,7 @@ public:
GsButton(const std::string& text,
CEvent *ev = nullptr,
const Style style = Style::UNSET,
const Style style = Style::NONE,
const float red = 0.875f,
const float green = 0.875f,
const float blue = 1.0f);
......
......@@ -20,7 +20,7 @@ public:
CGUIComboSelection( const std::string& text,
const std::list<std::string>& optionsList,
const GsControl::Style style = Style::UNSET);
const GsControl::Style style = Style::NONE);
const std::string& getSelection()
{
......
......@@ -28,7 +28,7 @@ GsControl::GsControl(const Style style) :
}
GsControl::GsControl() :
GsControl(Style::UNSET) {}
GsControl(Style::NONE) {}
void GsControl::processBlendEffects()
......
......@@ -19,7 +19,6 @@ class GsControl
public:
enum Style
{
UNSET,
NONE,
VORTICON,
GALAXY
......@@ -82,7 +81,6 @@ public:
void drawBlinker( const SDL_Rect& lRect );
// The relative rect describes the rect which is normally tied to its parent.
GsRect<float> mRect;
......@@ -105,7 +103,7 @@ protected:
int mLightRatio = 128; // This blends between selected and unselected item.
Style mStyle = Style::UNSET;
Style mStyle = Style::NONE;
/**
* @brief mHoverTriggers This is for touch friendly devices were there is no device
......
......@@ -19,7 +19,8 @@ const unsigned int MAX_ELEMENTS_PER_PAGE = 7;
const unsigned int MAX_STEPS = 20;
CGUIDialog::CGUIDialog(const GsRect<float> &SrGsRect, const FXKind fx) :
CGUIDialog::CGUIDialog(const GsRect<float> &SrGsRect,
const FXKind fx) :
mRect(SrGsRect),
mSelection(0),
mFXSetup(fx),
......@@ -105,7 +106,6 @@ CGUIDialog::addControl( GsControl *newControl )
}
void CGUIDialog::selectPrevItem()
{
if(!mpCurrentCtrl)
......
......@@ -19,7 +19,7 @@ public:
CGUIInputText(const std::string& text,
const int fontID = 0,
const GsControl::Style style = Style::UNSET);
const GsControl::Style style = Style::NONE);
bool sendEvent(const InputCommands command);
......
......@@ -24,7 +24,7 @@ public:
const int value,
const int fontid,
const bool slider,
const Style style = Style::UNSET);
const Style style = Style::NONE);
void increment();
......
......@@ -23,6 +23,7 @@
#include "core/VGamepads/vgamepadsimple.h"
#include "core/mode/CGameMode.h"
#include "core/menu/SettingsMenu.h"
#include "sdl/audio/Audio.h"
#include "fileio/ResourceMgmt.h"
#include "fileio/KeenFiles.h"
......@@ -112,7 +113,7 @@ bool CGameLauncher::setupMenu()
DEPTH_MAX_GAMES,
200, 900);
mpGameSelecList = new CGUITextSelectionList();
mpGameSelectionList = new CGUITextSelectionList();
// Save any custom labels
putLabels();
......@@ -130,7 +131,7 @@ bool CGameLauncher::setupMenu()
unsigned int i=0;
for( ; it != m_Entries.end() ; it++ )
{
mpGameSelecList->addText(it->name);
mpGameSelectionList->addText(it->name);
// And try to add a preview bitmap
std::string fullfilename = "preview.bmp";
......@@ -145,16 +146,30 @@ bool CGameLauncher::setupMenu()
i++;
}
mpGameSelecList->setConfirmButtonEvent(new GMStart());
mpGameSelecList->setBackButtonEvent(new GMQuit());
mpGameSelectionList->setConfirmButtonEvent(new GMStart());
mpGameSelectionList->setBackButtonEvent(new GMQuit());
mLauncherDialog.addControl(new CGUIText("Pick a Game"),
GsRect<float>(0.0f, 0.01f, 1.0f, 0.05f));
mLauncherDialog.addControl(new CGUIText("Pick a Game"), GsRect<float>(0.0f, 0.01f, 1.0f, 0.05f));
mLauncherDialog.addControl(new GsButton( "x", new GMQuit(),
GsControl::Style::UNSET,
GsControl::Style::NONE,
1.0f,
0.75f,
0.75f ), GsRect<float>(0.0f, 0.0f, 0.069f, 0.069f) );
mLauncherDialog.addControl(mpGameSelecList, GsRect<float>(0.01f, 0.07f, 0.49f, 0.79f));
0.75f ),
GsRect<float>(0.0f, 0.0f, 0.069f, 0.069f) );
mLauncherDialog.addControl(new GsButton( "|", new OpenSettingsMenuEvent(),
GsControl::Style::NONE,
0.75f,
1.0f,
1.0f ),
GsRect<float>(0.93f, 0.0f, 0.069f, 0.069f) );
mLauncherDialog.addControl(mpGameSelectionList,
GsRect<float>(0.01f, 0.07f, 0.49f, 0.79f));
#ifdef DOWNLOADER
verifyGameStore();
......@@ -166,7 +181,7 @@ bool CGameLauncher::setupMenu()
(
new GsButton( "Start >",
new GMStart(),
GsControl::UNSET,
GsControl::NONE,
0.675f, 1.0f, 0.675f),
GsRect<float>(0.60f, 0.865f, 0.25f, 0.07f)
)
......@@ -214,7 +229,7 @@ bool CGameLauncher::setupMenu()
}
// Set the first game selected and highlight the start button
mpGameSelecList->setSelection(0);
mpGameSelectionList->setSelection(0);
mLauncherDialog.setSelection(3);
......@@ -572,7 +587,7 @@ void CGameLauncher::pumpEvent(const CEvent *evPtr)
if( dynamic_cast<const GMStart*>(evPtr) )
{
setChosenGame(mpGameSelecList->getSelection());
setChosenGame(mpGameSelectionList->getSelection());
if(m_chosenGame >= 0)
{
......@@ -608,6 +623,12 @@ void CGameLauncher::pumpEvent(const CEvent *evPtr)
mpDloadCancel->enable(false);
mpDloadProgressCtrl->setBad(true);
}
else if( dynamic_cast<const OpenSettingsMenuEvent*>(evPtr) )
{
gEventManager.add( new OpenMenuEvent(
new SettingsMenu(GsControl::Style::NONE) ) );
}
// Check Scroll events happening on this Launcher
......@@ -662,9 +683,9 @@ void CGameLauncher::ponderGameSelDialog(const float deltaT)
}
// Check if the selection changed. Update the right data panel
if(mSelection != mpGameSelecList->getSelection())
if(mSelection != mpGameSelectionList->getSelection())
{
mSelection = mpGameSelecList->getSelection();
mSelection = mpGameSelectionList->getSelection();
auto &entry = m_Entries[mSelection];
const std::string nameText = "Episode " + itoa(entry.episode);
mpEpisodeText->setText(nameText);
......@@ -768,6 +789,11 @@ void CGameLauncher::ponder(const float deltaT)
return;
}
if(gMenuController.active())
{
return;
}
#ifdef DOWNLOADER
if(mpGameStoreDialog)
{
......@@ -790,7 +816,7 @@ void CGameLauncher::ponder(const float deltaT)
// Button should disabled unless a game was selected
if(mpStartButton)
{
if(mpGameSelecList->getSelection() >= 0)
if(mpGameSelectionList->getSelection() >= 0)
{
mpStartButton->enable(true);
}
......
......@@ -12,6 +12,8 @@
#include <base/GsVirtualinput.h>
#include <base/utils/ThreadPool.h>
#include <engine/core/menu/SettingsMenu.h>
#include <widgets/GsDialog.h>
#include <widgets/GsText.h>
#include <widgets/GsButton.h>
......@@ -167,7 +169,7 @@ private:
CGUITextSelectionList *mpGSSelList;
CGUITextSelectionList *mpGameSelecList;
CGUITextSelectionList *mpGameSelectionList;
CGUITextSelectionList *mpPatchSelList;
CGUITextSelectionList *mpDosExecSelList;
......
......@@ -199,41 +199,40 @@ void VirtualKeenControl::mouseState(const Vector2D<float> &Pos, const bool down)
SDL_Event ev;
ev.type = (down ? SDL_KEYDOWN : SDL_KEYUP);
/// Dpad presses
if(Pos.x >= 0.0f && Pos.x < dpadSize)
if( !mDPad.invisible &&
mDPad.isInside(Pos.x, Pos.y) )
{
if(!mDPad.invisible)
// Y-Direction
// Up presses
if(Pos.y<yTop+dpadSizePiece)
{
// Y-Direction
// Up presses
if(Pos.y<yTop+dpadSizePiece)
{
ev.key.keysym.sym = SDLK_UP;
SDL_PushEvent(&ev);
}
// Down presses
else if(Pos.y>=yBottom-dpadSizePiece)
{
ev.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&ev);
}
ev.key.keysym.sym = SDLK_UP;
SDL_PushEvent(&ev);
}
// Down presses
else if(Pos.y>=yBottom-dpadSizePiece)
{
ev.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&ev);
}
// X-Direction
// Left presses
if(Pos.x<dpadSizePiece)
{
ev.key.keysym.sym = SDLK_LEFT;
SDL_PushEvent(&ev);
}
// Right presses
else if(Pos.x>=dpadSize-dpadSizePiece)
{
ev.key.keysym.sym = SDLK_RIGHT;
SDL_PushEvent(&ev);
}
// X-Direction
// Left presses
if(Pos.x<dpadSizePiece)
{
ev.key.keysym.sym = SDLK_LEFT;
SDL_PushEvent(&ev);
}
// Right presses
else if(Pos.x>=dpadSize-dpadSizePiece)
{
ev.key.keysym.sym = SDLK_RIGHT;
SDL_PushEvent(&ev);
}
}
else
/// Dpad presses
if(Pos.x > dpadSize)
{
/// Then, if any other button was pressed...
const float buttonSize = 0.1f;
......
......@@ -19,7 +19,7 @@ void GameMenu::createGalaxyBackground()
// Besides the Background Bitmap we need to draw two lines
SDL_Rect scoreRect;
scoreRect.w = 15*gameRes.w/32;
scoreRect.w = (15*gameRes.w)/32;
scoreRect.h = gameRes.h/200;
scoreRect.x = gameRes.w/4;
scoreRect.y = 55;
......@@ -60,6 +60,26 @@ void GameMenu::initVorticonBackground()
mpMenuDialog->drawBorderRect(backSfc, sdlRect);
}
void GameMenu::initBackgroundNoStyle()
{
GsRect<float> rect = mpMenuDialog->getRect();
const SDL_Rect sdlRect = gVideoDriver.toBlitRect(rect);
mBackground.create(0, sdlRect.w, sdlRect.h, RES_BPP, 0, 0, 0, 0);
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(0);
GsColor backColor(0xFF, 0xFF, 0xFF);
GsColor borderColor(0x7F, 0x7F, 0x7F);
mBackground.fillRGBA(backColor);
mBackground.fillRGBA(GsRect<Uint16>(0, 0, sdlRect.w, 1), borderColor);
mBackground.fillRGBA(GsRect<Uint16>(0, 0, 1, sdlRect.h), borderColor);
mBackground.fillRGBA(GsRect<Uint16>(0, sdlRect.h-1, sdlRect.w, 1 ), borderColor);
mBackground.fillRGBA(GsRect<Uint16>(sdlRect.w-1, 0, 1, sdlRect.h), borderColor);
}
// Processes the stuff that the menus have in common
void
GameMenu::ponder(const float deltaT)
......@@ -93,6 +113,13 @@ void GameMenu::render()
mBackground.blitTo(blit, sdlRect);
}
else
{
GsRect<float> rect = mpMenuDialog->getRect();
const SDL_Rect sdlRect = gVideoDriver.toBlitRect(rect);
mBackground.blitTo(blit, sdlRect);
}
}
......
......@@ -37,7 +37,22 @@ public:
mpReturnButton = new GsButton( "x",
new CloseMenuEvent(),
GsControl::Style::UNSET);
GsControl::Style::NONE);
mpMenuDialog->addControl( mpReturnButton,
GsRect<float>(-0.05f, -0.05f,
0.08f/localRect.w,
0.08f/localRect.h) );
}
else
{
GsRect<float> localRect(0.15f, 0.282f, 0.70f, 0.5f);
mpMenuDialog->setRect(localRect);
mpReturnButton = new GsButton( "x",
new CloseMenuEvent(),
GsControl::Style::NONE);
mpMenuDialog->addControl( mpReturnButton,
GsRect<float>(-0.05f, -0.05f,
......@@ -56,7 +71,10 @@ public:
{
initVorticonBackground();
}
else
{
initBackgroundNoStyle();
}
}
......@@ -64,6 +82,8 @@ public:
void initVorticonBackground();
void initBackgroundNoStyle();
// Processes the stuff that the menus have in common
virtual void ponder(const float deltaT) override;
......
......@@ -69,7 +69,6 @@ GameMenu( GsRect<float>(0.25f, 0.24f, 0.5f, 0.40f),
new OpenMenuEvent( new CheatsMenu(style) ),
style ) );
setMenuLabel("CONFIGMENULABEL");
}
......@@ -16,4 +16,7 @@ public:
};
struct OpenSettingsMenuEvent : public CEvent {};
#endif /* GALAXY_SETTINGSMENU_H_INCLUDED */
......@@ -10,12 +10,18 @@ GameButton::GameButton(const std::string& text,
const Style style) :
GsButton(text, ev, style)
{
mFontID = 1;
if(mStyle == Style::GALAXY)
if(mStyle == Style::NONE)
{
mFontID = 0;
}
else if(mStyle == Style::GALAXY)
{
setText(text);
}
else
{
mFontID = 1;
}
}
......@@ -66,4 +72,8 @@ void GameButton::processRender(const GsRect<float> &RectDispCoordFloat)
{
drawVorticonStyle(lRect);
}
else
{
drawNoStyle(lRect);
}
}
......@@ -27,6 +27,10 @@ CGUINumberControl(text, startValue, endValue,
{
setupButtonSurface();
}
else
{
mFontID = 0;
}
}
......@@ -116,5 +120,9 @@ void NumberControl::processRender(const GsRect<float> &RectDispCoordFloat)
drawTwirl(lRect);
}
else
{
drawNoStyle(lRect);
}
}
......@@ -45,6 +45,40 @@ void Switch::drawVorticonStyle(SDL_Rect& lRect)
drawTwirl(lRect);
}
void Switch::drawNoStyle(SDL_Rect& lRect)
{
if(!mEnabled)
{
return;
}
ComboSelection::drawNoStyle(lRect);
/*
SDL_Surface *blitsfc = gVideoDriver.getBlitSurface();
// Now lets draw the text of the list control
GsFont &Font = gGraphics.getFont(0);
Font.drawFont( blitsfc, mText, lRect.x+24, lRect.y, false );
Font.drawFont( blitsfc, ":", lRect.x+24+mText.size()*8, lRect.y, false );
std::string text;
if( (*mOLCurrent) == "off" )
{
text = "\24\25\26\27";
}
else
{
text = "\34\35\36\37";
}
Font.drawFont( blitsfc, text,
lRect.x+24+(mText.size()+2)*8,
lRect.y, false );*/
}
void Switch::processRender(const GsRect<float> &RectDispCoordFloat)
{
......@@ -59,5 +93,12 @@ void Switch::processRender(const GsRect<float> &RectDispCoordFloat)
displayRect.transform(RectDispCoordFloat);
SDL_Rect lRect = displayRect.SDLRect();
drawVorticonStyle(lRect);
}
}
else
{
GsRect<float> displayRect = mRect;
displayRect.transform(RectDispCoordFloat);
SDL_Rect lRect = displayRect.SDLRect();
drawNoStyle(lRect);
}
}
......@@ -22,6 +22,8 @@ public:
*/
void drawVorticonStyle(SDL_Rect& lRect);
void drawNoStyle(SDL_Rect& lRect);
void processRender(const GsRect<float> &RectDispCoordFloat);
};
......
......@@ -110,8 +110,6 @@ void CGameLauncher::ponderDownloadDialog()
mFinishedDownload = true;
}
// TODO: The files are downloaded into a "Downloads" folder. Secondly they need to be extracted, if the directory does not exist yet.
// When everything is done, The launcher should be restarted, for searching new games.
if( mFinishedDownload &&
......@@ -191,7 +189,7 @@ void CGameLauncher::setupDownloadDialog()
mpDloadCancel = std::dynamic_pointer_cast<GsButton>(
mpGameStoreDialog->addControl( new GsButton( "Cancel", new CancelDownloadEvent(),
GsControl::Style::UNSET,
GsControl::Style::NONE,
1.0f, 0.675f, 0.675f) ,
GsRect<float>(0.375f, 0.865f, 0.25f, 0.07f) ) );
......
......@@ -3,14 +3,20 @@
#include <graphics/GsGraphics.h>
#include <base/video/CVideoDriver.h>
namespace galaxy
{
ComboSelection::ComboSelection( const std::string& text,
const std::list<std::string>& optionsList ) :
CGUIComboSelection(text, optionsList)
ComboSelection::ComboSelection(const std::string& text,
const std::list<std::string>& optionsList,
const Style &style) :
CGUIComboSelection(text, optionsList, style)
{
mFontID = 1;
if(mStyle == Style::NONE)
{
mFontID = 0;
}
else
{
mFontID = 1;
}
setupButtonSurface(mText);
}
......@@ -55,19 +61,41 @@ void ComboSelection::processRender(const GsRect<float> &RectDispCoordFloat)
GsRect<float> displayRect = mRect;
displayRect.transform(RectDispCoordFloat);
SDL_Rect lRect = displayRect.SDLRect();
GsWeakSurface blitsfc( gVideoDriver.getBlitSurface() );
if(!mEnabled)
GsWeakSurface blitsfc( gVideoDriver.getBlitSurface() );
if(mStyle