If the map from $X$ to the maxspec of $\mathcal O(X)$ is a bijection, then $X$ is indeed affine.
Here is an argument:
By assumption $X \to $ maxspec $\mathcal O(X)$ is bijective, thus quasi-finite,
and so by (Grothendieck's form of) Zariski's main theorem, this map factors as an open embedding of $X$ into a variety that is finite over maxspec $\mathcal O(X)$.
Any variety finite over an affine variety is again affine, and hence $X$ is an open subset of an affine variety, i.e. quasi-affine. So we are reduced to considering the case when $X$ is quasi-affine, which is well-known and straightforward.
(I'm not sure that the full strength of ZMT is needed, but it is a natural tool
to exploit to get mileage out of the assumption of a morphism having finite fibres, which is what your bijectivity hypothesis gives.)
In fact, the argument shows something stronger: suppose that we just assume
that the morphism $X \to $ maxspec $\mathcal O(X)$ has finite non-empty fibres,
i.e. is quasi-finite and surjective.
Then the same argument with ZMT shows that $X$ is quasi-affine. But it is standard that the map $X \to $ maxspec $\mathcal O(X)$ is an open immersion when $X$ is quasi-affine,
and since by assumption it is surjecive, it is an isomorphism.
Note that if we omit one of the hypotheses of surjectivity or quasi-finiteness, we can find a non-affine $X$ satisfying the other hypothesis.
E.g. if $X = \mathbb A^2 \setminus \{0\}$ (the basic example of a quasi-affine,
but non-affine, variety), then maxspec $\mathcal O(X) = \mathbb A^2$, and the open immersion $X \to \mathbb A^2$ is evidently not surjective.
E.g. if $X = \mathbb A^2$ blown up at $0$, then maxspec $\mathcal O(X) =
\mathbb A^2$, and $X \to \mathbb A^2$ is surjective, but has an infinite fibre
over $0$.
Caveat/correction: I should add the following caveat, namely that it is not always true, for a variety $X$ over a field $k$, that $\mathcal O(X)$ is finitely generated over $k$, in which case maxspec may not be such a good construction to apply, and the above argument may not go through. So in order to conclude that $X$ is affine, one should first insist that $\mathcal O(X)$ is finitely generated over $k$, and then that futhermore the natural map $X \to $ maxspec $\mathcal O(X)$ is quasi-finite and surjective.
(Of course, one could work more generally with arbitrary schemes and Spec rather than
maxspec, but I haven't thought about this general setting: in particular, ZMT requires some finiteness hypotheses, and I haven't thought about what conditions might guarantee that the map $X \to $ Spec $\mathcal O(X)$ satisfies them.)
Incidentally, for an example of a quasi-projective variety with non-finitely generated ring of regular functions, see this note of Ravi Vakil's
Each one of these definitions is morally just a restricted version of each of the more general definitions. To be precise, there are fully faithful functors from the less general definitions to the more general definitions which in some cases are equivalences of categories. Let's rewrite the definitions here so we have a quick reference. We'll cover the affine case first and then explain how to patch everything together to the global case afterwards.
"Classical" definition (affine case): A $k$-variety is an irreducible Zariski-closed subset of $k^n$ for an algebraically closed field $k$ and some integer $n$.
Milne's definition (affine $k$-variety): An affine $k$-variety is a locally ringed space isomorphic to $(V,\mathcal{O}_V)$ where $V\subset k^n$ is a "classical" $k$-variety and $\mathcal{O}_V$ is the sheaf of regular functions on $V$.
Liu's definition: An affine $k$-variety is the affine scheme $\operatorname{Spec} A$ associated to a finitely generated reduced $k$-algebra $A$.
General definition: An affine $k$-variety is $\operatorname{Spec} A$ for a finitely generated $k$-algebra $A$.
Basically what's going on here is that each of these definitions is slowly, grudgingly accepting greater generality and more extensible structure on the road to the general definition.
Milne's definition adds the structure sheaf, but is not yet all the way to a scheme - it's missing generic points. This in particular shows that generally $(V,\mathcal{O}_V)$ is not the spectrum of a ring. (Milne's definition is set up in such a way that there's only one way to get the structure sheaf, so there's an equivalence of categories between the "classical" category and Milne's category.)
From here, Liu's definition adds the generic points - there is a fully faithful functor between Milne's definition and Liu's definition, which has image exactly the irreducible varieties in Liu's definition.
The road from Liu's definition to the general definition is easy: we stop requiring reducedness, which is a technical advantage for some more advanced properties one may wish to consider later on (eg those involving cohomology).
The proof that there are fully faithful functors between all these definitions can be found (among other places) in Hartshorne II.2.6:
Proposition (Hartshorne II.2.6): Let $k$ be an algebraically closed field. There is a natural fully faithful functor $t:\mathfrak{Var}(k)\to \mathfrak{Sch}(k)$ from the category of varieties over $k$ to schemes over $k$. For any variety $V$, it's topological space is homeomorphic to the closed points of the underlying topological space of $t(V)$, and it's sheaf of regular functions is obtained by restricting the structure sheaf of $t(V)$ via this homeomorphism.
The idea of the proof is that one can add the generic points of each irreducible positive-dimensional closed subset and then construct the structure sheaf on this new space in a canonical way, which produces for you a scheme verifying the properties claimed. (In case you're wondering about Hartshorne's definition, Hartshorne defines his category of varieties as quasiprojective integral varieties, of which the affine varieties of the "classical" and Milne's definitions are full subcategories. This same idea of the proof works in all cases.)
This provides us the answer to the first part of your main question: there are fully faithful functors which lets you consider each category as a part of the next more general category. This means that you can generalize without fear.
Now we can talk about gluing and non-affine varieties. In full generality, just like a manifold is some space locally modeled on $\Bbb R^n$, we should have that varieties are locally modeled on affine varieties (and schemes are locally modeled on affine schemes). This is what Milne's getting at with his definition of a prevariety, and what Liu is getting at with the finite cover condition.
There are some pathologies one may wish to avoid, like the line with two origins, which one can get by gluing to copies of $\Bbb A^1$ along the open sets which are the complements of the origin in each copy. Such varieties are non-separated, and that's what the separated condition in Milne's "algebraic $k$-varieties" excludes.
The most general definition one normally sees of a variety over a field is the following:
Most general definition: A $k$-variety is a scheme of finite type over the field $k$.
This allows non-reduced, non-irreducible, non-separated schemes, but keeps the essential finiteness condition of "finite type", which implies that any $k$-variety has a finite cover by affine open $k$-varieties, which is exactly the finiteness condition that Liu and Milne both require. Be warned that many modern authors of papers will take this general definition plus some adjectives, and are not always clear on which adjectives they take. (If you're writing papers in algebraic geometry, please include a sentence in your conventions section which makes it clear what adjectives you take when you write "variety"!)
In this most general situation, affineness and projectiveness are easy to describe. Each is exactly the condition that our variety admits a closed embedding in to $\Bbb A^n_k$ or $\Bbb P^n_k$, respectively, for some $n$. (To connect this with the affine definition as $\operatorname{Spec} A$ of a finitely-generated $k$-algebra, note that we can choose a surjection $k[x_1,\cdots,x_n]\to A$, which gives us $A\cong k[x_1,\cdots,x_n]/I$ for some ideal $I$, and this exactly shows us that $\operatorname{Spec} A \to \operatorname{Spec} k[x_1,\cdots,x_n]=\Bbb A^n_k$ is a closed immersion.)
Best Answer
If you take the affine variety with its Zariski topology, it is (among other things) a topological space $V$.
Now given a topological space $V$, we can construct a new topological space $X$ whose points are (by definition) the irreducible closed subsets of $V$, and whose open sets are in bijection with the open sets of $V$ by mapping an open set $U$ in the latter to the set of irreducible subsets of $V$ which have non-empty intersection with $U$.
There is a map from $V$ to $X$ which sends a point in $V$ to its closure, and by construction the topology on $V$ is obtained by pull-back from the topology on $X$ (i.e. the open sets in $V$ are precisely the preimages of the open sets in $X$).
So: two points of $V$ map to the same point of $X$ if and only they have the same closure, and hence $V \to X$ is injective iff $V$ is $T_0$ (i.e. two points with the same closure coincide); in this case $V$ is a topological subspace of $X$.
The map $V\to X$ is a homeomorphism if and only if every irreducible subset of $V$ has a unique generic point, i.e. if and only if $V$ is sober.
Affine schemes are sober, so this construction does nothing in the case of an affine scheme.
But affine varieties are not sober (unless they are zero-dimensional), and the construction $V\mapsto X$ in this case gives rise to the corresponding affine scheme. Given $X$, we can recover $V$ as the subset of closed points in $X$.
(If we want to be more sophisticated and think about structure sheaves, we can do that too: the structure sheaf on the scheme $X$ is the pushforward of the structure sheaf on $V$, and the structure sheaf on $V$ is the restriction of the structure sheaf on $X$.)
So there is a completely functorial, purely topological mechanism for moving from the affine variety $V$ to the affine scheme $X$, and back again, and so the two objects carry identical information. But sometimes it is convenient to work explicitly on $X$, so that all the generic points are available; it often simplifies sheaf-theoretic arguments (but any argument using the generic points can be rephrased in a way that works entirely on $V$, via the above discussion). And of course the affine scheme $X$ sits in a wider world of all schemes, not all of which correspond to affine varieties, or to varieties at all, and this is often useful too.