Finished hud.md
This commit is contained in:
parent
d8e0380f4d
commit
acf02b57e3
@ -16,16 +16,16 @@ Das HUD akzeptiert keine Benutzereingaben; dafür sollten Sie eine [formspec](fo
|
|||||||
- [Positionierung](#positionierung)
|
- [Positionierung](#positionierung)
|
||||||
- [Position und Versatz](#position-und-versatz)
|
- [Position und Versatz](#position-und-versatz)
|
||||||
- [Ausrichtung](#ausrichtung)
|
- [Ausrichtung](#ausrichtung)
|
||||||
- [Scoreboard](#scoreboard)
|
- [Anzeigetafel](#anzeigetafel)
|
||||||
- [Textelemente](#textelemente)
|
- [Textelemente](#textelemente)
|
||||||
- [Parameters](#parameter)
|
- [Parameter](#parameter)
|
||||||
- [Unser Beispiel](#unser-beispiel)
|
- [Unser Beispiel](#unser-beispiel)
|
||||||
- [Image Elements](#image-elements)
|
- [Bild-Elemente](#bild-Elemente)
|
||||||
- [Parameter](#parameter-1)
|
- [Parameter](#parameter-1)
|
||||||
- [Scale](#scale)
|
- [Scale](#scale)
|
||||||
- [Changing an Element](#changing-an-element)
|
- [Ein Element verändern](#ein-element-verändern)
|
||||||
- [Storing IDs](#storing-ids)
|
- [IDs speichern](#ids-speichern)
|
||||||
- [Other Elements](#other-elements)
|
- [Andere Elemente](#andere-elemente)
|
||||||
|
|
||||||
## Positionierung
|
## Positionierung
|
||||||
|
|
||||||
@ -163,41 +163,41 @@ Daraus ergibt sich das Folgende:
|
|||||||
</figure>
|
</figure>
|
||||||
|
|
||||||
|
|
||||||
## Image Elements
|
## Bild-Elemente
|
||||||
|
|
||||||
Image elements are created in a very similar way to text elements:
|
Bild-Elemente werden auf sehr ähnliche Weise wie Text-Elemente erstellt:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
player:hud_add({
|
player:hud_add({
|
||||||
hud_elem_type = "image",
|
hud_elem_type = "image",
|
||||||
position = {x = 1, y = 0.5},
|
position = {x = 1, y = 0.5},
|
||||||
offset = {x = -220, y = 0},
|
offset = {x = -220, y = 0},
|
||||||
text = "score_background.png",
|
text = "punkte_hintergrund.png",
|
||||||
scale = { x = 1, y = 1},
|
scale = { x = 1, y = 1},
|
||||||
alignment = { x = 1, y = 0 },
|
alignment = { x = 1, y = 0 },
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
You will now have this:
|
Sie werden jetzt dies haben:
|
||||||
|
|
||||||
<figure>
|
<figure>
|
||||||
<img
|
<img
|
||||||
src="{{ page.root }}//static/hud_background_img.png"
|
src="{{ page.root }}//static/hud_background_img.png"
|
||||||
alt="screenshot of the HUD so far">
|
alt="Screenshot des bisherigen HUDs">
|
||||||
</figure>
|
</figure>
|
||||||
|
|
||||||
### Parameters
|
### Parameter
|
||||||
|
|
||||||
The `text` field is used to provide the image name.
|
Das Feld `text` wird für die Angabe des Bildnamens verwendet.
|
||||||
|
|
||||||
If a co-ordinate is positive, then it is a scale factor with 1 being the
|
Wenn eine Koordinate positiv ist, handelt es sich um einen Skalierungsfaktor, wobei 1
|
||||||
original image size, 2 being double the size, and so on.
|
die ursprüngliche Bildgröße, 2 die doppelte Größe usw. sind.
|
||||||
However, if a co-ordinate is negative, it is a percentage of the screen size.
|
Ist eine Koordinate jedoch negativ, handelt es sich um einen Prozentsatz der Bildschirmgröße.
|
||||||
For example, `x=-100` is 100% of the width.
|
Zum Beispiel ist `x=-100` 100% der Breite.
|
||||||
|
|
||||||
### Scale
|
### Scale
|
||||||
|
|
||||||
Let's make the progress bar for our score panel as an example of scale:
|
Lassen Sie uns den Fortschrittsbalken für unser Score-Panel als Beispiel für die Skala erstellen:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local percent = tonumber(meta:get("score:score") or 0.2)
|
local percent = tonumber(meta:get("score:score") or 0.2)
|
||||||
@ -206,7 +206,7 @@ player:hud_add({
|
|||||||
hud_elem_type = "image",
|
hud_elem_type = "image",
|
||||||
position = {x = 1, y = 0.5},
|
position = {x = 1, y = 0.5},
|
||||||
offset = {x = -215, y = 23},
|
offset = {x = -215, y = 23},
|
||||||
text = "score_bar_empty.png",
|
text = "punkte_balken_leer.png",
|
||||||
scale = { x = 1, y = 1},
|
scale = { x = 1, y = 1},
|
||||||
alignment = { x = 1, y = 0 },
|
alignment = { x = 1, y = 0 },
|
||||||
})
|
})
|
||||||
@ -215,80 +215,80 @@ player:hud_add({
|
|||||||
hud_elem_type = "image",
|
hud_elem_type = "image",
|
||||||
position = {x = 1, y = 0.5},
|
position = {x = 1, y = 0.5},
|
||||||
offset = {x = -215, y = 23},
|
offset = {x = -215, y = 23},
|
||||||
text = "score_bar_full.png",
|
text = "punkte_balken_voll.png",
|
||||||
scale = { x = percent, y = 1},
|
scale = { x = percent, y = 1},
|
||||||
alignment = { x = 1, y = 0 },
|
alignment = { x = 1, y = 0 },
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
We now have a HUD that looks like the one in the first post!
|
Wir haben jetzt ein HUD, der wie der im ersten Beitrag aussieht!
|
||||||
There is one problem however, it won't update when the stats change.
|
Es gibt jedoch ein Problem: Es wird nicht aktualisiert, wenn sich die Statistiken ändern.
|
||||||
|
|
||||||
## Changing an Element
|
## Ein Element verändern
|
||||||
|
|
||||||
You can use the ID returned by the `hud_add` method to update it or remove it later.
|
Sie können die von der Methode `hud_add` zurückgegebene ID verwenden, um es später zu aktualisieren oder zu entfernen.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local idx = player:hud_add({
|
local idx = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
text = "Hello world!",
|
text = "Hallo Welt!",
|
||||||
-- parameters removed for brevity
|
-- Parameter der Kürze halber entfernt
|
||||||
})
|
})
|
||||||
|
|
||||||
player:hud_change(idx, "text", "New Text")
|
player:hud_change(idx, "text", "Neuer Text")
|
||||||
player:hud_remove(idx)
|
player:hud_remove(idx)
|
||||||
```
|
```
|
||||||
|
|
||||||
The `hud_change` method takes the element ID, the property to change, and the new
|
Die Methode `hud_change` nimmt die Element-ID, die zu ändernde Eigenschaft und den
|
||||||
value. The above call changes the `text` property from "Hello World" to "New text".
|
neuen Wert. Der obige Aufruf ändert die Eigenschaft `text` von "Hallo Welt!" in "Neuer Text".
|
||||||
|
|
||||||
This means that doing the `hud_change` immediately after the `hud_add` is
|
Das bedeutet, dass die Ausführung von `hud_change` unmittelbar nach `hud_add` funktionell
|
||||||
functionally equivalent to the following, in a rather inefficient way:
|
äquivalent zu folgendem ist, und zwar auf eine ziemlich ineffiziente Weise:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local idx = player:hud_add({
|
local idx = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
text = "New Text",
|
text = "Neuer Text",
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## Storing IDs
|
## IDs speichern
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
score = {}
|
punkte = {}
|
||||||
local saved_huds = {}
|
local gespeicherte_huds = {}
|
||||||
|
|
||||||
function score.update_hud(player)
|
function punkte.update_hud(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
|
|
||||||
-- Get the dig and place count from storage, or default to 0
|
-- Holt die Anzahl der Abbauungen und Orte aus dem Speicher, oder setzt ihn auf standardmäßig 0
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
local digs_text = "Digs: " .. meta:get_int("score:digs")
|
local abbau_text = "Abbauungen: " .. meta:get_int("score:digs")
|
||||||
local places_text = "Places: " .. meta:get_int("score:places")
|
local platier_text = "Platzierungen: " .. meta:get_int("score:places")
|
||||||
local percent = tonumber(meta:get("score:score") or 0.2)
|
local prozent = tonumber(meta:get("score:score") or 0.2)
|
||||||
|
|
||||||
local ids = saved_huds[player_name]
|
local ids = gespeicherte_huds[player_name]
|
||||||
if ids then
|
if ids then
|
||||||
player:hud_change(ids["places"], "text", places_text)
|
player:hud_change(ids["platzierungen"], "text", places_text)
|
||||||
player:hud_change(ids["digs"], "text", digs_text)
|
player:hud_change(ids["abbauungen"], "text", digs_text)
|
||||||
player:hud_change(ids["bar_foreground"],
|
player:hud_change(ids["balken_vordergrund"],
|
||||||
"scale", { x = percent, y = 1 })
|
"scale", { x = prozent, y = 1 })
|
||||||
else
|
else
|
||||||
ids = {}
|
ids = {}
|
||||||
saved_huds[player_name] = ids
|
gespeicherte_huds[player_name] = ids
|
||||||
|
|
||||||
-- create HUD elements and set ids into `ids`
|
-- Erstellt HUD-Elemente und setzt die IDs in `ids`
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(score.update_hud)
|
minetest.register_on_joinplayer(punkte.update_hud)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
saved_huds[player:get_player_name()] = nil
|
gespeicherte_huds[player:get_player_name()] = nil
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Other Elements
|
## Andere Elemente
|
||||||
|
|
||||||
Read [lua_api.txt](https://minetest.gitlab.io/minetest/hud/) for a complete list of HUD elements.
|
Lesen Sie [lua_api.txt 🇬🇧](https://minetest.gitlab.io/minetest/hud/) für eine vollständige Liste der HUD-Elemente.
|
||||||
|
Loading…
Reference in New Issue
Block a user