Skip to content

Commit

Permalink
Some refactoring in the UI map field
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Dec 2, 2023
1 parent 8b105b6 commit 492d172
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
15 changes: 4 additions & 11 deletions src/common/ui/MI_MapField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ extern CObjectContainer objectcontainer[3];
* MI_MapField Class
**************************************/

MI_MapField::MI_MapField(gfxSprite * nspr, short x, short y, const char * name, short width, short indent, bool showtags)
MI_MapField::MI_MapField(gfxSprite* nspr, short x, short y, std::string name, short width, short indent, bool showtags)
: MI_MapPreview(nspr, x, y, width, indent)
, szName(std::move(name))
, sSearchString("")
, iSearchStringTimer(0)
, fShowtags(showtags)
{
szName = name;

miModifyImageLeft = new MI_Image(nspr, ix + indent - 26, iy + 4, 32, 64, 26, 24, 4, 1, 8);
miModifyImageLeft = std::make_unique<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 = std::make_unique<MI_Image>(nspr, ix + iWidth - 16, iy + 4, 32, 88, 26, 24, 4, 1, 8);
miModifyImageRight->Show(false);

if (fShowtags) {
Expand All @@ -39,12 +38,6 @@ MI_MapField::MI_MapField(gfxSprite * nspr, short x, short y, const char * name,
}
}

MI_MapField::~MI_MapField()
{
delete miModifyImageLeft;
delete miModifyImageRight;
}

MenuCodeEnum MI_MapField::Modify(bool modify)
{
if (fDisable)
Expand Down
34 changes: 15 additions & 19 deletions src/common/ui/MI_MapField.h
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
#ifndef UI_MAP_FIELD
#define UI_MAP_FIELD
#pragma once

#include "MI_MapPreview.h"

#include <memory>
#include <string>

class MI_Image;

class MI_MapField: public MI_MapPreview
{
public:

MI_MapField(gfxSprite * nspr, short x, short y, const char * name, short width, short indent, bool showtags);
virtual ~MI_MapField();
class MI_MapField: public MI_MapPreview {
public:
MI_MapField(gfxSprite* nspr, short x, short y, std::string name, short width, short indent, bool showtags);
virtual ~MI_MapField() = default;

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

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

//Draws every frame
void Draw();
void Draw() override;

//Sends player input to control on every frame
MenuCodeEnum SendInput(CPlayerInput * playerInput);
MenuCodeEnum SendInput(CPlayerInput * playerInput) override;
MenuCodeEnum MouseClick(short iMouseX, short iMouseY) override;

MenuCodeEnum ChooseRandomMap();

MenuCodeEnum MouseClick(short iMouseX, short iMouseY);

bool MovePrev(bool fScrollFast);
bool MoveNext(bool fScrollFast);

void SetDimensions(short iWidth, short iIndent);
void SetDimensions(short iWidth, short iIndent) override;

protected:

bool Move(bool fNext, bool fScrollFast);

std::string szName;

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

short iSlideListOutGoal;

Expand All @@ -50,5 +48,3 @@ class MI_MapField: public MI_MapPreview

bool fShowtags;
};

#endif // UI_MAP_FIELD

0 comments on commit 492d172

Please sign in to comment.