Skip to content

Commit

Permalink
Moved MI_AnnouncerField to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Dec 3, 2023
1 parent 3f2138f commit 70742cf
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 142 deletions.
2 changes: 2 additions & 0 deletions src/smw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ target_sources(smw PRIVATE
ui/MI_PowerupSelection.h
ui/MI_WorldPreviewDisplay.cpp
ui/MI_WorldPreviewDisplay.h
ui/MI_AnnouncerField.cpp
ui/MI_AnnouncerField.h
)

if(NO_NETWORK)
Expand Down
5 changes: 5 additions & 0 deletions src/smw/menu/options/SoundOptionsMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "ResourceManager.h"
#include "ui/MI_Image.h"
#include "ui/MI_Text.h"
#include "ui/MI_AnnouncerField.h"
#include "ui/MI_Button.h"
#include "ui/MI_SelectField.h"
#include "ui/MI_SliderField.h"
#include "uicustomcontrol.h"

extern CResourceManager* rm;
extern CGameValues game_values;
Expand Down
11 changes: 9 additions & 2 deletions src/smw/menu/options/SoundOptionsMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
#define MENU_SOUNDOPTIONS_H

#include "uimenu.h"
#include "uicontrol.h"
#include "uicustomcontrol.h"

class MI_AnnouncerField;
class MI_Button;
class MI_Image;
class MI_SelectField;
class MI_SliderField;
class MI_PacksField;
class MI_PlaylistField;
class MI_Text;

/*
Description.
Expand Down
98 changes: 98 additions & 0 deletions src/smw/ui/MI_AnnouncerField.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "MI_AnnouncerField.h"

#include "FileList.h"
#include "gfx.h"
#include "input.h"
#include "ResourceManager.h"
#include "ui/MI_Image.h"

extern CResourceManager* rm;


MI_AnnouncerField::MI_AnnouncerField(gfxSprite* nspr, short x, short y, std::string name, short width, short indent, SimpleFileList * pList)
: UI_Control(x, y)
, spr(nspr)
, szName(std::move(name))
, iWidth(width)
, iIndent(indent)
, list(pList)
{
UpdateName();

miModifyImageLeft = std::make_unique<MI_Image>(nspr, ix + indent - 26, iy + 4, 32, 64, 26, 24, 4, 1, 8);
miModifyImageLeft->Show(false);

miModifyImageRight = std::make_unique<MI_Image>(nspr, ix + iWidth - 16, iy + 4, 32, 88, 26, 24, 4, 1, 8);
miModifyImageRight->Show(false);
}

MenuCodeEnum MI_AnnouncerField::Modify(bool modify)
{
miModifyImageLeft->Show(modify);
miModifyImageRight->Show(modify);

fModifying = modify;
return MENU_CODE_MODIFY_ACCEPTED;
}

MenuCodeEnum MI_AnnouncerField::SendInput(CPlayerInput* playerInput)
{
for (int iPlayer = 0; iPlayer < 4; iPlayer++) {
if (playerInput->outputControls[iPlayer].menu_right.fPressed || playerInput->outputControls[iPlayer].menu_down.fPressed) {
list->next();
UpdateName();
return MENU_CODE_NONE;
}

if (playerInput->outputControls[iPlayer].menu_left.fPressed || playerInput->outputControls[iPlayer].menu_up.fPressed) {
list->prev();
UpdateName();
return MENU_CODE_NONE;
}

if (playerInput->outputControls[iPlayer].menu_random.fPressed) {
list->random();
UpdateName();
return MENU_CODE_NONE;
}

if (playerInput->outputControls[iPlayer].menu_select.fPressed || playerInput->outputControls[iPlayer].menu_cancel.fPressed) {
miModifyImageLeft->Show(false);
miModifyImageRight->Show(false);

fModifying = false;

return MENU_CODE_UNSELECT_ITEM;
}
}

return MENU_CODE_NONE;
}

void MI_AnnouncerField::UpdateName()
{
szFieldName = GetNameFromFileName(list->current_name());
}

void MI_AnnouncerField::Update()
{
miModifyImageRight->Update();
miModifyImageLeft->Update();
}

void MI_AnnouncerField::Draw()
{
if (!fShow)
return;

//Draw the select field background
spr->draw(ix, iy, 0, (fSelected ? 32 : 0), iIndent - 16, 32);
spr->draw(ix + iIndent - 16, iy, 0, (fSelected ? 96 : 64), 32, 32);
spr->draw(ix + iIndent + 16, iy, 528 - iWidth + iIndent, (fSelected ? 32 : 0), iWidth - iIndent - 16, 32);

rm->menu_font_large.drawChopRight(ix + 16, iy + 5, iIndent - 8, szName.c_str());
rm->menu_font_large.drawChopRight(ix + iIndent + 8, iy + 5, iWidth - iIndent - 24, szFieldName.c_str());

miModifyImageLeft->Draw();
miModifyImageRight->Draw();
}
44 changes: 44 additions & 0 deletions src/smw/ui/MI_AnnouncerField.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include "uicontrol.h"

#include <memory>
#include <string>

class gfxSprite;
class MI_Image;
class SimpleFileList;


class MI_AnnouncerField : public UI_Control {
public:
MI_AnnouncerField(gfxSprite* nspr, short x, short y, std::string name, short width, short indent, SimpleFileList* pList);

//Called when user selects this control to change it's value
MenuCodeEnum Modify(bool modify) override;

//Updates animations or other events every frame
void Update() override;

//Draws every frame
void Draw() override;

//Sends player input to control on every frame
MenuCodeEnum SendInput(CPlayerInput * playerInput) override;

protected:
void UpdateName();

gfxSprite* spr = nullptr;

std::string szName;
short iWidth = 0;
short iIndent = 0;

std::string szFieldName;

std::unique_ptr<MI_Image> miModifyImageLeft;
std::unique_ptr<MI_Image> miModifyImageRight;

SimpleFileList* list = nullptr;
};
104 changes: 0 additions & 104 deletions src/smw/uicustomcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,110 +54,6 @@ extern CResourceManager* rm;
extern CGame* smw;


/**************************************
* MI_AnnouncerField Class
**************************************/

