-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ipochto/highground fixes #581
Changes from all commits
bcc96b0
4892681
fcf60e1
92c6d8c
25ef33a
b60d1d2
27c3f66
1161285
425fa26
1cd638b
e4c0afb
889aa3c
b830561
f6231bf
5baf643
aaf7b0b
473fae6
63dae4e
5601b3f
166fefd
2d5ff4e
5e49b8d
d2d6b13
5ab2804
979a786
b9f41e6
3e08359
c936051
7aa38e1
dc9cc18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1056,6 +1056,71 @@ static int CclGetIsGameHoster(lua_State *l) | |
return 1; | ||
} | ||
|
||
/** | ||
** <b>Description</b> | ||
** | ||
** Set basic map caracteristics. | ||
** | ||
** @param l Lua state. | ||
** | ||
** Example: | ||
** | ||
** <div class="example"><code><strong>PresentMap</strong>("Map description", PlayerCount, Width, Height, uid_number [, "highgrounds-enabled"])</code></div> | ||
*/ | ||
static int CclPresentMap(lua_State *l) | ||
{ | ||
LuaCheckArgs_min(l, 5); | ||
|
||
Map.Info.Description = LuaToString(l, 1); | ||
// Number of players in LuaToNumber(l, 2); // Not used yet. | ||
Map.Info.MapWidth = LuaToNumber(l, 3); | ||
Map.Info.MapHeight = LuaToNumber(l, 4); | ||
Map.Info.MapUID = LuaToNumber(l, 5); | ||
|
||
if(LuaGetArgsNum(l) >= 6) { | ||
const std::string_view value = LuaToString(l, 6); | ||
if (value == "highgrounds-enabled") { | ||
Map.Info.EnableHighgrounds(); | ||
} else { | ||
LuaError(l, "Unknown value %s\n", value.data()); | ||
} | ||
ipochto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return 0; | ||
} | ||
|
||
static int CclMapEnableHighgrounds(lua_State *l) | ||
{ | ||
Map.Info.EnableHighgrounds(LuaGetArgsNum(l) >= 1 ? LuaToBoolean(l, 1) : true); | ||
|
||
return 0; | ||
} | ||
|
||
static int CclIsHighgroundsEnabled(lua_State *l) | ||
{ | ||
lua_pushboolean(l, Map.Info.IsHighgroundsEnabled()); | ||
return 1; | ||
} | ||
Comment on lines
+1092
to
+1103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might probably go in map.pkg (tolua++) instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference in principle? I just did it by analogy, depending on how existing functions with similar functionality were translated into lua. If, for example, what concerns gui was translated through 'tolua++', then almost everything I've encountered concerning engine settings or parameters of the current game was done through To change the method is not a problem. I just want to understand for the future on what principle to choose the translation method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure neither ;-) to_lua has been added after. BTW, the flag seems unused in the Engine :-/ ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It used here: Wargus/wargus#446 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to this flag we choose to load base tileset or run extended tileset generator to make tiles for highgrounds/ramps/cliffs etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently
With Tolua, it would be more consistent:
but it seems that Highgrounds is more related to tileset than map. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is a private member and I don't want to open it in case if we will need to do something else with enabling it in the future. At least the network synchronization may be required. I could use Tolua to open There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Don't breed entities. ) The player simply selects the basic tileset as before, and wargus chooses whether to load the extended version or not. Moreover, if wargus "sees" that the map contains highgrounds, it will simply hide the possibility to select (in dropDownList) the base tileset, for which there is no possibility to generate the extended version (I am talking about swamp specifically - there are certain difficulties with generation). For the editor, there is a checkbox to enable highgrounds or not. So the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've posted a visual explanation: https://discord.com/channels/780082494447288340/987001693474541570/1179091461820666008 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the map presentation is loaded before tileset. Tileset loads with game start, but map presentation is uploaded to the stage of choosing the game parameters by the player (in the create a new game menu). |
||
|
||
/** | ||
** <b>Description</b> | ||
** | ||
** Define the lua file that will build the map | ||
** | ||
** @param l Lua state. | ||
** | ||
** Example: | ||
** | ||
** <div class="example"><code>-- Load map setup from file | ||
** <strong>DefineMapSetup</strong>("Setup.sms")</code></div> | ||
*/ | ||
static int CclDefineMapSetup(lua_State *l) | ||
{ | ||
LuaCheckArgs(l, 1); | ||
Map.Info.Filename = LuaToString(l, 1); | ||
|
||
return 0; | ||
} | ||
/** | ||
** Register CCL features for map. | ||
*/ | ||
|
@@ -1114,6 +1179,11 @@ void MapCclRegister() | |
|
||
lua_register(Lua, "GetIsGameHoster", CclGetIsGameHoster); | ||
|
||
lua_register(Lua, "PresentMap", CclPresentMap); | ||
lua_register(Lua, "MapEnableHighgrounds", CclMapEnableHighgrounds); | ||
lua_register(Lua, "IsHighgroundsEnabled", CclIsHighgroundsEnabled); | ||
|
||
lua_register(Lua, "DefineMapSetup", CclDefineMapSetup); | ||
} | ||
|
||
//@} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -43,6 +43,7 @@ | |||||
#include "netconnect.h" | ||||||
#include "editor.h" | ||||||
#include "sound.h" | ||||||
#include "util.h" | ||||||
|
||||||
/*---------------------------------------------------------------------------- | ||||||
-- Variables | ||||||
|
@@ -1718,9 +1719,23 @@ void ImageTextField::drawBorder(gcn::Graphics *graphics) | |||||
} | ||||||
|
||||||
/*---------------------------------------------------------------------------- | ||||||
-- LuaListModel | ||||||
-- StringListModel | ||||||
----------------------------------------------------------------------------*/ | ||||||
|
||||||
int StringListModel::getIdxOfElement(std::string_view element) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
auto result = ranges::find(this->list, element); | ||||||
if (result != this->list.end()) { | ||||||
return result - this->list.begin(); | ||||||
} else { | ||||||
return -1; | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
/*---------------------------------------------------------------------------- | ||||||
-- LuaListModel | ||||||
----------------------------------------------------------------------------*/ | ||||||
|
||||||
/** | ||||||
** Set the list | ||||||
|
@@ -1735,6 +1750,16 @@ void LuaListModel::setList(lua_State *lua, lua_Object *lo) | |||||
} | ||||||
} | ||||||
|
||||||
int LuaListModel::getIdxOfElement(std::string_view element) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
auto result = ranges::find(this->list, element); | ||||||
if (result != this->list.end()) { | ||||||
return result - this->list.begin(); | ||||||
} else { | ||||||
return -1; | ||||||
} | ||||||
} | ||||||
|
||||||
/*---------------------------------------------------------------------------- | ||||||
-- ImageListBox | ||||||
----------------------------------------------------------------------------*/ | ||||||
|
@@ -2610,6 +2635,13 @@ int ImageDropDownWidget::getSelected() | |||||
return mListBox.getSelected(); | ||||||
} | ||||||
|
||||||
std::string ImageDropDownWidget::getSelectedItem() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
Assert(mScrollArea && mScrollArea->getContent() != nullptr); | ||||||
|
||||||
return listmodel.getElementAt(mListBox.getSelected()); | ||||||
} | ||||||
|
||||||
void ImageDropDownWidget::setSelected(int selected) | ||||||
{ | ||||||
Assert(mScrollArea && mScrollArea->getContent() != nullptr); | ||||||
|
@@ -2620,6 +2652,19 @@ void ImageDropDownWidget::setSelected(int selected) | |||||
} | ||||||
} | ||||||
|
||||||
int ImageDropDownWidget::setSelectedItem(lua_State *lua, lua_Object *lo) | ||||||
{ | ||||||
Assert(mScrollArea && mScrollArea->getContent() != nullptr); | ||||||
|
||||||
auto item = LuaToString(lua, *lo); | ||||||
int idx = this->listmodel.getIdxOfElement(item); | ||||||
if (idx >= 0) | ||||||
{ | ||||||
this->setSelected(idx); | ||||||
} | ||||||
return idx; | ||||||
} | ||||||
|
||||||
void ImageDropDownWidget::adjustHeight() | ||||||
{ | ||||||
Assert(mScrollArea && mScrollArea->getContent() != nullptr); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For next times, don't hesitate to split your PR.
That change might be a dedicated PR, is unrelated to HighgroundsEnabled feature.