Skip to content

Commit e80a83d

Browse files
bigfoot547nerzhul
authored andcommitted
[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
1 parent 6f641df commit e80a83d

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

clientmods/preview/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ local function preview_minimap()
6262
minimap:set_mode(4)
6363
minimap:show()
6464
minimap:set_pos({x=5, y=50, z=5})
65-
minimap:toggle_shape()
65+
minimap:set_shape(math.random(0, 1))
6666

6767
print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
6868
" position => " .. dump(minimap:get_pos()) ..

doc/client_lua_api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,8 @@ An interface to manipulate minimap on client UI
779779
* `get_angle()`: returns the current minimap angle in degrees
780780
* `set_mode(mode)`: sets the minimap mode (0 to 6)
781781
* `get_mode()`: returns the current minimap mode
782-
* `toggle_shape()`: toggles minimap shape to round or square.
782+
* `set_shape(shape)`: Sets the minimap shape. (0 = square, 1 = round)
783+
* `get_shape()`: Gets the minimap shape. (0 = square, 1 = round)
783784

784785
### LocalPlayer
785786
An interface to retrieve information about the player. The player is

src/minimap.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,28 @@ void Minimap::toggleMinimapShape()
272272
m_minimap_update_thread->deferUpdate();
273273
}
274274

275+
void Minimap::setMinimapShape(MinimapShape shape)
276+
{
277+
MutexAutoLock lock(m_mutex);
278+
279+
if (shape == MINIMAP_SHAPE_SQUARE)
280+
data->minimap_shape_round = false;
281+
else if (shape == MINIMAP_SHAPE_ROUND)
282+
data->minimap_shape_round = true;
283+
284+
g_settings->setBool("minimap_shape_round", data->minimap_shape_round);
285+
m_minimap_update_thread->deferUpdate();
286+
}
287+
288+
MinimapShape Minimap::getMinimapShape()
289+
{
290+
if (data->minimap_shape_round) {
291+
return MINIMAP_SHAPE_ROUND;
292+
} else {
293+
return MINIMAP_SHAPE_SQUARE;
294+
}
295+
}
296+
275297
void Minimap::setMinimapMode(MinimapMode mode)
276298
{
277299
static const MinimapModeDef modedefs[MINIMAP_MODE_COUNT] = {

src/minimap.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ enum MinimapMode {
4545
MINIMAP_MODE_COUNT,
4646
};
4747

48+
enum MinimapShape {
49+
MINIMAP_SHAPE_SQUARE,
50+
MINIMAP_SHAPE_ROUND,
51+
};
52+
4853
struct MinimapModeDef {
4954
bool is_radar;
5055
u16 scan_height;
@@ -128,6 +133,8 @@ class Minimap {
128133
void setMinimapMode(MinimapMode mode);
129134
MinimapMode getMinimapMode() const { return data->mode; }
130135
void toggleMinimapShape();
136+
void setMinimapShape(MinimapShape shape);
137+
MinimapShape getMinimapShape();
131138

132139

133140
video::ITexture *getMinimapTexture();

src/script/lua_api/l_minimap.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,23 @@ int LuaMinimap::l_set_mode(lua_State *L)
108108
return 1;
109109
}
110110

111-
int LuaMinimap::l_toggle_shape(lua_State *L)
111+
int LuaMinimap::l_set_shape(lua_State *L)
112+
{
113+
LuaMinimap *ref = checkobject(L, 1);
114+
Minimap *m = getobject(ref);
115+
if (!lua_isnumber(L, 2))
116+
return 0;
117+
118+
m->setMinimapShape((MinimapShape)lua_tonumber(L, 2));
119+
return 0;
120+
}
121+
122+
int LuaMinimap::l_get_shape(lua_State *L)
112123
{
113124
LuaMinimap *ref = checkobject(L, 1);
114125
Minimap *m = getobject(ref);
115126

116-
m->toggleMinimapShape();
127+
lua_pushnumber(L, (int)m->getMinimapShape());
117128
return 1;
118129
}
119130

@@ -210,6 +221,7 @@ const luaL_Reg LuaMinimap::methods[] = {
210221
luamethod(LuaMinimap, set_angle),
211222
luamethod(LuaMinimap, get_mode),
212223
luamethod(LuaMinimap, set_mode),
213-
luamethod(LuaMinimap, toggle_shape),
224+
luamethod(LuaMinimap, set_shape),
225+
luamethod(LuaMinimap, get_shape),
214226
{0,0}
215227
};

src/script/lua_api/l_minimap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class LuaMinimap : public ModApiBase
4545
static int l_show(lua_State *L);
4646
static int l_hide(lua_State *L);
4747

48-
static int l_toggle_shape(lua_State *L);
48+
static int l_set_shape(lua_State *L);
49+
static int l_get_shape(lua_State *L);
4950

5051
Minimap *m_minimap;
5152

0 commit comments

Comments
 (0)