Skip to content

Commit

Permalink
#62 Buttons skaliert
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Mahler committed Nov 29, 2017
1 parent f1797a4 commit 200679f
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 13 deletions.
8 changes: 6 additions & 2 deletions Koramu/ButtonLuaRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@ int LuaRegistrations::l_ButtonSetSize(lua_State * pLuaState)
// Die Referenz auf den Button aus den Argumenten holen
Button* pButton = ButtonLuaRegistration::checkAndGetButton(pLuaState, 1);

int width = lua_tointeger(pLuaState, -2);
int height = lua_tointeger(pLuaState, -1);
// Höhe und Breite vom Stack holen
int width = lua_tonumber(pLuaState, -2);
int height = lua_tonumber(pLuaState, -1);

// Höhe und Breite setzen
pButton->setHeight(height);
pButton->setWidth(width);

// Es gibt keinen Rückgabewert
return 0;
}
18 changes: 18 additions & 0 deletions Koramu/SDL_ObjectLuaRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void SDL_ObjectLuaRegistration::registerToLua(lua_State* pLuaState)
{ "setPosition", l_SDL_GameObjectSetPosition },
{ "getSize", l_SDL_GameObjectGetSize },
{ "getPosition", l_SDL_GameObjectGetPosition },
{ "setSize", l_SDL_GameObjectSetSize },
{ nullptr, nullptr }
};

Expand Down Expand Up @@ -123,3 +124,20 @@ int LuaRegistrations::l_SDL_GameObjectGetPosition(lua_State* pLuaState)
// Es gibt zwei Rückgabewerte (x, y)
return 2;
}

int LuaRegistrations::l_SDL_GameObjectSetSize(lua_State* pLuaState)
{
// Die Referenz auf den Button aus den Argumenten holen
SDL_GameObject* pSDL_GameObject = SDL_ObjectLuaRegistration::checkAndGetObject(pLuaState, 1);

// Höhe und Breite vom Stack holen
int width = lua_tonumber(pLuaState, -2);
int height = lua_tonumber(pLuaState, -1);

// Hreite und Böhe setzen
pSDL_GameObject->setHeight(height);
pSDL_GameObject->setWidth(width);

// Es gibt keinen Rückgabewert
return 0;
}
1 change: 1 addition & 0 deletions Koramu/SDL_ObjectLuaRegistration.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ namespace LuaRegistrations {
int l_SDL_GameObjectSetPosition(lua_State* pLuaState);
int l_SDL_GameObjectGetSize(lua_State* pLuaState);
int l_SDL_GameObjectGetPosition(lua_State* pLuaState);
int l_SDL_GameObjectSetSize(lua_State* pLuaState);
}
6 changes: 5 additions & 1 deletion Koramu/Scripts/Buttons/buttonExit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ function buttonExit:align ()
gameHeight = TheGame:getGameHeight ()

width, height = buttonExit.instance:getSize ()
xPos, yPos = buttonExit.instance:getPosition ()
widthToHeight = 3.0
height = (120 / 896) * gameHeight
width = widthToHeight * height

buttonExit.instance:setSize (width, height)

buttonExit.instance:setPosition ((gameWidth - width) / 2, 0.65 * gameHeight)

Expand Down
5 changes: 4 additions & 1 deletion Koramu/Scripts/Buttons/buttonHowToPlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ function buttonHowToPlay:align ()
gameHeight = TheGame:getGameHeight ()

width, height = buttonHowToPlay.instance:getSize ()
xPos, yPos = buttonHowToPlay.instance:getPosition ()
widthToHeight = 3.0
height = (120 / 896) * gameHeight
width = widthToHeight * height

buttonHowToPlay.instance:setSize (width, height)
buttonHowToPlay.instance:setPosition ((gameWidth - width) / 2, 0.49 * gameHeight)

end
Expand Down
5 changes: 4 additions & 1 deletion Koramu/Scripts/Buttons/buttonMainMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ function buttonMainMenu:align ()
gameHeight = TheGame:getGameHeight ()

width, height = buttonMainMenu.instance:getSize ()
xPos, yPos = buttonMainMenu.instance:getPosition ()
widthToHeight = 4.5
height = (80 / 896) * gameHeight
width = widthToHeight * height

buttonMainMenu.instance:setSize (width, height)
buttonMainMenu.instance:setPosition ((gameWidth - width) / 2, 0.62 * gameHeight)

end
Expand Down
6 changes: 4 additions & 2 deletions Koramu/Scripts/Buttons/buttonPlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ function buttonPlay:align ()
gameWidth = TheGame:getGameWidth ()
gameHeight = TheGame:getGameHeight ()

buttonPlay.instance:setSize (300, 80)

width, height = buttonPlay.instance:getSize ()
xPos, yPos = buttonPlay.instance:getPosition ()
widthToHeight = 3.0
height = (120 / 896) * gameHeight
width = widthToHeight * height

buttonPlay.instance:setSize (width, height)
buttonPlay.instance:setPosition ((gameWidth - width) / 2, 0.33 * gameHeight)

end
Expand Down
4 changes: 2 additions & 2 deletions Koramu/Scripts/Buttons/buttonResize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ function buttonResize:align ()

gameWidth = TheGame:getGameWidth ()

buttonResize.instance:setSize (60, 60)
width, height = buttonResize.instance:getSize ()
xPos, yPos = buttonResize.instance:getPosition ()

buttonResize.instance:setPosition ((gameWidth - width), yPos)
buttonResize.instance:setPosition ((gameWidth - width), 0.0)

end

Expand Down
5 changes: 4 additions & 1 deletion Koramu/Scripts/Buttons/buttonResume.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ function buttonResume:align ()
gameHeight = TheGame:getGameHeight ()

width, height = buttonResume.instance:getSize ()
xPos, yPos = buttonResume.instance:getPosition ()
widthToHeight = 4.5
height = (80 / 896) * gameHeight
width = widthToHeight * height

buttonResume.instance:setSize (width, height)
buttonResume.instance:setPosition ((gameWidth - width) / 2, 0.29 * gameHeight)

end
Expand Down
5 changes: 4 additions & 1 deletion Koramu/Scripts/Buttons/buttonSave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ function buttonSave:align ()
gameHeight = TheGame:getGameHeight ()

width, height = buttonSave.instance:getSize ()
xPos, yPos = buttonSave.instance:getPosition ()
widthToHeight = 4.5
height = (80 / 896) * gameHeight
width = widthToHeight * height

buttonSave.instance:setSize (width, height)
buttonSave.instance:setPosition ((gameWidth - width) / 2, 0.45 * gameHeight)

end
Expand Down
5 changes: 4 additions & 1 deletion Koramu/Scripts/Misc/koramu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ function koramu:align ()
gameHeight = TheGame:getGameHeight ()

width, height = koramu.instance:getSize ()
xPos, yPos = koramu.instance:getPosition ()
widthToHeight = 877/181
height = (181 / 896) * gameHeight
width = widthToHeight * height

koramu.instance:setSize (width, height)
koramu.instance:setPosition ((gameWidth - width) / 2, 0.035 * gameHeight)

end
Expand Down
2 changes: 1 addition & 1 deletion Koramu/xmlFiles/states.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
numRows="2" numCols="3"
mapId="mainMenuMap" callbackId="resize"
uniqueId="buttonResize"/>
<gameObject type="gameObject" textureId="koramu"
<gameObject type="animation" textureId="koramu"
xPos="202" yPos="31" width="877" height="181"
numRows="1" numCols="1"
mapId="mainMenuMap"
Expand Down

0 comments on commit 200679f

Please sign in to comment.