Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CSM] Add function to set minimap shape (#5569)
* [CSM] Add function to set minimap shape

Also deprecates `toggle_shape`.

* Oh fish, I messed that one up!

* Fix Style

* Sorry, I missed something

I still had the `luamethod` call in there!

* Add getters

* Remove extra line

* Remove useless variable

Please review again @nerzhul . Thanks!

* Satisfy nerzhul
  • Loading branch information
bigfoot547 authored and nerzhul committed Apr 14, 2017
1 parent 6f641df commit e80a83d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion clientmods/preview/init.lua
Expand Up @@ -62,7 +62,7 @@ local function preview_minimap()
minimap:set_mode(4)
minimap:show()
minimap:set_pos({x=5, y=50, z=5})
minimap:toggle_shape()
minimap:set_shape(math.random(0, 1))

print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
" position => " .. dump(minimap:get_pos()) ..
Expand Down
3 changes: 2 additions & 1 deletion doc/client_lua_api.md
Expand Up @@ -779,7 +779,8 @@ An interface to manipulate minimap on client UI
* `get_angle()`: returns the current minimap angle in degrees
* `set_mode(mode)`: sets the minimap mode (0 to 6)
* `get_mode()`: returns the current minimap mode
* `toggle_shape()`: toggles minimap shape to round or square.
* `set_shape(shape)`: Sets the minimap shape. (0 = square, 1 = round)
* `get_shape()`: Gets the minimap shape. (0 = square, 1 = round)

### LocalPlayer
An interface to retrieve information about the player. The player is
Expand Down
22 changes: 22 additions & 0 deletions src/minimap.cpp
Expand Up @@ -272,6 +272,28 @@ void Minimap::toggleMinimapShape()
m_minimap_update_thread->deferUpdate();
}

void Minimap::setMinimapShape(MinimapShape shape)
{
MutexAutoLock lock(m_mutex);

if (shape == MINIMAP_SHAPE_SQUARE)
data->minimap_shape_round = false;
else if (shape == MINIMAP_SHAPE_ROUND)
data->minimap_shape_round = true;

g_settings->setBool("minimap_shape_round", data->minimap_shape_round);
m_minimap_update_thread->deferUpdate();
}

MinimapShape Minimap::getMinimapShape()
{
if (data->minimap_shape_round) {
return MINIMAP_SHAPE_ROUND;
} else {
return MINIMAP_SHAPE_SQUARE;
}
}

void Minimap::setMinimapMode(MinimapMode mode)
{
static const MinimapModeDef modedefs[MINIMAP_MODE_COUNT] = {
Expand Down
7 changes: 7 additions & 0 deletions src/minimap.h
Expand Up @@ -45,6 +45,11 @@ enum MinimapMode {
MINIMAP_MODE_COUNT,
};

enum MinimapShape {
MINIMAP_SHAPE_SQUARE,
MINIMAP_SHAPE_ROUND,
};

struct MinimapModeDef {
bool is_radar;
u16 scan_height;
Expand Down Expand Up @@ -128,6 +133,8 @@ class Minimap {
void setMinimapMode(MinimapMode mode);
MinimapMode getMinimapMode() const { return data->mode; }
void toggleMinimapShape();
void setMinimapShape(MinimapShape shape);
MinimapShape getMinimapShape();


video::ITexture *getMinimapTexture();
Expand Down
18 changes: 15 additions & 3 deletions src/script/lua_api/l_minimap.cpp
Expand Up @@ -108,12 +108,23 @@ int LuaMinimap::l_set_mode(lua_State *L)
return 1;
}

int LuaMinimap::l_toggle_shape(lua_State *L)
int LuaMinimap::l_set_shape(lua_State *L)
{
LuaMinimap *ref = checkobject(L, 1);
Minimap *m = getobject(ref);
if (!lua_isnumber(L, 2))
return 0;

m->setMinimapShape((MinimapShape)lua_tonumber(L, 2));

This comment has been minimized.

Copy link
@SmallJoker

SmallJoker Apr 15, 2017

Member

MSVC going its own way again. Apparently it requires to double-typecast: (MinimapShape)((int)lua_tonumber(L, 2))
Will create a patch for this.

This comment has been minimized.

Copy link
@bigfoot547

bigfoot547 Apr 15, 2017

Author Contributor
return 0;
}

int LuaMinimap::l_get_shape(lua_State *L)
{
LuaMinimap *ref = checkobject(L, 1);
Minimap *m = getobject(ref);

m->toggleMinimapShape();
lua_pushnumber(L, (int)m->getMinimapShape());
return 1;
}

Expand Down Expand Up @@ -210,6 +221,7 @@ const luaL_Reg LuaMinimap::methods[] = {
luamethod(LuaMinimap, set_angle),
luamethod(LuaMinimap, get_mode),
luamethod(LuaMinimap, set_mode),
luamethod(LuaMinimap, toggle_shape),
luamethod(LuaMinimap, set_shape),
luamethod(LuaMinimap, get_shape),
{0,0}
};
3 changes: 2 additions & 1 deletion src/script/lua_api/l_minimap.h
Expand Up @@ -45,7 +45,8 @@ class LuaMinimap : public ModApiBase
static int l_show(lua_State *L);
static int l_hide(lua_State *L);

static int l_toggle_shape(lua_State *L);
static int l_set_shape(lua_State *L);
static int l_get_shape(lua_State *L);

Minimap *m_minimap;

Expand Down

0 comments on commit e80a83d

Please sign in to comment.