MI_AnnouncerField::MI_AnnouncerField(gfxSprite * nspr, short x, short y, const char * name, short width, short indent, SimpleFileList * pList) :
UI_Control(x, y)
{
spr = nspr;

szName = new char[strlen(name) + 1];
strcpy(szName, name);

iWidth = width;
iIndent = indent;

list = pList;
UpdateName();

miModifyImageLeft = new MI_Image(nspr, ix + indent - 26, iy + 4, 32, 64, 26, 24, 4, 1, 8);
miModifyImageLeft->Show(false);

miModifyImageRight = new MI_Image(nspr, ix + iWidth - 16, iy + 4, 32, 88, 26, 24, 4, 1, 8);
miModifyImageRight->Show(false);
}

MI_AnnouncerField::~MI_AnnouncerField()
{
delete [] szName;
delete miModifyImageLeft;
delete miModifyImageRight;
}

MenuCodeEnum MI_AnnouncerField::Modify(bool modify)
{
miModifyImageLeft->Show(modify);
miModifyImageRight->Show(modify);

fModifying = modify;
return MENU_CODE_MODIFY_ACCEPTED;
}

MenuCodeEnum MI_AnnouncerField::SendInput(CPlayerInput * playerInput)
{
for (int iPlayer = 0; iPlayer < 4; iPlayer++) {
if (playerInput->outputControls[iPlayer].menu_right.fPressed || playerInput->outputControls[iPlayer].menu_down.fPressed) {
list->next();
UpdateName();
return MENU_CODE_NONE;
}

if (playerInput->outputControls[iPlayer].menu_left.fPressed || playerInput->outputControls[iPlayer].menu_up.fPressed) {
list->prev();
UpdateName();
return MENU_CODE_NONE;
}

if (playerInput->outputControls[iPlayer].menu_random.fPressed) {
list->random();
UpdateName();
return MENU_CODE_NONE;
}

if (playerInput->outputControls[iPlayer].menu_select.fPressed || playerInput->outputControls[iPlayer].menu_cancel.fPressed) {
miModifyImageLeft->Show(false);
miModifyImageRight->Show(false);

fModifying = false;

return MENU_CODE_UNSELECT_ITEM;
}
}

return MENU_CODE_NONE;
}

void MI_AnnouncerField::UpdateName()
{
szFieldName = GetNameFromFileName(list->current_name());
}

void MI_AnnouncerField::Update()
{
miModifyImageRight->Update();
miModifyImageLeft->Update();
}

void MI_AnnouncerField::Draw()
{
if (!fShow)
return;

//Draw the select field background
spr->draw(ix, iy, 0, (fSelected ? 32 : 0), iIndent - 16, 32);
spr->draw(ix + iIndent - 16, iy, 0, (fSelected ? 96 : 64), 32, 32);
spr->draw(ix + iIndent + 16, iy, 528 - iWidth + iIndent, (fSelected ? 32 : 0), iWidth - iIndent - 16, 32);

rm->menu_font_large.drawChopRight(ix + 16, iy + 5, iIndent - 8, szName);
rm->menu_font_large.drawChopRight(ix + iIndent + 8, iy + 5, iWidth - iIndent - 24, szFieldName.c_str());

miModifyImageLeft->Draw();
miModifyImageRight->Draw();
}


/**************************************
* MI_PacksField Class
**************************************/
Expand Down
37 changes: 1 addition & 36 deletions src/smw/uicustomcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "input.h"
#include "uicontrol.h"
#include "ui/MI_AnnouncerField.h"
#include "ui/MI_Button.h"
#include "ui/MI_MapField.h"
#include "ui/MI_PowerupSlider.h"
Expand All @@ -22,42 +23,6 @@ class MI_ScoreText;
class MI_Text;


class MI_AnnouncerField : public UI_Control
{
public:

MI_AnnouncerField(gfxSprite * nspr, short x, short y, const char * name, short width, short indent, SimpleFileList * pList);
virtual ~MI_AnnouncerField();

//Called when user selects this control to change it's value
MenuCodeEnum Modify(bool modify);

//Updates animations or other events every frame
void Update();

//Draws every frame
void Draw();

//Sends player input to control on every frame
virtual MenuCodeEnum SendInput(CPlayerInput * playerInput);

protected:

void UpdateName();

gfxSprite * spr;

char * szName;
short iWidth, iIndent;

std::string szFieldName;

MI_Image * miModifyImageLeft;
MI_Image * miModifyImageRight;

SimpleFileList * list;
};

class MI_PacksField : public MI_AnnouncerField
{
public:
Expand Down

0 comments on commit 70742cf

Please sign in to comment.